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