You are here

function nodequeue_view_queues in Nodequeue 6.2

Same name and namespace in other branches
  1. 5.2 nodequeue.module \nodequeue_view_queues()
  2. 7.3 includes/nodequeue.admin.inc \nodequeue_view_queues()
  3. 7.2 includes/nodequeue.admin.inc \nodequeue_view_queues()

Display a list of queues and their status for the administrator.

1 string reference to 'nodequeue_view_queues'
nodequeue_menu in ./nodequeue.module
Implementation of hook_menu

File

includes/nodequeue.admin.inc, line 215
Admin page callbacks for the nodequeue module.

Code

function nodequeue_view_queues() {
  $output = '';
  if (module_exists('advanced_help')) {
    $output .= '<p>' . theme('advanced_help_topic', 'nodequeue', 'about', 'icon') . '&nbsp;' . theme('advanced_help_topic', 'nodequeue', 'about', t('Click here for information about this module')) . '</p>';
  }

  // Fetch all of the queues.
  $queues = nodequeue_load_queues(nodequeue_get_all_qids(25));
  foreach ($queues as $queue) {
    if (!nodequeue_queue_access($queue)) {
      unset($queues[$queue->qid]);
    }
  }
  if (empty($queues)) {
    return $output . t('No nodequeues exist.');
  }
  $header = array(
    array(
      'data' => t('Title'),
      'field' => 'title',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Max nodes'),
      'field' => 'size',
    ),
    array(
      'data' => t('Subqueues'),
      'field' => 'subqueues',
    ),
    array(
      'data' => t('Operation'),
    ),
  );
  $table_sort = tablesort_init($header);
  $qids = array();
  $sort_primary = array();
  $sort_secondary = array();
  $sort_direction_regular = array(
    'asc' => SORT_ASC,
    'desc' => SORT_DESC,
  );
  $sort_direction_reverse = array(
    'asc' => SORT_DESC,
    'desc' => SORT_ASC,
  );
  foreach ($queues as $queue) {

    // If a queue has only one subqueue, store the qid so we can display
    // the number of nodes in the subqueue.
    if ($queue->subqueues == 1) {
      $qids[] = $queue->qid;
    }
    $sort_secondary[] = drupal_strtolower($queue->title);
    switch ($table_sort['sql']) {
      case 'title':
      default:
        $sort_primary[] = drupal_strtolower($queue->title);
        $sort_direction = $sort_direction_regular;
        break;
      case 'size':
        $sort_primary[] = $queue->size;
        $sort_direction = $sort_direction_reverse;
        break;
      case 'subqueues':
        $sort_primary[] = $queue->subqueues;
        $sort_direction = $sort_direction_regular;
        break;
    }
  }
  $subqueues = nodequeue_load_subqueues_by_queue($qids);

  // Relate all the subqueues we loaded back to our queues.
  foreach ($subqueues as $subqueue) {
    if (nodequeue_api_subqueue_access($subqueue, NULL, $queues[$subqueue->qid])) {
      $queues[$subqueue->qid]->subqueue = $subqueue;
    }
  }
  if (!empty($table_sort)) {
    if (strtolower($table_sort['sort']) == 'desc') {
      array_multisort($sort_primary, $sort_direction['desc'], $sort_secondary, $queues);

      // Re-indexes array keys; key no longer equals qid.
    }
    else {
      array_multisort($sort_primary, $sort_direction['asc'], $sort_secondary, $queues);

      // Re-indexes array keys; key no longer equals qid.
    }
  }
  $rows = array();
  foreach ($queues as $queue) {
    $operations = array();
    $sub_text = $queue->subqueues;

    // If this queue has only one subqueue.
    if ($sub_text == 1) {
      $sub_text .= " (" . nodequeue_subqueue_size_text($queue->size, $queue->subqueue->count) . ")";
      $operations[] = l(t('View'), "admin/content/nodequeue/{$queue->qid}/view/" . $queue->subqueue->sqid);
    }
    else {
      $operations[] = l(t('View'), "admin/content/nodequeue/{$queue->qid}/view");
    }
    if (user_access('administer nodequeue')) {
      $operations[] = l(t('Edit'), "admin/content/nodequeue/{$queue->qid}/edit");
      $operations[] = l(t('Delete'), "admin/content/nodequeue/{$queue->qid}/delete");
    }
    $rows[] = array(
      array(
        'class' => 'nodequeue-title',
        'data' => check_plain($queue->title),
      ),
      array(
        'class' => 'nodequeue-max-nodes',
        'data' => $queue->size == 0 ? t('Infinite') : $queue->size,
      ),
      array(
        'class' => 'nodequeue-subqueues',
        'data' => $sub_text,
      ),
      array(
        'class' => 'nodequeue-operation',
        'data' => implode(' | ', $operations),
      ),
    );
  }
  $output .= theme('table', $header, $rows);
  $output .= theme('pager', NULL, 25);
  return $output;
}