Go to the documentation of this file.00001 <?php
00013 class views_handler_argument_numeric extends views_handler_argument {
00018 var $operator;
00019
00024 var $value;
00025
00026 function option_definition() {
00027 $options = parent::option_definition();
00028
00029 $options['break_phrase'] = array('default' => FALSE);
00030 $options['not'] = array('default' => FALSE);
00031
00032 return $options;
00033 }
00034
00035 function options_form(&$form, &$form_state) {
00036 parent::options_form($form, $form_state);
00037
00038
00039 $form['break_phrase'] = array(
00040 '#type' => 'checkbox',
00041 '#title' => t('Allow multiple values'),
00042 '#description' => t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'),
00043 '#default_value' => !empty($this->options['break_phrase']),
00044 '#fieldset' => 'more',
00045 );
00046
00047 $form['not'] = array(
00048 '#type' => 'checkbox',
00049 '#title' => t('Exclude'),
00050 '#description' => t('If selected, the numbers entered for the filter will be excluded rather than limiting the view.'),
00051 '#default_value' => !empty($this->options['not']),
00052 '#fieldset' => 'more',
00053 );
00054 }
00055
00056 function title() {
00057 if (!$this->argument) {
00058 return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
00059 }
00060
00061 if (!empty($this->options['break_phrase'])) {
00062 views_break_phrase($this->argument, $this);
00063 }
00064 else {
00065 $this->value = array($this->argument);
00066 $this->operator = 'or';
00067 }
00068
00069 if (empty($this->value)) {
00070 return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
00071 }
00072
00073 if ($this->value === array(-1)) {
00074 return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input');
00075 }
00076
00077 return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query());
00078 }
00079
00085 function title_query() {
00086 return $this->value;
00087 }
00088
00089 function query($group_by = FALSE) {
00090 $this->ensure_my_table();
00091
00092 if (!empty($this->options['break_phrase'])) {
00093 views_break_phrase($this->argument, $this);
00094 }
00095 else {
00096 $this->value = array($this->argument);
00097 }
00098
00099 $placeholder = $this->placeholder();
00100 $null_check = empty($this->options['not']) ? '' : "OR $this->table_alias.$this->real_field IS NULL";
00101
00102 if (count($this->value) > 1) {
00103 $operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
00104 $this->query->add_where_expression(0, "$this->table_alias.$this->real_field $operator($placeholder) $null_check", array($placeholder => $this->value));
00105 }
00106 else {
00107 $operator = empty($this->options['not']) ? '=' : '!=';
00108 $this->query->add_where_expression(0, "$this->table_alias.$this->real_field $operator $placeholder $null_check", array($placeholder => $this->argument));
00109 }
00110 }
00111
00112 function get_sort_name() {
00113 return t('Numerical', array(), array('context' => 'Sort order'));
00114 }
00115 }