Example #1
0
 /**
  * getReccurentAlerts 
  * 
  * @param mixed $start 
  * @param mixed $end 
  * @access public
  * @return void
  */
 function getReccurentAlerts($start, $end) {
   $of = &OccurrenceFactory::getInstance();
   $this->logger->debug("Getting alerts on reccurent events between $start and $end");
   $r_q = run_query_calendar_repeat_alerts($start,$end);
   $this->logger->debug($r_q->nf().' potentials alerts founded on reccurent events');
   while ($r_q->next_record()) {
     $id = $r_q->f('event_id');
     $title = $r_q->f('event_title');
     $privacy = $r_q->f('event_privacy');
     $description = $r_q->f('event_description');
     $properties = $r_q->f('event_properties');
     $location = $r_q->f('event_location'); 
     $category1 = $r_q->f('eventcategory1_label');
     $date = new Of_Date($r_q->f('event_date'), 'GMT');
     $duration = $r_q->f('event_duration');
     $repeatkind = $r_q->f('event_repeatkind');
     $endrepeat = new Of_Date($r_q->f('event_endrepeat'),'GMT');
     $entity = $r_q->f('eventlink_entity');
     $all_day = $r_q->f('event_allday');
     $color = $r_q->f('event_color');
     $repeatfrequence = $r_q->f('event_repeatfrequence');
     $repeatdays = $r_q->f('event_repeatdays');
     $entity_id = $r_q->f('eventlink_entity_id');    
     $entity_state = $r_q->f('eventlink_state');
     $owner = $r_q->f('event_owner');
     $entity_label = $r_q->f('userobm_lastname') .' '.$r_q->f('userobm_firstname');
     $state = $r_q->f('eventlink_state');
     $timezone = $r_q->f('event_timezone');
     $opacity = $r_q->f('event_opacity');
     $tag = $r_q->f('eventtag_id');
     if ($endrepeat->error() == Of_Date::WARN_EMPTY_DATE) {
       $endrepeat = $end;
     }
     if (isset($of->events[$id])) {
       $event = $of->events[$id];
     } else {
       $event = new Event($id,$duration,$title,$location,$category1,$privacy,$description,$properties,$all_day,$repeatkind,$owner,'',$color,$opacity,$tag);
       $event->setTimezone($timezone);
     }
     $this->logger->debug("$entity $entity_id ($entity_label) added on event ".$event->id);
     $tz = new DateTimeZone($timezone);
     $date->setTimezone($tz);
     $event->addAttendee($entity,$entity_id,$entity_label,$state);      
     $event_start = clone $start;
     $event_start->setTimezone($tz); 
     $event_start->subSecond($duration)->setHour($date)->setMinute($date)->setSecond($date);
     $event_end = ($end->compare($endrepeat) > 0)? clone $endrepeat: clone $end; 
     $event_end->setTimezone($tz);
     $event_end->setHour($date)->setMinute($date)->setSecond($date)->addSecond($duration);
     switch ($repeatkind) {
     case 'daily' :
       calendar_daily_repeatition($date,$event_start,$event_end,$repeatfrequence,$event,$entity_id,$entity, $entity_state);
       break;
     case 'weekly' :
       calendar_weekly_repeatition($date,$event_start,$event_end,$repeatdays,$repeatfrequence,$event,$entity_id,$entity, $entity_state);
       break;
     case 'monthlybyday' :
       $stored = calendar_monthlybyday_repeatition($date,$event_start,$event_end,$repeatfrequence,$event,$entity_id,$entity, $entity_state);
       break;
     case 'monthlybydate' :
       $stored = calendar_monthlybydate_repeatition($date,$event_start,$event_end,$repeatfrequence,$event,$entity_id,$entity, $entity_state);
       break;
     case 'yearly' :
       $stored = calendar_yearly_repeatition($date,$event_start,$event_end,$repeatfrequence,$event,$entity_id,$entity, $entity_state);
       break;
     }
   }
   $this->logger->debug("Removing exceptions");
   if (count($of->events) > 0) {
     $exception_q = run_query_get_events_exception(array_keys($of->events),$start,NULL);
     $this->logger->debug($exception_q->nf()." exceptions founded");
     while($exception_q->next_record()) {
       $of->removeOccurrences($exception_q->f('eventexception_parent_id'), new Of_Date($exception_q->f('eventexception_date'), 'GMT'));
     }
   }
 }