• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

handlers/views_handler_argument_many_to_one.inc

00001 <?php
00015 class views_handler_argument_many_to_one extends views_handler_argument {
00016   function init(&$view, &$options) {
00017     parent::init($view, $options);
00018     $this->helper = new views_many_to_one_helper($this);
00019 
00020     // Ensure defaults for these, during summaries and stuff:
00021     $this->operator = 'or';
00022     $this->value = array();
00023   }
00024 
00025   function option_definition() {
00026     $options = parent::option_definition();
00027 
00028     if (!empty($this->definition['numeric'])) {
00029       $options['break_phrase'] = array('default' => FALSE);
00030     }
00031 
00032     $options['add_table'] = array('default' => FALSE);
00033     $options['require_value'] = array('default' => FALSE);
00034 
00035     if (isset($this->helper)) {
00036       $this->helper->option_definition($options);
00037     }
00038     else {
00039       $helper = new views_many_to_one_helper($this);
00040       $helper->option_definition($options);
00041     }
00042 
00043     return $options;
00044   }
00045 
00046   function options_form(&$form, &$form_state) {
00047     parent::options_form($form, $form_state);
00048 
00049     // allow + for or, , for and
00050     if (!empty($this->definition['numeric'])) {
00051       $form['break_phrase'] = array(
00052         '#type' => 'checkbox',
00053         '#title' => t('Allow multiple values'),
00054         '#description' => t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'),
00055         '#default_value' => !empty($this->options['break_phrase']),
00056         '#fieldset' => 'more',
00057       );
00058     }
00059 
00060     $form['add_table'] = array(
00061       '#type' => 'checkbox',
00062       '#title' => t('Allow multiple filter values to work together'),
00063       '#description' => t('If selected, multiple instances of this filter can work together, as though multiple values were supplied to the same filter. This setting is not compatible with the "Reduce duplicates" setting.'),
00064       '#default_value' => !empty($this->options['add_table']),
00065       '#fieldset' => 'more',
00066     );
00067 
00068     $form['require_value'] = array(
00069       '#type' => 'checkbox',
00070       '#title' => t('Do not display items with no value in summary'),
00071       '#default_value' => !empty($this->options['require_value']),
00072       '#fieldset' => 'more',
00073     );
00074 
00075     $this->helper->options_form($form, $form_state);
00076   }
00077 
00082   function ensure_my_table() {
00083     $this->helper->ensure_my_table();
00084   }
00085 
00086   function query($group_by = FALSE) {
00087     $empty = FALSE;
00088     if (isset($this->definition['zero is null']) && $this->definition['zero is null']) {
00089       if (empty($this->argument)) {
00090         $empty = TRUE;
00091       }
00092     }
00093     else {
00094       if (!isset($this->argument)) {
00095         $empty = TRUE;
00096       }
00097     }
00098     if ($empty) {
00099       parent::ensure_my_table();
00100       $this->query->add_where(0, "$this->table_alias.$this->real_field", NULL, 'IS NULL');
00101       return;
00102     }
00103 
00104     if (!empty($this->options['break_phrase'])) {
00105       views_break_phrase($this->argument, $this);
00106     }
00107     else {
00108       $this->value = array($this->argument);
00109       $this->operator = 'or';
00110     }
00111 
00112     $this->helper->add_filter();
00113   }
00114 
00115   function title() {
00116     if (!$this->argument) {
00117       return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
00118     }
00119 
00120     if (!empty($this->options['break_phrase'])) {
00121       views_break_phrase($this->argument, $this);
00122     }
00123     else {
00124       $this->value = array($this->argument);
00125       $this->operator = 'or';
00126     }
00127 
00128     // @todo -- both of these should check definition for alternate keywords.
00129 
00130     if (empty($this->value)) {
00131       return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
00132     }
00133 
00134     if ($this->value === array(-1)) {
00135       return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input');
00136     }
00137 
00138     return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query());
00139   }
00140 
00141   function summary_query() {
00142     $field = $this->table . '.' . $this->field;
00143     $join = $this->get_join();
00144 
00145     if (!empty($this->options['require_value'])) {
00146       $join->type = 'INNER';
00147     }
00148 
00149     if (empty($this->options['add_table']) || empty($this->view->many_to_one_tables[$field])) {
00150       $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join);
00151     }
00152     else {
00153       $this->table_alias = $this->helper->summary_join();
00154     }
00155 
00156     // Add the field.
00157     $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
00158 
00159     $this->summary_name_field();
00160 
00161     return $this->summary_basics();
00162   }
00163 
00164   function summary_argument($data) {
00165     $value = $data->{$this->base_alias};
00166     if (empty($value)) {
00167       $value = 0;
00168     }
00169 
00170     return $value;
00171   }
00172 
00176   function title_query() {
00177     return $this->value;
00178   }
00179 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1