Skip to content

Commit ed4c25d

Browse files
authored
Merge pull request #60 from mymatenige/schedules-table-sort
Add support for table header sorting with recording schedules.
2 parents 736e379 + ca8d0da commit ed4c25d

File tree

4 files changed

+107
-35
lines changed

4 files changed

+107
-35
lines changed

includes/sorting.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,53 @@ function by_transcoder(&$a, &$b) {
235235
if ($a->transcoder == $b->transcoder) return 0;
236236
return ($a->transcoder > $b->transcoder) ? 1 : -1;
237237
}
238+
239+
function by_callsign_with_type(&$a, &$b) {
240+
// If this is an 'always on any channel' or 'find one' recording without the 'This Channel' filter, set the callsign to 'Any'
241+
if (($a->type == rectype_always || $a->type == rectype_findone) && !($a->filter & (1 << 10)))
242+
$ac = '['.t('Any').']';
243+
else
244+
$ac = $a->channel->callsign;
245+
246+
if (($b->type == rectype_always || $b->type == rectype_findone) && !($b->filter & (1 << 10)))
247+
$bc = '['.t('Any').']';
248+
else
249+
$bc = $b->channel->callsign;
250+
251+
return strnatcasecmp($ac, $bc);
252+
}
253+
254+
function by_channum_with_type(&$a, &$b) {
255+
// If this is an 'always on any channel' or 'find one' recording without the 'This Channel' filter, set the channum to 'Any'
256+
if (($a->type == rectype_always || $a->type == rectype_findone) && !($a->filter & (1 << 10)))
257+
$ac = '['.t('Any').']';
258+
else
259+
$ac = $a->channel->channum;
260+
261+
if (($b->type == rectype_always || $b->type == rectype_findone) && !($b->filter & (1 << 10)))
262+
$bc = '['.t('Any').']';
263+
else
264+
$bc = $b->channel->channum;
265+
266+
return strnatcasecmp($ac, $bc);
267+
}
268+
269+
function by_endoffset(&$a, &$b) {
270+
if ($a->endoffset == $b->endoffset) return 0;
271+
return ($a->endoffset > $b->endoffset) ? 1 : -1;
272+
}
273+
274+
function by_last_record(&$a, &$b) {
275+
if ($a->last_record == $b->last_record) return 0;
276+
return ($a->last_record > $b->last_record) ? 1 : -1;
277+
}
278+
279+
function by_startoffset(&$a, &$b) {
280+
if ($a->startoffset == $b->startoffset) return 0;
281+
return ($a->startoffset > $b->startoffset) ? 1 : -1;
282+
}
283+
284+
function by_storagegroup(&$a, &$b) {
285+
if ($a->storagegroup == $b->storagegroup) return 0;
286+
return ($a->storagegroup > $b->storagegroup) ? 1 : -1;
287+
}

modules/tv/classes/Schedule.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ public static function findAll($sort = true) {
112112
case 'airdate':
113113
$orderby .= 'starttime';
114114
break;
115+
case 'callsign_with_type':
116+
$orderby .= 'CASE WHEN (type = '.rectype_always.' OR type = '.rectype_findone.') AND !(filter & (1 << 10)) THEN "" ELSE callsign END';
117+
break;
118+
case 'channum_with_type':
119+
$orderby .= 'CASE WHEN (type = '.rectype_always.' OR type = '.rectype_findone.') AND !(filter & (1 << 10)) THEN 0 ELSE channum END';
120+
break;
121+
case 'last_record':
122+
$orderby .= 'record.last_record';
123+
break;
115124
case 'recpriority':
116125
$orderby .= 'record.recpriority';
117126
break;

modules/tv/tmpl/default/schedules.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// Print the page contents
3030
$group_field = $_GET['sortby'];
31-
if ($group_field == 'title' || !in_array($group_field, array('title', 'channum', 'type', 'profile', 'recgroup')))
31+
if ($group_field == 'title' || !in_array($group_field, array('title', 'callsign', 'channum', 'type', 'profile', 'recgroup')))
3232
$group_field = '';
3333
?>
3434

@@ -71,17 +71,17 @@ function attempt_to_show_tip(element) {
7171
<thead>
7272
<tr class="menu">
7373
<?php if ($group_field != '') echo "<th class=\"list\">&nbsp;</th>\n"; ?>
74-
<th class="x-title"><?php echo t('Title' ); ?></th>
75-
<th class="x-priority"><?php echo t('Recording Priority' ); ?></th>
76-
<th class="x-channel" sort_hint="sortMythwebChannel"><?php echo t('Channel' ); ?></th>
77-
<th class="x-profile"><?php echo t('Profile' ); ?></th>
78-
<th class="x-transcoder"><?php echo t('Transcoder'); ?></th>
79-
<th class="x-group"><?php echo t('Recording Group'); ?></th>
80-
<th class="x-type"><?php echo t('Type'); ?></th>
81-
<th class="x-sgroup"><?php echo t('Storage Group'); ?></th>
82-
<th class="x-startoffset"><?php echo t('Start Early'); ?></th>
83-
<th class="x-endoffset"><?php echo t('End Late'); ?></th>
84-
<th class="x-lastrec"><?php echo t('Last Recorded'); ?></th>
74+
<th class="x-title"><?php echo get_sort_link('title', t('Title' )); ?></th>
75+
<th class="x-priority"><?php echo get_sort_link('recpriority', t('Recording Priority' )); ?></th>
76+
<th class="x-channel"><?php echo get_sort_link($_SESSION["prefer_channum"] ? 'channum_with_type' : 'callsign_with_type', t('Channel' )); ?></th>
77+
<th class="x-profile"><?php echo get_sort_link('profile', t('Profile' )); ?></th>
78+
<th class="x-transcoder"><?php echo get_sort_link('transcoder', t('Transcoder')); ?></th>
79+
<th class="x-group"><?php echo get_sort_link('recgroup', t('Recording Group')); ?></th>
80+
<th class="x-type"><?php echo get_sort_link('type', t('Type')); ?></th>
81+
<th class="x-sgroup"><?php echo get_sort_link('storagegroup', t('Storage Group')); ?></th>
82+
<th class="x-startoffset"><?php echo get_sort_link('startoffset', t('Start Early')); ?></th>
83+
<th class="x-endoffset"><?php echo get_sort_link('endoffset', t('End Late')); ?></th>
84+
<th class="x-lastrec"><?php echo get_sort_link('last_record', t('Last Recorded')); ?></th>
8585
</tr>
8686
</thead>
8787
<?php
@@ -97,8 +97,9 @@ function attempt_to_show_tip(element) {
9797
$css_class = ($schedule->type == rectype_dontrec ? 'deactivated' : 'scheduled');
9898
// If this is an 'always on any channel' or 'find one' recording without the 'This Channel' filter, set the channel name to 'Any'
9999
if (($schedule->type == rectype_always || $schedule->type == rectype_findone) && !($schedule->filter & (1 << 10))) {
100-
$schedule->channel->name = '[ '.t('Any').' ]';
101-
$schedule->channel->channum = 0;
100+
$any_channel = true;
101+
} else {
102+
$any_channel = false;
102103
}
103104
// A program id counter for popup info
104105
if ($_SESSION["show_popup_info"]) {
@@ -109,6 +110,8 @@ function attempt_to_show_tip(element) {
109110
// Print a dividing row if grouping changes
110111
if ($group_field == 'type')
111112
$cur_group = $schedule->texttype;
113+
elseif ($group_field == 'callsign')
114+
$cur_group = ($schedule->channel->callsign ? $schedule->channel->callsign.' - ' : '').$schedule->channel->name;
112115
elseif ($group_field == 'channum')
113116
$cur_group = ($schedule->channel->channum ? $schedule->channel->channum.' - ' : '').$schedule->channel->name;
114117
elseif ($group_field == 'profile')
@@ -163,15 +166,19 @@ function attempt_to_show_tip(element) {
163166
echo $schedule->recpriority
164167
?></td>
165168
<td class="x-channel"><?php
166-
if ($_SESSION["prefer_channum"]) {
167-
if ($schedule->channel->channum)
168-
echo $schedule->channel->channum.' - ';
169+
if ($any_channel) {
170+
echo '[ '.t('Any').' ]';
171+
} else {
172+
if ($_SESSION["prefer_channum"]) {
173+
if ($schedule->channel->channum)
174+
echo $schedule->channel->channum.' - ';
175+
}
176+
else {
177+
if ($schedule->channel->callsign)
178+
echo $schedule->channel->callsign.' - ';
179+
}
180+
echo $schedule->channel->name;
169181
}
170-
else {
171-
if ($schedule->channel->callsign)
172-
echo $schedule->channel->callsign.' - ';
173-
}
174-
echo $schedule->channel->name;
175182
?></td>
176183
<td class="x-profile"><?php echo _or($schedule->profile, '&nbsp;') ?></td>
177184
<td class="x-transcoder"><?php

modules/tv/tmpl/lite/schedules.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
// Print the page contents
3333
$group_field = $_GET['sortby'];
34-
if ($group_field == 'title' || !in_array($group_field, array('title', 'channum', 'type', 'profile', 'recgroup')))
34+
if ($group_field == 'title' || !in_array($group_field, array('title', 'callsign', 'channum', 'type', 'profile', 'recgroup')))
3535
$group_field = '';
3636
?>
3737

@@ -40,7 +40,7 @@
4040
<?php if ($group_field != '') echo "<td class=\"list\">&nbsp;</td>\n" ?>
4141
<td><?php echo get_sort_link('title', t('title')) ?></td>
4242
<td><?php echo get_sort_link('recpriority', t('recpriority')) ?></td>
43-
<td><?php echo get_sort_link($_SESSION["prefer_channum"] ? 'channum' : 'callsign', t('channel')) ?></td>
43+
<td><?php echo get_sort_link($_SESSION["prefer_channum"] ? 'channum_with_type' : 'callsign_with_type', t('channel')) ?></td>
4444
<td><?php echo get_sort_link('profile', t('profile')) ?></td>
4545
<td><?php echo get_sort_link('transcoder', t('transcoder')) ?></td>
4646
<td><?php echo get_sort_link('recgroup', t('recgroup')) ?></td>
@@ -58,13 +58,15 @@
5858
$css_class = ($schedule->type == rectype_dontrec ? 'deactivated' : 'scheduled');
5959
// If this is an 'always on any channel' or 'find one' recording without the 'This Channel' filter, set the channel name to 'Any'
6060
if (($schedule->type == rectype_always || $schedule->type == rectype_findone) && !($schedule->filter & (1 << 10))) {
61-
$schedule->channel->name = '[ '.t('Any').' ]';
62-
$schedule->channel->channum = 0;
61+
$any_channel = true;
62+
} else {
63+
$any_channel = false;
6364
}
64-
6565
// Print a dividing row if grouping changes
6666
if ($group_field == 'type')
6767
$cur_group = $schedule->texttype;
68+
elseif ($group_field == 'callsign')
69+
$cur_group = ($schedule->channel->callsign ? $schedule->channel->callsign.' - ' : '').$schedule->channel->name;
6870
elseif ($group_field == 'channum')
6971
$cur_group = ($schedule->channel->channum ? $schedule->channel->channum.' - ' : '').$schedule->channel->name;
7072
elseif ($group_field == 'profile')
@@ -112,15 +114,19 @@
112114
echo $schedule->recpriority
113115
?></td>
114116
<td><?php
115-
if ($_SESSION["prefer_channum"]) {
116-
if ($schedule->channel->channum)
117-
echo $schedule->channel->channum.' - ';
118-
}
119-
else {
120-
if ($schedule->channel->callsign)
121-
echo $schedule->channel->callsign.' - ';
117+
if ($any_channel) {
118+
echo '[ '.t('Any').' ]';
119+
} else {
120+
if ($_SESSION["prefer_channum"]) {
121+
if ($schedule->channel->channum)
122+
echo $schedule->channel->channum.' - ';
123+
}
124+
else {
125+
if ($schedule->channel->callsign)
126+
echo $schedule->channel->callsign.' - ';
127+
}
128+
echo $schedule->channel->name;
122129
}
123-
echo $schedule->channel->name;
124130
?></td>
125131
<td nowrap><?php echo _or($schedule->profile, '&nbsp;') ?></td>
126132
<td nowrap>

0 commit comments

Comments
 (0)