| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: views_handler_argument_many_to_one.inc,v 1.1.4.2 2010/03/22 20:40:41 merlinofchaos Exp $ 3 /** 4 * An argument handler for use in fields that have a many to one relationship 5 * with the table(s) to the left. This adds a bunch of options that are 6 * reasonably common with this type of relationship. 7 * Definition terms: 8 * - numeric: If true, the field will be considered numeric. Probably should 9 * always be set TRUE as views_handler_argument_string has many to one 10 * capabilities. 11 * - zero is null: If true, a 0 will be handled as empty, so for example 12 * a default argument can be provided or a summary can be shown. 13 * 14 * @ingroup views_argument_handlers 15 */ 16 class views_handler_argument_many_to_one extends views_handler_argument { 17 function init(&$view, &$options) { 18 parent::init($view, $options); 19 $this->helper = new views_many_to_one_helper($this); 20 21 // Ensure defaults for these, during summaries and stuff: 22 $this->operator = 'or'; 23 $this->value = array(); 24 } 25 26 function option_definition() { 27 $options = parent::option_definition(); 28 29 if (!empty($this->definition['numeric'])) { 30 $options['break_phrase'] = array('default' => FALSE); 31 } 32 33 $options['add_table'] = array('default' => FALSE); 34 $options['require_value'] = array('default' => FALSE); 35 36 views_many_to_one_helper::option_definition($options); 37 return $options; 38 } 39 40 function options_form(&$form, &$form_state) { 41 parent::options_form($form, $form_state); 42 43 // allow + for or, , for and 44 if (!empty($this->definition['numeric'])) { 45 $form['break_phrase'] = array( 46 '#type' => 'checkbox', 47 '#title' => t('Allow multiple terms per argument.'), 48 '#description' => t('If selected, users can enter multiple arguments in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'), 49 '#default_value' => !empty($this->options['break_phrase']), 50 ); 51 } 52 53 $form['add_table'] = array( 54 '#type' => 'checkbox', 55 '#title' => t('Allow multiple arguments to work together.'), 56 '#description' => t('If selected, multiple instances of this argument can work together, as though multiple terms were supplied to the same argument. This setting is not compatible with the "Reduce duplicates" setting.'), 57 '#default_value' => !empty($this->options['add_table']), 58 ); 59 60 $form['require_value'] = array( 61 '#type' => 'checkbox', 62 '#title' => t('Do not display items with no value in summary'), 63 '#default_value' => !empty($this->options['require_value']), 64 ); 65 66 $this->helper->options_form($form, $form_state); 67 } 68 69 /** 70 * Override ensure_my_table so we can control how this joins in. 71 * The operator actually has influence over joining. 72 */ 73 function ensure_my_table() { 74 $this->helper->ensure_my_table(); 75 } 76 77 function query() { 78 $empty = FALSE; 79 if (isset($this->definition['zero is null']) && $this->definition['zero is null']) { 80 if (empty($this->argument)) { 81 $empty = TRUE; 82 } 83 } 84 else { 85 if (!isset($this->argument)) { 86 $empty = TRUE; 87 } 88 } 89 if ($empty) { 90 parent::ensure_my_table(); 91 $this->query->add_where(0, "$this->table_alias.$this->real_field IS NULL"); 92 return; 93 } 94 95 if (!empty($this->options['break_phrase'])) { 96 views_break_phrase($this->argument, $this); 97 } 98 else { 99 $this->value = array($this->argument); 100 $this->operator = 'or'; 101 } 102 103 $this->helper->add_filter(); 104 } 105 106 function title() { 107 if (!$this->argument) { 108 return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); 109 } 110 111 if (!empty($this->options['break_phrase'])) { 112 views_break_phrase($this->argument, $this); 113 } 114 else { 115 $this->value = array($this->argument); 116 $this->operator = 'or'; 117 } 118 119 // @todo -- both of these should check definition for alternate keywords. 120 121 if (empty($this->value)) { 122 return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); 123 } 124 125 if ($this->value === array(-1)) { 126 return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input'); 127 } 128 129 return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query()); 130 } 131 132 function summary_query() { 133 $field = $this->table . '.' . $this->field; 134 $join = $this->get_join(); 135 136 if (!empty($this->options['require_value'])) { 137 $join->type = 'INNER'; 138 } 139 140 if (empty($this->options['add_table']) || empty($this->view->many_to_one_tables[$field])) { 141 $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); 142 } 143 else { 144 $this->table_alias = $this->helper->summary_join(); 145 } 146 147 // Add the field. 148 $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field); 149 150 $this->summary_name_field(); 151 152 return $this->summary_basics(); 153 } 154 155 function summary_argument($data) { 156 $value = $data->{$this->base_alias}; 157 if (empty($value)) { 158 $value = 0; 159 } 160 161 return $value; 162 } 163 164 /** 165 * Override for specific title lookups. 166 */ 167 function title_query() { 168 return $this->value; 169 } 170 } 171
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |