function workbench_scheduler_schedules_action in Workbench Scheduler 7.2
Same name and namespace in other branches
- 7 actions/workbench_scheduler.action.inc \workbench_scheduler_schedules_action()
Implements the action that is applied to the revisions.
Parameters
$entity:
array $context:
File
- actions/
workbench_scheduler.action.inc, line 150
Code
function workbench_scheduler_schedules_action(&$entity, $context = array()) {
// Change vid to latest.
$latest_revision = workbench_moderation_node_current_load($entity);
$entity->vid = $latest_revision->vid;
// Only save schedules for content that supports them.
$types_moderated = workbench_moderation_moderate_node_types();
$is_moderated = in_array($entity->type, $types_moderated) ? TRUE : FALSE;
$schedules = workbench_scheduler_type_schedules_load($entity->type);
if ($is_moderated && !empty($schedules)) {
// Reset the workbench schedule.
if ($context['workbench_scheduler_reset']) {
$entity->workbench_schedule = array();
workbench_scheduler_delete_node_schedule($entity->nid, $entity->vid);
}
foreach ($context['workbench_scheduler_sid'] as $sid => $sid_enabled) {
foreach ($schedules as $name => $info) {
if ($sid_enabled && $info->sid == $sid) {
// Format date.
if (!empty($context['workbench_scheduler_date'][$sid])) {
$date = strtotime($context['workbench_scheduler_date'][$sid]);
}
else {
$date = '';
}
// Add new properties.
$info->date = $date;
$info->completed = 0;
// Does this schedule already exist?
$updated = FALSE;
if (!empty($entity->workbench_schedule)) {
foreach ($entity->workbench_schedule as $index => $entity_schedule) {
// Instead of creating a new element, update the existing one.
if ($info->sid == $entity_schedule->sid) {
$entity->workbench_schedule[$index] = $info;
$updated = TRUE;
}
}
}
// If schedule doesn't already exist create it.
if (!$updated) {
$entity->workbench_schedule[] = $info;
}
}
}
}
}
}