Beispiel #1
0
 /**
  * @see http://symphony-cms.com/learn/api/2.2/toolkit/field/#appendFormattedElement
  */
 public function appendFormattedElement(&$wrapper, $data, $encode = false)
 {
     $datetime = new XMLElement($this->get('element_name'));
     // Prepare data
     if (!is_array($data['start'])) {
         $data['start'] = array($data['start']);
     }
     if (!is_array($data['end'])) {
         $data['end'] = array($data['end']);
     }
     // Get timeline
     $timeline = $data['start'];
     sort($timeline);
     // Generate XML
     foreach ($data['start'] as $id => $date) {
         $date = new XMLElement('date');
         $date->setAttribute('timeline', array_search($data['start'][$id], $timeline) + 1);
         // Start date
         $start = new DateTime($data['start'][$id]);
         $date->appendChild($start = new XMLElement('start', $start->format('Y-m-d'), array('iso' => $start->format('c'), 'time' => $start->format('H:i'), 'weekday' => $start->format('N'), 'offset' => $start->format('O'))));
         // Date range
         if ($data['end'][$id] != $data['start'][$id]) {
             $end = new DateTime($data['end'][$id]);
             $date->appendChild($end = new XMLElement('end', $end->format('Y-m-d'), array('iso' => $end->format('c'), 'time' => $end->format('H:i'), 'weekday' => $end->format('N'), 'offset' => $end->format('O'))));
             $date->setAttribute('type', 'range');
         } else {
             $date->setAttribute('type', 'exact');
         }
         $datetime->appendChild($date);
     }
     // append date and time to data source
     $wrapper->appendChild($datetime);
 }