77use App \Facades \PlaylistFacade ;
88use App \Http \Controllers \Controller ;
99use App \Http \Controllers \LogoProxyController ;
10+ use App \Http \Controllers \PlaylistGenerateController ;
1011use App \Models \Epg ;
1112use App \Models \Playlist ;
1213use App \Models \StreamProfile ;
@@ -191,27 +192,7 @@ public function getDataForPlaylist(string $uuid, Request $request)
191192 ]);
192193 try {
193194 // Get enabled channels from the playlist
194- $ playlistChannels = $ playlist ->channels ()
195- ->leftJoin ('groups ' , 'channels.group_id ' , '= ' , 'groups.id ' )
196- ->where ('channels.enabled ' , true )
197- ->when (! $ vod , function ($ query ) {
198- return $ query ->where ('channels.is_vod ' , false );
199- })
200- ->with (['epgChannel ' , 'tags ' , 'group ' ])
201- ->orderBy ('groups.sort_order ' ) // Primary sort
202- ->orderBy ('channels.sort ' ) // Secondary sort
203- ->orderBy ('channels.channel ' )
204- ->orderBy ('channels.title ' )
205- ->when ($ search , function ($ queryBuilder ) use ($ search ) {
206- $ search = Str::lower ($ search );
207-
208- return $ queryBuilder ->where (function ($ query ) use ($ search ) {
209- $ query ->whereRaw ('LOWER(channels.name) LIKE ? ' , ['% ' .$ search .'% ' ])
210- ->orWhereRaw ('LOWER(channels.name_custom) LIKE ? ' , ['% ' .$ search .'% ' ])
211- ->orWhereRaw ('LOWER(channels.title) LIKE ? ' , ['% ' .$ search .'% ' ])
212- ->orWhereRaw ('LOWER(channels.title_custom) LIKE ? ' , ['% ' .$ search .'% ' ]);
213- });
214- })
195+ $ playlistChannels = PlaylistGenerateController::getChannelQuery ($ playlist )
215196 ->limit ($ perPage )
216197 ->offset ($ skip )
217198 ->select ('channels.* ' )
@@ -249,7 +230,7 @@ public function getDataForPlaylist(string $uuid, Request $request)
249230 $ playlistChannelData = [];
250231 $ channelSortIndex = $ skip ;
251232 foreach ($ playlistChannels as $ channel ) {
252- $ epgData = $ channel ->epgChannel ?? null ;
233+ $ epgId = $ channel ->epg_id ?? null ;
253234 $ channelNo = $ channel ->channel ;
254235 if (! $ channelNo && ($ playlist ->auto_channel_increment || $ idChannelBy === PlaylistChannelId::Number)) {
255236 $ channelNo = ++$ channelNumber ;
@@ -258,25 +239,24 @@ public function getDataForPlaylist(string $uuid, Request $request)
258239 // Ensure we always have a unique identifier for the channel
259240 // Use database ID as fallback if channel number is not set
260241 $ channelKey = $ channelNo ?: $ channel ->id ;
261- if ($ epgData ) {
262- $ epgId = $ epgData ->epg_id ;
242+ if ($ epgId ) {
263243 $ epgIds [] = $ epgId ;
264244 if (! isset ($ epgChannelMap [$ epgId ])) {
265245 $ epgChannelMap [$ epgId ] = [];
266246 }
267247
268248 // Map EPG channel ID to playlist channel info
269249 // Store array of playlist channels for each EPG channel (one-to-many mapping)
270- if (! isset ($ epgChannelMap [$ epgId ][$ epgData -> channel_id ])) {
271- $ epgChannelMap [$ epgId ][$ epgData -> channel_id ] = [];
250+ if (! isset ($ epgChannelMap [$ epgId ][$ channel -> epg_channel_id ])) {
251+ $ epgChannelMap [$ epgId ][$ channel -> epg_channel_id ] = [];
272252 }
273253
274254 $ logo = url ('/placeholder.png ' );
275255 if ($ channel ->logo ) {
276256 // Logo override takes precedence
277257 $ logo = $ channel ->logo ;
278- } elseif ($ channel ->logo_type === ChannelLogoType::Epg && $ channel ->epgChannel && $ channel ->epgChannel -> icon ) {
279- $ logo = $ channel ->epgChannel -> icon ;
258+ } elseif ($ channel ->logo_type === ChannelLogoType::Epg && ( $ channel ->epg_icon || $ channel ->epg_icon_custom ) ) {
259+ $ logo = $ channel ->epg_icon_custom ?? $ channel -> epg_icon ?? '' ;
280260 } elseif ($ channel ->logo_type === ChannelLogoType::Channel && ($ channel ->logo || $ channel ->logo_internal )) {
281261 $ logo = $ channel ->logo ?? $ channel ->logo_internal ?? '' ;
282262 $ logo = filter_var ($ logo , FILTER_VALIDATE_URL ) ? $ logo : url ('/placeholder.png ' );
@@ -286,7 +266,7 @@ public function getDataForPlaylist(string $uuid, Request $request)
286266 }
287267
288268 // Add the playlist channel info to the EPG channel map
289- $ epgChannelMap [$ epgId ][$ epgData -> channel_id ][] = [
269+ $ epgChannelMap [$ epgId ][$ channel -> epg_channel_id ][] = [
290270 'playlist_channel_id ' => $ channelKey ,
291271 'display_name ' => $ channel ->title_custom ?? $ channel ->title ,
292272 'title ' => $ channel ->name_custom ?? $ channel ->name ,
@@ -381,8 +361,8 @@ public function getDataForPlaylist(string $uuid, Request $request)
381361 'channel_number ' => $ channelNo ,
382362 'group ' => $ channel ->group ?? $ channel ->group_internal ,
383363 'icon ' => $ icon ,
384- 'has_epg ' => $ epgData !== null ,
385- 'epg_channel_id ' => $ epgData -> channel_id ?? null ,
364+ 'has_epg ' => $ epgId !== null ,
365+ 'epg_channel_id ' => $ channel -> epg_channel_id ?? null ,
386366 'tvg_shift ' => (int ) ($ channel ->tvg_shift ?? 0 ), // EPG time shift in hours
387367 'sort_index ' => $ channelSortIndex ++,
388368 ];
0 commit comments