Example #1
0
 /**
  * Apply the given changes to already existing exceptions
  */
 protected function update_recurrence_exceptions(&$master, $event, $old, $savemode)
 {
     $saved = false;
     $existing = null;
     // determine added and removed attendees
     $added_attendees = $removed_attendees = array();
     if ($savemode == 'future') {
         $old_attendees = $current_attendees = array();
         foreach ((array) $old['attendees'] as $attendee) {
             $old_attendees[] = $attendee['email'];
         }
         foreach ((array) $event['attendees'] as $attendee) {
             $current_attendees[] = $attendee['email'];
             if (!in_array($attendee['email'], $old_attendees)) {
                 $added_attendees[] = $attendee;
             }
         }
         $removed_attendees = array_diff($old_attendees, $current_attendees);
     }
     foreach ($master['recurrence']['EXCEPTIONS'] as $i => $exception) {
         // update a specific instance
         if ($exception['_instance'] == $old['_instance']) {
             $existing = $i;
             // check savemode against existing exception mode.
             // if matches, we can update this existing exception
             if ((bool) $exception['thisandfuture'] === ($savemode == 'future')) {
                 $event['_instance'] = $old['_instance'];
                 $event['thisandfuture'] = $old['thisandfuture'];
                 $event['recurrence_date'] = $old['recurrence_date'];
                 $master['recurrence']['EXCEPTIONS'][$i] = $event;
                 $saved = true;
             }
         }
         // merge the new event properties onto future exceptions
         if ($savemode == 'future' && $exception['_instance'] >= $old['_instance']) {
             unset($event['thisandfuture']);
             self::merge_exception_data($master['recurrence']['EXCEPTIONS'][$i], $event, array('attendees'));
             if (!empty($added_attendees) || !empty($removed_attendees)) {
                 calendar::merge_attendee_data($master['recurrence']['EXCEPTIONS'][$i], $added_attendees, $removed_attendees);
             }
         }
     }
     /*
         // we could not update the existing exception due to savemode mismatch...
         if (!$saved && $existing !== null && $master['recurrence']['EXCEPTIONS'][$existing]['thisandfuture']) {
           // ... try to move the existing this-and-future exception to the next occurrence
           foreach ($this->get_recurring_events($master, $existing['start']) as $candidate) {
             // our old this-and-future exception is obsolete
             if ($candidate['thisandfuture']) {
               unset($master['recurrence']['EXCEPTIONS'][$existing]);
               $saved = true;
               break;
             }
             // this occurrence doesn't yet have an exception
             else if (!$candidate['isexception']) {
               $event['_instance'] = $candidate['_instance'];
               $event['recurrence_date'] = $candidate['recurrence_date'];
               $master['recurrence']['EXCEPTIONS'][$i] = $event;
               $saved = true;
               break;
             }
           }
         }
     */
     // set link to top-level exceptions
     $master['exceptions'] =& $master['recurrence']['EXCEPTIONS'];
     // returning false here will add a new exception
     return $saved;
 }
 /**
  * Update the participant status for the given attendees
  *
  * @see calendar_driver::update_attendees()
  */
 public function update_attendees(&$event, $attendees)
 {
     $success = $this->edit_event($event, true);
     // apply attendee updates to recurrence exceptions too
     if ($success && $event['_savemode'] == 'all' && !empty($event['recurrence']) && empty($event['recurrence_id']) && ($exceptions = $this->_load_exceptions($event))) {
         foreach ($exceptions as $exception) {
             calendar::merge_attendee_data($exception, $attendees);
             $this->_update_event($exception, false);
         }
     }
     return $success;
 }