View source
<?php
define('WS_DATEFIELD_DATE_VALUE_FORMAT', 'Y-m-d H:i:s');
function ws_datefield_wsfields_datetime2_data_alter($data, $field) {
$repeat = TRUE;
$end_date = TRUE;
$field_data = array();
if (!empty($field['translatable'])) {
$languages = language_list();
}
else {
$languages = array(
LANGUAGE_NONE => LANGUAGE_NONE,
);
}
foreach ($languages as $lang => $language) {
foreach ($data[$lang] as $key => $lang_data) {
_ws_datefield_populate_datetime_field_data($field_data, $value, $repeat, $end_date, $language);
}
}
$data = $field_data;
return $data;
}
function _ws_datefield_populate_datetime_field_data(&$field_data, &$value, $repeat = FALSE, $end_date = FALSE, $language = LANGUAGE_NONE) {
$value['value']
->setTimezone(new DateTimeZone('UTC'));
if (isset($value['value2'])) {
$value['value2']
->setTimezone(new DateTimeZone('UTC'));
}
$field_data[$language][] = array(
'value' => $value['value']
->format(WS_DATEFIELD_DATE_VALUE_FORMAT),
'timezone' => $value['value']
->getTimezone()
->getName(),
'offset' => $value['value']
->getOffset(),
);
if ($repeat and isset($value['rrule'])) {
$field_data[$language][count($field_data[$language]) - 1]['rrule'] = $value['rrule'];
}
if ($end_date and isset($value['value2'])) {
$field_data[$language][count($field_data[$language]) - 1]['value2'] = $value['value2']
->format(WS_DATEFIELD_DATE_VALUE_FORMAT);
}
}
function ws_datefield_wsfields_datetime_data_alter($data, $field) {
if (!is_array($data)) {
$field_data = _ws_datefield_map_datetime($data, $field);
}
else {
if (isset($field['storage']['settings']['translation']) and $field['storage']['settings']['translation']) {
foreach ($data as $language => $values) {
foreach ($values as $value) {
$field_data = _ws_datefield_map_datetime($value, $field);
}
}
}
else {
foreach ($data as $value) {
$field_data = _ws_datefield_map_datetime($value, $field);
}
}
}
return $field_data;
}
function _ws_datefield_map_datetime(&$data, $field) {
$field_data = array();
if (isset($data['schedule']['vevents'])) {
$dates = $data['schedule']['vevents'];
foreach ($dates as $k => $v) {
$value = array(
'value' => new DateTime($v['start_datetime']),
'value2' => new DateTime($v['end_datetime']),
);
if (isset($v['repeat']) && isset($v['exceptions'])) {
$value['rrule'] = $v['repeat'] . sizeof($v['exceptions']) > 0 ? 'exceptions=' . implode(',', $v['exceptions']) : '';
}
_ws_datefield_populate_datetime_field_data($field_data, $value, true, true);
}
}
return $field_data;
}
function ws_datefield_wsconfig_processor_info() {
return array(
'ws_datefield_processor' => array(
'fields' => array(
'datetime' => 'Date',
),
),
);
}