? schedule/_station_schedule.module
Index: schedule/station_schedule.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.module,v
retrieving revision 1.35
diff -u -p -r1.35 station_schedule.module
--- schedule/station_schedule.module	10 Aug 2007 17:42:54 -0000	1.35
+++ schedule/station_schedule.module	10 Aug 2007 17:43:57 -0000
@@ -1,6 +1,6 @@
 <?php
 
-define('STATION_SCHEDULE_CVS_ID', '$Id: station_schedule.module,v 1.35 2007/08/10 17:42:54 drewish Exp $');
+define('STATION_SCHEDULE_CVS_ID', '$Id: station_schedule.module,v 1.33 2007/08/10 17:13:22 drewish Exp $');
 
 if (module_exists('views')) {
   require_once(drupal_get_path('module', 'station_schedule') .'/views.inc');
@@ -80,7 +80,7 @@ function station_schedule_menu($may_cach
             'path' => "node/$nid/view/". strtolower($dayname),
             'title' => t(substr($dayname, 0, 3)),
             'callback' => 'station_schedule_day_page',
-            'callback arguments' => array($nid, $day),
+            'callback arguments' => array($node, $day),
             'type' => ($today == $day) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
             'weight' => $day,
           );
@@ -215,8 +215,27 @@ function station_schedule_form($node) {
  * Implementation of hook_load().
  */
 function station_schedule_load($node) {
-  $data = db_fetch_array(db_query('SELECT increment FROM {station_schedule} WHERE nid = %d', $node->nid));
-  return array('station_schedule' => $data);
+  $ret['settings'] = db_fetch_array(db_query('SELECT increment FROM {station_schedule} WHERE nid = %d', $node->nid));
+
+  for ($day = 0; $day < 7; $day++) {
+    $start = $day * MINUTES_IN_DAY;
+    $finish = $start + MINUTES_IN_DAY;
+
+    $result = db_query('SELECT * FROM {station_schedule_item} i WHERE i.schedule_nid = %d AND i.finish > %d AND i.start < %d ORDER BY i.start', $node->nid, $start, $finish);
+    while ($s = db_fetch_object($result)) {
+      // If a show spans a day, limit its start and finish times to be with-in
+      // the day.
+      if ($s->start < $start) {
+        $s->start = $start;
+      }
+      if ($s->finish > $finish) {
+        $s->finish = $finish;
+      }
+      $ret['schedule'][$day][] = $s;
+    }
+  }
+
+  return array('station_schedule' => $ret);
 }
 
 /**
@@ -499,7 +518,7 @@ function station_schedule_nodeapi(&$node
             '#weight' => -5,
           );
           $node->content['times']['#weight'] = -4;
-          foreach ($timesBySchedule as $schedule_nid => $times) {
+          foreach ($times_by_schedule as $schedule_nid => $times) {
             $schedule = node_load($schedule_nid);
             $node->content['times'][$schedule_nid] = array(
               '#type' => 'item',
@@ -704,7 +723,7 @@ function station_schedule_program_get_at
   $day = date('w', $ts);
   $hour = date('G', $ts);
   $minute = station_minute_from_day_hour($day, $hour);
-  $schedule_nid = $schedule_nid ? (int) $schedule_nid : variable_get('station_schedule_default', 0);
+  $schedule_nid = (int) ($schedule_nid ? $schedule_nid : variable_get('station_schedule_default', 0));
   $schedule_item = station_schedule_load_item_at($schedule_nid, $minute);
 
   // If there's an associated program, load it
@@ -1126,13 +1145,14 @@ function theme_station_schedule_item($st
  * Today's schedule. This is just a short cut for the menu system.
  */
 function station_schedule_today_page($schedule_nid) {
-  return station_schedule_day_page($schedule_nid, station_today());
+  $node = node_load($schedule_nid);
+  return station_schedule_day_page($node, station_today());
 }
 
 /**
  * Print a day's schedule page.
  */
-function station_schedule_day_page($schedule_nid, $day) {
+function station_schedule_day_page($node, $day) {
   $day = station_valid_day($day);
   $dayname = station_day_name($day);
 
@@ -1141,24 +1161,20 @@ function station_schedule_day_page($sche
 
   $rows = array();
   $row = array();
-  foreach (station_schedule_load_day($schedule_nid, $day) as $hour) {
+  foreach ($node->station_schedule['schedule'][$day] as $hour) {
     if ($hour->program_nid) {
       $program = node_load($hour->program_nid);
-      $row['time'] = array('width' => 70,
-        'data' => theme('station_hour_range', $hour->start, $hour->finish));
+      $row['time'] = array('width' => 70, 'data' => theme('station_hour_range', $hour->start, $hour->finish));
       if (station_has_archive()) {
         $listen = '';
-        foreach(station_schedule_archive_links($program->nid, TRUE) as $link) {
+        foreach (station_schedule_archive_links($program->nid, TRUE) as $link) {
           $listen .= l($link['title'], $link['href'], NULL, NULL, NULL, TRUE, TRUE) .' ';
         }
         $row['listen'] = array('width' => 50, 'data' => $listen);
       }
-      $row['program'] = array('width' => 240,
-        'data' => l($program->title, 'node/' . $program->nid));
-      $row['genre'] = array('width' => 240,
-        'data' => check_plain($program->genre));
-      $row['djs'] = array('width' => 200,
-        'data' => implode(', ', station_schedule_program_get_themed_djs($program->nid)));
+      $row['program'] = array('width' => 240, 'data' => l($program->title, 'node/' . $program->nid));
+      $row['genre'] = array('width' => 240, 'data' => check_plain($program->genre));
+      $row['djs'] = array('width' => 200, 'data' => implode(', ', station_schedule_program_get_themed_djs($program->nid)));
 
       $rows[] = $row;
     }
