/** * Compares two event instances by start time * * @param EventInstance $a Instance * @param EventInstance $b Instance * @return int */ public static function compareInstancesByStartTime($a, $b) { $start_a = $a->getStartTimestamp(); $start_b = $b->getStartTimestamp(); if ($start_a == $start_b) { return 0; } return $start_a < $start_b ? -1 : 1; }
/** * 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(); }