? .git ? station_views.patch ? schedule/views/station_schedule_plugin_argument_validate_day.inc Index: schedule/views/station_schedule.views.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/views/station_schedule.views.inc,v retrieving revision 1.10 diff -u -p -r1.10 station_schedule.views.inc --- schedule/views/station_schedule.views.inc 22 Sep 2009 21:56:21 -0000 1.10 +++ schedule/views/station_schedule.views.inc 22 Sep 2009 23:43:05 -0000 @@ -70,7 +70,11 @@ function station_schedule_views_plugins( * Implementation of views_query_substitutions(). */ function station_schedule_views_query_substitutions($view) { - return array('***CURRENT_STATION_MINUTE***' => station_minute_from_local_ts()); + $minute = station_minute_from_local_ts(); + return array( + '***STATION_CURRENT_MINUTE***' => $minute, + '***STATION_CURRENT_DAY_IN_MINUTES***' => $minute - ($minute % MINUTES_IN_DAY), + ); } /** Index: schedule/views/station_schedule_handler_filter_time.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/views/station_schedule_handler_filter_time.inc,v retrieving revision 1.1 diff -u -p -r1.1 station_schedule_handler_filter_time.inc --- schedule/views/station_schedule_handler_filter_time.inc 21 Sep 2009 17:43:32 -0000 1.1 +++ schedule/views/station_schedule_handler_filter_time.inc 22 Sep 2009 23:43:05 -0000 @@ -25,6 +25,7 @@ class station_schedule_handler_filter_ti '#title' => 'Mode', '#options' => array( 'now' => t('Current time'), + 'today' => t('Current day'), 'minutes' => t('Specific time'), ), '#default_value' => $this->value['mode'], @@ -37,9 +38,9 @@ class station_schedule_handler_filter_ti '#title' => empty($form_state['exposed']) ? t('Minute offset') : '', '#size' => 10, '#default_value' => $this->value['offset'], - '#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.'), '#process' => array('views_process_dependency'), - '#dependency' => array('radio:options[value][mode]' => array('now')), + '#dependency' => array('radio:options[value][mode]' => array('now', 'today')), ); $form['value']['value'] = array( '#type' => 'station_schedule_daytime', @@ -61,10 +62,22 @@ class station_schedule_handler_filter_ti $output .= t('Now'); } elseif ($this->value['offset'] < 0) { - $output .= t('Now minus @offset minutes', array('@offset' => (int) $this->value['offset'])); + $output .= t('Now -@offset', array('@offset' => format_interval($this->value['offset'] * 60))); } else { - $output .= t('Now plus @offset minutes', array('@offset' => (int) $this->value['offset'])); + $output .= t('Now +@offset', array('@offset' => format_interval($this->value['offset'] * 60))); + } + break; + + case 'today': + if (empty($this->value['offset'])) { + $output .= t('Midnight today'); + } + elseif ($this->value['offset'] < 0) { + $output .= t('Midnight today -@offset', array('@offset' => format_interval($this->value['offset'] * 60))); + } + else { + $output .= t('Midnight today +@offset', array('@offset' => format_interval($this->value['offset'] * 60))); } break; @@ -80,26 +93,40 @@ class station_schedule_handler_filter_ti function query() { $this->ensure_my_table(); + $field = "$this->table_alias.$this->real_field"; + $offset = (int) $this->value['offset']; + $min_in_day = MINUTES_IN_DAY; - $minutes_in_week = MINUTES_IN_WEEK; $info = $this->operators(); if (!empty($info[$this->operator]['method'])) { - switch ($this->value['mode']) { - case 'now': - $offset = (int) $this->value['offset']; + $formula = $field . ' ' . $this->operator . ' '; + $params = array(); + $tokens = array( + 'now' => '***STATION_CURRENT_MINUTE***', + 'today' => '***STATION_CURRENT_DAY_IN_MINUTES***', + ); + if (isset($tokens[$this->value['mode']])) { if (empty($offset)) { - $this->query->add_where($this->options['group'], "$field $this->operator ***CURRENT_STATION_MINUTE***"); + $formula .= $tokens[$this->value['mode']]; } else { - $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 + // ends of the week. + $minutes_in_week = MINUTES_IN_WEEK; + $formula .= "({$tokens[$this->value['mode']]} + %d + {$minutes_in_week}) %% {$minutes_in_week}"; + $params[] = $offset; } - break; - - case 'minutes': - $this->query->add_where($this->options['group'], "$field $this->operator %d", $this->value['value']); - break; } + else if ('at' == $this->value['mode']) { + $formula .= '%d'; + $params[] = $this->value['value']; + } + else { + // Unknown. + return; + } + $this->query->add_where($this->options['group'], $formula, $params); } return; } Index: schedule/views/station_schedule_handler_sort_time.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/views/station_schedule_handler_sort_time.inc,v retrieving revision 1.3 diff -u -p -r1.3 station_schedule_handler_sort_time.inc --- schedule/views/station_schedule_handler_sort_time.inc 8 Jun 2009 21:53:06 -0000 1.3 +++ schedule/views/station_schedule_handler_sort_time.inc 22 Sep 2009 23:43:05 -0000 @@ -36,7 +36,7 @@ class station_schedule_handler_sort_time break; case 'now': - $formula = "(($this->table_alias.$this->real_field - ***CURRENT_STATION_MINUTE***) + $minutes_in_week) %% $minutes_in_week"; + $formula = "(($this->table_alias.$this->real_field - ***STATION_CURRENT_MINUTE***) + $minutes_in_week) %% $minutes_in_week"; break; default: