You are here

function nodequeue_view_queues in Nodequeue 7.3

Same name and namespace in other branches
  1. 5.2 nodequeue.module \nodequeue_view_queues()
  2. 6.2 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
Implements hook_menu().

File

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

Code

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

  // Fetch all of the queues.
  $queues = nodequeue_load_queues(nodequeue_get_all_queues(25));
  foreach ($queues as $queue) {
    if (!nodequeue_queue_access($queue)) {
      unset($queues[$queue->name]);
    }
  }
  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);
  $queue_names = 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 name so we can display
    // the number of nodes in the subqueue.
    if ($queue->subqueues == 1) {
      $queue_names[] = $queue->name;
    }
    $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($queue_names);

  // Relate all the subqueues we loaded back to our queues.
  foreach ($subqueues as $subqueue) {
    if (nodequeue_api_subqueue_access($subqueue, NULL, $queues[$subqueue->name])) {
      $queues[$subqueue->name]->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 name.
    }
    else {
      array_multisort($sort_primary, $sort_direction['asc'], $sort_secondary, $queues);

      // Re-indexes array keys; key no longer equals name.
    }
  }
  $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['view'] = l(t('View'), "admin/structure/nodequeue/{$queue->name}/view/" . $queue->subqueue->sqid);
    }
    else {
      $operations['view'] = l(t('View'), "admin/structure/nodequeue/{$queue->name}/view");
    }
    if (user_access('administer nodequeue')) {
      $operations['edit'] = l(t('Edit'), "admin/structure/nodequeue/{$queue->name}/edit");
      $operations['delete'] = l(t('Delete'), "admin/structure/nodequeue/{$queue->name}/delete");
    }
    $rows[] = array(
      array(
        'class' => array(
          'nodequeue-title',
        ),
        'data' => check_plain($queue->title),
      ),
      array(
        'class' => array(
          'nodequeue-max-nodes',
        ),
        'data' => $queue->size == 0 ? t('Infinite') : $queue->size,
      ),
      array(
        'class' => array(
          'nodequeue-subqueues',
        ),
        'data' => $sub_text,
      ),
      array(
        'class' => array(
          'nodequeue-operation',
        ),
        'data' => implode(' | ', $operations),
      ),
    );
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  $output .= theme('pager', array(
    'tags' => NULL,
  ));
  return $output;
}