nodequeue_handler_relationship_nodequeue.inc

Specialized relationship handler to add nodequeues.

Classes

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

File

sites/all/modules/local_contrib/nodequeue/includes/views/nodequeue_handler_relationship_nodequeue.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Specialized relationship handler to add nodequeues.
  5. */
  6. class nodequeue_handler_relationship_nodequeue extends views_handler_relationship {
  7. /**
  8. * Init handler to let relationships live on tables other than
  9. * the table they operate on.
  10. */
  11. function init(&$view, &$options) {
  12. parent::init($view, $options);
  13. // Tranlate an older setting which was using qids instead of machine names.
  14. if (!empty($options['qids'])) {
  15. $map = array_flip(nodequeue_get_qid_map());
  16. foreach ($options['qids'] as $key => $value) {
  17. $this->options['names'][$map[$key]] = ($value) ? $map[$key] : 0;
  18. }
  19. unset($this->options['qids']);
  20. }
  21. }
  22. function option_definition() {
  23. $options = parent::option_definition();
  24. $options['limit']['default'] = FALSE;
  25. $options['names']['default'] = array();
  26. return $options;
  27. }
  28. /**
  29. * Default options form that provides the label widget that all fields
  30. * should have.
  31. */
  32. function options_form(&$form, &$form_state) {
  33. parent::options_form($form, $form_state);
  34. $form['limit'] = array(
  35. '#type' => 'checkbox',
  36. '#title' => t('Limit to one or more queues (recommended)'),
  37. '#default_value' => $this->options['limit'],
  38. );
  39. $options = array();
  40. $queues = nodequeue_load_queues(nodequeue_get_all_qids(0, 0, TRUE), TRUE);
  41. foreach ($queues as $queue) {
  42. $options[$queue->name] = $queue->title;
  43. }
  44. $form['names'] = array(
  45. '#prefix' => '<div><div id="edit-options-names">',
  46. '#suffix' => '</div></div>',
  47. '#type' => 'checkboxes',
  48. '#title' => t('Queues'),
  49. '#options' => $options,
  50. '#default_value' => $this->options['names'],
  51. '#process' => array('form_process_checkboxes', 'ctools_dependent_process'),
  52. '#dependency' => array('edit-options-limit' => array(TRUE)),
  53. );
  54. }
  55. /**
  56. * Called to implement a relationship in a query.
  57. */
  58. function query() {
  59. // Figure out what base table this relationship brings to the party.
  60. $join = new views_join();
  61. $join->definition = array(
  62. 'table' => 'nodequeue_nodes',
  63. 'field' => 'nid',
  64. 'left_table' => 'node',
  65. 'left_field' => 'nid',
  66. );
  67. if (!empty($this->options['required'])) {
  68. $join->definition['type'] = 'INNER';
  69. }
  70. if (!empty($this->options['limit'])) {
  71. $names = array_keys(array_filter($this->options['names']));
  72. $qids = array();
  73. $map = nodequeue_get_qid_map();
  74. foreach ($names as $name) {
  75. if (isset($map[$name])) {
  76. $qids[] = $map[$name];
  77. }
  78. }
  79. $join->definition['extra'] = array(array(
  80. 'field' => 'qid',
  81. 'value' => $qids,
  82. ));
  83. }
  84. $join->construct();
  85. $alias = $join->definition['table'] . '_' . $join->definition['left_table'];
  86. $this->alias = $this->query->add_relationship($alias, $join, 'nodequeue_nodes', $this->relationship);
  87. }
  88. }