recursIn() public method

Determines if the event recurs in the given time span.
public recursIn ( Horde_Date $startDate, Horde_Date $endDate ) : boolean
$startDate Horde_Date Start of the time span.
$endDate Horde_Date End of the time span.
return boolean True if the event recurs in this time span.
Exemplo n.º 1
0
 /**
  * Lists all events in the given time range.
  *
  * @param Horde_Date $startDate Start of range date object.
  * @param Horde_Date $endDate   End of range data object.
  *
  * @return array Events in the given time range.
  *
  * @throws Horde_Kolab_FreeBusy_Exception If retrieving the events failed.
  */
 public function listEvents(Horde_Date $startDate, Horde_Date $endDate)
 {
     try {
         $objects = $this->getData()->getObjects();
     } catch (Horde_Kolab_Storage_Exception $e) {
         //todo: prior exception
         throw new Horde_Kolab_FreeBusy_Exception($e);
     }
     $startts = $startDate->timestamp();
     $endts = $endDate->timestamp();
     $result = array();
     /**
      * PERFORMANCE START
      *
      * The following section has been performance optimized using
      * xdebug and kcachegrind.
      *
      * If there are many events it takes a lot of time and memory to create
      * new objects from the array and use those for time comparison. So the
      * code tries to use the original data array as long as possible and
      * only converts it to an object if really required (e.g. the event
      * actually lies in the time span or it recurs in which case the
      * calculations are more complex).
      */
     foreach ($objects as $object) {
         /* check if event period intersects with given period */
         if (!($object['start-date'] > $endts || $object['end-date'] < $startts)) {
             $result[] = new Horde_Kolab_FreeBusy_Object_Event($object);
             continue;
         }
         /* do recurrence expansion if not keeping anyway */
         if (isset($object['recurrence'])) {
             $event = new Horde_Kolab_FreeBusy_Object_Event($object);
             if ($event->recursIn($startDate, $endDate)) {
                 $result[] = $event;
             }
         }
     }
     /** PERFORMANCE END */
     return $result;
 }