function scheduler_list in Scheduler 7
Same name and namespace in other branches
- 5 scheduler.module \scheduler_list()
- 6 scheduler.module \scheduler_list()
Page callback: Displays a list of nodes scheduled for (un)publication.
This will appear as a tab on the Scheduler admin page at admin/config/content/scheduler/list and the content admin page at admin/content/scheduler. It is also shown on the 'My account' page user/{uid}/scheduler if the user has permission to schedule content.
Parameters
string $show: 'user_only' if viewing a user page, NULL otherwise.
int $uid: The uid when viewing a user page, NULL otherwise.
Return value
array A render array for a page containing a list of nodes.
1 string reference to 'scheduler_list'
- scheduler_menu in ./
scheduler.module - Implements hook_menu().
File
- ./
scheduler.admin.inc, line 543 - Administration forms for the Scheduler module.
Code
function scheduler_list($show, $uid) {
$header = array(
array(
'data' => t('Title'),
'field' => 'n.title',
),
array(
'data' => t('Type'),
'field' => 'n.type',
),
array(
'data' => t('Author'),
'field' => 'u.name',
),
array(
'data' => t('Status'),
'field' => 'n.status',
),
array(
'data' => t('Publish on'),
'field' => 's.publish_on',
),
array(
'data' => t('Unpublish on'),
'field' => 's.unpublish_on',
),
array(
'data' => t('Operations'),
),
);
// Default ordering.
if (!isset($_GET['order']) && !isset($_GET['sort'])) {
$_GET['order'] = t('Publish on');
$_GET['sort'] = 'ASC';
}
$query = db_select('scheduler', 's')
->extend('PagerDefault');
$query
->limit(50);
$query
->addJoin('LEFT', 'node', 'n', 's.nid = n.nid');
$query
->addJoin('LEFT', 'users', 'u', 'u.uid = n.uid');
$query
->fields('s', array(
'nid',
'publish_on',
'unpublish_on',
));
$query
->fields('n', array(
'uid',
'status',
'title',
'type',
'status',
));
$query
->addField('u', 'name');
// If this function is being called from a user account page then only select
// the nodes owned by that user. If the current user is viewing another users'
// profile and they do not have 'administer nodes' permission then it won't
// even get this far, as the tab will not be accessible.
if ($show == 'user_only') {
$query
->condition('n.uid', $uid, '=');
// Get user account for use later.
$user = user_load($uid);
}
$query = $query
->extend('TableSort')
->orderByHeader($header);
$result = $query
->execute();
$destination = drupal_get_destination();
$rows = array();
foreach ($result as $node) {
// Check the access allowed on this node.
$can_edit = node_access('update', $node);
$can_delete = node_access('delete', $node);
// Set the operations depending on whether the node is valid or corrupt.
$ops = array();
if ($node->type) {
// Node type is present so this indicates a valid join with the node
// table. Provide regular operations to edit and delete the node.
if ($can_edit) {
$ops[] = l(t('edit'), 'node/' . $node->nid . '/edit', array(
'query' => $destination,
));
}
if ($can_delete) {
$ops[] = l(t('delete'), 'node/' . $node->nid . '/delete', array(
'query' => $destination,
));
}
}
else {
// There was no matching row in the node table. Provide a special link to
// delete the row from the Scheduler table.
if ($can_delete) {
$ops[] = l(t('delete'), 'admin/content/scheduler/delete/' . $node->nid, array(
'query' => $destination,
));
}
}
$rows[] = array(
$node->title ? l($node->title, "node/{$node->nid}") : t('Missing data for node @nid', array(
'@nid' => $node->nid,
)),
$node->type ? check_plain(node_type_get_name($node)) : '',
$node->type ? theme('username', array(
'account' => $node,
)) : '',
$node->type ? $node->status ? t('Published') : t('Unpublished') : '',
$node->publish_on ? format_date($node->publish_on) : ' ',
$node->unpublish_on ? format_date($node->unpublish_on) : ' ',
implode(' ', $ops),
);
}
if (count($rows) && ($pager = theme('pager'))) {
$rows[] = array(
array(
'data' => $pager,
'colspan' => count($rows['0']),
),
);
}
$build['scheduler_list'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $show == 'user_only' ? t('There are no scheduled nodes for @username.', array(
'@username' => $user->name,
)) : t('There are no scheduled nodes.'),
);
return $build;
}