/**
  * Insert "fake" entries for recurring occurences of this event
  */
 private function _update_recurring($event)
 {
     if (empty($this->calendars)) {
         return;
     }
     if (!empty($event['recurrence'])) {
         $exdata = array();
         $exceptions = $this->_load_exceptions($event);
         foreach ($exceptions as $exception) {
             $exdate = substr($exception['_instance'], 0, 8);
             $exdata[$exdate] = $exception;
         }
     }
     // clear existing recurrence copies
     $this->rc->db->query("DELETE FROM " . $this->db_events . "\n       WHERE recurrence_id=?\n       AND isexception=0\n       AND calendar_id IN (" . $this->calendar_ids . ")", $event['id']);
     // create new fake entries
     if (!empty($event['recurrence'])) {
         // include library class
         require_once $this->cal->home . '/lib/calendar_recurrence.php';
         $recurrence = new calendar_recurrence($this->cal, $event);
         $count = 0;
         $event['allday'] = $event['all_day'];
         $duration = $event['start']->diff($event['end']);
         $recurrence_id_format = libcalendaring::recurrence_id_format($event);
         while ($next_start = $recurrence->next_start()) {
             $instance = $next_start->format($recurrence_id_format);
             $datestr = substr($instance, 0, 8);
             // skip exceptions
             // TODO: merge updated data from master event
             if ($exdata[$datestr]) {
                 continue;
             }
             $next_start->setTimezone($this->server_timezone);
             $next_end = clone $next_start;
             $next_end->add($duration);
             $notify_at = $this->_get_notification(array('alarms' => $event['alarms'], 'start' => $next_start, 'end' => $next_end, 'status' => $event['status']));
             $query = $this->rc->db->query(sprintf("INSERT INTO " . $this->db_events . "\n           (calendar_id, recurrence_id, created, changed, uid, instance, %s, %s, all_day, sequence, recurrence, title, description, location, categories, url, free_busy, priority, sensitivity, status, alarms, attendees, notifyat)\n            SELECT calendar_id, ?, %s, %s, uid, ?, ?, ?, all_day, sequence, recurrence, title, description, location, categories, url, free_busy, priority, sensitivity, status, alarms, attendees, ?\n            FROM  " . $this->db_events . " WHERE event_id=? AND calendar_id IN (" . $this->calendar_ids . ")", $this->rc->db->quote_identifier('start'), $this->rc->db->quote_identifier('end'), $this->rc->db->now(), $this->rc->db->now()), $event['id'], $instance, $next_start->format(self::DB_DATE_FORMAT), $next_end->format(self::DB_DATE_FORMAT), $notify_at, $event['id']);
             if (!$this->rc->db->affected_rows($query)) {
                 break;
             }
             // stop adding events for inifinite recurrence after 20 years
             if (++$count > 999 || !$recurrence->recurEnd && !$recurrence->recurCount && $next_start->format('Y') > date('Y') + 20) {
                 break;
             }
         }
         // remove all exceptions after recurrence end
         if ($next_end && !empty($exceptions)) {
             $this->rc->db->query("DELETE FROM " . $this->db_events . "\n           WHERE `recurrence_id`=?\n           AND `isexception`=1\n           AND `start` > ?\n           AND `calendar_id` IN (" . $this->calendar_ids . ")", $event['id'], $next_end->format(self::DB_DATE_FORMAT));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Insert "fake" entries for recurring occurences of this event
  */
 private function _update_recurring($event)
 {
     if (empty($this->calendars)) {
         return;
     }
     // clear existing recurrence copies
     $this->rc->db->query("DELETE FROM " . $this->db_events . "\n       WHERE recurrence_id=?\n       AND calendar_id IN (" . $this->calendar_ids . ")", $event['id']);
     // create new fake entries
     if ($event['recurrence']) {
         // include library class
         require_once $this->cal->home . '/lib/calendar_recurrence.php';
         $recurrence = new calendar_recurrence($this->cal, $event);
         $count = 0;
         $duration = $event['start']->diff($event['end']);
         while ($next_start = $recurrence->next_start()) {
             $next_start->setTimezone($this->server_timezone);
             $next_end = clone $next_start;
             $next_end->add($duration);
             $notify_at = $this->_get_notification(array('alarms' => $event['alarms'], 'start' => $next_start, 'end' => $next_end, 'status' => $event['status']));
             $query = $this->rc->db->query(sprintf("INSERT INTO " . $this->db_events . "\n           (calendar_id, recurrence_id, created, changed, uid, %s, %s, all_day, recurrence, title, description, location, categories, url, free_busy, priority, sensitivity, status, alarms, attendees, notifyat)\n            SELECT calendar_id, ?, %s, %s, uid, ?, ?, all_day, recurrence, title, description, location, categories, url, free_busy, priority, sensitivity, status, alarms, attendees, ?\n            FROM  " . $this->db_events . " WHERE event_id=? AND calendar_id IN (" . $this->calendar_ids . ")", $this->rc->db->quote_identifier('start'), $this->rc->db->quote_identifier('end'), $this->rc->db->now(), $this->rc->db->now()), $event['id'], $next_start->format(self::DB_DATE_FORMAT), $next_end->format(self::DB_DATE_FORMAT), $notify_at, $event['id']);
             if (!$this->rc->db->affected_rows($query)) {
                 break;
             }
             // stop adding events for inifinite recurrence after 20 years
             if (++$count > 999 || !$recurrence->recurEnd && !$recurrence->recurCount && $next_start->format('Y') > date('Y') + 20) {
                 break;
             }
         }
     }
 }