~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Service/DisplayNotifyService.php

  • Committer: Dan Garner
  • Date: 2015-03-26 14:08:33 UTC
  • Revision ID: git-v1:70d14044444f8dc5d602b99890d59dea46d9470c
Moved web servable files to web folder

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2016 Spring Signage Ltd
5
 
 * (DisplayNotifyService.php)
6
 
 */
7
 
 
8
 
 
9
 
namespace Xibo\Service;
10
 
use Stash\Interfaces\PoolInterface;
11
 
use Xibo\Entity\Display;
12
 
use Xibo\Exception\DeadlockException;
13
 
use Xibo\Factory\DayPartFactory;
14
 
use Xibo\Factory\ScheduleFactory;
15
 
use Xibo\Storage\StorageServiceInterface;
16
 
use Xibo\XMR\CollectNowAction;
17
 
 
18
 
/**
19
 
 * Class DisplayNotifyService
20
 
 * @package Xibo\Service
21
 
 */
22
 
class DisplayNotifyService implements DisplayNotifyServiceInterface
23
 
{
24
 
    /** @var ConfigServiceInterface */
25
 
    private $config;
26
 
 
27
 
    /** @var  LogServiceInterface */
28
 
    private $log;
29
 
 
30
 
    /** @var  StorageServiceInterface */
31
 
    private $store;
32
 
 
33
 
    /** @var  PoolInterface */
34
 
    private $pool;
35
 
 
36
 
    /** @var  PlayerActionServiceInterface */
37
 
    private $playerActionService;
38
 
 
39
 
    /** @var  DateServiceInterface */
40
 
    private $dateService;
41
 
 
42
 
    /** @var  ScheduleFactory */
43
 
    private $scheduleFactory;
44
 
 
45
 
    /** @var  DayPartFactory */
46
 
    private $dayPartFactory;
47
 
 
48
 
    /** @var bool */
49
 
    private $collectRequired = false;
50
 
 
51
 
    /** @var int[] */
52
 
    private $displayIds = [];
53
 
 
54
 
    /** @var int[] */
55
 
    private $displayIdsRequiringActions = [];
56
 
 
57
 
    /** @inheritdoc */
58
 
    public function __construct($config, $log, $store, $pool, $playerActionService, $dateService, $scheduleFactory, $dayPartFactory)
59
 
    {
60
 
        $this->config = $config;
61
 
        $this->log = $log;
62
 
        $this->store = $store;
63
 
        $this->pool = $pool;
64
 
        $this->playerActionService = $playerActionService;
65
 
        $this->dateService = $dateService;
66
 
        $this->scheduleFactory = $scheduleFactory;
67
 
        $this->dayPartFactory = $dayPartFactory;
68
 
    }
69
 
 
70
 
    /** @inheritdoc */
71
 
    public function init()
72
 
    {
73
 
        $this->collectRequired = false;
74
 
        return $this;
75
 
    }
76
 
 
77
 
    /** @inheritdoc */
78
 
    public function collectNow()
79
 
    {
80
 
        $this->collectRequired = true;
81
 
        return $this;
82
 
    }
83
 
 
84
 
    /** @inheritdoc */
85
 
    public function collectLater()
86
 
    {
87
 
        $this->collectRequired = false;
88
 
        return $this;
89
 
    }
90
 
 
91
 
    /** @inheritdoc */
92
 
    public function processQueue()
93
 
    {
94
 
        if (count($this->displayIds) <= 0)
95
 
            return;
96
 
 
97
 
        $this->log->debug('Process queue of ' . count($this->displayIds) . ' display notifications');
98
 
 
99
 
        // We want to do 3 things.
100
 
        // 1. Drop the Cache for each displayId
101
 
        // 2. Update the mediaInventoryStatus on each DisplayId to 3 (pending)
102
 
        // 3. Fire a PlayerAction if appropriate - what is appropriate?!
103
 
 
104
 
        // Unique our displayIds
105
 
        $displayIds = array_values(array_unique($this->displayIds, SORT_NUMERIC));
106
 
 
107
 
        // Make a list of them that we can use in the update statement
108
 
        $qmarks = str_repeat('?,', count($displayIds) - 1) . '?';
109
 
 
110
 
        try {
111
 
            $this->store->updateWithDeadlockLoop('UPDATE `display` SET mediaInventoryStatus = 3 WHERE displayId IN (' . $qmarks . ')', $displayIds);
112
 
        } catch (DeadlockException $deadlockException) {
113
 
            $this->log->error('Failed to update media inventory status: ' . $deadlockException->getMessage());
114
 
        }
115
 
 
116
 
        // Dump the cache
117
 
        foreach ($displayIds as $displayId) {
118
 
            $this->pool->deleteItem(Display::getCachePrefix() . $displayId);
119
 
        }
120
 
 
121
 
        // Player actions
122
 
        $this->processPlayerActions();
123
 
    }
124
 
 
125
 
    /**
126
 
     * Process Actions
127
 
     */
128
 
    private function processPlayerActions()
129
 
    {
130
 
        if (count($this->displayIdsRequiringActions) <= 0)
131
 
            return;
132
 
 
133
 
        $this->log->debug('Process queue of ' . count($this->displayIdsRequiringActions) . ' display actions');
134
 
 
135
 
        $displayIdsRequiringActions = array_values(array_unique($this->displayIdsRequiringActions, SORT_NUMERIC));
136
 
        $qmarks = str_repeat('?,', count($displayIdsRequiringActions) - 1) . '?';
137
 
        $displays = $this->store->select('SELECT displayId, xmrChannel, xmrPubKey FROM `display` WHERE displayId IN (' . $qmarks . ')', $displayIdsRequiringActions);
138
 
 
139
 
        foreach ($displays as $display) {
140
 
            $stdObj = new \stdClass();
141
 
            $stdObj->displayId = $display['displayId'];
142
 
            $stdObj->xmrChannel = $display['xmrChannel'];
143
 
            $stdObj->xmrPubKey = $display['xmrPubKey'];
144
 
 
145
 
            try {
146
 
                $this->playerActionService->sendAction($stdObj, new CollectNowAction());
147
 
            } catch (\Exception $e) {
148
 
                $this->log->notice('DisplayId ' . $display['displayId'] . ' Save would have triggered Player Action, but the action failed with message: ' . $e->getMessage());
149
 
            }
150
 
        }
151
 
    }
152
 
 
153
 
    /** @inheritdoc */
154
 
    public function notifyByDisplayId($displayId)
155
 
    {
156
 
        $this->log->debug('Notify by DisplayId ' . $displayId);
157
 
 
158
 
        $this->displayIds[] = $displayId;
159
 
 
160
 
        if ($this->collectRequired)
161
 
            $this->displayIdsRequiringActions[] = $displayId;
162
 
    }
163
 
 
164
 
    /** @inheritdoc */
165
 
    public function notifyByDisplayGroupId($displayGroupId)
166
 
    {
167
 
        $this->log->debug('Notify by DisplayGroupId ' . $displayGroupId);
168
 
 
169
 
        $sql = '
170
 
          SELECT DISTINCT `lkdisplaydg`.displayId 
171
 
            FROM `lkdgdg`
172
 
              INNER JOIN `lkdisplaydg`
173
 
              ON `lkdisplaydg`.displayGroupID = `lkdgdg`.childId
174
 
           WHERE `lkdgdg`.parentId = :displayGroupId
175
 
        ';
176
 
 
177
 
        foreach ($this->store->select($sql, ['displayGroupId' => $displayGroupId]) as $row) {
178
 
            $this->displayIds[] = $row['displayId'];
179
 
 
180
 
            $this->log->debug('DisplayGroup[' . $displayGroupId .'] change caused notify on displayId[' . $row['displayId'] . ']');
181
 
 
182
 
            if ($this->collectRequired)
183
 
                $this->displayIdsRequiringActions[] = $row['displayId'];
184
 
        }
185
 
    }
186
 
 
187
 
    /** @inheritdoc */
188
 
    public function notifyByCampaignId($campaignId)
189
 
    {
190
 
        $this->log->debug('Notify by CampaignId ' . $campaignId);
191
 
 
192
 
        $sql = '
193
 
            SELECT DISTINCT display.displayId, 
194
 
                schedule.eventId, 
195
 
                schedule.fromDt, 
196
 
                schedule.toDt, 
197
 
                schedule.recurrence_type AS recurrenceType,
198
 
                schedule.recurrence_detail AS recurrenceDetail,
199
 
                schedule.recurrence_range AS recurrenceRange,
200
 
                schedule.recurrenceRepeatsOn,
201
 
                schedule.lastRecurrenceWatermark,
202
 
                schedule.dayPartId
203
 
             FROM `schedule`
204
 
               INNER JOIN `lkscheduledisplaygroup`
205
 
               ON `lkscheduledisplaygroup`.eventId = `schedule`.eventId
206
 
               INNER JOIN `lkdgdg`
207
 
               ON `lkdgdg`.parentId = `lkscheduledisplaygroup`.displayGroupId
208
 
               INNER JOIN `lkdisplaydg`
209
 
               ON lkdisplaydg.DisplayGroupID = `lkdgdg`.childId
210
 
               INNER JOIN `display`
211
 
               ON lkdisplaydg.DisplayID = display.displayID
212
 
               INNER JOIN (
213
 
                  SELECT campaignId
214
 
                    FROM campaign
215
 
                   WHERE campaign.campaignId = :activeCampaignId
216
 
                   UNION
217
 
                  SELECT DISTINCT parent.campaignId
218
 
                    FROM `lkcampaignlayout` child
219
 
                      INNER JOIN `lkcampaignlayout` parent
220
 
                      ON parent.layoutId = child.layoutId 
221
 
                   WHERE child.campaignId = :activeCampaignId
222
 
                      
223
 
               ) campaigns
224
 
               ON campaigns.campaignId = `schedule`.campaignId
225
 
             WHERE (
226
 
                  (`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt) 
227
 
                  OR `schedule`.recurrence_range >= :fromDt 
228
 
                  OR (
229
 
                    IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\' 
230
 
                  )
231
 
              )
232
 
            UNION
233
 
            SELECT DISTINCT display.DisplayID,
234
 
                0 AS eventId, 
235
 
                0 AS fromDt, 
236
 
                0 AS toDt, 
237
 
                NULL AS recurrenceType, 
238
 
                NULL AS recurrenceDetail,
239
 
                NULL AS recurrenceRange,
240
 
                NULL AS recurrenceRepeatsOn,
241
 
                NULL AS lastRecurrenceWatermark,
242
 
                NULL AS dayPartId
243
 
             FROM `display`
244
 
               INNER JOIN `lkcampaignlayout`
245
 
               ON `lkcampaignlayout`.LayoutID = `display`.DefaultLayoutID
246
 
             WHERE `lkcampaignlayout`.CampaignID = :activeCampaignId2
247
 
            UNION
248
 
            SELECT `lkdisplaydg`.displayId,
249
 
                0 AS eventId, 
250
 
                0 AS fromDt, 
251
 
                0 AS toDt, 
252
 
                NULL AS recurrenceType, 
253
 
                NULL AS recurrenceDetail,
254
 
                NULL AS recurrenceRange,
255
 
                NULL AS recurrenceRepeatsOn,
256
 
                NULL AS lastRecurrenceWatermark,
257
 
                NULL AS dayPartId
258
 
              FROM `lkdisplaydg`
259
 
                INNER JOIN `lklayoutdisplaygroup`
260
 
                ON `lklayoutdisplaygroup`.displayGroupId = `lkdisplaydg`.displayGroupId
261
 
                INNER JOIN `lkcampaignlayout`
262
 
                ON `lkcampaignlayout`.layoutId = `lklayoutdisplaygroup`.layoutId
263
 
             WHERE `lkcampaignlayout`.campaignId = :assignedCampaignId
264
 
        ';
265
 
 
266
 
        $currentDate = $this->dateService->parse();
267
 
        $rfLookAhead = $currentDate->copy()->addSeconds($this->config->GetSetting('REQUIRED_FILES_LOOKAHEAD'));
268
 
 
269
 
        $params = [
270
 
            'fromDt' => $currentDate->subHour()->format('U'),
271
 
            'toDt' => $rfLookAhead->format('U'),
272
 
            'activeCampaignId' => $campaignId,
273
 
            'activeCampaignId2' => $campaignId,
274
 
            'assignedCampaignId' => $campaignId
275
 
        ];
276
 
 
277
 
        foreach ($this->store->select($sql, $params) as $row) {
278
 
 
279
 
            // Is this schedule active?
280
 
            if ($row['eventId'] != 0) {
281
 
                $scheduleEvents = $this->scheduleFactory
282
 
                    ->createEmpty()
283
 
                    ->hydrate($row)
284
 
                    ->getEvents($currentDate, $rfLookAhead);
285
 
 
286
 
                if (count($scheduleEvents) <= 0) {
287
 
                    $this->log->debug('Skipping eventId ' . $row['eventId'] . ' because it doesnt have any active events in the window');
288
 
                    continue;
289
 
                }
290
 
            }
291
 
 
292
 
            $this->log->debug('Campaign[' . $campaignId .'] change caused notify on displayId[' . $row['displayId'] . ']');
293
 
 
294
 
            $this->displayIds[] = $row['displayId'];
295
 
 
296
 
            if ($this->collectRequired)
297
 
                $this->displayIdsRequiringActions[] = $row['displayId'];
298
 
        }
299
 
    }
300
 
 
301
 
    /** @inheritdoc */
302
 
    public function notifyByDataSetId($dataSetId)
303
 
    {
304
 
        $this->log->debug('Notify by DataSetId ' . $dataSetId);
305
 
 
306
 
        $sql = '
307
 
           SELECT DISTINCT display.displayId, 
308
 
                schedule.eventId, 
309
 
                schedule.fromDt, 
310
 
                schedule.toDt, 
311
 
                schedule.recurrence_type AS recurrenceType,
312
 
                schedule.recurrence_detail AS recurrenceDetail,
313
 
                schedule.recurrence_range AS recurrenceRange,
314
 
                schedule.recurrenceRepeatsOn,
315
 
                schedule.lastRecurrenceWatermark,
316
 
                schedule.dayPartId
317
 
             FROM `schedule`
318
 
               INNER JOIN `lkscheduledisplaygroup`
319
 
               ON `lkscheduledisplaygroup`.eventId = `schedule`.eventId
320
 
               INNER JOIN `lkdgdg`
321
 
               ON `lkdgdg`.parentId = `lkscheduledisplaygroup`.displayGroupId
322
 
               INNER JOIN `lkdisplaydg`
323
 
               ON lkdisplaydg.DisplayGroupID = `lkdgdg`.childId
324
 
               INNER JOIN `display`
325
 
               ON lkdisplaydg.DisplayID = display.displayID
326
 
               INNER JOIN `lkcampaignlayout`
327
 
               ON `lkcampaignlayout`.campaignId = `schedule`.campaignId
328
 
               INNER JOIN `region`
329
 
               ON `region`.layoutId = `lkcampaignlayout`.layoutId
330
 
               INNER JOIN `lkregionplaylist`
331
 
               ON `lkregionplaylist`.regionId = `region`.regionId
332
 
               INNER JOIN `widget`
333
 
               ON `widget`.playlistId = `lkregionplaylist`.playlistId
334
 
               INNER JOIN `widgetoption`
335
 
               ON `widgetoption`.widgetId = `widget`.widgetId
336
 
                    AND `widgetoption`.type = \'attrib\'
337
 
                    AND `widgetoption`.option = \'dataSetId\'
338
 
                    AND `widgetoption`.value = :activeDataSetId
339
 
            WHERE (
340
 
               (schedule.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt) 
341
 
                  OR `schedule`.recurrence_range >= :fromDt 
342
 
                  OR (
343
 
                    IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\' 
344
 
                  )
345
 
               )
346
 
           UNION
347
 
           SELECT DISTINCT display.displayId,
348
 
                0 AS eventId, 
349
 
                0 AS fromDt, 
350
 
                0 AS toDt, 
351
 
                NULL AS recurrenceType, 
352
 
                NULL AS recurrenceDetail,
353
 
                NULL AS recurrenceRange,
354
 
                NULL AS recurrenceRepeatsOn,
355
 
                NULL AS lastRecurrenceWatermark,
356
 
                NULL AS dayPartId
357
 
             FROM `display`
358
 
               INNER JOIN `lkcampaignlayout`
359
 
               ON `lkcampaignlayout`.LayoutID = `display`.DefaultLayoutID
360
 
               INNER JOIN `region`
361
 
               ON `region`.layoutId = `lkcampaignlayout`.layoutId
362
 
               INNER JOIN `lkregionplaylist`
363
 
               ON `lkregionplaylist`.regionId = `region`.regionId
364
 
               INNER JOIN `widget`
365
 
               ON `widget`.playlistId = `lkregionplaylist`.playlistId
366
 
               INNER JOIN `widgetoption`
367
 
               ON `widgetoption`.widgetId = `widget`.widgetId
368
 
                    AND `widgetoption`.type = \'attrib\'
369
 
                    AND `widgetoption`.option = \'dataSetId\'
370
 
                    AND `widgetoption`.value = :activeDataSetId2
371
 
           UNION
372
 
           SELECT DISTINCT `lkdisplaydg`.displayId,
373
 
                0 AS eventId, 
374
 
                0 AS fromDt, 
375
 
                0 AS toDt, 
376
 
                NULL AS recurrenceType, 
377
 
                NULL AS recurrenceDetail,
378
 
                NULL AS recurrenceRange,
379
 
                NULL AS recurrenceRepeatsOn,
380
 
                NULL AS lastRecurrenceWatermark,
381
 
                NULL AS dayPartId
382
 
              FROM `lklayoutdisplaygroup`
383
 
                INNER JOIN `lkdgdg`
384
 
                ON `lkdgdg`.parentId = `lklayoutdisplaygroup`.displayGroupId
385
 
                INNER JOIN `lkdisplaydg`
386
 
                ON lkdisplaydg.DisplayGroupID = `lkdgdg`.childId
387
 
                INNER JOIN `lkcampaignlayout`
388
 
                ON `lkcampaignlayout`.layoutId = `lklayoutdisplaygroup`.layoutId
389
 
                INNER JOIN `region`
390
 
                ON `region`.layoutId = `lkcampaignlayout`.layoutId
391
 
                INNER JOIN `lkregionplaylist`
392
 
               ON `lkregionplaylist`.regionId = `region`.regionId
393
 
                INNER JOIN `widget`
394
 
                ON `widget`.playlistId = `lkregionplaylist`.playlistId
395
 
                INNER JOIN `widgetoption`
396
 
                ON `widgetoption`.widgetId = `widget`.widgetId
397
 
                    AND `widgetoption`.type = \'attrib\'
398
 
                    AND `widgetoption`.option = \'dataSetId\'
399
 
                    AND `widgetoption`.value = :activeDataSetId3
400
 
        ';
401
 
 
402
 
        $currentDate = $this->dateService->parse();
403
 
        $rfLookAhead = $currentDate->copy()->addSeconds($this->config->GetSetting('REQUIRED_FILES_LOOKAHEAD'));
404
 
 
405
 
        $params = [
406
 
            'fromDt' => $currentDate->subHour()->format('U'),
407
 
            'toDt' => $rfLookAhead->format('U'),
408
 
            'activeDataSetId' => $dataSetId,
409
 
            'activeDataSetId2' => $dataSetId,
410
 
            'activeDataSetId3' => $dataSetId
411
 
        ];
412
 
 
413
 
        foreach ($this->store->select($sql, $params) as $row) {
414
 
 
415
 
            // Is this schedule active?
416
 
            if ($row['eventId'] != 0) {
417
 
                $scheduleEvents = $this->scheduleFactory
418
 
                    ->createEmpty()
419
 
                    ->hydrate($row)
420
 
                    ->getEvents($currentDate, $rfLookAhead);
421
 
 
422
 
                if (count($scheduleEvents) <= 0) {
423
 
                    $this->log->debug('Skipping eventId ' . $row['eventId'] . ' because it doesnt have any active events in the window');
424
 
                    continue;
425
 
                }
426
 
            }
427
 
 
428
 
            $this->log->debug('DataSet[' . $dataSetId .'] change caused notify on displayId[' . $row['displayId'] . ']');
429
 
 
430
 
            $this->displayIds[] = $row['displayId'];
431
 
 
432
 
            if ($this->collectRequired)
433
 
                $this->displayIdsRequiringActions[] = $row['displayId'];
434
 
        }
435
 
    }
436
 
 
437
 
    /** @inheritdoc */
438
 
    public function notifyByPlaylistId($playlistId)
439
 
    {
440
 
        $this->log->debug('Notify by PlaylistId ' . $playlistId);
441
 
 
442
 
        $sql = '
443
 
            SELECT DISTINCT display.displayId, 
444
 
                schedule.eventId, 
445
 
                schedule.fromDt, 
446
 
                schedule.toDt, 
447
 
                schedule.recurrence_type AS recurrenceType,
448
 
                schedule.recurrence_detail AS recurrenceDetail,
449
 
                schedule.recurrence_range AS recurrenceRange,
450
 
                schedule.recurrenceRepeatsOn,
451
 
                schedule.lastRecurrenceWatermark,
452
 
                schedule.dayPartId
453
 
             FROM `schedule`
454
 
               INNER JOIN `lkscheduledisplaygroup`
455
 
               ON `lkscheduledisplaygroup`.eventId = `schedule`.eventId
456
 
               INNER JOIN `lkdgdg`
457
 
               ON `lkdgdg`.parentId = `lkscheduledisplaygroup`.displayGroupId
458
 
               INNER JOIN `lkdisplaydg`
459
 
               ON lkdisplaydg.DisplayGroupID = `lkdgdg`.childId
460
 
               INNER JOIN `display`
461
 
               ON lkdisplaydg.DisplayID = display.displayID
462
 
               INNER JOIN `lkcampaignlayout`
463
 
               ON `lkcampaignlayout`.campaignId = `schedule`.campaignId
464
 
               INNER JOIN `region`
465
 
               ON `lkcampaignlayout`.layoutId = region.layoutId
466
 
               INNER JOIN `lkregionplaylist`
467
 
               ON `lkregionplaylist`.regionId = `region`.regionId
468
 
             WHERE `lkregionplaylist`.playlistId = :playlistId
469
 
              AND (
470
 
                  (schedule.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt) 
471
 
                  OR `schedule`.recurrence_range >= :fromDt 
472
 
                  OR (
473
 
                    IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\' 
474
 
                  )
475
 
              )
476
 
            UNION
477
 
            SELECT DISTINCT display.DisplayID,
478
 
                0 AS eventId, 
479
 
                0 AS fromDt, 
480
 
                0 AS toDt, 
481
 
                NULL AS recurrenceType, 
482
 
                NULL AS recurrenceDetail,
483
 
                NULL AS recurrenceRange,
484
 
                NULL AS recurrenceRepeatsOn,
485
 
                NULL AS lastRecurrenceWatermark,
486
 
                NULL AS dayPartId
487
 
             FROM `display`
488
 
               INNER JOIN `lkcampaignlayout`
489
 
               ON `lkcampaignlayout`.LayoutID = `display`.DefaultLayoutID
490
 
               INNER JOIN `region`
491
 
               ON `lkcampaignlayout`.layoutId = region.layoutId
492
 
               INNER JOIN `lkregionplaylist`
493
 
               ON `lkregionplaylist`.regionId = `region`.regionId
494
 
             WHERE `lkregionplaylist`.playlistId = :playlistId
495
 
            UNION
496
 
            SELECT `lkdisplaydg`.displayId,
497
 
                0 AS eventId, 
498
 
                0 AS fromDt, 
499
 
                0 AS toDt, 
500
 
                NULL AS recurrenceType, 
501
 
                NULL AS recurrenceDetail,
502
 
                NULL AS recurrenceRange,
503
 
                NULL AS recurrenceRepeatsOn,
504
 
                NULL AS lastRecurrenceWatermark,
505
 
                NULL AS dayPartId
506
 
              FROM `lkdisplaydg`
507
 
                INNER JOIN `lklayoutdisplaygroup`
508
 
                ON `lklayoutdisplaygroup`.displayGroupId = `lkdisplaydg`.displayGroupId
509
 
                INNER JOIN `lkcampaignlayout`
510
 
                ON `lkcampaignlayout`.layoutId = `lklayoutdisplaygroup`.layoutId
511
 
                INNER JOIN `region`
512
 
                ON `lkcampaignlayout`.layoutId = region.layoutId
513
 
                INNER JOIN `lkregionplaylist`
514
 
                ON `lkregionplaylist`.regionId = `region`.regionId
515
 
             WHERE `lkregionplaylist`.playlistId = :playlistId
516
 
        ';
517
 
 
518
 
        $currentDate = $this->dateService->parse();
519
 
        $rfLookAhead = $currentDate->copy()->addSeconds($this->config->GetSetting('REQUIRED_FILES_LOOKAHEAD'));
520
 
 
521
 
        $params = [
522
 
            'fromDt' => $currentDate->subHour()->format('U'),
523
 
            'toDt' => $rfLookAhead->format('U'),
524
 
            'playlistId' => $playlistId
525
 
        ];
526
 
 
527
 
        foreach ($this->store->select($sql, $params) as $row) {
528
 
 
529
 
            // Is this schedule active?
530
 
            if ($row['eventId'] != 0) {
531
 
                $scheduleEvents = $this->scheduleFactory
532
 
                    ->createEmpty()
533
 
                    ->hydrate($row)
534
 
                    ->getEvents($currentDate, $rfLookAhead);
535
 
 
536
 
                if (count($scheduleEvents) <= 0) {
537
 
                    $this->log->debug('Skipping eventId ' . $row['eventId'] . ' because it doesnt have any active events in the window');
538
 
                    continue;
539
 
                }
540
 
            }
541
 
 
542
 
            $this->log->debug('Playlist[' . $playlistId .'] change caused notify on displayId[' . $row['displayId'] . ']');
543
 
 
544
 
            $this->displayIds[] = $row['displayId'];
545
 
 
546
 
            if ($this->collectRequired)
547
 
                $this->displayIdsRequiringActions[] = $row['displayId'];
548
 
        }
549
 
    }
550
 
}
 
 
b'\\ No newline at end of file'