Exemple #1
0
 protected function apiArrayFromEvent(ICalEvent $event, $version)
 {
     $standardAttributes = array('datetime', 'start', 'end', 'uid', 'summary', 'description', 'location', 'geo');
     $result = array('id' => $event->get_uid(), 'title' => $event->get_summary(), 'description' => nl2br($event->get_description()), 'start' => $event->get_start(), 'end' => $event->get_end(), 'allday' => $event->isAllDay(), 'location' => $event->get_location(), 'locationLabel' => '');
     // iCal GEO property -- subclass if event lat/lon comes from somewhere else
     $coords = $event->get_location_coordinates();
     if ($coords) {
         $result['latitude'] = $coords['lat'];
         $result['longitude'] = $coords['lon'];
     }
     foreach ($this->fieldConfig as $aField => $fieldInfo) {
         if (in_array($aField, $standardAttributes)) {
             continue;
         }
         // Handled these above
         $id = self::argVal($fieldInfo, 'id', $aField);
         $title = self::argVal($fieldInfo, 'label', $id);
         $section = self::argVal($fieldInfo, 'section', '');
         $type = self::argVal($fieldInfo, 'type', '');
         $value = $event->get_attribute($aField);
         if ($value) {
             if (self::argVal($fieldInfo, 'type', '') == 'category' && is_array($value)) {
                 $value = $this->apiArrayFromCategories($value);
             }
             if ($version < 2) {
                 $result[$title] = $value;
             } else {
                 if (!isset($result['fields'])) {
                     $result['fields'] = array();
                 }
                 $result['fields'][] = array('id' => $id, 'section' => $section, 'type' => $type, 'title' => $title, 'value' => $value);
             }
         }
     }
     return $result;
 }
Exemple #2
0
 function occurrences(ICalEvent $event, TimeRange $range = null, $max = null)
 {
     $occurrences = array();
     $time = $event->get_start();
     $diff = $event->get_end() - $event->get_start();
     $limitType = $this->limitType;
     $limit = $this->limit;
     $count = 0;
     //    echo date('m/d/Y H:i:s', $time) . "<br>\n";
     $time = $this->nextIncrement($time, $this->type, $this->interval);
     while ($time <= $range->get_end()) {
         //      echo date('m/d/Y H:i:s', $time) . "<br>\n";
         if ($limitType == 'UNTIL' && $time > $limit) {
             break;
         }
         $occurrence_range = new TimeRange($time, $time + $diff);
         if ($occurrence_range->overlaps($range)) {
             if ($recurrence_exception = $event->getRecurrenceException($time)) {
                 $occurrence = clone $recurrence_exception;
             } else {
                 $occurrence = clone $event;
                 $occurrence->setRange($occurrence_range);
                 $occurrence->clear_rrules();
                 $recurrence_id = strftime("%Y%m%dT%H%M%S", $time);
                 if ($tzid = $occurrence->get_tzid()) {
                     $recurrence_id = sprintf("TZID=%s:%s", $tzid, $recurrence_id);
                 }
                 $occurrence->set_attribute('RECURRENCE-ID', $recurrence_id);
             }
             $occurrences[] = $occurrence;
         }
         if ($limitType == 'COUNT' && $count < $limit) {
             break;
         }
         if ($count > ICalRecurrenceRule::MAX_OCCURRENCES) {
             break;
         }
         if (!is_null($max) && count($occurrences) >= $max) {
             break;
         }
         $time = $this->nextIncrement($time, $this->type, $this->interval);
         $count++;
     }
     return $occurrences;
 }
function formatDayTitle(ICalEvent $event) {
  $start = $event->get_start();
  $end = $event->get_end();
  if ($start != $end) {
    // all of acad calendar time units are in days so
    // we can end 23:59:00 instead of 00:00:00 next day
    $timeRange = new TimeRange($start, $end - 1);
    $dateTitle = $timeRange->format('l F j');
  } else {
    $dateTitle = date('l F j', $start);
  }
  return $dateTitle;
}