Next Scheduled Program Block

tim.plunkett - September 17, 2009 - 22:26
Project:Station
Version:6.x-2.x-dev
Component:Schedule
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Always wanted one of these.

90% of it was copy/paste, but I had to mess around with some of the logic in station_schedule_program_get_next.
Also, didn't write a station_program_get_next, since I didn't understand the XMLRPC/caching stuff.

Works for me, even on the wrap-around between Sunday and Monday.

Cheers!

AttachmentSize
station_next.patch6.46 KB

#1

drewish - September 17, 2009 - 23:07

I think I'd rather focus on the views half of it... it doesn't really seem to be used by the rest of the patch though...

#2

tim.plunkett - September 17, 2009 - 23:19

You mean the changes made to station/schedule/views.inc?
Yeah, I just copied everything related to "current_program" and made a "next_program" version, then made appropriate changes.

I ended up not changing anything there, I guess.

I was uncertain pretty much the entire time, so if something seems arbitrary or unnecessary, it probably is.

#3

drewish - September 20, 2009 - 02:31

I think you can actually do this all with the current views code. Try importing this view and playing with it:

<?php
$view
= new view;
$view->name = 'station_schedule_upcoming';
$view->description = 'Upcoming programming.';
$view->tag = 'station_schedule';
$view->view_php = '';
$view->base_table = 'station_schedule_item';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
 
'program_nid' => array(
   
'label' => 'Program',
   
'required' => 0,
   
'id' => 'program_nid',
   
'table' => 'station_schedule_item',
   
'field' => 'program_nid',
   
'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
 
'title' => array(
   
'label' => '',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'link_to_node' => 1,
   
'exclude' => 0,
   
'id' => 'title',
   
'table' => 'node',
   
'field' => 'title',
   
'relationship' => 'program_nid',
  ),
 
'start' => array(
   
'label' => '',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'style' => 'station_hour_range',
   
'exclude' => 0,
   
'id' => 'start',
   
'table' => 'station_schedule_item',
   
'field' => 'start',
   
'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
 
'finish' => array(
   
'order' => 'ASC',
   
'start_from' => 'now',
   
'id' => 'finish',
   
'table' => 'station_schedule_item',
   
'field' => 'finish',
   
'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
 
'type' => 'none',
));
$handler->override_option('title', 'Upcoming Programs');
$handler->override_option('items_per_page', 2);
$handler->override_option('use_more', 0);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
?>

#4

tim.plunkett - September 20, 2009 - 16:28

I'm still baffled by Views sometimes.
For example, why is it that I can use "Station schedule item: Finish" to sort by, but I can't seem to filter by "Station schedule item: Start"?

Otherwise, this code works great, except it includes the show currently on-air. Not sure how to get around that.

#5

drewish - September 20, 2009 - 17:37

Because I never finished the filter handler for that field ;) I got sort of stalled out trying to decide how the option should work. It seemed like it should have options, perhaps:

  • now
  • now + [number of minutes]
  • at [specific time]
  • between [start time] and [end time]

Though the first two seems like the most important options. I'll spend some time on it today and see what I can whip up. I'd really like to get a "stable" 2.x release out the door and I feel like the schedule views support is one of the last big things to do.

#6

drewish - September 20, 2009 - 21:14

i've committed some other views fixes but here's a patch i'm working on to rework the start and finish handling.

AttachmentSize
station_views.patch 13.09 KB

#7

drewish - September 21, 2009 - 17:36

This is getting pretty close. I've broken the schedule item times up into start, finish and time range. This might break some existing views but it should be easy enough to correct.

Updated export of the demo view:

<?php
$view
= new view;
$view->name = 'station_schedule_upcoming';
$view->description = 'Upcoming programs';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'station_schedule_item';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
 
'program_nid' => array(
   
'label' => 'Program',
   
'required' => 0,
   
'id' => 'program_nid',
   
'table' => 'station_schedule_item',
   
'field' => 'program_nid',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
 
'schedule_nid' => array(
   
'label' => 'Schedule',
   
'required' => 0,
   
'id' => 'schedule_nid',
   
'table' => 'station_schedule_item',
   
'field' => 'schedule_nid',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
 
'title' => array(
   
'label' => '',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'link_to_node' => 1,
   
'exclude' => 0,
   
'id' => 'title',
   
'table' => 'node',
   
'field' => 'title',
   
'relationship' => 'program_nid',
   
'override' => array(
     
'button' => 'Override',
    ),
  ),
 
'start' => array(
   
'label' => 'Start',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'style' => 'station_dayhour',
   
'exclude' => 0,
   
'id' => 'start',
   
'table' => 'station_schedule_item',
   
'field' => 'start',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
 
'finish' => array(
   
'label' => 'Finish',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'style' => 'station_hour',
   
'exclude' => 0,
   
'id' => 'finish',
   
'table' => 'station_schedule_item',
   
'field' => 'finish',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
 
'time' => array(
   
'label' => 'Duration',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'style' => 'station_hour_duration',
   
'exclude' => 0,
   
'id' => 'time',
   
'table' => 'station_schedule_item',
   
'field' => 'time',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
 
'start' => array(
   
'operator' => '<=',
   
'value' => array(
     
'mode' => 'now',
     
'offset' => '',
     
'value' => 0,
     
'min' => '',
     
'max' => '',
    ),
   
'group' => '0',
   
'exposed' => FALSE,
   
'expose' => array(
     
'operator' => 'start_op',
     
'label' => 'Station schedule item: Start',
     
'use_operator' => FALSE,
     
'identifier' => 'start',
     
'remember' => FALSE,
     
'single' => TRUE,
     
'optional' => TRUE,
    ),
   
'id' => 'start',
   
'table' => 'station_schedule_item',
   
'field' => 'start',
   
'relationship' => 'none',
   
'override' => array(
     
'button' => 'Override',
    ),
  ),
 
'finish' => array(
   
'operator' => '>',
   
'value' => array(
     
'mode' => 'now',
     
'offset' => '0',
     
'value' => 1800,
     
'min' => '',
     
'max' => '',
    ),
   
'group' => '0',
   
'exposed' => FALSE,
   
'expose' => array(
     
'operator' => FALSE,
     
'label' => '',
    ),
   
'id' => 'finish',
   
'table' => 'station_schedule_item',
   
'field' => 'finish',
   
'relationship' => 'none',
   
'override' => array(
     
'button' => 'Override',
    ),
  ),
 
'status_extra' => array(
   
'operator' => '=',
   
'value' => '',
   
'group' => '0',
   
'exposed' => FALSE,
   
'expose' => array(
     
'operator' => FALSE,
     
'label' => '',
    ),
   
'id' => 'status_extra',
   
'table' => 'node',
   
'field' => 'status_extra',
   
'relationship' => 'program_nid',
  ),
));
$handler->override_option('access', array(
 
'type' => 'perm',
 
'perm' => 'view station schedule content',
));
$handler->override_option('title', 'Upcomming programs');
$handler->override_option('empty', 'Nothing is scheduled.');
$handler->override_option('empty_format', '1');
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', 'Station Schedule Upcoming Programs');
$handler->override_option('block_caching', -1);
?>

AttachmentSize
station_580806.patch 16.28 KB

#8

drewish - September 21, 2009 - 17:44
Status:needs review» needs work

I committed the patch for the views code since I'm pretty happy with it. I do want to work on a default "now playing" block view to ship with the module (probably disabled).

#9

tim.plunkett - September 21, 2009 - 18:29

double post

#10

tim.plunkett - September 21, 2009 - 18:23

Just a heads up to anyone applying these patches:
I updated to HEAD, and it broke the views code from comment #3 pretty horribly.
Make sure to delete that view!

So, "Upcoming" is spelled wrong.
Also, before I go crazy trying to get it in there: what's an easy way to get the "Tune In" with links to the streams into this block?

On second review: this displays the current program. Purposeful?

#11

tim.plunkett - September 21, 2009 - 22:41

The views code in comment #7 is perfect for current programs, this is what I came up with for next program.

<?php
$view
= new view;
$view->name = 'station_schedule_upcoming';
$view->description = 'Upcoming programs';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'station_schedule_item';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
 
'program_nid' => array(
   
'label' => 'Program',
   
'required' => 0,
   
'id' => 'program_nid',
   
'table' => 'station_schedule_item',
   
'field' => 'program_nid',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
 
'schedule_nid' => array(
   
'label' => 'Schedule',
   
'required' => 0,
   
'id' => 'schedule_nid',
   
'table' => 'station_schedule_item',
   
'field' => 'schedule_nid',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
 
'title' => array(
   
'label' => '',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'link_to_node' => 1,
   
'exclude' => 0,
   
'id' => 'title',
   
'table' => 'node',
   
'field' => 'title',
   
'relationship' => 'program_nid',
   
'override' => array(
     
'button' => 'Override',
    ),
  ),
 
'start' => array(
   
'label' => '',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'link_class' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'target' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'empty' => '',
   
'hide_empty' => 0,
   
'empty_zero' => 0,
   
'style' => 'station_dayhour',
   
'exclude' => 0,
   
'id' => 'start',
   
'table' => 'station_schedule_item',
   
'field' => 'start',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
 
'finish' => array(
   
'label' => '',
   
'alter' => array(
     
'alter_text' => 0,
     
'text' => '',
     
'make_link' => 0,
     
'path' => '',
     
'link_class' => '',
     
'alt' => '',
     
'prefix' => '',
     
'suffix' => '',
     
'target' => '',
     
'help' => '',
     
'trim' => 0,
     
'max_length' => '',
     
'word_boundary' => 1,
     
'ellipsis' => 1,
     
'strip_tags' => 0,
     
'html' => 0,
    ),
   
'empty' => '',
   
'hide_empty' => 0,
   
'empty_zero' => 0,
   
'style' => 'station_hour',
   
'exclude' => 0,
   
'id' => 'finish',
   
'table' => 'station_schedule_item',
   
'field' => 'finish',
   
'override' => array(
     
'button' => 'Override',
    ),
   
'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
 
'start' => array(
   
'order' => 'ASC',
   
'start_from' => 'begin_week',
   
'id' => 'start',
   
'table' => 'station_schedule_item',
   
'field' => 'start',
   
'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
 
'start' => array(
   
'operator' => '>',
   
'value' => array(
     
'mode' => 'now',
     
'value' => 0,
     
'min' => '',
     
'max' => '',
     
'offset' => '',
    ),
   
'group' => '0',
   
'exposed' => FALSE,
   
'expose' => array(
     
'operator' => 'start_op',
     
'label' => 'Station schedule item: Start',
     
'use_operator' => FALSE,
     
'identifier' => 'start',
     
'remember' => FALSE,
     
'single' => TRUE,
     
'optional' => TRUE,
    ),
   
'id' => 'start',
   
'table' => 'station_schedule_item',
   
'field' => 'start',
   
'relationship' => 'none',
   
'override' => array(
     
'button' => 'Override',
    ),
  ),
 
'status_extra' => array(
   
'operator' => '=',
   
'value' => '',
   
'group' => '0',
   
'exposed' => FALSE,
   
'expose' => array(
     
'operator' => FALSE,
     
'label' => '',
    ),
   
'id' => 'status_extra',
   
'table' => 'node',
   
'field' => 'status_extra',
   
'relationship' => 'program_nid',
  ),
));
$handler->override_option('access', array(
 
'type' => 'perm',
 
'perm' => 'view station schedule content',
));
$handler->override_option('cache', array(
 
'type' => 'none',
));
$handler->override_option('title', 'Upcoming programs');
$handler->override_option('empty', 'Nothing is scheduled.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 1);
$handler->override_option('row_options', array(
 
'inline' => array(
   
'start' => 'start',
   
'finish' => 'finish',
  ),
 
'separator' => ' - ',
 
'hide_empty' => 0,
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', 'Station Schedule Upcoming Programs');
$handler->override_option('block_caching', -1);
?>

#12

drewish - September 23, 2009 - 05:16

If there's only one program in the block you can just add a relation to the schedule and add its tune in link. If there's more than one it'll appear in each item (which might be what you want if you've got multiple schedules).

#13

drewish - September 27, 2009 - 06:33
Status:needs work» fixed

i think this has been addressed. if not feel free to re-open the issue.

#14

System Message - October 11, 2009 - 06:40
Status:fixed» closed

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

#15

daggerhart - November 19, 2009 - 21:41

I'm using the view from Comment #11, but it doesn't seem to be wrapping back around to Sunday. Just getting Thursday -> Saturday programs.

Anyone else have the same result ?

 
 

Drupal is a registered trademark of Dries Buytaert.