private function apiArrayFromEvent(ICalEvent $event)
 {
     foreach ($this->fieldConfig as $aField => $fieldInfo) {
         $fieldName = isset($fieldInfo['label']) ? $fieldInfo['label'] : $aField;
         $attribute = $event->get_attribute($aField);
         if ($attribute) {
             if (isset($fieldInfo['section'])) {
                 $section = $fieldInfo['section'];
                 if (!isset($result[$section])) {
                     $result[$section] = array();
                 }
                 $result[$section][$fieldName] = $attribute;
             } else {
                 $result[$fieldName] = $attribute;
             }
         }
     }
     return $result;
 }
Exemple #2
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;
 }