/[drupal]/contributions/modules/views/handlers/views_handler_sort_date.inc
ViewVC logotype

Contents of /contributions/modules/views/handlers/views_handler_sort_date.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Sep 3 19:21:28 2008 UTC (14 months, 3 weeks ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, DRUPAL-6--2-6, DRUPAL-6--2-5, DRUPAL-6--2-4, DRUPAL-6--2-3, DRUPAL-6--2-2, DRUPAL-6--2-1, DRUPAL-6--2-0, DRUPAL-6--3-0-ALPHA1, DRUPAL-6--2-0-RC5, DRUPAL-6--2-0-RC4, DRUPAL-6--2-0-RC3, DRUPAL-6--2-0-RC2, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3, DRUPAL-7--3
File MIME type: text/x-php
Major re-organization of handlers. PLEASE NOTE: This drastically affected the Views module API and until modules are updated to match, they will stop working. Efforts have been made to ensure that this won't cause your site to crash, but that's partly up to the individual module as well.
1 <?php
2 // $Id$
3
4 /**
5 * Basic sort handler for dates.
6 *
7 * This handler enables granularity, which is the ability to make dates
8 * equivalent based upon nearness.
9 *
10 * @ingroup views_sort_handlers
11 */
12 class views_handler_sort_date extends views_handler_sort {
13 function option_definition() {
14 $options = parent::option_definition();
15
16 $options['granularity'] = array('default' => 'second');
17
18 return $options;
19 }
20
21 function options_form(&$form, &$form_state) {
22 parent::options_form($form, $form_state);
23
24 $form['granularity'] = array(
25 '#type' => 'radios',
26 '#title' => t('Granularity'),
27 '#options' => array(
28 'second' => t('Second'),
29 'minute' => t('Minute'),
30 'hour' => t('Hour'),
31 'day' => t('Day'),
32 'month' => t('Month'),
33 'year' => t('Year'),
34 ),
35 '#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.'),
36 '#default_value' => $this->options['granularity'],
37 );
38 }
39
40 /**
41 * Called to add the sort to a query.
42 */
43 function query() {
44 $this->ensure_my_table();
45 switch ($this->options['granularity']) {
46 case 'second':
47 default:
48 $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
49 return;
50 case 'minute':
51 $formula = views_date_sql_format('YmdHi', "$this->table_alias.$this->real_field");
52 break;
53 case 'hour':
54 $formula = views_date_sql_format('YmdH', "$this->table_alias.$this->real_field");
55 break;
56 case 'day':
57 $formula = views_date_sql_format('Ymd', "$this->table_alias.$this->real_field");
58 break;
59 case 'month':
60 $formula = views_date_sql_format('Ym', "$this->table_alias.$this->real_field");
61 break;
62 case 'year':
63 $formula = views_date_sql_format('Y', "$this->table_alias.$this->real_field");
64 break;
65 }
66
67 // Add the field.
68 $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']);
69 }
70 }

  ViewVC Help
Powered by ViewVC 1.1.2