The station I work for doesn't broadcast 24 hours a day, so a large amount of the schedule weekly grid is wasted.
It would be useful to have an option to set the overall start and end times for the schedule, eg 8am - 10pm.

Comments

drewish’s picture

Version: 5.x-0.3 » 5.x-2.x-dev

that's a good idea.

joachim’s picture

StatusFileSize
new1.78 KB

Here's a patch.

My idea was to automatically get the earliest and latest broadcast time from the schedule, and use those to define the range of the schedule grid, thus saving the site admin some config work.

However, I'm new to drupal, PHP, and mySQL, so it only partially works ;)
Specifically, while I can get what I want from the database running a query in phpmyadmin's web interface, I'm not getting the right thing back from it in drupal. The comments should explain it.
In the meantime, I've hardcoded the start and end time variables so the rest of it works.

drewish’s picture

Status: Active » Needs work

that really needs to be stored as a setting rather than hard coded.

joachim’s picture

Yes -- though I think that deducing the start and end times from the database is better, as a stored setting is one more thing for a site admin to have to set up.

It needs more work but it's beyond my capabilities. I've clearly made some fairly basic mistake with the db_query call, as it looks like its returning an object instead of a number. I was hoping someone else would fix that ;)

joachim’s picture

I just realized -- did you mean add an admin option for whether this whole grid-trimming feature is on or off? That I can do :)

drewish’s picture

yeah as an admin configurable variable. the trick would be making it customizable enough that it'd work for your station which wants to hide the hours between 22:00 and 08:00 and my station which would hide them between 02:00 and 08:00. i think the way to handle it would be, rather than excluding those times from the query, just omit them when displaying the schedule.

now regarding your patch there's a few things wrong:
- table names are quoted using {}, not fields
- db_query() returns a query result not a value. you'll need to use db_fetch_array(), db_fetch_object(), db_result().
- eh, well i can't really figure out what the rest is supposed to be doing

joachim’s picture

Thanks for the tips! I've fixed the query and it works properly.

> rather than excluding those times from the query, just omit them when displaying the schedule.
Not sure what you mean here. I'm not excluding anything from the query, what I'm doing is ensuring that the gap at the start and end of the grid isn't drawn.

I'll try to explain how my patch works:

The basic idea is that instead of creating a schedule table in station_schedule_week_page() from 00:00 to 24:00, start later and finish sooner.

First, I figure out when to start and finish.

$earliest = db_result(db_query('SELECT MIN(mod( start ,1440)) FROM {station_schedule}'));
$latest = db_result(db_query('SELECT MAX(mod( finish,1440)) FROM {station_schedule}'));

This (with the db query fixed, thankyou!) finds out from the database the start time of the earliest-starting program and the end time of the latest-ending program. It's modded with 1440=24*60 so times are compared relative to each day -- if you have only two shows in the week, one starting at 3am on Monday and the other and 6am Tuesday, the start time field for each has 180 and (1440+360), the modding returns 180 and 360, and the min returns the 180.

This is good if those times happen to be on the hour, but if they're not, say the earliest start is 09:30, then the grid must still begin at 09:00.
So $hour_start and $hour_finish does some calculations to round this to complete hours. If the earliest start is something like 9:30, it rounds that down to 09:00. If the latest finish is 10:15, it rounds that up to 11. This is to deal with people who have set their schedule slot size to 30 or 15. The schedule grid still needs complete hours in the first column.
I now know that the grid should run from, say, 09:00 to 22:00. Nothing is getting excluded -- I simply now know that no program begins before 9am, and no program ends after 10pm.

The next two lines where I hardcoded the numbers were just so I could test the rest of it :)

Now it's simply a question of using that to change the way the grid is drawn.
The first column of hours runs from $hour_start to $hour_finish instead of 0 to 24:
// put in a column of hours
for ($i = $hour_start; $i < $hour_finish; $i++) {
$cell .= theme('station_schedule_hour', $i);
}

And the programs shown in the grid need to figure out how much blank space above them is needed. Originally, $day_start is a multiple of 1440, which is 00:00 on the particular day. I add something on to get 09:00 or whatever:
$day_start = $i * 1440 + $hour_start * 60;

So basically, what determines how much of the grid is shown is the currently schedule programs. Add an earlier program, and the schedule grid will change accordingly.
If a station has shows from 6am to 8pm daily, the grid will show 06:00 - 20:00. If the station operator decides to add a special late-night Friday show that runs till 22:00, then the grid will automatically change, and now it will show 06:00 - 22:00.
Hope that all make sense :)

What won't work however is your example of going off-air between 02:00 and 08:00, because that period falls in the middle of the day. My patch can only trim the top and bottom of the grid, not strip out a band in the middle.
I see two ways to address this sort of case:
a. Change the schedule grid so programs past midnight appear on the same day -- the way many TV guides do it. This is somewhat illogical, but people tend to think that 1am Tuesday morning is still part of Monday night.
b. Instead of my current test for a late start and early finish to the day, look for hours during the day where there is no program on air, and eliminate those from the table. Eg, if there are never programs on between 12:00 and 15:00, condense that piece of the table. What I want to do then becomes a special case at the start or end of the day.

I'm not sure how to do either of those... :(
I'll keep pondering it though.

In the meantime, I'll work on adding an admin option and post the updated patch sometime next week.

joachim’s picture

StatusFileSize
new2.53 KB

Updated version of the patch.

- fixed the database query
- added an admin option to enable trimming the grid, set to off by default.

This now works as originally described. The grid will be trimmed to start later and finish earlier according to scheduled programs.

drewish’s picture

that's looking really good. i'll try to get it in in the next week or so.

joachim’s picture

Oops.
Just noticed I left some old comments in there:

+ // !!!! these queries work directly on the databse in phpmyadmin,
+ // but appear to return the wrong sort of thing.

Those two lines should be cut.

drewish’s picture

Status: Needs work » Needs review
StatusFileSize
new12.48 KB

hey could you take a look at this patch? i took your changes and incorporated them into some other fixes i was working on. it should be functionally the same thing i've just been trying to use clearer names.

andy.clarke’s picture

Priority: Normal » Critical

Hi, i'm a bit of a novice, but trimming the schedule is also something i need to do. Can someone help me with regards applying the patch? Where do i put the patch code?

Also, another related fix that i need is to do with spanning. If i try and schedule a program on a Saturday night, say 10pm-3am, i recieve a warning telling me that my program must start before it finnishes. This must be because Sunday is before saturday on the schedule perhaps?

Cheers

andy.clarke’s picture

***Also posted as a new issue***

I have applied the patch which trims the schedule. This has helped no end. However, we do live broadcasts from nightclubs which may start at 10pm and go on until 3am the next day.

All normal programs start at 6pm. So ideally, the 'day' will start at 6pm, and everything previous can by trimmed using the patch. However, with programs overrunning until 3am for example, the trimming patch doesn't really work.

Would it be possible, although technically incorrect, to have a day starting at 6pm and going through until 3am and calling it 'Tuesday' or whatever. Then 'Wednesday' starts at 6pm again.

I feel this would also solve the secondary problem i am having. I try to schedule a program on Saturday night, to finish at midnight, however i am told 'a program must begin before it can end'. Obviously, the schedule module doesn't take into account 'weeks', and therefore thinks that my program finishing at midnight on Sunday morning, is before Saturday (Sunday must be the first day if the week?).

But if a 'day' ran through until 3am anyway, this would solve both my problems perhaps?

Thanks in advance.

joachim’s picture

Drewish, which version is your patch against? I can't get it to apply on the latest 5.1-1.x-dev snapshot.

Just reading the patch, it looks good.

There's one thing that doesn't work though -- assuming I'm reading it correctly.

Line 187 of the patch:
+ $last_hour = station_time_from_minute($o->max, 'G');

This doesn't get what we want.
The function call does this:
$hour24 = (int) (($minutes % 1440) / 60);

That's always rounding down. Here's a case where it fails:

Suppose the entire week has only one show, from midnight to 1.30am on the first day. That's stored as 0 - 90.

$o->max returns 90
$hour24 = (int) (($minutes % 1440) / 60); returns (int) ((90 % 1440)/60) == (int) (1.5) == 1
So $last_hour is set to 1, and the schedule grid ends at 1am -- but we have a show that goes on till half past one! What we want is the grid to go from midnight - 2am.

The $last_hour has to be rounded UP, BUT only if it's not a whole hour -- hence the quite nasty expression in my patch,
$hour_finish = ($latest + ($latest % 60 != 0 ? 60 - $latest % 60 : 0))/60;
which is pretty ugly.
A cleaner version of that expression would be:
$hour_finish = (int) ($latest / 60) + ($latest % 60 == 0 ? 0 : 1);
which using your variable names is
$last_hour = (int) ($o->max / 60) + ($o->max % 60 == 0 ? 0 : 1);

Alternatively, you could add the rounded-up hour to dayhour.inc, like this:
$hour24up = (int) (($minutes % 1440) / 60) + ($min ? 1 : 0);

drewish’s picture

good catch, though i think the easiest way to handle it would be

// add 59 minutes to ensure that it's rounded up to the next hour.
$last_hour = station_time_from_minute($o->max + 59, 'G');

it's less efficient pushing everything through station_time_from_minute() but i'm very reluctant to spread the date handling code around. that function is well tested and bugs will be apparent in many spots instead of just one off.

i'm not sure exactly what version it was against but it should have the CVS IDs in the patch. i'll try to re-roll something before long.

joachim’s picture

Can't get it to apply on the latest version, 5.x-1.2, either.
It says Hunk #3 in dayhour.inc and hunk #9 in schedule/station_schedule.module failed.

joachim’s picture

I should warn anyone wanting to use this patch that I've tried it again on my site and found a bug:

If the schedule ends at midnight (in other words, if your station runs from say 8am - midnight), the times down the side don't show properly.
This is because the code that calculates the latest ending show doesn't pick up the midnight bit because it's stored as 00:00 the following day.

I'm not going to be fixing this as this code is obsolete anyway -- I am planning to write a patch that lets the admin set the start and end times manually to replace this patch.

If you want to use this patch anyway (as I'm doing on my site), I suggest you just hardcode the start and end times ($hour_start and $hour_finish) for now :)

drewish’s picture

marked http://drupal.org/node/128890 as a duplicate

drewish’s picture

Status: Needs review » Needs work

(based on joachim's comment #17)

joachim’s picture

Yup, that patch is totally kaputt.... ;)
I found that if you *do* hardcode it, and then put in a show before the starting hour, it's displayed anyway and messes up the grid.

I've started from scratch and done a crude hack for my site that makes the schedule wrap from 7am round to 7am: http://seasideradio.co.uk/station/schedule/week
Over the weekend I plan to work on adapting that for CVS HEAD.

joachim’s picture

Status: Needs work » Needs review
StatusFileSize
new9.17 KB

Here's a patch on HEAD.

This patch:
- adds two columns to the station_schedule table, for start and end times, with defaults 0 and 24
- adds a station_schedule_update_5204() function to add these two columns
- adds widgets to the schedule edit page to edit these, and validates that start is less than end (but see below...)
- trims the schedule View page according to these values
- trims the schedule Alter page according to these values

I've tested it on a clean Drupal 5.3, and also on a Drupal 5.3 that had station HEAD already installed, to see the update.php does its stuff properly.

What it DOESN'T do is allow the schedule to wrap past midnight into the next morning (ie, end time EARLIER than start time). I know this is a feature many users want (including me!), but doing that gets a bit complicated (because it involves some messing about with the special case of Sunday morning, which must appear at the end of Saturday, but the way it's stored internally gets in the way... more on this later!)

So what I want to do is tackle wrapping in a separate patch, as this patch is already pretty big and I'm starting to diverge quite far from HEAD.

If it's ok with you, drewish, could you commit this patch if it's satisfactory, and I'll work on the wrapping stuff next, probably in a separate issue too.

drewish’s picture

i don't really like the names of the new fields in {station_schedule}. i think i'd prefer just start and finish or perhaps start_hour and finish_hour. though i'm sort of thinking it might be good to store that value in minutes. that way we can share code with the schedule items start and finish times.

i'd really like to get the wrapping working before we commit half of this. i'm worried that it'll be complex enough that we end up un-doing some of this.

joachim’s picture

'start' and 'finish' is fine by me.
I suppose there's a logic in storing the values as minutes, since we're using them to compare again rows in {station_schedule_item} which are also in minutes. But then we'd need to do the multiplication or division by 24 for the user interface... swings and roundabouts really. What code sharing did you have in mind? I don't think that allowing a schedule to start at 15/30/45 past the hour is desirable (it'll look ugly in the schedule grid) or feasible.

Wrapping involves two things. One I've got working on my site (latest stable station release) and one I've not yet tackled.
1) A show that's on Sunday morning has to appear at the end of Saturday. This is done with a special case within function station_schedule_load(), along the lines of if ($day == 6 and $finish > 7 * MINUTES_IN_DAY) { ... } . You then load schedule items from both the end of Saturday and the start of Sunday, spoof the Sunday times by adding (7 * 1440), and the schedule display code handles it all smoothly.
2) What I've not yet tackled is allowing an actual show to wrap across the end of the week, eg from Saturday 10pm to Sunday 2am. I'm less sure about how to store that, and how that'll affect existing code. I think some code PRIOR to this patch will be affected, as it's going to affect the way schedule items are queried. Any thoughts on how to go about this?

joachim’s picture

StatusFileSize
new10.2 KB

Here's an updated patch.

- I've changed the field names in {station_schedule} as you requested, and, having thought about it, I think you're right about storing the schedule start and end as minutes rather than hours -- it makes sense to store in the same format as the program times that will be compared against it, and convert for the user. So that's changed too :)
- I've rearranged station_schedule_load(). Since the schedule start and end have to be loaded before the programs, I thought it made sense to put all the schedule stuff together at the top.
- A schedule can go past midnight. There's no restriction on the values for start and end any more -- set both to 7 to get 7am-7am for each day. Sunday morning shows are correctly shown at the end of Saturday.

What it doesn't do is allow a particular program to start Saturday night and end Sunday morning, wrapping over the break at the end of the way the week is stored.

I've started looking at how to handle that, but should this be a separate issue? I thought there was one open for it, but I don't see it.

It turns out that to accommodate extreme but possible cases of a show that starts Saturday night and runs till (say) Tuesday, or that starts Thursday and runs to Sunday morning, station_schedule_load() needs to do quite a few more queries.
Assuming the wrapped show is stored as "normal" numbers, ie with its finish less than its start:

    for all days:
      query for a wrapped item (tail end)
        trim it as usual, and if the end doesn't need trimming, 
          set a flag so we can skip this query for future days
    
      regular query
        trim items
      
      query for a wrapped item (front end)
        trim it as usual
          set a flag so future days can skip this & the regular query. we're obviously full till Saturday night
      
    if day = 6 AND schedule goes past midnight:
        query for Sunday morning items
        trim them        

I'm thinking it might be better to store the wrapping show 'spoofed', with its end time beyond 10080. That would mean that the front of the wrapping show can be handled by the regular query; only the tail end needs the special case.

drewish’s picture

StatusFileSize
new10.61 KB

re-roll with some cleanups.

joachim’s picture

Your patch has a problem with loading the trim values from the database on the schedule edit page: I see both as 12am no matter what I've previously saved.
The values I enter are saving properly though, and the schedule is getting displayed as expected.

It's also a bit confusing having 12am appear twice, at the top and bottom of the list.

drewish’s picture

marked http://drupal.org/node/219649 as a duplicate.

hurricane_rufo’s picture

Hi drewish,

could you please update this patch to work with the latest dev version? I tried to run it, but it fails in three places in station_schedule.module...

Markus

maco’s picture

Hi Drewish,
has this patch been actually applied on HEAD or has the discussion and application been abbandoned?

This is the last issue why we are not using the system for our radio station yet - our station director does not like the idea of having user to see half of the schedule empty :)

Thanks,
Marcel

drewish’s picture

marco, per #26 it still has some issues. please feel free to test it out though.

bernd07’s picture

Version: 5.x-2.x-dev » 5.x-2.0
StatusFileSize
new3.24 KB

I also tried this patch on the final version 5.x-2.0 and there are also 3 fails in station_schedule.module! This would be also a great feature for our radio station. I attached the file "station_schedule.module.rej" below for review.

kelizabeth’s picture

Can a patch be made for the current build? I would really like to have my schedule trimmed. :)

kelizabeth’s picture

Priority: Critical » Normal

Sorry, forgot to change the dropdown from 'critical' to 'normal'. Though it is pretty important for my overall table design. I would try to look at the old patch and make the changes to have it work with the new one, but I'm a kindergartner when it comes to PhP coding.

drewish’s picture

Version: 5.x-2.0 » 6.x-2.x-dev
Status: Needs review » Needs work

I want to bump this to the D6 version and get it fixed there then consider what to do with the D5 version.

kelizabeth’s picture

Are you thinking of putting it directly into the dev module that you're working on for D6 (rather than a patch)? I have your most recent update and was looking through the code but as I'm not too weathered in php, I couldn't figure out which strings needed changing/additions.

drewish’s picture

Honestly what I'd really like to do is convert the weekly schedule into a view so that it can be modified by admins easily. Then it'd just be a matter of adjusting the filter to set the start and end of the day.

joachim’s picture

I'm supposing we expose schedule slots as views primary objects. Their data is then their start and end times and there's a relationship to program nodes. This is potentially powerful stuff!
But how are we going to handle stuff at the tail end of the week?

I'm afraid I've no time at the moment to spend on this one, and as I'm not doing radio stuff any more it's low on my radar. One thing I would say about potential views support though is to allow for schedules that are longer or shorter than a week -- one of my ideas was to uncouple schedule module from the station package and allow it to be schedules of any length, holding any node type, for school timetables, conference sessions, etc :)
Getting more and more off-topic here, but maybe we could get this going for the Drupalcon site if they haven't already got this bit ready?

kelizabeth’s picture

I agree, converting it into a view would be really useful for admins. I don't really understand what joachim was taking about as far as how things are handled at the tail end of the week, however.

joachim’s picture

The 'tail end of the week problem':
- The schedule runs from Monday midnight to Sunday midnight, say.
- You have a late night show that starts Sunday 8pm and runs till 2 in the morning.
- You can't put this in the schedule as a single slot.
- Currently you can sort of get away with having 2 slots for this show, though the show page will look odd listing 8-12 and 12-2.
- If you use this patch to make the schedule go from 10 am to 2am, your show is split in two.

I can't seem to find a dedicated issue to this though. I did look at various ways to approach this and nothing works cleanly that I could find.

kelizabeth’s picture

Well, luckily, as of now, our station doesn't have any shows that runs past midnight, but that could always change. I guess if there was a way to cut out a chunk of time like, say, 2am to 7am for each day. Is this possible? That the table starts at 12am is what doesn't work. If the table started at, say, 7am and the 12am-6:59am time slots were pinned on to the end, that would be acceptable. Are any of these things remotely doable? Or would it involve completely changing how the module is run?

Poking around I found this site: http://www.rfcradio.com/schedule/ . I don't know that they're using php, and its a wordpress system rather than drupal, but maybe the webmaster has some insight? Their schedule drops off the after midnight stuff at the end rather than at the beginning.

These are all just thoughts. I look at php and, save for doing string searches to change little things when I know what I'm looking for, its all Greek to me. I'm here and eager to test whatever you come up with though!

drewish’s picture

joachim, i'm not sure it would really affect the possible lengths of the schedule unless we do some admin UI over hauling... which isn't to say it's not a good goal just that I think it's a bit more complex than it appears at first glance.

kelizabeth, it looks like that schedule is only one hour blocks so it wouldn't encounter this particular problem.

kelizabeth’s picture

Is there a way to just hack the schedule module to the desired hours as a temporary fix? Tell me what lines I should be looking for and I'll play around with it myself. The site I'm working on has gone live (http://www.berkeleyliberationradio.net) and I'd like to get this thing at least temporarily looking the way I want it to while changes to the module get sorted out. Any direction is greatly appreciated. :)

kelizabeth’s picture

Like, if there something one of the files in the station schedule view folder (e.g. station_schedule_handler_field_start_time, station_schedule_handler_sort_time) that I could change so the schedule spans 24 hours, but starts and ends at 7am? I feel like it shouldn't be a big change, but I'm awful at php.

rogueturnip’s picture

I'm guessing this isn't in the D6 version yet.

tim.plunkett’s picture

Marked #516724: Schedule time boundaries as duplicate.
Though I feel bad doing that, considering there hasn't been a patch for seven months, and no discussion for a month.

Where did this get left? What might I be able to help with?

michel3’s picture

it's very important this patch! there is a hope to have this feature?

meramo’s picture

Subscribing, the patch must be implemented in module functionality!
Also any progress on a patch for D6?

daggerhart’s picture

Hacked schedule module & template

Drupal - 6.15
Station - beta 3

I recently launched http://www.ashevillefm.org, and we needed to change the schedule a little bit. I made most of the changes in the template, with a few edits to the module itself. All of my changes are commented.

Any feedback is appreciated.

Added to my template.php

/**
 * Schedule Display
 */

// this is the left column 'time'
function avlfm_station_schedule_hour($hour)
{  
  // get rid of the first 8 hours 
  if ($hour < 8) {
    $output = '';
  }
  // we want our schedule to go to 2am,
  // so append an extra couple of hours
  // to the last one
  elseif ($hour == 23)
  {
    $class = 'station-sch-box station-sch-hour';
    $height = 60;
    // 23 o'clock
    $output = "<div class='{$class}' style='height:{$height}px;'>";
    $output .= theme('station_hour', $hour * 60);
    $output .= "</div>\n";
    // 24 o'clock
    $output .= "<div class='{$class}' style='height:{$height}px;'>";
    $output .= theme('station_hour', ($hour + 1) * 60);
    $output .= "</div>\n";
    // 25 o'clock
    $output .= "<div class='{$class}' style='height:{$height}px;'>";
    $output .= theme('station_hour', ($hour + 2) * 60);
    $output .= "</div>\n";
  }
  else
  {
    // The default.  this is the normal action
    $class = 'station-sch-box station-sch-hour';
    $height = 60;
    $output = "<div class='{$class}' style='height:{$height}px;'>";
    $output .= theme('station_hour', $hour * 60);
    $output .= "</div>\n";
  }
  return $output;
}

// this is the unscheduled spacers between scheduled times
function avlfm_station_schedule_spacer($start, $finish) {
  $class = 'station-sch-box station-sch-unscheduled';
  $height = ($finish - $start);
  
  // 8 hours = 480 minutes.
  // remove spacers that are 480 or bigger
  if ($height >= 480)  
  {
    $height = $height - 480;
    $output = "<div class='{$class}' style='height:{$height}px;'>";
    $output .= "<span class='station-sch-time'>".theme('station_hour_range', $start, $finish) ."</span>";
    $output .= "</div>\n";
  }
  else
  {
    // normal sized spacers
    $output = "<div class='{$class}' style='height:{$height}px;'>";
    $output .= /*$start." -> ".$finish." = ".$height.*/"<span class='station-sch-time'>".theme('station_hour_range', $start, $finish) ."</span>";
    $output .= "</div>\n";
  }
  
  return $output;
}

// these are the scheduled items
function avlfm_station_schedule_item($start, $finish, $program)
{
  $class = 'station-sch-box station-sch-scheduled';
  $height = ($finish - $start);
  $link = url('node/'. $program->nid);

  $output = "<div class='{$class}' style='height: {$height}px;'>";
  $output .= "<a href='{$link}'><span class='station-sch-time'>". theme('station_hour_range', $start, $finish) ."</span>";
  $output .= '<span class="station-sch-title">'. check_plain($program->title) .'</span>';
  
  if (!empty($program->field_station_program_dj)) {
    $djs = array();
    foreach ($program->field_station_program_dj as $entry) {
      $user = user_load($entry);
      $content_profile = content_profile_load('profile', $user->uid);
      $djs[] .= $content_profile->title;
    }
    $output .= '<span class="station-sch-djs">'. check_plain(implode(', ', $djs)) .'</span>';
  }
  
  // if we have enough room, show the Archive link
  // we use a static link for the 'most recent archive'
  // of each program.  
  if ($height >= 60) {
    $output .= "<a class='archive' href='".$program->field_stream[0][url]."'>Listen</a>";
  }
  
  $output .= "</div>\n";
  return $output;
}

/**
 * These next three I copied from the module
 * just in case I needed them, but I don't
 * think i've changed anything. 
 */
function avlfm_station_schedule_form_streams($form) {
  $header = array(t('Name'), t('Description'), t('URLs'));
  foreach (element_children($form) as $key) {
    $row = array();
    $row[] = drupal_render($form[$key]['name']);
    $row[] = drupal_render($form[$key]['description']);
    $row[] = drupal_render($form[$key]['urls']);
    $rows[] = $row;
  }
  return theme('table', $header, $rows) . drupal_render($form);
}

function avlfm_station_schedule_daytime_range($element) {
  return theme('form_element', $element, $element['#children'] );
}

function avlfm_station_schedule_daytime($element) {
  return theme('form_element', $element, '<div class="container-inline">'. $element['#children'] .'</div>');
}

/******** end schedule *********/

The edits I made to the module. (station_schedule.module)

function station_schedule_load ~ line 404
The changes here allow for programs to last past midnight, and not show those programs in the next day.

/**
 * Implementation of hook_load().
 */
function station_schedule_load($node) {
  $schedule = array();
  // Use station_day_name() for the day ordering in case Sunday isn't the
  // first day of the week.
  foreach (station_day_name() as $day => $name) {
    $schedule[$day] = array();

    $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;
      }
      // jonathan: commented this out so it wouldn't cut off shows
      // that go past midnight
      //if ($s->finish > $finish) {
      //  $s->finish = $finish;
      //}
      // jonathan: don't want to show anything that starts at the beginning of the day
      if (($s->start == 1440)
        ||($s->start == 2880)
        ||($s->start == 4320)
        ||($s->start == 5760)
        ||($s->start == 7200)
        ||($s->start == 8640))
        {
          // do nothing
        } else {
         $schedule[$day][] = $s;
        }
    }
  }

  // Load the settings.
  $settings = db_fetch_array(db_query('SELECT increment, streams, unscheduled_message FROM {station_schedule} WHERE nid = %d', $node->nid));
  if (isset($settings['streams']) && $streams = unserialize($settings['streams'])) {
    $settings['streams'] = array();
    foreach ($streams as $key => $stream) {
      // Add in the M3U URL.
      $stream['m3u_url'] = file_create_url('station/'. $node->nid .'-'. $key .'.m3u');
      $settings['streams'][$key] = $stream;
    }
  }
  else {
    $settings['streams'] = array();
  }

  return array(
    'settings' => $settings,
    'schedule' => $schedule,
  );
}

function station_schedule_week_page ~ line 913
The changes here increase the minutes in a day by 120 (so it shows until 2am of each day) and inserts spacers between two items that don't bump up. Not sure why I had to do it this way, but it seems to work for now.

  /**
 * Print a weekly schedule page.
 */
function station_schedule_week_page($node) {
  $header[0] = array('data' => t('Time'));
  $row = array();

  // First column is hours.
  $row[0] = array('id' => 'station-sch-hours', 'data' => '');
  for ($hour = 0; $hour < 24; $hour++) {
    $row[0]['data'] .= theme('station_schedule_hour', $hour);
  }

  // Then a column for each day of the week.
  foreach ((array) $node->schedule as $day => $items) {
    $header[$day + 1]['data'] = station_day_name($day);
    $row[$day + 1]['data'] = '';

    // The last finish pointer starts at the beginning of the day.
    $last_finish = $day * MINUTES_IN_DAY;
    $day_finish = (($day + 1) * MINUTES_IN_DAY) + 120; // jonathan: day finishes at 2am, so at 120 minutes
    foreach ($items as $item) {
      // Display blocks for unscheduled time periods
      /**
       * jonathan: insert a spacer if two items don't bump up.
       */ 
      if ($last_finish != $item->start) {
        $row[$day + 1]['data'] .= theme('station_schedule_spacer', $last_finish, $item->start);
      }
      /* end edits */
      // new last_finish
      $last_finish = $item->finish;

      // Display the schedule item.
      $program = node_load($item->program_nid);
      
      // theme the schedule item
      $row[$day + 1]['data'] .= theme('station_schedule_item', $item->start, $item->finish, $program);
    }
    // Display a block for any remaining time during the day.
    if ($last_finish < $day_finish) {
      $row[$day + 1]['data'] .= theme('station_schedule_spacer', $last_finish, $day_finish);
    }
  }

  // Add a class to indicate what day it is.
  $today = station_today();
  $header[$today + 1]['class'] = 'station-sch-now-day';
  $row[$today + 1]['class'] = 'station-sch-now-day';

  return theme('table', $header, array($row), array('id' => 'station-sch'));
}

Of course, any instances of 'avlfm' should be your theme name.

After doing all of this, I totally understand why an admin option isn't a simple patch.

zoen’s picture

Status: Needs work » Needs review
StatusFileSize
new12.95 KB
new7.74 KB

Here's a patch to make the schedule start and end times configurable, based on parts of daggerhart's code from the previous comment, there.

I created the patch from the sites/all/modules/station/schedule directory, against the current HEAD version. It makes changes to station_schedule.install and station_schedule.module.

You need to run update.php after patching, because the patch changes the schema of the station_schedule table.

If this works properly, when you create or edit a Schedule node, you'll see two new fields, "Programming start time" and "Programming end time". They're in increments of 1 hour, because the way the schedule renders with the 1-hour-incremented left-hand "Time" column, I didn't think smaller increments would work. Here's a screenshot of the "Create Schedule" form: http://skitch.com/zoen/nhsxk/create-schedule-local.station-alteration

And a screenshot of a sample schedule, configured to show programs from 9pm to 4am: http://skitch.com/zoen/nhs1p/all-klezmer-all-the-time-local.station-alte...

The "Programming start time" field allows for start times between 00:00 and 23:00. "Programming end time" allows times between 01:00 and noon the next day. These time limitations, while useful for our needs, feel very arbitrary to me as part of a community tool, and I'm not sure what limitations to suggest... If anyone wants more time flexibility than this (eg, programming starting earlier than 00:00), talk about it and we'll cross that bridge etc etc. Oh, and I included some validation to prevent end times earlier than the start time.

Another thing people may want changed: the "Alter Schedule" table still goes from 00:00 to 24:00.

Just in case the patch doesn't work for you, I'm also including the altered versions of station_schedule.install and station_schedule.module.

drewish’s picture

I like where this is going but I'm not sure about station_schedule_hour_options(). Seems like we should probably use the schedule's increment to determine the intervals so the start and end times should be in minutes rather than hours. We can change the schedule themeing to round down to the previous hour.

meramo’s picture

ZoeN`s patch worked excellent for me! Thanks for this.

This functionality should be included into module for sure

pribeh’s picture

@51 Bump.

tim.plunkett’s picture

StatusFileSize
new7.74 KB

I was halfway done a patch to implement the schedule's increments, and I think this patch makes more sense.

If the theme layer is going to be rounding down, that creates a disconnect between what the user selected and what they see. And without a complete overhaul, the schedule theming can't handle anything other than 60 minute increments. Also, I think sticking with hour-based increments makes more visual sense, regardless of the schedule's increment.

Rerolled against HEAD to apply from station instead of station/schedule. I'd say RTBC, but it's up to you drewish.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Worked on this more, couldn't come up with anything better, seems to work great.

drewish’s picture

Status: Reviewed & tested by the community » Needs work

Final nit-picky review on my part.

start_time and end_time are okay names but since they're hours would start_hour and end_hour be more accurate?

I think the doxygen standard is two stars to open the comment: http://drupal.org/node/1354#general

+/*
+ * Returns an array of possible programming start and end times.
+ */

The case statement should have a return after the breaks: http://drupal.org/coding-standards#controlstruct

Same goes for the else if and else later:

} else if ($i == 12) {

So looking at:

+    $start_time = $settings['start_time'] * 60;
+    $start = $day * MINUTES_IN_DAY + $start_time;
+    $end_time = $settings['end_time'] * 60;
+    $finish = $day * MINUTES_IN_DAY + $end_time;

and

     // The last finish pointer starts at the beginning of the day.
-    $last_finish = $day * MINUTES_IN_DAY;
-    $day_finish = ($day + 1) * MINUTES_IN_DAY;
+    $last_finish = $day * MINUTES_IN_DAY + ($settings['start_time']*60);
+    $day_finish = (($day) * MINUTES_IN_DAY) + ($settings['end_time']*60);

it seems like they're in minutes... did that not get updated? Also need to have spaces around the multiple operator.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new7.76 KB

Good catches on the formatting, and a good point with the naming.

I don't understand your last comment. $day * MINUTES_IN_DAY results in minutes, and $settings['start_time'] * 60 also results in minutes (basically $hour * MINUTES_IN_HOUR). Anything wrong with that?

drewish’s picture

Status: Needs review » Reviewed & tested by the community

Ah, my misunderstanding from just reading the patch rather than the full context. I'd thought the result needed to be hours not minutes so the * 60 seemed like an unnecessary operation. Looks great to me. A nice conclusion to a three-year-old issue.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

Whew, that was a long standing issue. Thanks everyone, committed to HEAD!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.