/[drupal]/contributions/modules/station/schedule/views/station_schedule_handler_filter_time.inc
ViewVC logotype

Diff of /contributions/modules/station/schedule/views/station_schedule_handler_filter_time.inc

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

revision 1.1, Mon Sep 21 17:43:32 2009 UTC revision 1.2, Tue Sep 22 23:47:56 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: views_handler_filter_upload_fid.inc,v 1.1 2008/09/03 19:21:30 merlinofchaos Exp $  // $Id: station_schedule_handler_filter_time.inc,v 1.1 2009/09/21 17:43:32 drewish Exp $
3    
4  class station_schedule_handler_filter_time extends views_handler_filter_numeric {  class station_schedule_handler_filter_time extends views_handler_filter_numeric {
5    // Hide a bunch of the operators.    // Hide a bunch of the operators.
# Line 25  class station_schedule_handler_filter_ti Line 25  class station_schedule_handler_filter_ti
25        '#title' => 'Mode',        '#title' => 'Mode',
26        '#options' => array(        '#options' => array(
27          'now' => t('Current time'),          'now' => t('Current time'),
28            'today' => t('Current day'),
29          'minutes' => t('Specific time'),          'minutes' => t('Specific time'),
30        ),        ),
31        '#default_value' => $this->value['mode'],        '#default_value' => $this->value['mode'],
# Line 37  class station_schedule_handler_filter_ti Line 38  class station_schedule_handler_filter_ti
38        '#title' => empty($form_state['exposed']) ? t('Minute offset') : '',        '#title' => empty($form_state['exposed']) ? t('Minute offset') : '',
39        '#size' => 10,        '#size' => 10,
40        '#default_value' => $this->value['offset'],        '#default_value' => $this->value['offset'],
41        '#description' => t('Offset in minutes, e.g. -60 for one hour ago, 1440 for one day from now.'),        '#description' => t('Offset in minutes, e.g. -60 for one hour previous, 1440 for one day in the future.'),
42        '#process' => array('views_process_dependency'),        '#process' => array('views_process_dependency'),
43        '#dependency' => array('radio:options[value][mode]' => array('now')),        '#dependency' => array('radio:options[value][mode]' => array('now', 'today')),
44      );      );
45      $form['value']['value'] = array(      $form['value']['value'] = array(
46        '#type' => 'station_schedule_daytime',        '#type' => 'station_schedule_daytime',
# Line 61  class station_schedule_handler_filter_ti Line 62  class station_schedule_handler_filter_ti
62            $output .= t('Now');            $output .= t('Now');
63          }          }
64          elseif ($this->value['offset'] < 0) {          elseif ($this->value['offset'] < 0) {
65            $output .= t('Now minus @offset minutes', array('@offset' => (int) $this->value['offset']));            $output .= t('Now -@offset', array('@offset' => format_interval($this->value['offset'] * 60)));
66          }          }
67          else {          else {
68            $output .= t('Now plus @offset minutes', array('@offset' => (int) $this->value['offset']));            $output .= t('Now +@offset', array('@offset' => format_interval($this->value['offset'] * 60)));
69            }
70            break;
71    
72          case 'today':
73            if (empty($this->value['offset'])) {
74              $output .= t('Midnight today');
75            }
76            elseif ($this->value['offset'] < 0) {
77              $output .= t('Midnight today -@offset', array('@offset' => format_interval($this->value['offset'] * 60)));
78            }
79            else {
80              $output .= t('Midnight today +@offset', array('@offset' => format_interval($this->value['offset'] * 60)));
81          }          }
82          break;          break;
83    
# Line 80  class station_schedule_handler_filter_ti Line 93  class station_schedule_handler_filter_ti
93    
94    function query() {    function query() {
95      $this->ensure_my_table();      $this->ensure_my_table();
96    
97      $field = "$this->table_alias.$this->real_field";      $field = "$this->table_alias.$this->real_field";
98        $offset = (int) $this->value['offset'];
99        $min_in_day = MINUTES_IN_DAY;
100    
     $minutes_in_week = MINUTES_IN_WEEK;  
101      $info = $this->operators();      $info = $this->operators();
102      if (!empty($info[$this->operator]['method'])) {      if (!empty($info[$this->operator]['method'])) {
103        switch ($this->value['mode']) {        $formula = $field . ' ' . $this->operator . ' ';
104        case 'now':        $params = array();
105          $offset = (int) $this->value['offset'];        $tokens = array(
106            'now' => '***STATION_CURRENT_MINUTE***',
107            'today' => '***STATION_CURRENT_DAY_IN_MINUTES***',
108          );
109          if (isset($tokens[$this->value['mode']])) {
110          if (empty($offset)) {          if (empty($offset)) {
111            $this->query->add_where($this->options['group'], "$field $this->operator ***CURRENT_STATION_MINUTE***");            $formula .= $tokens[$this->value['mode']];
112          }          }
113          else {          else {
114            $this->query->add_where($this->options['group'], "$field $this->operator (***CURRENT_STATION_MINUTE*** + %d + {$minutes_in_week}) %% {$minutes_in_week}", $offset);            // If there's an offset we need to make sure that it wraps at the
115              // ends of the week.
116              $minutes_in_week = MINUTES_IN_WEEK;
117              $formula .= "({$tokens[$this->value['mode']]} + %d + {$minutes_in_week}) %% {$minutes_in_week}";
118              $params[] = $offset;
119          }          }
         break;  
   
       case 'minutes':  
         $this->query->add_where($this->options['group'], "$field $this->operator %d", $this->value['value']);  
         break;  
120        }        }
121          else if ('at' == $this->value['mode']) {
122            $formula .= '%d';
123            $params[] = $this->value['value'];
124          }
125          else {
126            // Unknown.
127            return;
128          }
129          $this->query->add_where($this->options['group'], $formula, $params);
130      }      }
131      return;      return;
132    }    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2