You are here

nodequeue_handler_relationship_nodequeue.inc in Nodequeue 7.3

Specialized relationship handler to add nodequeues.

File

includes/views/nodequeue_handler_relationship_nodequeue.inc
View source
<?php

/**
 * @file
 * Specialized relationship handler to add nodequeues.
 */
class nodequeue_handler_relationship_nodequeue extends views_handler_relationship {

  /**
   * Init handler to let relationships live on tables other than
   * the table they operate on.
   */
  function init(&$view, &$options) {
    parent::init($view, $options);
  }
  function option_definition() {
    $options = parent::option_definition();
    $options['limit']['default'] = FALSE;
    $options['queues']['default'] = array();
    return $options;
  }

  /**
   * Default options form that provides the label widget that all fields
   * should have.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['limit'] = array(
      '#type' => 'checkbox',
      '#title' => t('Limit to one or more queues (recommended)'),
      '#default_value' => $this->options['limit'],
    );
    $options = array();
    $queues = nodequeue_load_queues(nodequeue_get_all_queues(0, 0, TRUE), TRUE);
    foreach ($queues as $queue) {
      $options[$queue->name] = $queue->title;
    }
    $form['queues'] = array(
      '#prefix' => '<div><div id="edit-options-queues">',
      '#suffix' => '</div></div>',
      '#type' => 'checkboxes',
      '#title' => t('Queues'),
      '#options' => $options,
      '#default_value' => $this->options['queues'],
      '#process' => array(
        'form_process_checkboxes',
        'ctools_dependent_process',
      ),
      '#dependency' => array(
        'edit-options-limit' => array(
          TRUE,
        ),
      ),
    );
  }

  /**
   * Validate the options form.
   */
  function options_validate(&$form, &$form_state) {
    parent::options_validate($form, $form_state);

    // Check that at least on queue has been selected.
    $options = $form_state['values']['options'];
    if ($options['limit'] && empty($options['queues'])) {
      form_set_error('queues', t('You must check at least one queue.'));
    }
  }

  /**
   * Called to implement a relationship in a query.
   */
  function query() {

    // Figure out what base table this relationship brings to the party.
    $join = new views_join();
    $join->definition = array(
      'table' => 'nodequeue_nodes',
      'field' => 'nid',
      'left_table' => 'node',
      'left_field' => 'nid',
    );
    if (!empty($this->options['required'])) {
      $join->definition['type'] = 'INNER';
    }
    if (!empty($this->options['limit'])) {
      $queues = array_keys(array_filter($this->options['queues']));
      $join->definition['extra'] = array(
        array(
          'field' => 'name',
          'value' => $queues,
        ),
      );
    }
    $join
      ->construct();
    $alias = $join->definition['table'] . '_' . $join->definition['left_table'];
    $this->alias = $this->query
      ->add_relationship($alias, $join, 'nodequeue_nodes', $this->relationship);
  }

}

Classes

Namesort descending Description
nodequeue_handler_relationship_nodequeue @file Specialized relationship handler to add nodequeues.