Skip to content

Commit ece58eb

Browse files
committed
Fixes #12822 - Duplicate programs showing in listings.
1 parent ba6598a commit ece58eb

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

modules/tv/includes/programs.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,32 @@ function &load_all_program_data($start_time, $end_time, $chanid = false, $single
9797
trigger_error("load_all_program_data() attempted with out any channels", FATAL);
9898
$these_channels = implode(',', $these_channels);
9999
// Build the sql query, and execute it
100+
// The weird stuff with pr1 and pr2 is to eliminate the mutiple ratings
101+
// per program which causes duplicates to be found.
102+
// This code selects the "rater" with the highest name alphabetically,
103+
// so for example where raters available for a program are CHVRS ClassInd and VCHIP,
104+
// it selects VCHIP.
100105
$query = 'SELECT DISTINCT program.*,
101106
UNIX_TIMESTAMP(program.starttime) AS starttime_unix,
102107
UNIX_TIMESTAMP(program.endtime) AS endtime_unix,
103-
IFNULL(programrating.system, "") AS rater,
104-
IFNULL(programrating.rating, "") AS rating,
108+
IFNULL(pr1.system, "") AS rater,
109+
IFNULL(pr1.rating, "") AS rating,
105110
channel.callsign,
106111
channel.channum
107112
FROM program USE INDEX (id_start_end)
108-
LEFT JOIN programrating USING (chanid, starttime)
109-
LEFT JOIN channel USING (chanid)
110-
LEFT JOIN credits USING (chanid, starttime)
113+
LEFT JOIN programrating pr1
114+
on program.chanid = pr1.chanid
115+
and program.starttime = pr1.starttime
116+
LEFT OUTER JOIN programrating pr2
117+
on program.chanid = pr2.chanid
118+
and program.starttime = pr2.starttime
119+
and pr2.system > pr1.system
120+
LEFT JOIN channel on channel.chanid = program.chanid
121+
LEFT JOIN credits
122+
on program.chanid = credits.chanid
123+
and program.starttime = credits.starttime
111124
LEFT JOIN people USING (person)
112-
WHERE';
125+
WHERE pr2.system is null and ';
113126
// Only loading a single channel worth of information
114127
if ($chanid > 0)
115128
$query .= ' program.chanid='.$db->escape($chanid);

0 commit comments

Comments
 (0)