| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: views_handler_argument_string.inc,v 1.5 2009/06/25 21:58:17 merlinofchaos Exp $ 3 4 /** 5 * Basic argument handler to implement string arguments that may have length 6 * limits. 7 * 8 * @ingroup views_argument_handlers 9 */ 10 class views_handler_argument_string extends views_handler_argument { 11 function init(&$view, &$options) { 12 parent::init($view, $options); 13 if (!empty($this->definition['many to one'])) { 14 $this->helper = new views_many_to_one_helper($this); 15 16 // Ensure defaults for these, during summaries and stuff: 17 $this->operator = 'or'; 18 $this->value = array(); 19 } 20 } 21 22 function option_definition() { 23 $options = parent::option_definition(); 24 25 $options['glossary'] = array('default' => FALSE); 26 $options['limit'] = array('default' => 0); 27 $options['case'] = array('default' => 'none'); 28 $options['path_case'] = array('default' => 'none'); 29 $options['transform_dash'] = array('default' => FALSE); 30 31 if (!empty($this->definition['many to one'])) { 32 $options['add_table'] = array('default' => FALSE); 33 $options['require_value'] = array('default' => FALSE); 34 } 35 36 return $options; 37 } 38 39 function options_form(&$form, &$form_state) { 40 parent::options_form($form, $form_state); 41 42 $form['glossary'] = array( 43 '#type' => 'checkbox', 44 '#title' => t('Glossary mode'), 45 '#description' => t('Glossary mode applies a limit to the number of characters used in the argument, which allows the summary view to act as a glossary.'), 46 '#default_value' => $this->options['glossary'], 47 ); 48 49 $form['limit'] = array( 50 '#type' => 'textfield', 51 '#title' => t('Character limit'), 52 '#description' => t('How many characters of the argument to filter against. If set to 1, all fields starting with the letter in the argument would be matched.'), 53 '#default_value' => $this->options['limit'], 54 '#process' => array('views_process_dependency'), 55 '#dependency' => array('edit-options-glossary' => array(TRUE)), 56 ); 57 58 $form['case'] = array( 59 '#type' => 'select', 60 '#title' => t('Case'), 61 '#description' => t('When printing the argument result, how to transform the case.'), 62 '#options' => array( 63 'none' => t('No transform'), 64 'upper' => t('Upper case'), 65 'lower' => t('Lower case'), 66 'ucfirst' => t('Capitalize first letter'), 67 'ucwords' => t('Capitalize each word'), 68 ), 69 '#default_value' => $this->options['case'], 70 ); 71 72 $form['path_case'] = array( 73 '#type' => 'select', 74 '#title' => t('Case in path'), 75 '#description' => t('When printing url paths, how to transform the case of the argument. Do not use this unless with Postgres as it uses case sensitive comparisons.'), 76 '#options' => array( 77 'none' => t('No transform'), 78 'upper' => t('Upper case'), 79 'lower' => t('Lower case'), 80 'ucfirst' => t('Capitalize first letter'), 81 'ucwords' => t('Capitalize each word'), 82 ), 83 '#default_value' => $this->options['path_case'], 84 ); 85 86 $form['transform_dash'] = array( 87 '#type' => 'checkbox', 88 '#title' => t('Transform spaces to dashes in URL'), 89 '#default_value' => $this->options['transform_dash'], 90 ); 91 92 if (!empty($this->definition['many to one'])) { 93 $form['add_table'] = array( 94 '#type' => 'checkbox', 95 '#title' => t('Allow multiple arguments to work together.'), 96 '#description' => t('If selected, multiple instances of this argument can work together, as though multiple terms were supplied to the same argument. This setting is not compatible with the "Reduce duplicates" setting.'), 97 '#default_value' => !empty($this->options['add_table']), 98 ); 99 100 $form['require_value'] = array( 101 '#type' => 'checkbox', 102 '#title' => t('Do not display items with no value in summary'), 103 '#default_value' => !empty($this->options['require_value']), 104 ); 105 } 106 } 107 108 /** 109 * Build the summary query based on a string 110 */ 111 function summary_query() { 112 if (empty($this->definition['many to one'])) { 113 $this->ensure_my_table(); 114 } 115 else { 116 $this->table_alias = $this->helper->summary_join(); 117 } 118 119 if (empty($this->options['glossary'])) { 120 // Add the field. 121 $this->base_alias = $this->name_alias = $this->query->add_field($this->table_alias, $this->real_field); 122 $this->query->set_count_field($this->table_alias, $this->real_field); 123 } 124 else { 125 // Add the field. 126 $formula = $this->get_formula(); 127 $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field . '_truncated'); 128 $this->query->set_count_field(NULL, $formula, $this->field, $this->field . '_truncated'); 129 } 130 131 return $this->summary_basics(FALSE); 132 } 133 134 /** 135 * Get the formula for this argument. 136 * 137 * $this->ensure_my_table() MUST have been called prior to this. 138 */ 139 function get_formula() { 140 return "SUBSTR($this->table_alias.$this->real_field, 1, " . intval($this->options['limit']) . ")"; 141 } 142 143 /** 144 * Build the query based upon the formula 145 */ 146 function query() { 147 $argument = $this->argument; 148 if (!empty($this->options['transform_dash'])) { 149 $argument = strtr($argument, '-', ' '); 150 } 151 152 if (!empty($this->definition['many to one'])) { 153 if (!empty($this->options['glossary'])) { 154 $this->helper->formula = TRUE; 155 } 156 $this->value = array($argument); 157 $this->helper->ensure_my_table(); 158 $this->helper->add_filter(); 159 return; 160 } 161 162 $this->ensure_my_table(); 163 if (empty($this->options['glossary'])) { 164 $field = "$this->table_alias.$this->real_field"; 165 } 166 else { 167 $field = $this->get_formula(); 168 } 169 170 $this->query->add_where(0, "$field = '%s'", $argument); 171 } 172 173 function summary_argument($data) { 174 $value = $this->case_transform($data->{$this->base_alias}, 'path_case'); 175 if (!empty($this->options['transform_dash'])) { 176 $value = strtr($value, ' ', '-'); 177 } 178 return $value; 179 } 180 181 function case_transform($string, $option) { 182 global $multibyte; 183 184 switch ($this->options[$option]) { 185 default: 186 return $string; 187 case 'upper': 188 return drupal_strtoupper($string); 189 case 'lower': 190 return drupal_strtolower($string); 191 case 'ucfirst': 192 return drupal_strtoupper(drupal_substr($string, 0, 1)) . drupal_substr($string, 1); 193 case 'ucwords': 194 if ($multibyte == UNICODE_MULTIBYTE) { 195 return mb_convert_case($string, MB_CASE_TITLE); 196 } else { 197 return ucwords($string); 198 } 199 } 200 } 201 202 function title() { 203 $title = $this->case_transform($this->argument, 'case'); 204 if (!empty($this->options['transform_dash'])) { 205 $title = strtr($title, '-', ' '); 206 } 207 208 return check_plain($title); 209 } 210 211 function summary_name($data) { 212 return $this->case_transform(parent::summary_name($data), 'case'); 213 } 214 215 } 216
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |