You are here

function nodequeue_views_tables in Nodequeue 5.2

Same name and namespace in other branches
  1. 5 nodequeue.module \nodequeue_views_tables()

Implementation of hook_views_tables()

File

./nodequeue.views.inc, line 11
nodequeue.views.inc Provides support for the Views module.

Code

function nodequeue_views_tables() {
  $tables['nodequeue_nodes'] = array(
    "name" => "nodequeue_nodes",
    "join" => array(
      "left" => array(
        "table" => "node",
        "field" => "nid",
      ),
      "right" => array(
        "field" => "nid",
      ),
    ),
    "fields" => array(
      'timestamp' => array(
        'name' => t('NodeQueue: Timestamp'),
        'sortable' => true,
        'handler' => views_handler_field_dates(),
        'option' => 'string',
        'help' => t('Display the time the node was added to a given node queue.') . ' ' . t('The option field may be used to specify the custom date format as it\'s required by the date() function or if "as time ago" has been chosen to customize the granularity of the time interval.'),
      ),
      'ajaxtoggle' => array(
        'name' => t('NodeQueue: AJAX Add/Remove Link'),
        'handler' => 'nodequeue_views_ajax_link',
        'notafield' => true,
      ),
      'nodequeue_link' => array(
        'name' => t('NodeQueue: Link to nodequeue tab'),
        'sortable' => false,
        'notafield' => TRUE,
        'handler' => 'nodequeue_views_tab_link',
        'option' => 'string',
        'help' => t('Display a link to the nodequeue tab for the node.  Enter the text of this link into the option field; if blank the default "Node queues" will be used.'),
      ),
    ),
    "filters" => array(
      "qid" => array(
        'name' => t("NodeQueue: Queue"),
        'value' => array(
          '#type' => 'select',
          '#multiple' => TRUE,
          '#options' => 'nodequeue_handler_queuelist',
          '#simple_queues' => TRUE,
        ),
        'operator' => 'views_handler_operator_andor',
        'help' => t('Filter the view to a specific Node Queue. This only applies to queues with a single subqueue.'),
      ),
      "position" => array(
        'name' => t("NodeQueue: Queue Position"),
        'field' => 'position',
        'operator' => 'views_handler_operator_gtlt',
        'help' => t('Filter by where in the queue an item is.'),
      ),
      "timestamp" => array(
        'name' => t('NodeQueue: Queue Timestamp'),
        'operator' => 'views_handler_operator_gtlt',
        'value' => views_handler_filter_date_value_form(),
        'handler' => 'views_handler_filter_timestamp',
        'option' => 'string',
        'help' => t('This filter allows nodes to be filtered by the time they were added to a given NodeQueue.') . ' ' . views_t_strings('filter date'),
      ),
      "exclusion" => array(
        'name' => t('NodeQueue: Not in a queue'),
        'operator' => array(
          'IS' => t('is'),
        ),
        'value' => array(
          '#type' => 'select',
          '#options' => 'nodequeue_handler_queuelist',
          '#all_ok' => TRUE,
        ),
        'field' => 'qid',
        'handler' => 'nodequeue_handler_filter_exclusion',
        'help' => t('This filter allows nodes to be filtered that do not belong to any node queue, or do not belong to a particular node queue.'),
      ),
    ),
    "sorts" => array(
      "position" => array(
        'name' => t("NodeQueue: Queue Position"),
        'field' => 'position',
        'help' => t('When sorting by queue position, be sure the view is filtered to a single queue or the sort will not work very well.'),
      ),
      'timestamp' => array(
        'name' => t('NodeQueue: Timestamp'),
        'handler' => 'views_handler_sort_date',
        'option' => views_handler_sort_date_options(),
        'help' => t('Sort by the time the node was added to a node queue.'),
      ),
    ),
  );
  foreach (nodequeue_load_queues(nodequeue_get_all_qids(NULL)) as $queue) {
    if ($queue->subqueues > 1) {
      $tables['nodequeue_nodes']['filters']["qid_{$queue->qid}"] = array(
        'name' => t("NodeQueue: Subqueues for @queue", array(
          '@queue' => $queue->title,
        )),
        'field' => 'qid',
        'value' => array(
          '#type' => 'select',
          '#options' => 'nodequeue_handler_queuelist',
          '#qid' => $queue->qid,
        ),
        'operator' => 'views_handler_operator_andor',
        'help' => t('Filter the view to a specific Node Queue.'),
      );
    }
    else {
      $tables['nodequeue_nodes_' . $queue->qid] = array(
        "name" => "nodequeue_nodes",
        "join" => array(
          "left" => array(
            "table" => "node",
            "field" => "nid",
          ),
          "right" => array(
            "field" => "nid",
          ),
          'extra' => array(
            'qid' => $queue->qid,
          ),
        ),
        "sorts" => array(
          "position" => array(
            'name' => t("NodeQueue: Queue Position in @queue", array(
              '@queue' => $queue->title,
            )),
            'field' => 'position',
            'help' => t('Sort by the position of the node in a given queue. Use this only if, for some reason, you are filtering in such a way that you are including nodes from multiple queues; otherwise use the simpler "NodeQueue: Queue Position" filter.'),
          ),
        ),
      );
    }
  }
  $tables['nodequeue_subqueue'] = array(
    "name" => "nodequeue_subqueue",
    "join" => array(
      "left" => array(
        "table" => "nodequeue_nodes",
        "field" => "sqid",
      ),
      "right" => array(
        "field" => "sqid",
      ),
    ),
  );
  $tables['nodequeue_queue'] = array(
    "name" => "nodequeue_queue",
    "join" => array(
      "left" => array(
        "table" => "nodequeue_subqueue",
        "field" => "qid",
      ),
      "right" => array(
        "field" => "qid",
      ),
    ),
  );
  return $tables;
}