function revision_scheduler_list_page in Revision scheduler 7
1 string reference to 'revision_scheduler_list_page'
- revision_scheduler_menu in ./
revision_scheduler.module - Implements hook_menu().
File
- ./
revision_scheduler.pages.inc, line 3
Code
function revision_scheduler_list_page($entity_type, $entity) {
list($entity_id) = entity_extract_ids($entity_type, $entity);
$header = array(
t('Revision'),
t('Action'),
array(
'data' => t('Scheduled Date'),
'sort' => 'desc',
'field' => 'time_scheduled',
),
t('Operations'),
);
$query = db_select('revision_scheduler', 'r')
->extend('TableSort')
->extend('PagerDefault')
->limit(25)
->fields('r')
->orderByHeader($header)
->condition('entity_type', $entity_type)
->condition('entity_id', $entity_id);
// For operations that have the same scheduled time, sort by executed time,
// and then queued time, and then ID since that is the order of execution.
// @todo This should probably be removed at some point.
$order = $query
->getOrderBy();
if (!empty($order['time_scheduled'])) {
$query
->orderBy('time_executed', $order['time_scheduled']);
$query
->orderBy('time_queued', $order['time_scheduled']);
$query
->orderBy('id', $order['time_scheduled']);
}
$operations = $query
->execute()
->fetchAll();
$revision_ids = array();
foreach ($operations as $operation) {
$revision_ids[] = $operation->revision_id;
}
$revisions = revision_scheduler_entity_revision_load_multiple($entity_type, $entity_id, $revision_ids);
$rows = array();
foreach ($operations as $id => $operation) {
$revision = !empty($revisions[$operation->revision_id]) ? $revisions[$operation->revision_id] : FALSE;
$operation_info = revision_scheduler_entity_revision_operation_get_info($entity_type, $operation->operation);
$row = array(
t('Revision @id: @label', array(
'@id' => $operation->revision_id,
'@label' => $revision ? entity_label($entity_type, $revision) : t('(Deleted)'),
)),
check_plain($operation_info['label']),
format_date($operation->time_scheduled),
);
if (!empty($operation->time_executed)) {
$row[] = t('Completed on @date', array(
'@date' => format_date($operation->time_executed),
));
}
elseif (!empty($operation->time_queued)) {
$row[] = t('Queued on @date', array(
'@date' => format_date($operation->time_queued),
));
}
else {
$operations = array();
if (revision_scheduler_operation_access('run', $operation)) {
$value = implode('-', array(
'run',
$operation->id,
$operation->operation,
$operation->time_scheduled,
));
$operations['run'] = array(
'title' => t('Run now'),
'href' => 'revision-scheduler/' . $operation->id . '/run',
'query' => array(
'token' => drupal_get_token($value),
) + drupal_get_destination(),
);
}
if (revision_scheduler_operation_access('update', $operation)) {
$operations['edit'] = array(
'title' => t('Edit'),
'href' => 'revision-scheduler/' . $operation->id . '/edit',
'query' => drupal_get_destination(),
);
}
if (revision_scheduler_operation_access('delete', $operation)) {
$operations['delete'] = array(
'title' => t('Cancel'),
'href' => 'revision-scheduler/' . $operation->id . '/delete',
'query' => drupal_get_destination(),
);
}
$row[] = array(
'data' => array(
'#theme' => 'links',
'#links' => $operations,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
),
);
}
$rows[$id] = $row;
}
$build['table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No scheduled revisions available.'),
);
// Add the pager
$build['pager'] = array(
'#theme' => 'pager',
'#weight' => 5,
);
return $build;
}