/** * Grok the TZID and return an offset in seconds from UTC for this * date and time. */ function _parseTZID($date, $time, $tzid) { $vtimezone = $this->_container->findComponentByAttribute('vtimezone', 'TZID', $tzid); if (!$vtimezone) { return false; } $change_times = array(); foreach ($vtimezone->getComponents() as $o) { $t = $vtimezone->parseChild($o, $date['year']); if ($t !== false) { $change_times[] = $t; } } if (!$change_times) { return false; } sort($change_times); // Time is arbitrarily based on UTC for comparison. $t = @gmmktime($time['hour'], $time['minute'], $time['second'], $date['month'], $date['mday'], $date['year']); if ($t < $change_times[0]['time']) { return $change_times[0]['from']; } for ($i = 0, $n = count($change_times); $i < $n - 1; $i++) { if ($t >= $change_times[$i]['time'] && $t < $change_times[$i + 1]['time']) { return $change_times[$i]['to']; } } if ($t >= $change_times[$n - 1]['time']) { return $change_times[$n - 1]['to']; } return false; }
/** * Generates the free/busy export. * * @return Horde_iCalendar The iCal object. */ public function export() { /* Create the new iCalendar. */ $vCal = new Horde_iCalendar(); $vCal->setAttribute('PRODID', $this->_backend->getProductId()); $vCal->setAttribute('METHOD', 'PUBLISH'); /* Create the new vFreebusy component. */ $vFb =& Horde_iCalendar::newComponent('vfreebusy', $vCal); $vFb->setAttribute('ORGANIZER', $this->getOrganizerMail(), $this->getOrganizerName()); $vFb->setAttribute('DTSTAMP', $this->getDateStamp()); $vFb->setAttribute('DTSTART', $this->getStart()->timestamp()); $vFb->setAttribute('DTEND', $this->getEnd()->timestamp()); $url = $this->_backend->getUrl(); if (!empty($url)) { $vFb->setAttribute('URL', $this->getUrl()); } /* Add all the busy periods. */ foreach ($this->_resource->listEvents($this->getStart(), $this->getEnd()) as $event) { $status = $this->_status_map->map($event->getStatus()); $duration = $event->duration(); $extra = $event->getEncodedInformation(); foreach ($event->getBusyTimes($this->getStart(), $this->getEnd()) as $busy) { $vFb->addBusyPeriod($status, $busy, null, $duration, $extra); } } /* Remove the overlaps. */ $vFb->simplify(); /* Combine and return. */ $vCal->addComponent($vFb); return $vCal; }