本文整理汇总了PHP中XMLElement::format方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLElement::format方法的具体用法?PHP XMLElement::format怎么用?PHP XMLElement::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLElement
的用法示例。
在下文中一共展示了XMLElement::format方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: appendFormattedElement
/**
* @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);
}