| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Basic sort handler for dates. 5 * 6 * This handler enables granularity, which is the ability to make dates 7 * equivalent based upon nearness. 8 * 9 * @ingroup views_sort_handlers 10 */ 11 class views_handler_sort_date extends views_handler_sort { 12 function option_definition() { 13 $options = parent::option_definition(); 14 15 $options['granularity'] = array('default' => 'second'); 16 17 return $options; 18 } 19 20 function options_form(&$form, &$form_state) { 21 parent::options_form($form, $form_state); 22 23 $form['granularity'] = array( 24 '#type' => 'radios', 25 '#title' => t('Granularity'), 26 '#options' => array( 27 'second' => t('Second'), 28 'minute' => t('Minute'), 29 'hour' => t('Hour'), 30 'day' => t('Day'), 31 'month' => t('Month'), 32 'year' => t('Year'), 33 ), 34 '#description' => t('The granularity is the smallest unit to use when determining whether two dates are the same; for example, if the granularity is "Year" then all dates in 1999, regardless of when they fall in 1999, will be considered the same date.'), 35 '#default_value' => $this->options['granularity'], 36 ); 37 } 38 39 /** 40 * Called to add the sort to a query. 41 */ 42 function query() { 43 $this->ensure_my_table(); 44 switch ($this->options['granularity']) { 45 case 'second': 46 default: 47 $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']); 48 return; 49 case 'minute': 50 $formula = views_date_sql_format('YmdHi', "$this->table_alias.$this->real_field"); 51 break; 52 case 'hour': 53 $formula = views_date_sql_format('YmdH', "$this->table_alias.$this->real_field"); 54 break; 55 case 'day': 56 $formula = views_date_sql_format('Ymd', "$this->table_alias.$this->real_field"); 57 break; 58 case 'month': 59 $formula = views_date_sql_format('Ym', "$this->table_alias.$this->real_field"); 60 break; 61 case 'year': 62 $formula = views_date_sql_format('Y', "$this->table_alias.$this->real_field"); 63 break; 64 } 65 66 // Add the field. 67 $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']); 68 } 69 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |