Пример #1
0
 /**
  * Returns all event occurrences (one-time and recurring) in a given time range
  * To prevent memory leaks, the return is a sorted array formatted as:
  * <code>
  *  array(
  *   0 => array(
  *    'id' => $guid,
  *    'start' => $start_time,
  *    'end' => $end_time,
  *    'title' => $title,
  *    'description' => $description,
  *    'url' => $url,
  *    ...
  *   ),
  *  );
  * </code>
  *
  * @param int    $starttime Range start timestamp
  * @param int    $endtime   Range end timestamp
  * @param bool   $export    Export EventInstance objects to array
  * @param string $consumer  Consumer name (passed to the export hook, so plugins can decide on exportable values)
  * @return EventsInstance[]|array
  */
 public function getAllEventInstances($starttime = null, $endtime = null, $export = true, $consumer = '', $tz = null)
 {
     $instances = array();
     if (!Util::isValidTimezone($tz)) {
         if (elgg_is_logged_in()) {
             // if logged in use the timezone settings of the current user
             $tz = Util::getClientTimezone();
         } else {
             // use timezone of calendar owner
             $tz = Util::getClientTimezone($this->getOwnerEntity());
         }
     }
     $events = $this->getAllEvents($starttime, $endtime);
     foreach ($events as $event) {
         /* @var $event Event */
         if (!$event instanceof Event) {
             continue;
         }
         $start_times = $event->getStartTimes($starttime, $endtime, $tz);
         foreach ($start_times as $start_time) {
             $instance = new EventInstance($event, $start_time);
             $instance->setCalendar($this);
             $instances[] = $instance;
         }
     }
     usort($instances, array($this, 'compareInstancesByStartTime'));
     if ($export) {
         foreach ($instances as $key => $instance) {
             $instances[$key] = $instance->export($consumer);
         }
     }
     return $instances;
 }