Newer
Older
Earl Miles
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
// $Id$
/**
* @file
* Contains the numeric argument handler.
*/
/**
* Basic argument handler for arguments that are numeric. Incorporates
* break_phrase.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_numeric extends views_handler_argument {
function option_definition() {
$options = parent::option_definition();
$options['break_phrase'] = array('default' => FALSE);
$options['not'] = array('default' => FALSE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// allow + for or, , for and
$form['break_phrase'] = array(
'#type' => 'checkbox',
'#title' => t('Allow multiple terms per argument.'),
'#description' => t('If selected, users can enter multiple arguments in the form of 1+2+3 or 1,2,3.'),
'#default_value' => !empty($this->options['break_phrase']),
);
$form['not'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude the argument'),
'#description' => t('If selected, the numbers entered in the argument will be excluded rather than limiting the view.'),
'#default_value' => !empty($this->options['not']),
);
}
function title() {
if (!$this->argument) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
}
if (!empty($this->options['break_phrase'])) {
views_break_phrase($this->argument, $this);
}
else {
$this->value = array($this->argument);
$this->operator = 'or';
}
if (empty($this->value)) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
}
if ($this->value === array(-1)) {
return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input');
}
return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query());
}
/**
* Override for specific title lookups.
*/
function title_query() {
return $this->value;
}
function query() {
$this->ensure_my_table();
if (!empty($this->options['break_phrase'])) {
views_break_phrase($this->argument, $this);
}
else {
$this->value = array($this->argument);
}
if (count($this->value) > 1) {
$operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$this->query->add_where(0, "$this->table_alias.$this->real_field $operator ($placeholders)", $this->value);
}
else {
$operator = empty($this->options['not']) ? '=' : '!=';
$this->query->add_where(0, "$this->table_alias.$this->real_field $operator %d", $this->argument);
}
}
}