Example #1
0
 /**
  * Saves a repeated event
  */
 public function saveRepeat(Calendar_Event $event)
 {
     // if this event has a parent id, don't try and save repeats
     if ($event->pid) {
         return true;
     }
     // This event is not repeating
     if (empty($event->repeat_type)) {
         // Previously, the event repeated, remove the copies
         $result = $event->clearRepeats();
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
         }
         return true;
     }
     // Event is repeating
     // First check if the repeat scheme changed
     if ($event->_previous_repeat && $event->getCurrentHash() == $event->_previous_settings) {
         // The event has not changed, so we just update the repeats
         // that exist and return
         return $event->updateRepeats();
     }
     // The repeat setting changed or were never set, so need to recreate the copies
     $result = $event->clearRepeats();
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
     }
     $repeat_info = explode(':', $event->repeat_type);
     $repeat_mode = $repeat_info[0];
     if (isset($repeat_info[1])) {
         $repeat_vars = explode(';', $repeat_info[1]);
     }
     switch ($repeat_mode) {
         case 'daily':
             $result = $this->repeatDaily($event);
             break;
         case 'weekly':
             $result = $this->repeatWeekly($event);
             break;
         case 'monthly':
             $result = $this->repeatMonthly($event);
             break;
         case 'yearly':
             $result = $this->repeatYearly($event);
             break;
         case 'every':
             $result = $this->repeatEvery($event);
             break;
     }
     if (!$result) {
         return false;
     }
     if (PHPWS_Error::isError($result)) {
         return $result;
     } else {
         return true;
     }
 }