function fullcalendar_update in FullCalendar 7.2
Same name and namespace in other branches
- 6.2 fullcalendar.module \fullcalendar_update()
- 6 fullcalendar.module \fullcalendar_update()
- 7 fullcalendar.module \fullcalendar_update()
Saves the updated FullCalendar event's datetime.
Parameters
string $action: Value can be 'drop' or 'resize'.
int $eid: The id of the entity that will be updated.
1 string reference to 'fullcalendar_update'
- fullcalendar_menu in ./
fullcalendar.module - Implements hook_menu().
File
- ./
fullcalendar.module, line 152 - Provides a views style plugin for FullCalendar
Code
function fullcalendar_update($action, $eid) {
if (empty($_POST['field']) || !isset($_POST['index'])) {
return;
}
// Retrieve the post vars form the ajax call.
$field = check_plain($_POST['field']);
$index = check_plain($_POST['index']);
$all_day = isset($_POST['all_day']) ? check_plain($_POST['all_day']) : '';
$delta = ' ' . check_plain($_POST['day_delta']) . ' days ' . check_plain($_POST['minute_delta']) . ' minutes';
$entity_type = check_plain($_POST['entity_type']);
$entity = entity_load($entity_type, array(
$eid,
));
$entity = reset($entity);
$langcode = field_language($entity_type, $entity, $field);
$item =& $entity->{$field}[$langcode][$index];
$old_start = $item['value'];
$old_end = $item['value2'];
// Adjust for different date formats.
$format = date_type_format($item['date_type']);
// Datestamp can't combine with words for strtotime, convert to ISO for now.
if ($format == DATE_FORMAT_UNIX) {
$old_start = date(DATE_FORMAT_ISO, $old_start);
$old_end = date(DATE_FORMAT_ISO, $old_end);
}
// No break after 'drop' so it will reuse the code of 'resize'.
switch ($action) {
case 'drop':
$item['value'] = date($format, strtotime($old_start . $delta));
case 'resize':
$item['value2'] = date($format, strtotime($old_end . $delta));
break;
}
// Save the new start/end values.
if (module_exists('entity')) {
entity_save($entity_type, $entity);
}
else {
field_attach_presave($entity_type, $entity);
field_attach_update($entity_type, $entity);
}
drupal_json_output(array(
'msg' => t('The new event time has been saved.') . ' [' . l(t('Close'), NULL, array(
'attributes' => array(
'class' => array(
'fullcalendar-status-close',
),
),
)) . ']',
'dom_id' => $_POST['dom_id'],
));
}