Showing with 195 additions and 57 deletions.
  1. +9 −2 modules/tv/classes/Program.php
  2. +1 −0 modules/tv/detail.php
  3. +83 −2 modules/tv/includes/programs.php
  4. +3 −2 modules/tv/tmpl/default/list_cell_program.php
  5. +99 −51 modules/tv/tmpl/default/list_data.php
11 changes: 9 additions & 2 deletions modules/tv/classes/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Program extends MythBase {
public $description;
public $category;
public $chanid;
public $chanicon;
public $channum;
public $callsign;
public $channame;
Expand Down Expand Up @@ -198,6 +199,12 @@ public function __construct($data) {
$this->category = _or($data['category'], t('Unknown'));
$this->category_type = _or($data['category_type'], t('Unknown'));
$this->chanid = $data['chanid'];
$this->channum = $data['channum'];
$this->channame = $data['channame'];
if ($data['chanicon']){
$this->chanicon = 'data/tv_icons/'.basename($data['chanicon']);
}
$this->callsign = $data['callsign'];
$this->description = $data['description'];
$this->endtime = $data['endtime_unix'];
$this->previouslyshown = $data['previouslyshown'];
Expand Down Expand Up @@ -265,8 +272,8 @@ public function __construct($data) {
if (in_array($this->airdate, array('0000-00-00', '0000', '1900-01-01')))
$this->airdate = NULL;
// Do we have a chanid? Load some info about it
if ($this->chanid && !isset($this->channel))
$this->channel =& Channel::find($this->chanid);
// if ($this->chanid && !isset($this->channel))
// $this->channel =& Channel::find($this->chanid);

// Calculate the duration
if ($this->recendts)
Expand Down
1 change: 1 addition & 0 deletions modules/tv/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@

// If there is a program for this, import its values into the schedule
if ($program) {
$program->channel =& Channel::find($program->chanid);
// Back up the search title
if ($schedule->search) {
$schedule->search_title = $schedule->title;
Expand Down
85 changes: 83 additions & 2 deletions modules/tv/includes/programs.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function &load_one_program($start_time, $chanid, $manualid) {
$program =& load_all_program_data($start_time, $start_time, $chanid, true, 'program.manualid='.intval($manualid));
else
$program =& load_all_program_data($start_time, $start_time, $chanid, true);

$program->channel =& Channel::find($program->chanid);
if (!is_object($program) || strcasecmp(get_class($program), 'program'))
return NULL;
return $program;
Expand Down Expand Up @@ -107,8 +109,6 @@ function &load_all_program_data($start_time, $end_time, $chanid = false, $single
FROM program USE INDEX (id_start_end)
LEFT JOIN programrating USING (chanid, starttime)
LEFT JOIN channel ON program.chanid = channel.chanid
LEFT JOIN credits ON (program.chanid = credits.chanid AND program.starttime = credits.starttime)
LEFT JOIN people ON (credits.person = people.person)
WHERE';
// Only loading a single channel worth of information
if ($chanid > 0)
Expand Down Expand Up @@ -201,3 +201,84 @@ function &load_all_program_data($start_time, $end_time, $chanid = false, $single
// Just in case, return an array of all programs found
return $these_programs;
}

function &load_program_list($start_time, $end_time) {
global $db;
// Don't allow negative timestamps; it confuses MySQL
if ($start_time < 0)
$start_time = 0;
if ($end_time < 0)
$end_time = 0;
// build a recorded map of episodes we need to mark as recorded
$recorded_map = array();
$sh2 = $db->prepare('select program.programid, oldrecorded.recstatus from program
INNER JOIN oldrecorded ON oldrecorded.title = program.title AND oldrecorded.recstatus IN (-3, 11) AND future = 0 AND
oldrecorded.subtitle = program.subtitle AND oldrecorded.description = program.description
where
program.starttime < FROM_UNIXTIME('.$db->escape($end_time).') and program.starttime > FROM_UNIXTIME('.$db->escape($start_time - 60 * 60 * 12).') AND
program.endtime > FROM_UNIXTIME('.$db->escape($start_time).') AND program.starttime != program.endtime
AND (program.category_type = "movie" OR (length(program.title) > 0 AND length(program.subtitle) > 0 AND length(program.description) > 0))');
if ($sh2->num_rows() > 0){
while ($data = $sh2->fetch_assoc()){
$recorded_map[$data['programid']] = $data['recstatus'];
}
}
$sh2->finish();

// Build the sql query, and execute it
$query = 'SELECT program.*,
UNIX_TIMESTAMP(program.starttime) AS starttime_unix,
UNIX_TIMESTAMP(program.endtime) AS endtime_unix,
IFNULL(programrating.system, "") AS rater,
IFNULL(programrating.rating, "") AS rating,
channel.callsign, channel.name as channame, channel.icon as chanicon,
channel.channum, recstatus
FROM program
INNER JOIN channel ON program.chanid = channel.chanid AND channel.visible = 1
LEFT JOIN programrating on programrating.chanid = channel.chanid AND programrating.starttime = program.starttime
LEFT JOIN oldrecorded ON oldrecorded.recstatus IN (-3, 11) AND future = 0 AND
oldrecorded.programid = program.programid AND oldrecorded.seriesid = program.seriesid
WHERE program.starttime < FROM_UNIXTIME('.$db->escape($end_time).') and program.starttime > FROM_UNIXTIME('.$db->escape($start_time - 60 * 60 * 12).') AND
program.endtime > FROM_UNIXTIME('.$db->escape($start_time).') AND program.starttime != program.endtime
GROUP BY channel.callsign, program.chanid, program.starttime
ORDER BY (channel.channum + 0), channel.channum, program.chanid, program.starttime';

// Query
$sh = $db->query($query);
// No results
if ($sh->num_rows() < 1) {
$sh->finish();
return array();
}

// Load in all of the programs (if any?)
$these_programs = array();

// $scheduledRecordings = Schedule::findScheduled();
while ($data = $sh->fetch_assoc()) {
if (!$data['chanid'])
continue;
// This program has already been loaded, and is attached to a recording schedule
if (!empty($data['title']) && $scheduledRecordings[$data['callsign']][$data['starttime_unix']][0]->title == $data['title']) {
$program =& $scheduledRecordings[$data['callsign']][$data['starttime_unix']][0];
// merge in data fetched from DB
$program->merge(new Program($data));
}
// Otherwise, create a new instance of the program
else {
// Create a new instance
if ($recorded_map[$program->programid])
$data['recstatus'] = $recorded_map[$program->programid];

$program =& Program::find($data);
}
// Add this program to the channel hash, etc.
$these_programs[] =& $program;
// Cleanup
unset($program);
}
// Cleanup
$sh->finish();
return $these_programs;
}

5 changes: 3 additions & 2 deletions modules/tv/tmpl/default/list_cell_program.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// then, we just display the info
$percent = intVal($timeslots_used * 96 / num_time_slots);
?>
<td class="small <?php echo $program->css_class; ?>" colspan="<?php echo $timeslots_used ?>" style="width: <?php echo $percent; ?>%" valign="top"><?php
<td class="small <?php echo $program->css_class; ?>" colspan="<?php echo $timeslots_used ?>" valign="top"><?php
// hdtv?
if ($program->hdtv && $percent > 5)
echo '<span class="hdtv_icon">HD</span>';
Expand Down Expand Up @@ -56,9 +56,10 @@ class = "program"
}
$parens = '';
// Finally, print some other information
if ($percent > 5){
if ($program->previouslyshown)
$parens = '<i>'.t('Repeat').'</i>';
if ($parens)
echo "<BR>($parens)";

}
?></td>
150 changes: 99 additions & 51 deletions modules/tv/tmpl/default/list_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,71 +38,119 @@

<table width="100%" border="0" cellpadding="4" cellspacing="2" class="list small">
<?php

if (defined('theme_num_time_slots')) {
$num_time_slots = theme_num_time_slots;
$timeslot_size = theme_timeslot_size;
} else {
$number_of_time_slots = num_time_slots;
$timeslot_size = timeslot_size;
}
?>
<col width="96px"/>
<col span="<?=$number_of_time_slots?>"/>
<col width="24px"/>
<?php
$timeslot_anchor = 0;
$channel_count = 0;
$displayed_channels = array();
$timeslots_left = 0;
$timeslots_used = 0;

$Callsigns = Channel::getCallsignList();

// Go through each channel and load/print its info - use references to avoid "copy" overhead
foreach ($Callsigns as $chanid) {
$channel =& Channel::find($chanid);
$last_chan_id = -1;
// this loads a program list, sorted by channel, then start time
$program_list = load_program_list($list_starttime, $list_endtime);

// Ignore channels with no number
if (strlen($channel->channum) < 1)
continue;
foreach ($program_list as $program) {
if ($last_chan_id == $program->chanid && $program->starttime < $program_ends){
//this is a guard against invalid programs that start before the last program ends
continue;
}
// Get a modified start/end time for this program (in case it starts/ends outside of the aloted time
$program_starts = $program->starttime;
$program_ends = $program->endtime;
if ($program_starts < $list_starttime)
$program_starts = $list_starttime;
if ($program_ends > $list_endtime)
$program_ends = $list_endtime;
// check to see if we've moved onto a new channel row
if ($last_chan_id != $program->chanid){
// Ignore channels with no number
if (strlen($program->channum) < 1)
continue;
// Skip already-displayed channels
if ($displayed_channels[$program->channum][$program->callsign])
continue;
$displayed_channels[$program->channum][$program->callsign] = 1;

// Skip already-displayed channels
if ($displayed_channels[$channel->channum][$channel->callsign])
continue;
$displayed_channels[$channel->channum][$channel->callsign] = 1;

// Display the timeslot bar?
if ($channel_count % timeslotbar_skip == 0) {
// Update the timeslot anchor
$timeslot_anchor++;
if ($last_chan_id != -1){
// close the row, first rows have no rows to close
// Uh oh, there are leftover timeslots - display a no data message
if ($timeslots_left > 0) {
$timeslots_used = $timeslots_left;
require tmpl_dir.'list_cell_nodata.php';
}
echo '<td>&nbsp;</td></tr>';
}
$last_chan_id = $program->chanid;
// Display the timeslot bar?
if ($channel_count % timeslotbar_skip == 0) {
// Update the timeslot anchor
$timeslot_anchor++;
?><tr>
<td class="menu" align="right"><a class="link" onclick="list_update(<?php echo $list_starttime - (timeslot_size * num_time_slots); ?>);" name="anchor<?php echo $timeslot_anchor ?>"><img src="<?php echo skin_url ?>img/left.gif" alt="left"></a></td>
<?php
$block_count = 0;
foreach ($Timeslots as $time) {
if ($block_count++ % timeslot_blocks)
continue;
$block_count = 0;
foreach ($Timeslots as $time) {
if ($block_count++ % timeslot_blocks)
continue;
?>
<td class="menu nowrap" colspan="<?php echo timeslot_blocks ?>" style="width: <?php echo intVal(timeslot_blocks * 94 / num_time_slots) ?>%" align="center"><a class="link" onclick="list_update(<?php echo $time; ?>);"><?php echo strftime($_SESSION['time_format'], $time) ?></a></td>
<td class="menu nowrap" colspan="<?php echo timeslot_blocks ?>" align="center"><a class="link" onclick="list_update(<?php echo $time; ?>);"><?php echo strftime($_SESSION['time_format'], $time) ?></a></td>
<?php
}
}
?>
<td class="menu nowrap"><a class="link" onclick="list_update(<?php echo $list_starttime + (timeslot_size * num_time_slots); ?>);"><img src="<?php echo skin_url ?>img/right.gif" alt="right"></a></td>
</tr><?php
}
// Count this channel
$channel_count++;
// Print the data
?><tr>
<td class="x-channel">
<a href="<?php echo root_url ?>tv/channel/<?php echo $channel->chanid, '/', $list_starttime ?>"
title="<?php
echo t('Details for: $1',
html_entities($channel->name).'; '.$channel->channum)
?>">
<?php if ($_SESSION["show_channel_icons"] == true && !empty($channel->icon)) { ?>
<img src="<?php echo $channel->icon ?>" style="padding:5px;"><br>
<?php } ?>
<?php echo ($_SESSION["prefer_channum"] ? $channel->channum : $channel->callsign), "\n" ?>
<?php if ($_SESSION["show_channel_icons"] == false || empty($channel->icon)) {
echo '<br>('.($_SESSION["prefer_channum"] ? $channel->callsign : $channel->channum), ")\n";
} ?>
</a>
</td>
<?php
// Let the channel object figure out how to display its programs
$channel->display_programs($list_starttime, $list_endtime);
?>
<td>&nbsp;</td>
</tr><?php
flush();
}
// Count this channel
$channel_count++;
// Print the data
?><tr>
<td class="x-channel">
<a href="<?php echo root_url ?>tv/channel/<?php echo $program->chanid, '/', $list_starttime ?>"
title="<?php
echo t('Details for: $1',
html_entities($program->channame).'; '.$program->channum)
?>">
<?php if ($_SESSION["show_channel_icons"] == true && !empty($program->chanicon)) { ?>
<img src="<?php echo $program->chanicon ?>" style="padding:5px;"><br>
<?php } ?>
<?php echo ($_SESSION["prefer_channum"] ? $program->channum : $program->callsign), "\n" ?>
<?php if ($_SESSION["show_channel_icons"] == false || empty($program->chanicon)) {
echo '<br>('.($_SESSION["prefer_channum"] ? $program->callsign : $program->channum), ")\n";
} ?>
</a>
</td>
<?php
$timeslots_left = $number_of_time_slots;
if ($program_starts > $list_starttime) {
$length = (($program_starts - $list_starttime) / $timeslot_size);
if ($length >= 0.5) {
$timeslots_used = round($length);
require tmpl_dir.'list_cell_nodata.php';
$timeslots_left -= $timeslots_used;
}
}
} // end new channel

// Calculate the number of time slots this program gets
$length = round($program_ends / $timeslot_size) - round($program_starts / $timeslot_size);
if ($length < .5) continue; // ignore shows that don't take up at least half a timeslot
$timeslots_used = round($length);
$timeslots_left -= $timeslots_used;
require tmpl_dir.'list_cell_program.php';
// Cleanup is good
unset($program);
// flush();
}
?>
</table>