0

我是完整日历的新手,所以我真的不确定在哪里闯入我的问题的代码。

首先,完整日历很棒,哇,节省时间,很棒的工作!其次,我使用的是荷兰人保罗的修改版本:在此处下载:http: //www.paulthedutchman.nl/portfolio/? mi=113

我需要在“周”视图中将多日事件视为那些日子的多个事件,而不是默认事件,其中多日事件跨越设置事件日期的列的高度。

最好这样想。3 天的工作是 3 个具有不同细节的轮班工作。(..但实际上是 Full Calender 的三个事件)

周一:3 之 1 | 周二:3 之 2 | 周三:3 之 3

  • 我不需要 ID 来为事件“片段”保留,它们是真正独立的事件。
  • 我只是想帮助用户在他们创建新事件时设置多个工作班次
  • 为什么?= 用户可能有连续三个工作日..但随后一个班次/团队被移动,这就是为什么默认事件行为(和单独的 ID)是最佳解决方案的原因

我在 addEvent 函数的服务器端代码中想象了一些简单的东西:

  1. 检查开始结束日期,减去差额
  2. php "while" $i <= date diff - 创建单独的事件,只传递名称

    $ck_str= date("d",$frm_submitted['date_start'] );
    $ck_end= date("d",$frm_submitted['date_end'] ); <br/>
    
    if( $ck_str != $ck_end){ // are the day the same? if not do this
    
    $ck_diff = $ck_end - $ck_str; // subtract days  for events needed
     $i = 1;
    while ($i <= $ck_diff) {
    // add event or modify array if already inside the add function
    // customize the name "Day1: Job Name"
    
    }}
    

最终结果,创建同名的多个事件

可以这么简单吗?

这是 Pauls Modified Calendar 中的 addEvent 函数:

function addEvent() {

global $error;

$arr_submit         = array(
    array('cal_id',         'int',          false,  ''),
    array('color',          'varchar',      false,  ''),
    array('date_end',       'int',          false,  ''),
    array('date_start',     'int',          false,  ''),
    array('title',          'varchar',      false,  ''),
    array('location',       'varchar',      false,  ''),
    array('description',    'varchar',      false,  ''),
    array('cal_type',       'varchar',      false,  ''),
    array('interval',       'varchar',      false,  ''),
    array('weekdays',       'varchar',      false,  ''),
    array('monthday',       'varchar',      false,  ''),
);

$frm_submitted      = validate_var($arr_submit);
    $frm_submitted['title'] = stripslashes($frm_submitted['title']);
    $frm_submitted['cal_id'] = 1;  // for this test there is only one calendar

// time offset
$frm_submitted['date_start'] -= TIME_OFFSET;
if(empty($frm_submitted['date_end'])) {
    $frm_submitted['date_end'] = $frm_submitted['date_start'];
} else {
    $frm_submitted['date_end'] -= TIME_OFFSET;
}
if($frm_submitted['title'] == 'undefined') {
    echo json_encode(array('success'=>false));exit;
}

//if(USE_CALENDAR_COLOR_FOR_EVENT) {
if(empty($frm_submitted['color']) || $frm_submitted['color'] == 'undefined') {
    $frm_submitted['color'] = Calendar::getColor($frm_submitted['cal_id']);
}
//}
if(empty($error)) {

    // check if repeating event
    if(isset($frm_submitted['interval']) && ($frm_submitted['interval'] == 'W' ||
                $frm_submitted['interval'] == '2W' ||
                $frm_submitted['interval'] == 'M' ||
                $frm_submitted['interval'] == 'Y')) {
        // weekday

        $arr_days = Utils::getDaysInPattern($frm_submitted);
        $arr_event = Events::insertRepeatingEvent($arr_days, $frm_submitted);

        echo json_encode(array('success'=>true));exit;
    } else {
        // check if this calendar allows overlapping
        //if(!CalendarOwners::allowOverlapping($frm_submitted['cal_id'])) {
            if(Events::isTimeAvailable($frm_submitted) || $frm_submitted['date_end'] != $frm_submitted['date_start']) {
                $arr_event = Events::insertEvent($frm_submitted);
                echo json_encode(array('success'=>true, 'event'=>$arr_event ));exit;
            } else {
                echo json_encode(array('success'=>false, 'error'=>'Overlapping'));exit;
            }
        //} else {
            //$arr_event = Events::insertEvent($frm_submitted);
            //echo json_encode(array('success'=>true, 'event'=>$arr_event   ));exit;
        //}
    }
}
echo json_encode(array('success'=>false));exit;
}
4

1 回答 1

0

我对事件重复有类似的需求,并在 Full Calendar 提供的基础上构建了自己的逻辑。在用户界面上,当用户添加新事件时,我允许他们指定是否希望该事件成为重复事件。如果是,那么我给他们“每天”、“每周”、“每月”等选项。如果他们选择“每天”,我会问:“几天?”

我将描述我在 PHP/伪代码中所做的事情,因为每个人都有自己独特的此类功能实现。

然后,我会像往常一样添加原始事件。如果,event_recurring = TRUE,则:

$appointment_start; // The original start time of the original event
$appointment_end; // The original end time of the original event
$max_recurence; // The number of days the user wants to recur

if ($max_recurence <  $today) // Skip
else {
   // If frequency == DAILY , other options can be weekly, monthly

   $event_recur_counter = $original_event_start + 1;
   while ($event_recur_counter < $max_recurence){

      $appointment_start = $appointment_start + 1;
      $appointment_end = $appointment_end + 1;

      //Insert the new event (everything else apart from start and end time is the same

      $event_recur_counter = $original_event_start + 1;


}

就像我说的,有几种方法可以做这样的事情,但这是基本思想。您将有多个事件,它们之间唯一不同的是它们的开始和结束时间。从那里开始,您可以为每个事件单独编辑一些内容,而不会影响其他任何内容。

希望这可以帮助。

于 2013-05-11T20:58:13.940 回答