Closed (fixed)
Project:
Station
Version:
6.x-2.x-dev
Component:
Schedule
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2007 at 15:19 UTC
Updated:
23 Jul 2010 at 21:10 UTC
Jump to comment: Most recent file
Comments
Comment #1
drewish commentedthat's a good idea.
Comment #2
joachim commentedHere'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.
Comment #3
drewish commentedthat really needs to be stored as a setting rather than hard coded.
Comment #4
joachim commentedYes -- 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 ;)
Comment #5
joachim commentedI just realized -- did you mean add an admin option for whether this whole grid-trimming feature is on or off? That I can do :)
Comment #6
drewish commentedyeah 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
Comment #7
joachim commentedThanks 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.
Comment #8
joachim commentedUpdated 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.
Comment #9
drewish commentedthat's looking really good. i'll try to get it in in the next week or so.
Comment #10
joachim commentedOops.
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.
Comment #11
drewish commentedhey 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.
Comment #12
andy.clarke commentedHi, 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
Comment #13
andy.clarke commented***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.
Comment #14
joachim commentedDrewish, 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);
Comment #15
drewish commentedgood catch, though i think the easiest way to handle it would be
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.
Comment #16
joachim commentedCan'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.
Comment #17
joachim commentedI 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 :)
Comment #18
drewish commentedmarked http://drupal.org/node/128890 as a duplicate
Comment #19
drewish commented(based on joachim's comment #17)
Comment #20
joachim commentedYup, 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.
Comment #21
joachim commentedHere'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.
Comment #22
drewish commentedi 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.
Comment #23
joachim commented'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?
Comment #24
joachim commentedHere'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:
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.
Comment #25
drewish commentedre-roll with some cleanups.
Comment #26
joachim commentedYour 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.
Comment #27
drewish commentedmarked http://drupal.org/node/219649 as a duplicate.
Comment #28
hurricane_rufo commentedHi 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
Comment #29
maco commentedHi 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
Comment #30
drewish commentedmarco, per #26 it still has some issues. please feel free to test it out though.
Comment #31
bernd07 commentedI 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.
Comment #32
kelizabeth commentedCan a patch be made for the current build? I would really like to have my schedule trimmed. :)
Comment #33
kelizabeth commentedSorry, 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.
Comment #34
drewish commentedI want to bump this to the D6 version and get it fixed there then consider what to do with the D5 version.
Comment #35
kelizabeth commentedAre 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.
Comment #36
drewish commentedHonestly 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.
Comment #37
joachim commentedI'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?
Comment #38
kelizabeth commentedI 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.
Comment #39
joachim commentedThe '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.
Comment #40
kelizabeth commentedWell, 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!
Comment #41
drewish commentedjoachim, 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.
Comment #42
kelizabeth commentedIs 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. :)
Comment #43
kelizabeth commentedLike, 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.
Comment #44
rogueturnip commentedI'm guessing this isn't in the D6 version yet.
Comment #45
tim.plunkettMarked #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?
Comment #46
michel3 commentedit's very important this patch! there is a hope to have this feature?
Comment #47
meramo commentedSubscribing, the patch must be implemented in module functionality!
Also any progress on a patch for D6?
Comment #48
daggerhart commentedHacked 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
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.
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.
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.
Comment #49
zoen commentedHere'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.
Comment #50
drewish commentedI 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.
Comment #51
meramo commentedZoeN`s patch worked excellent for me! Thanks for this.
This functionality should be included into module for sure
Comment #52
pribeh commented@51 Bump.
Comment #53
tim.plunkettI 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.
Comment #54
tim.plunkettWorked on this more, couldn't come up with anything better, seems to work great.
Comment #55
drewish commentedFinal 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
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:
So looking at:
it seems like they're in minutes... did that not get updated? Also need to have spaces around the multiple operator.
Comment #56
tim.plunkettGood 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?
Comment #57
drewish commentedAh, 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.
Comment #58
tim.plunkettWhew, that was a long standing issue. Thanks everyone, committed to HEAD!