Example #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;
 }
Example #2
0
 /**
  * Returns an iCal feed for this event
  *
  * @param int    $starttime Range start timestamp
  * @param int    $endtime   Range end timestamp
  * @param string $filename  Filename used for output file
  * @return string
  */
 public function toIcal($starttime = null, $endtime = null, $filename = 'event.ics')
 {
     if (is_null($starttime)) {
         $starttime = $this->getNextOccurrence();
     }
     $eventInstance = new EventInstance($this, $starttime);
     //$this->getAllEventInstances($starttime, $endtime, true, 'ical');
     $instance = $eventInstance->export('ical');
     $config = array('unique_id' => $this->guid, 'allowEmpty' => true, 'nl' => "\r\n", 'format' => 'iCal', 'delimiter' => DIRECTORY_SEPARATOR, 'filename' => $filename);
     $v = new vcalendar($config);
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty("X-WR-CALNAME", implode(' - ', array(elgg_get_config('sitename'), $this->getDisplayName())));
     $v->setProperty("X-WR-CALDESC", strip_tags($this->description));
     $v->setProperty("X-WR-TIMEZONE", Util::UTC);
     $e =& $v->newComponent('vevent');
     $organizer = elgg_extract('organizer', $instance, array());
     unset($instance['organizer']);
     $reminders = elgg_extract('reminders', $instance, array());
     unset($instance['reminders']);
     foreach ($instance as $property => $value) {
         $e->setProperty($property, $value);
     }
     if (!empty($organizer)) {
         if (is_email_address($organizer)) {
             $e->setProperty('organizer', $organizer);
         } else {
             $e->setProperty('organizer', elgg_get_site_entity()->email, array('CN' => $organizer));
         }
     }
     if (!empty($reminders)) {
         foreach ($reminders as $reminder) {
             $a =& $e->newComponent('valarm');
             $a->setProperty('action', 'DISPLAY');
             $a->setProperty('trigger', "-PT{$reminder}S");
         }
     }
     $v->returnCalendar();
 }