| 1 |
<?php
|
| 2 |
// $Id: views_handler_filter_many_to_one.inc,v 1.1 2008/09/03 19:21:28 merlinofchaos Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Complex filter to handle filtering for many to one relationships,
|
| 6 |
* such as terms (many terms per node) or roles (many roles per user).
|
| 7 |
*
|
| 8 |
* The construct method needs to be overridden to provide a list of options;
|
| 9 |
* alternately, the value_form and admin_summary methods need to be overriden
|
| 10 |
* to provide something that isn't just a select list.
|
| 11 |
*/
|
| 12 |
class views_handler_filter_many_to_one extends views_handler_filter_in_operator {
|
| 13 |
function init(&$view, &$options) {
|
| 14 |
parent::init($view, $options);
|
| 15 |
$this->helper = new views_many_to_one_helper($this);
|
| 16 |
}
|
| 17 |
|
| 18 |
function option_definition() {
|
| 19 |
$options = parent::option_definition();
|
| 20 |
|
| 21 |
$options['operator']['default'] = 'or';
|
| 22 |
$options['value']['default'] = array();
|
| 23 |
|
| 24 |
return $options;
|
| 25 |
}
|
| 26 |
|
| 27 |
function operators() {
|
| 28 |
$operators = array(
|
| 29 |
'or' => array(
|
| 30 |
'title' => t('Is one of'),
|
| 31 |
'short' => t('or'),
|
| 32 |
'short_single' => t('='),
|
| 33 |
'method' => 'op_helper',
|
| 34 |
'values' => 1,
|
| 35 |
'ensure_my_table' => 'helper',
|
| 36 |
),
|
| 37 |
'and' => array(
|
| 38 |
'title' => t('Is all of'),
|
| 39 |
'short' => t('and'),
|
| 40 |
'short_single' => t('='),
|
| 41 |
'method' => 'op_helper',
|
| 42 |
'values' => 1,
|
| 43 |
'ensure_my_table' => 'helper',
|
| 44 |
),
|
| 45 |
'not' => array(
|
| 46 |
'title' => t('Is none of'),
|
| 47 |
'short' => t('not'),
|
| 48 |
'short_single' => t('<>'),
|
| 49 |
'method' => 'op_helper',
|
| 50 |
'values' => 1,
|
| 51 |
'ensure_my_table' => 'helper',
|
| 52 |
),
|
| 53 |
);
|
| 54 |
// if the definition allows for the empty operator, add it.
|
| 55 |
if (!empty($this->definition['allow empty'])) {
|
| 56 |
$operators += array(
|
| 57 |
'empty' => array(
|
| 58 |
'title' => t('Is empty (NULL)'),
|
| 59 |
'method' => 'op_empty',
|
| 60 |
'short' => t('empty'),
|
| 61 |
'values' => 0,
|
| 62 |
),
|
| 63 |
'not empty' => array(
|
| 64 |
'title' => t('Is not empty (NULL)'),
|
| 65 |
'method' => 'op_empty',
|
| 66 |
'short' => t('not empty'),
|
| 67 |
'values' => 0,
|
| 68 |
),
|
| 69 |
);
|
| 70 |
}
|
| 71 |
|
| 72 |
return $operators;
|
| 73 |
}
|
| 74 |
|
| 75 |
var $value_form_type = 'select';
|
| 76 |
function value_form(&$form, &$form_state) {
|
| 77 |
parent::value_form($form, $form_state);
|
| 78 |
|
| 79 |
if (empty($form_state['exposed'])) {
|
| 80 |
$this->helper->options_form($form, $form_state);
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
/**
|
| 85 |
* Override ensure_my_table so we can control how this joins in.
|
| 86 |
* The operator actually has influence over joining.
|
| 87 |
*/
|
| 88 |
function ensure_my_table() {
|
| 89 |
// Defer to helper if the operator specifies it.
|
| 90 |
$info = $this->operators();
|
| 91 |
if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') {
|
| 92 |
return $this->helper->ensure_my_table();
|
| 93 |
}
|
| 94 |
|
| 95 |
return parent::ensure_my_table();
|
| 96 |
}
|
| 97 |
|
| 98 |
function op_helper() {
|
| 99 |
if (empty($this->value)) {
|
| 100 |
return;
|
| 101 |
}
|
| 102 |
$this->helper->add_filter();
|
| 103 |
}
|
| 104 |
}
|