[mythtv] [mythtv-commits] Ticket #8075: Patch to allow switching between all and only favorite channels in mythweb listings

Tom Dexter digitalaudiorock at gmail.com
Wed Mar 24 00:20:22 UTC 2010


I went ahead and added an option list for the channel group in the settings.

If I try to add the attachment to the 8075 bug I get this error:

 Trac detected an internal error:

error: nothing to repeat

There was an internal error in Trac. It is recommended that you inform
your local Trac administrator and give him all the information he
needs to reproduce the issue.

The action that triggered the error was:

POST: /attachment/ticket/8075/

...any idea what's going in there?  In any case I've attached a patch
with the entire mod here.

Note that this has two new strings for translation: 'All channels' and
'Channel group to display'.

Tom
-------------- next part --------------
Index: mythweb/includes/config.php
===================================================================
--- mythweb/includes/config.php	(revision 23769)
+++ mythweb/includes/config.php	(working copy)
@@ -41,8 +41,8 @@
          $_SESSION['recorded_pixmaps'] = (tmpl == 'default') ? true : false;
 
 // Guide settings
-    if (!isset($_SESSION['guide_favonly']))
-        $_SESSION['guide_favonly'] = false;
+    if (!$_SESSION['guide_channelgroup'])
+        $_SESSION['guide_channelgroup'] = 0;
 
 // The size of timeslots, in seconds (1800 = 30 minutes)
     if ($_SESSION['timeslot_size'] < 300) {
Index: mythweb/modules/tv/set_session.php
===================================================================
--- mythweb/modules/tv/set_session.php	(revision 23769)
+++ mythweb/modules/tv/set_session.php	(working copy)
@@ -29,7 +29,7 @@
         $_SESSION['recorded_pixmaps']   = $_POST['recorded_pixmaps']   ? true : false;
         if (isset($_POST['file_url_override']))  $_SESSION['file_url_override']  = trim(preg_replace('#^file://#', '', $_POST['file_url_override']));
     // Guide Settings
-        $_SESSION['guide_favonly']    = $_POST['guide_favonly'] ? true : false;
+        $_SESSION['guide_channelgroup'] = $_POST['guide_channelgroup'];
         $_SESSION['timeslot_size']    = max(5, intVal($_POST['timeslot_size'])) * 60;
         $_SESSION['num_time_slots']   = max(3, intVal($_POST['num_time_slots']));
         $_SESSION['timeslot_blocks']  = max(1, intVal($_POST['timeslot_blocks']));
@@ -38,3 +38,25 @@
         $_SESSION['star_character']   = $_POST['star_character'];
         $_SESSION['recorded_paging']  = $_POST['recorded_paging'];
     }
+
+/**
+ * Prints a <select> of channel groups
+/**/
+    function channelgroup_select () {
+        global $db;
+        $sh = $db->query('SELECT grpid, name FROM channelgroupnames
+            WHERE EXISTS (SELECT * FROM channelgroup
+            WHERE channelgroup.grpid=channelgroupnames.grpid) ORDER BY name');
+        echo "<select name=\"cgrp\">";
+        echo '<option value="0"';
+        if (!$_SESSION['guide_channelgroup']) echo ' SELECTED';
+        echo '>'.t('All channels').'</option>';
+        while ($grow = $sh->fetch_row()) {
+            echo '<option value="'.$grow[0].'"';
+            if ($_SESSION['guide_channelgroup']==$grow[0]) echo ' SELECTED';
+            echo '>'.htmlspecialchars($grow[1]).'</option>';
+        }
+        $sh->finish();
+        echo '</select>';
+    }
+
Index: mythweb/modules/tv/list.php
===================================================================
--- mythweb/modules/tv/list.php	(revision 23769)
+++ mythweb/modules/tv/list.php	(working copy)
@@ -23,7 +23,7 @@
         $list_starttime = unixtime(sprintf('%08d%04d00', $_REQUEST['date'], $_REQUEST['daytime']));
 // Did we get passed a date (and probably an hour, too)?
     elseif(isset($_REQUEST['date']))
-        $list_starttime = unixtime(sprintf('%08d%02d0000', $_REQUEST['date'], $_REQUEST['hour']));
+        $list_starttime = unixtime(sprintf('%08d%02d0000', date('Ymd',$_REQUEST['date']), $_REQUEST['hour']));
 // Default value - just use the current time
     else
         $list_starttime = time();
@@ -42,6 +42,9 @@
 // Set a session variable so other sections know how to get back to this particular page
     $_SESSION['list_time'] = $list_starttime;
 
+// Set channel group
+    if (isset($_REQUEST['cgrp'])) $_SESSION['guide_channelgroup'] = $_REQUEST['cgrp'];
+    $list_channelgroup = $_SESSION['guide_channelgroup'];
 // Populate the $Channels array
     load_all_channels();
 
@@ -55,6 +58,27 @@
         require_once tmpl_dir.'list.php';
 
 /**
+ * Prints a <select> of channel groups
+/**/
+    function channelgroup_select ($params = '') {
+        global $db;
+        $sh = $db->query('SELECT grpid, name FROM channelgroupnames
+            WHERE EXISTS (SELECT * FROM channelgroup
+            WHERE channelgroup.grpid=channelgroupnames.grpid) ORDER BY name');
+        echo "<select name=\"cgrp\" $params>";
+        echo '<option value="0"';
+        if (!$_SESSION['guide_channelgroup']) echo ' SELECTED';
+        echo '>'.t('All channels').'</option>';
+        while ($grow = $sh->fetch_row()) {
+            echo '<option value="'.$grow[0].'"';
+            if ($_SESSION['guide_channelgroup']==$grow[0]) echo ' SELECTED';
+            echo '>'.htmlspecialchars($grow[1]).'</option>';
+        }
+        $sh->finish();
+        echo '</select>';
+    }
+
+/**
  * Prints a <select> of the available hour range
 /**/
     function hour_select($params = '') {
Index: mythweb/modules/tv/includes/channels.php
===================================================================
--- mythweb/modules/tv/includes/channels.php	(revision 23769)
+++ mythweb/modules/tv/includes/channels.php	(working copy)
@@ -33,10 +33,14 @@
         global $Callsigns;
         $Channels = array();
     // Initialize the query
-        if ($_SESSION['guide_favonly'])
-            $sql = 'SELECT channel.* FROM channel, favorites WHERE channel.chanid = favorites.chanid AND';
-        else
+        if ($_SESSION['guide_channelgroup']) {
+            $sql = 'SELECT channel.* FROM channel JOIN channelgroup ON channelgroup.chanid=channel.chanid ' .
+                'WHERE channelgroup.grpid=? AND';
+            $params = array($_SESSION['guide_channelgroup']);
+        } else {
             $sql = 'SELECT * FROM channel WHERE';
+            $params = array();
+        }
         $sql .= ' channel.visible=1';
         $sql .= ' GROUP BY channel.channum, channel.callsign';
     // Sort
@@ -44,7 +48,7 @@
                 .($_SESSION["sortby_channum"] ? '' : 'channel.callsign, ')
                 .'(channel.channum + 0), channel.channum, channel.chanid';  // sort by channum as both int and string to grab subchannels
     // Query
-        $sh = $db->query($sql);
+        $sh = $db->query($sql, $params);
         while ($channel_data = $sh->fetch_assoc())  {
             $Channels[$channel_data['chanid']] = new Channel($channel_data);
             if (empty($Callsigns[$channel_data['channum'].':'.$channel_data['callsign']]))
@@ -53,9 +57,10 @@
         $sh->finish();
     // No channels returned?
         if (empty($Channels)) {
-            unset($_SESSION['guide_favonly']);
+            $cgrp = $_SESSION['guide_channelgroup'];
+            $_SESSION['guide_channelgroup'] = 0;
             trigger_error('No channels were detected.  '
-                         .($_SESSION['guide_favonly']
+                         .($cgrp
                             ? 'The "favorites only" option has now been turned off, please reload this page to try again.'
                             : 'Are you sure that MythTV is properly configured?'),
                           FATAL);
Index: mythweb/modules/tv/tmpl/default/set_session.php
===================================================================
--- mythweb/modules/tv/tmpl/default/set_session.php	(revision 23769)
+++ mythweb/modules/tv/tmpl/default/set_session.php	(working copy)
@@ -42,8 +42,8 @@
 </tr><tr class="x-sep">
     <td colspan="2"><?php echo t('Guide Settings') ?>:</th>
 </tr><tr>
-    <th><?php echo t('Only display favourite channels') ?>:</th>
-    <td ><input class="radio" type="checkbox" title="In the program listing, only show channels marked as favourite channels" name="guide_favonly"<?php if ($_SESSION['guide_favonly']) echo ' CHECKED' ?>></td>
+    <th><?php echo t('Channel group to display') ?>:</th>
+    <td><?php channelgroup_select(); ?></td>
 </tr><tr>
     <th><?php echo t('Max star rating for movies') ?>:</th>
     <td><input type="text" size="5" name="max_stars" value="<?php echo intVal($_SESSION['max_stars']) ?>"></td>
Index: mythweb/modules/tv/tmpl/default/list_data.php
===================================================================
--- mythweb/modules/tv/tmpl/default/list_data.php	(revision 23769)
+++ mythweb/modules/tv/tmpl/default/list_data.php	(working copy)
@@ -25,13 +25,14 @@
     <table id="x-jumpto" class="commandbox commands" border="0" cellspacing="0" cellpadding="0">
     <tr>
         <td class="x-jumpto"><?php echo t('Jump To') ?>:</td>
-        <td class="x-hour"><?php hour_select('id="hour_select" onchange="list_update($(\'hour_select\')[$(\'hour_select\').selectedIndex].value);"') ?></td>
+        <td class="x-cgrp"><?php channelgroup_select('id="cgrp_select" onchange="list_update('.$list_starttime.',$(\'cgrp_select\')[$(\'cgrp_select\').selectedIndex].value);"') ?></td>
+        <td class="x-hour"><?php hour_select('id="hour_select" onchange="list_update($(\'hour_select\')[$(\'hour_select\').selectedIndex].value,'.$list_channelgroup.');"') ?></td>
         <td class="x-day">
-            <a class="link" onclick="list_update(<?php echo $list_starttime - (24 * 60 * 60); ?>);">
+            <a class="link" onclick="list_update(<?php echo ($list_starttime - (24 * 60 * 60)).','.$list_channelgroup; ?>);">
                 <img src="<?php echo skin_url ?>img/left.gif" alt="<?php echo t('left'); ?>">
             </a>
-            <?php date_select('id="date_select" onchange="list_update($(\'date_select\')[$(\'date_select\').selectedIndex].value);"') ?>
-            <a class="link" onclick="list_update(<?php echo $list_starttime + (24 * 60 * 60); ?>);">
+            <?php date_select('id="date_select" onchange="list_update($(\'date_select\')[$(\'date_select\').selectedIndex].value,'.$list_channelgroup.');"') ?>
+            <a class="link" onclick="list_update(<?php echo ($list_starttime + (24 * 60 * 60)).','.$list_channelgroup; ?>);">
                 <img src="<?php echo skin_url ?>img/right.gif" alt="<?php echo t('right'); ?>">
             </a>
         </td>
Index: mythweb/modules/tv/tmpl/default/list.php
===================================================================
--- mythweb/modules/tv/tmpl/default/list.php	(revision 23769)
+++ mythweb/modules/tv/tmpl/default/list.php	(working copy)
@@ -24,14 +24,15 @@
 ?>
 
 <script type="text/javascript">
-    function list_update(timestamp) {
+    function list_update(timestamp, cgrp) {
         ajax_add_request();
         new Ajax.Updater($('list_content'),
                          '<?php echo root_url ?>tv/list',
                          {
                             parameters: {
                                             ajax: true,
-                                            time: timestamp
+                                            time: timestamp,
+                                            cgrp: cgrp
                                         },
                             onComplete: ajax_remove_request
                          }
Index: mythweb/modules/tv/tmpl/lite/set_session.php
===================================================================
--- mythweb/modules/tv/tmpl/lite/set_session.php	(revision 23769)
+++ mythweb/modules/tv/tmpl/lite/set_session.php	(working copy)
@@ -28,8 +28,8 @@
 </tr><tr>
     <td colspan="2"><?php echo t('Guide Settings') ?>:</td>
 </tr><tr>
-    <td align="right"><?php echo t('Only display favourite channels') ?>:</td>
-    <td ><input class="radio" type="checkbox" title="In the program listing, only show channels marked as favourite channels" name="guide_favonly"<?php if ($_SESSION['guide_favonly']) echo ' CHECKED' ?>></td>
+    <th><?php echo t('Channel group to display') ?>:</th>
+    <td><?php channelgroup_select(); ?></td>
 </tr><tr>
     <td align="right"><?php echo t('Max star rating for movies') ?>:</td>
     <td><input type="text" size="5" name="max_stars" value="<?php echo intVal($_SESSION['max_stars']) ?>"></td>
Index: mythweb/modules/tv/tmpl/lite/list.php
===================================================================
--- mythweb/modules/tv/tmpl/lite/list.php	(revision 23769)
+++ mythweb/modules/tv/tmpl/lite/list.php	(working copy)
@@ -31,6 +31,7 @@
         <tr>
 
             <td nowrap align="center"><?php echo t('Jump To') ?>:&nbsp;&nbsp;</td>
+            <td><?php channelgroup_select() ?></td>
             <td align="right"><?php echo t('Hour') ?>:&nbsp;</td>
             <td><select name="hour" style="text-align: right"><?php
                 for ($h=0;$h<24;$h++) {
@@ -41,7 +42,7 @@
                 }
                 ?></select></td>
             <td align="right"><?php echo t('Date') ?>:&nbsp;</td>
-            <tdnowrap><?php date_select() ?></td>
+            <td nowrap><?php date_select() ?></td>
             <td align="center"><input type="submit" class="submit" value="<?php echo t('Jump') ?>"></td>
         </tr>
         </table>


More information about the mythtv-dev mailing list