~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Controller/DisplayGroup.php

  • Committer: Dan Garner
  • Date: 2015-09-29 15:16:59 UTC
  • mto: (454.2.11) (471.2.2)
  • mto: This revision was merged to the branch mainline in revision 468.
  • Revision ID: git-v1:ae24387a7b1397750b6ec86d0f286373da05eb16
Fixed Display Version Information Form (not showing media name)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
namespace Xibo\Controller;
22
22
 
23
23
use Xibo\Entity\Display;
 
24
use Xibo\Entity\Permission;
24
25
use Xibo\Exception\AccessDeniedException;
25
 
use Xibo\Exception\ConfigurationException;
26
 
use Xibo\Exception\InvalidArgumentException;
27
 
use Xibo\Exception\XiboException;
28
 
use Xibo\Factory\CommandFactory;
29
26
use Xibo\Factory\DisplayFactory;
30
27
use Xibo\Factory\DisplayGroupFactory;
31
 
use Xibo\Factory\LayoutFactory;
32
28
use Xibo\Factory\MediaFactory;
33
29
use Xibo\Factory\ModuleFactory;
34
 
use Xibo\Factory\ScheduleFactory;
35
 
use Xibo\Factory\TagFactory;
36
 
use Xibo\Service\ConfigServiceInterface;
37
 
use Xibo\Service\DateServiceInterface;
38
 
use Xibo\Service\LogServiceInterface;
39
 
use Xibo\Service\PlayerActionServiceInterface;
40
 
use Xibo\Service\SanitizerServiceInterface;
41
 
use Xibo\XMR\ChangeLayoutAction;
42
 
use Xibo\XMR\CollectNowAction;
43
 
use Xibo\XMR\CommandAction;
44
 
use Xibo\XMR\OverlayLayoutAction;
45
 
use Xibo\XMR\RevertToSchedule;
46
 
 
47
 
/**
48
 
 * Class DisplayGroup
49
 
 * @package Xibo\Controller
50
 
 */
 
30
use Xibo\Factory\PermissionFactory;
 
31
use Xibo\Helper\Help;
 
32
use Xibo\Helper\Sanitize;
 
33
 
 
34
 
51
35
class DisplayGroup extends Base
52
36
{
53
37
    /**
54
 
     * @var PlayerActionServiceInterface
55
 
     */
56
 
    private $playerAction;
57
 
 
58
 
    /**
59
 
     * @var DisplayGroupFactory
60
 
     */
61
 
    private $displayGroupFactory;
62
 
 
63
 
    /**
64
 
     * @var DisplayFactory
65
 
     */
66
 
    private $displayFactory;
67
 
 
68
 
    /**
69
 
     * @var ModuleFactory
70
 
     */
71
 
    private $moduleFactory;
72
 
 
73
 
    /**
74
 
     * @var MediaFactory
75
 
     */
76
 
    private $mediaFactory;
77
 
 
78
 
    /**
79
 
     * @var LayoutFactory
80
 
     */
81
 
    private $layoutFactory;
82
 
 
83
 
    /**
84
 
     * @var CommandFactory
85
 
     */
86
 
    private $commandFactory;
87
 
 
88
 
    /**
89
 
     * @var ScheduleFactory
90
 
     */
91
 
    private $scheduleFactory;
92
 
 
93
 
    /**
94
 
     * @var TagFactory
95
 
     */
96
 
    private $tagFactory;
97
 
 
98
 
    /**
99
 
     * Set common dependencies.
100
 
     * @param LogServiceInterface $log
101
 
     * @param SanitizerServiceInterface $sanitizerService
102
 
     * @param \Xibo\Helper\ApplicationState $state
103
 
     * @param \Xibo\Entity\User $user
104
 
     * @param \Xibo\Service\HelpServiceInterface $help
105
 
     * @param DateServiceInterface $date
106
 
     * @param ConfigServiceInterface $config
107
 
     * @param PlayerActionServiceInterface $playerAction
108
 
     * @param DisplayFactory $displayFactory
109
 
     * @param DisplayGroupFactory $displayGroupFactory
110
 
     * @param LayoutFactory $layoutFactory
111
 
     * @param ModuleFactory $moduleFactory
112
 
     * @param MediaFactory $mediaFactory
113
 
     * @param CommandFactory $commandFactory
114
 
     * @param ScheduleFactory $scheduleFactory
115
 
     * @param TagFactory $tagFactory
116
 
     */
117
 
    public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $playerAction, $displayFactory, $displayGroupFactory, $layoutFactory, $moduleFactory, $mediaFactory, $commandFactory, $scheduleFactory, $tagFactory)
118
 
    {
119
 
        $this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
120
 
 
121
 
        $this->playerAction = $playerAction;
122
 
        $this->displayFactory = $displayFactory;
123
 
        $this->displayGroupFactory = $displayGroupFactory;
124
 
        $this->layoutFactory = $layoutFactory;
125
 
        $this->moduleFactory = $moduleFactory;
126
 
        $this->mediaFactory = $mediaFactory;
127
 
        $this->commandFactory = $commandFactory;
128
 
        $this->scheduleFactory = $scheduleFactory;
129
 
        $this->tagFactory = $tagFactory;
130
 
    }
131
 
 
132
 
    /**
133
38
     * Display Group Page Render
134
39
     */
135
40
    public function displayPage()
136
41
    {
137
42
        $this->getState()->template = 'displaygroup-page';
138
 
        $this->getState()->setData([
139
 
            'displays' => $this->displayFactory->query()
140
 
        ]);
141
43
    }
142
44
 
143
45
    /**
146
48
     *  summary="Get Display Groups",
147
49
     *  tags={"displayGroup"},
148
50
     *  operationId="displayGroupSearch",
149
 
     *  @SWG\Parameter(
150
 
     *      name="displayGroupId",
151
 
     *      in="formData",
152
 
     *      description="Filter by DisplayGroup Id",
153
 
     *      type="integer",
154
 
     *      required=false
155
 
     *   ),
156
 
     *  @SWG\Parameter(
157
 
     *      name="displayGroup",
158
 
     *      in="formData",
159
 
     *      description="Filter by DisplayGroup Name",
160
 
     *      type="string",
161
 
     *      required=false
162
 
     *   ),
163
 
     *  @SWG\Parameter(
164
 
     *      name="displayId",
165
 
     *      in="formData",
166
 
     *      description="Filter by DisplayGroups containing a specific display",
167
 
     *      type="integer",
168
 
     *      required=false
169
 
     *   ),
170
 
     *  @SWG\Parameter(
171
 
     *      name="nestedDisplayId",
172
 
     *      in="formData",
173
 
     *      description="Filter by DisplayGroups containing a specific display in there nesting",
174
 
     *      type="integer",
175
 
     *      required=false
176
 
     *   ),
177
 
     *  @SWG\Parameter(
178
 
     *      name="dynamicCriteria",
179
 
     *      in="formData",
180
 
     *      description="Filter by DisplayGroups containing a specific dynamic criteria",
181
 
     *      type="string",
182
 
     *      required=false
183
 
     *   ),
184
51
     *  @SWG\Response(
185
52
     *      response=200,
186
53
     *      description="a successful response",
198
65
     */
199
66
    public function grid()
200
67
    {
201
 
        $filter = [
202
 
            'displayGroupId' => $this->getSanitizer()->getInt('displayGroupId'),
203
 
            'displayGroup' => $this->getSanitizer()->getString('displayGroup'),
204
 
            'displayId' => $this->getSanitizer()->getInt('displayId'),
205
 
            'nestedDisplayId' => $this->getSanitizer()->getInt('nestedDisplayId'),
206
 
            'dynamicCriteria' => $this->getSanitizer()->getString('dynamicCriteria'),
207
 
            'tags' => $this->getSanitizer()->getString('tags'),
208
 
            'exactTags' => $this->getSanitizer()->getCheckbox('exactTags')
209
 
        ];
210
 
 
211
 
        $displayGroups = $this->displayGroupFactory->query($this->gridRenderSort(), $this->gridRenderFilter($filter));
 
68
        $displayGroups = DisplayGroupFactory::query();
212
69
 
213
70
        foreach ($displayGroups as $group) {
214
71
            /* @var \Xibo\Entity\DisplayGroup $group */
221
78
            if ($this->getUser()->checkEditable($group)) {
222
79
                // Show the edit button, members button
223
80
 
224
 
                if ($group->isDynamic == 0) {
225
 
                    // Group Members
226
 
                    $group->buttons[] = array(
227
 
                        'id' => 'displaygroup_button_group_members',
228
 
                        'url' => $this->urlFor('displayGroup.members.form', ['id' => $group->displayGroupId]),
229
 
                        'text' => __('Members')
230
 
                    );
231
 
 
232
 
                    $group->buttons[] = ['divider' => true];
233
 
                }
 
81
                // Group Members
 
82
                $group->buttons[] = array(
 
83
                    'id' => 'displaygroup_button_group_members',
 
84
                    'url' => $this->urlFor('displayGroup.members.form', ['id' => $group->displayGroupId]),
 
85
                    'text' => __('Displays')
 
86
                );
234
87
 
235
88
                // Edit
236
89
                $group->buttons[] = array(
258
111
                    'url' => $this->urlFor('displayGroup.media.form', ['id' => $group->displayGroupId]),
259
112
                    'text' => __('Assign Files')
260
113
                );
261
 
 
262
 
                // Layout Assignments
263
 
                $group->buttons[] = array(
264
 
                    'id' => 'displaygroup_button_layout_associations',
265
 
                    'url' => $this->urlFor('displayGroup.layout.form', ['id' => $group->displayGroupId]),
266
 
                    'text' => __('Assign Layouts')
267
 
                );
268
114
            }
269
115
 
270
116
            if ($this->getUser()->checkPermissionsModifyable($group)) {
282
128
                    'text' => __('Version Information')
283
129
                );
284
130
            }
285
 
 
286
 
            if ($this->getUser()->checkEditable($group)) {
287
 
                $group->buttons[] = ['divider' => true];
288
 
 
289
 
                $group->buttons[] = array(
290
 
                    'id' => 'displaygroup_button_command',
291
 
                    'url' => $this->urlFor('displayGroup.command.form', ['id' => $group->displayGroupId]),
292
 
                    'text' => __('Send Command')
293
 
                );
294
 
 
295
 
                $group->buttons[] = array(
296
 
                    'id' => 'displaygroup_button_collectNow',
297
 
                    'url' => $this->urlFor('displayGroup.collectNow.form', ['id' => $group->displayGroupId]),
298
 
                    'text' => __('Collect Now')
299
 
                );
300
 
            }
301
131
        }
302
132
 
303
133
        $this->getState()->template = 'grid';
304
 
        $this->getState()->recordsTotal = $this->displayGroupFactory->countLast();
 
134
        $this->getState()->recordsTotal = DisplayGroupFactory::countLast();
305
135
        $this->getState()->setData($displayGroups);
306
136
    }
307
137
 
312
142
    {
313
143
        $this->getState()->template = 'displaygroup-form-add';
314
144
        $this->getState()->setData([
315
 
            'help' => $this->getHelp()->link('DisplayGroup', 'Add')
 
145
            'help' => Help::Link('DisplayGroup', 'Add')
316
146
        ]);
317
147
    }
318
148
 
322
152
     */
323
153
    public function editForm($displayGroupId)
324
154
    {
325
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
155
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
326
156
 
327
157
        if (!$this->getUser()->checkEditable($displayGroup))
328
158
            throw new AccessDeniedException();
330
160
        $this->getState()->template = 'displaygroup-form-edit';
331
161
        $this->getState()->setData([
332
162
            'displayGroup' => $displayGroup,
333
 
            'help' => $this->getHelp()->link('DisplayGroup', 'Edit')
 
163
            'help' => Help::Link('DisplayGroup', 'Edit')
334
164
        ]);
335
165
    }
336
166
 
340
170
     */
341
171
    function deleteForm($displayGroupId)
342
172
    {
343
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
173
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
344
174
 
345
175
        if (!$this->getUser()->checkDeleteable($displayGroup))
346
176
            throw new AccessDeniedException();
348
178
        $this->getState()->template = 'displaygroup-form-delete';
349
179
        $this->getState()->setData([
350
180
            'displayGroup' => $displayGroup,
351
 
            'help' => $this->getHelp()->link('DisplayGroup', 'Delete')
 
181
            'help' => Help::Link('DisplayGroup', 'Delete')
352
182
        ]);
353
183
    }
354
184
 
358
188
     */
359
189
    public function membersForm($displayGroupId)
360
190
    {
361
 
        
362
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
191
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
363
192
 
364
193
        if (!$this->getUser()->checkEditable($displayGroup))
365
194
            throw new AccessDeniedException();
366
195
 
367
196
        // Displays in Group
368
 
        $displaysAssigned = $this->displayFactory->getByDisplayGroupId($displayGroup->displayGroupId);
369
 
        // Get all the DisplayGroups assigned to this Group directly
370
 
        $groupsAssigned = $this->displayGroupFactory->getByParentId($displayGroup->displayGroupId);
 
197
        $displaysAssigned = DisplayFactory::getByDisplayGroupId($displayGroup->displayGroupId);
 
198
 
 
199
        // All Displays
 
200
        $allDisplays = DisplayFactory::query();
 
201
 
 
202
        // The available users are all users except users already in assigned users
 
203
        $checkboxes = array();
 
204
 
 
205
        foreach ($allDisplays as $display) {
 
206
            /* @var Display $display */
 
207
            // Check to see if it exists in $usersAssigned
 
208
            $exists = false;
 
209
            foreach ($displaysAssigned as $displayAssigned) {
 
210
                /* @var Display $displayAssigned */
 
211
                if ($displayAssigned->displayId == $display->displayId) {
 
212
                    $exists = true;
 
213
                    break;
 
214
                }
 
215
            }
 
216
 
 
217
            // Store this checkbox
 
218
            $checkbox = array(
 
219
                'id' => $display->displayId,
 
220
                'name' => $display->display,
 
221
                'value_checked' => (($exists) ? 'checked' : '')
 
222
            );
 
223
 
 
224
            $checkboxes[] = $checkbox;
 
225
        }
 
226
 
371
227
 
372
228
        $this->getState()->template = 'displaygroup-form-members';
373
229
        $this->getState()->setData([
374
230
            'displayGroup' => $displayGroup,
375
 
            'extra' => [
376
 
                'displaysAssigned' => $displaysAssigned,
377
 
                'displayGroupsAssigned' => $groupsAssigned
378
 
            ],
379
 
            'tree' => $this->displayGroupFactory->getRelationShipTree($displayGroupId),
380
 
            'help' => $this->getHelp()->link('DisplayGroup', 'Members')
 
231
            'checkboxes' => $checkboxes,
 
232
            'help' => Help::Link('DisplayGroup', 'Delete')
381
233
        ]);
382
234
    }
383
235
 
403
255
     *      type="string",
404
256
     *      required=false
405
257
     *  ),
406
 
     *  @SWG\Parameter(
407
 
     *      name="tags",
408
 
     *      in="formData",
409
 
     *      description="A comma separated list of tags for this item",
410
 
     *      type="string",
411
 
     *      required=false
412
 
     *   ),
413
 
     *  @SWG\Parameter(
414
 
     *      name="isDynamic",
415
 
     *      in="formData",
416
 
     *      description="Flag indicating whether this DisplayGroup is Dynamic",
417
 
     *      type="integer",
418
 
     *      required=true
419
 
     *   ),
420
 
     *  @SWG\Parameter(
421
 
     *      name="dynamicContent",
422
 
     *      in="formData",
423
 
     *      description="The filter criteria for this dynamic group. A command separated set of regular expressions to apply",
424
 
     *      type="string",
425
 
     *      required=false
426
 
     *   ),
427
258
     *  @SWG\Response(
428
259
     *      response=201,
429
260
     *      description="successful operation",
438
269
     */
439
270
    public function add()
440
271
    {
441
 
        $displayGroup = $this->displayGroupFactory->createEmpty();
442
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
443
 
 
444
 
        $displayGroup->displayGroup = $this->getSanitizer()->getString('displayGroup');
445
 
        $displayGroup->description = $this->getSanitizer()->getString('description');
446
 
        $displayGroup->tags = $this->tagFactory->tagsFromString($this->getSanitizer()->getString('tags'));
447
 
        $displayGroup->isDynamic = $this->getSanitizer()->getCheckbox('isDynamic');
448
 
        $displayGroup->dynamicCriteria = $this->getSanitizer()->getString('dynamicCriteria');
449
 
        $displayGroup->userId = $this->getUser()->userId;
 
272
        $displayGroup = new \Xibo\Entity\DisplayGroup();
 
273
        $displayGroup->displayGroup = Sanitize::getString('displayGroup');
 
274
        $displayGroup->description = Sanitize::getString('description');
450
275
        $displayGroup->save();
451
276
 
 
277
        // Add full permissions for this user to this group
 
278
        /* @var Permission $permission */
 
279
        $permission = PermissionFactory::create($this->getUser()->groupId, get_class($displayGroup), $displayGroup->displayGroupId, 1, 1, 1);
 
280
        $permission->save();
 
281
 
452
282
        // Return
453
283
        $this->getState()->hydrate([
454
284
            'httpState' => 201,
489
319
     *      type="string",
490
320
     *      required=false
491
321
     *  ),
492
 
     *  @SWG\Parameter(
493
 
     *      name="tags",
494
 
     *      in="formData",
495
 
     *      description="A comma separated list of tags for this item",
496
 
     *      type="string",
497
 
     *      required=false
498
 
     *   ),
499
 
     *  @SWG\Parameter(
500
 
     *      name="isDynamic",
501
 
     *      in="formData",
502
 
     *      description="Flag indicating whether this DisplayGroup is Dynamic",
503
 
     *      type="integer",
504
 
     *      required=true
505
 
     *   ),
506
 
     *  @SWG\Parameter(
507
 
     *      name="dynamicCriteria",
508
 
     *      in="formData",
509
 
     *      description="The filter criteria for this dynamic group. A command separated set of regular expressions to apply",
510
 
     *      type="string",
511
 
     *      required=false
512
 
     *   ),
513
322
     *  @SWG\Response(
514
323
     *      response=200,
515
324
     *      description="successful operation",
519
328
     */
520
329
    public function edit($displayGroupId)
521
330
    {
522
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
331
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
523
332
 
524
333
        if (!$this->getUser()->checkEditable($displayGroup))
525
334
            throw new AccessDeniedException();
526
335
 
527
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
528
 
        $displayGroup->displayGroup = $this->getSanitizer()->getString('displayGroup');
529
 
        $displayGroup->description = $this->getSanitizer()->getString('description');
530
 
        $displayGroup->replaceTags($this->tagFactory->tagsFromString($this->getSanitizer()->getString('tags')));
531
 
        $displayGroup->isDynamic = $this->getSanitizer()->getCheckbox('isDynamic');
532
 
        $displayGroup->dynamicCriteria = ($displayGroup->isDynamic == 1) ? $this->getSanitizer()->getString('dynamicCriteria') : null;
 
336
        $displayGroup->displayGroup = Sanitize::getString('displayGroup');
 
337
        $displayGroup->description = Sanitize::getString('description');
533
338
        $displayGroup->save();
534
339
 
535
340
        // Return
565
370
     */
566
371
    function delete($displayGroupId)
567
372
    {
568
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
569
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
 
373
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
570
374
 
571
375
        if (!$this->getUser()->checkDeleteable($displayGroup))
572
376
            throw new AccessDeniedException();
583
387
    /**
584
388
     * Sets the Members of a group
585
389
     * @param int $displayGroupId
586
 
     * @throws InvalidArgumentException
587
390
     *
588
391
     * @SWG\Post(
589
392
     *  path="/displaygroup/{displayGroupId}/display/assign",
621
424
     *      description="successful operation"
622
425
     *  )
623
426
     * )
624
 
     *
625
 
     * @throws XiboException
626
427
     */
627
428
    public function assignDisplay($displayGroupId)
628
429
    {
629
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
630
 
 
631
 
        if ($displayGroup->isDisplaySpecific == 1)
632
 
            throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
633
 
 
634
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
 
430
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
635
431
 
636
432
        if (!$this->getUser()->checkEditable($displayGroup))
637
433
            throw new AccessDeniedException();
638
434
 
639
 
        if ($displayGroup->isDynamic == 1)
640
 
            throw new \InvalidArgumentException(__('Displays cannot be manually assigned to a Dynamic Group'));
641
 
 
642
 
        $modifiedDisplays = [];
643
 
 
644
 
        $displays = $this->getSanitizer()->getIntArray('displayId');
 
435
        $displays = Sanitize::getIntArray('displayId');
645
436
 
646
437
        foreach ($displays as $displayId) {
647
 
            $display = $this->displayFactory->getById($displayId);
 
438
            $display = DisplayFactory::getById($displayId);
648
439
 
649
 
            if (!$this->getUser()->checkViewable($this->displayGroupFactory->getById($display->displayGroupId)))
 
440
            if (!$this->getUser()->checkViewable(DisplayGroupFactory::getById($display->displayGroupId)))
650
441
                throw new AccessDeniedException(__('Access Denied to Display'));
651
442
 
652
443
            $displayGroup->assignDisplay($display);
653
 
 
654
 
            // Store so that we can flag as incomplete
655
 
            if (!in_array($display, $modifiedDisplays))
656
 
                $modifiedDisplays[] = $display;
657
444
        }
658
445
 
659
446
        // Have we been provided with unassign id's as well?
660
 
        $displays = $this->getSanitizer()->getIntArray('unassignDisplayId');
 
447
        $displays = Sanitize::getIntArray('unassignDisplayId');
661
448
 
662
449
        foreach ($displays as $displayId) {
663
 
            $display = $this->displayFactory->getById($displayId);
 
450
            $display = DisplayFactory::getById($displayId);
664
451
 
665
 
            if (!$this->getUser()->checkViewable($this->displayGroupFactory->getById($display->displayGroupId)))
 
452
            if (!$this->getUser()->checkViewable(DisplayGroupFactory::getById($display->displayGroupId)))
666
453
                throw new AccessDeniedException(__('Access Denied to Display'));
667
454
 
668
455
            $displayGroup->unassignDisplay($display);
669
 
 
670
 
            // Store so that we can flag as incomplete
671
 
            if (!in_array($display, $modifiedDisplays))
672
 
                $modifiedDisplays[] = $display;
673
456
        }
674
457
 
675
458
        // Save the result
676
 
        $displayGroup->save(['validate' => false]);
677
 
 
678
 
        // Save the displays themselves
679
 
        foreach ($modifiedDisplays as $display) {
680
 
            /** @var Display $display */
681
 
            $display->notify();
682
 
        }
 
459
        $displayGroup->save(false);
683
460
 
684
461
        // Return
685
462
        $this->getState()->hydrate([
692
469
    /**
693
470
     * Unassign displays from a Display Group
694
471
     * @param int $displayGroupId
695
 
     * @throws InvalidArgumentException
696
472
     *
697
473
     * @SWG\Post(
698
474
     *  path="/displaygroup/{displayGroupId}/display/unassign",
722
498
     *      description="successful operation"
723
499
     *  )
724
500
     * )
725
 
     *
726
 
     * @throws XiboException
727
501
     */
728
502
    public function unassignDisplay($displayGroupId)
729
503
    {
730
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
731
 
 
732
 
        if ($displayGroup->isDisplaySpecific == 1)
733
 
            throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
734
 
 
735
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
 
504
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
736
505
 
737
506
        if (!$this->getUser()->checkEditable($displayGroup))
738
507
            throw new AccessDeniedException();
739
508
 
740
 
        if ($displayGroup->isDynamic == 1)
741
 
            throw new \InvalidArgumentException(__('Displays cannot be manually unassigned to a Dynamic Group'));
742
 
 
743
 
        $displays = $this->getSanitizer()->getIntArray('displayId');
 
509
        $displays = Sanitize::getIntArray('displayId');
744
510
 
745
511
        foreach ($displays as $displayId) {
746
 
            $display = $this->displayFactory->getById($displayId);
747
 
 
748
 
            if (!$this->getUser()->checkViewable($this->displayGroupFactory->getById($display->displayGroupId)))
749
 
                throw new AccessDeniedException(__('Access Denied to Display'));
750
 
 
751
 
            $this->getLog()->debug('Unassigning ' . $display->display);
752
 
 
753
 
            $displayGroup->unassignDisplay($display);
 
512
            $displayGroup->unassignDisplay(DisplayFactory::getById($displayId));
754
513
        }
755
514
 
756
 
        $displayGroup->save(['validate' => false]);
 
515
        $displayGroup->save(false);
757
516
 
758
517
        // Return
759
518
        $this->getState()->hydrate([
764
523
    }
765
524
 
766
525
    /**
767
 
     * Sets the Members of a group
768
 
     * @param int $displayGroupId
769
 
     * @throws InvalidArgumentException
770
 
     *
771
 
     * @SWG\Post(
772
 
     *  path="/displaygroup/{displayGroupId}/displayGroup/assign",
773
 
     *  operationId="displayGroupDisplayGroupAssign",
774
 
     *  tags={"displayGroup"},
775
 
     *  summary="Assign one or more DisplayGroups to a Display Group",
776
 
     *  description="Adds the provided DisplayGroups to the Display Group",
777
 
     *  @SWG\Parameter(
778
 
     *      name="displayGroupId",
779
 
     *      type="integer",
780
 
     *      in="path",
781
 
     *      description="The Display Group to assign to",
782
 
     *      required=true
783
 
     *  ),
784
 
     *  @SWG\Parameter(
785
 
     *      name="displayGroupId",
786
 
     *      type="array",
787
 
     *      in="formData",
788
 
     *      description="The displayGroup Ids to assign",
789
 
     *      required=true,
790
 
     *      @SWG\Items(
791
 
     *          type="integer"
792
 
     *      )
793
 
     *  ),
794
 
     *  @SWG\Parameter(
795
 
     *      name="unassignDisplayGroupId",
796
 
     *      in="formData",
797
 
     *      description="An optional array of displayGroup IDs to unassign",
798
 
     *      type="array",
799
 
     *      required=false,
800
 
     *      @SWG\Items(type="integer")
801
 
     *   ),
802
 
     *  @SWG\Response(
803
 
     *      response=204,
804
 
     *      description="successful operation"
805
 
     *  )
806
 
     * )
807
 
     *
808
 
     * @throws XiboException
809
 
     */
810
 
    public function assignDisplayGroup($displayGroupId)
811
 
    {
812
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
813
 
 
814
 
        if ($displayGroup->isDisplaySpecific == 1)
815
 
            throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
816
 
 
817
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
818
 
 
819
 
        if (!$this->getUser()->checkEditable($displayGroup))
820
 
            throw new AccessDeniedException();
821
 
 
822
 
        if ($displayGroup->isDynamic == 1)
823
 
            throw new \InvalidArgumentException(__('DisplayGroups cannot be manually assigned to a Dynamic Group'));
824
 
 
825
 
        $displayGroups = $this->getSanitizer()->getIntArray('displayGroupId');
826
 
 
827
 
        foreach ($displayGroups as $assignDisplayGroupId) {
828
 
            $displayGroupAssign = $this->displayGroupFactory->getById($assignDisplayGroupId);
829
 
 
830
 
            if (!$this->getUser()->checkViewable($displayGroupAssign))
831
 
                throw new AccessDeniedException(__('Access Denied to DisplayGroup'));
832
 
 
833
 
            $displayGroup->assignDisplayGroup($displayGroupAssign);
834
 
        }
835
 
 
836
 
        // Have we been provided with unassign id's as well?
837
 
        $displayGroups = $this->getSanitizer()->getIntArray('unassignDisplayGroupId');
838
 
 
839
 
        foreach ($displayGroups as $assignDisplayGroupId) {
840
 
            $displayGroupUnassign = $this->displayGroupFactory->getById($assignDisplayGroupId);
841
 
 
842
 
            if (!$this->getUser()->checkViewable($displayGroupUnassign))
843
 
                throw new AccessDeniedException(__('Access Denied to DisplayGroup'));
844
 
 
845
 
            $displayGroup->unassignDisplayGroup($displayGroupUnassign);
846
 
        }
847
 
 
848
 
        // Save the result
849
 
        $displayGroup->save(['validate' => false]);
850
 
 
851
 
        // Return
852
 
        $this->getState()->hydrate([
853
 
            'httpStatus' => 204,
854
 
            'message' => sprintf(__('DisplayGroups assigned to %s'), $displayGroup->displayGroup),
855
 
            'id' => $displayGroup->displayGroupId
856
 
        ]);
857
 
    }
858
 
 
859
 
    /**
860
 
     * Unassign DisplayGroups from a Display Group
861
 
     * @param int $displayGroupId
862
 
     * @throws InvalidArgumentException
863
 
     *
864
 
     * @SWG\Post(
865
 
     *  path="/displaygroup/{displayGroupId}/displayGroup/unassign",
866
 
     *  operationId="displayGroupDisplayGroupUnassign",
867
 
     *  tags={"displayGroup"},
868
 
     *  summary="Unassigns one or more DisplayGroups to a Display Group",
869
 
     *  description="Removes the provided DisplayGroups from the Display Group",
870
 
     *  @SWG\Parameter(
871
 
     *      name="displayGroupId",
872
 
     *      type="integer",
873
 
     *      in="path",
874
 
     *      description="The Display Group to unassign from",
875
 
     *      required=true
876
 
     *  ),
877
 
     *  @SWG\Parameter(
878
 
     *      name="displayGroupId",
879
 
     *      type="array",
880
 
     *      in="formData",
881
 
     *      description="The DisplayGroup Ids to unassign",
882
 
     *      required=true,
883
 
     *      @SWG\Items(
884
 
     *          type="integer"
885
 
     *      )
886
 
     *  ),
887
 
     *  @SWG\Response(
888
 
     *      response=204,
889
 
     *      description="successful operation"
890
 
     *  )
891
 
     * )
892
 
     *
893
 
     * @throws XiboException
894
 
     */
895
 
    public function unassignDisplayGroup($displayGroupId)
896
 
    {
897
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
898
 
 
899
 
        if ($displayGroup->isDisplaySpecific == 1)
900
 
            throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
901
 
 
902
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
903
 
        if (!$this->getUser()->checkEditable($displayGroup))
904
 
            throw new AccessDeniedException();
905
 
 
906
 
        if ($displayGroup->isDynamic == 1)
907
 
            throw new \InvalidArgumentException(__('DisplayGroups cannot be manually unassigned to a Dynamic Group'));
908
 
 
909
 
        $displayGroups = $this->getSanitizer()->getIntArray('displayGroupId');
910
 
 
911
 
        foreach ($displayGroups as $assignDisplayGroupId) {
912
 
            $displayGroup->unassignDisplayGroup($this->displayGroupFactory->getById($assignDisplayGroupId));
913
 
        }
914
 
 
915
 
        $displayGroup->save(['validate' => false]);
916
 
 
917
 
        // Return
918
 
        $this->getState()->hydrate([
919
 
            'httpStatus' => 204,
920
 
            'message' => sprintf(__('DisplayGroups unassigned from %s'), $displayGroup->displayGroup),
921
 
            'id' => $displayGroup->displayGroupId
922
 
        ]);
923
 
    }
924
 
 
925
 
    /**
926
526
     * Media Form (media linked to displays)
927
527
     * @param int $displayGroupId
928
 
     * @throws XiboException
929
528
     */
930
529
    public function mediaForm($displayGroupId)
931
530
    {
932
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
531
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
933
532
 
934
533
        if (!$this->getUser()->checkEditable($displayGroup))
935
534
            throw new AccessDeniedException();
936
535
 
937
536
        // Load the groups details
938
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
939
537
        $displayGroup->load();
940
538
 
941
539
        $this->getState()->template = 'displaygroup-form-media';
942
540
        $this->getState()->setData([
943
541
            'displayGroup' => $displayGroup,
944
 
            'modules' => $this->moduleFactory->query(null, ['regionSpecific' => 0]),
945
 
            'media' => $this->mediaFactory->getByDisplayGroupId($displayGroup->displayGroupId),
946
 
            'help' => $this->getHelp()->link('DisplayGroup', 'FileAssociations')
 
542
            'modules' => ModuleFactory::query(null, ['regionSpecific' => 0]),
 
543
            'media' => MediaFactory::getByDisplayGroupId($displayGroup->displayGroupId),
 
544
            'help' => Help::Link('DisplayGroup', 'FileAssociations')
947
545
        ]);
948
546
    }
949
547
 
989
587
     *      description="successful operation"
990
588
     *  )
991
589
     * )
992
 
     *
993
 
     * @throws XiboException
994
590
     */
995
591
    public function assignMedia($displayGroupId)
996
592
    {
997
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
593
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
998
594
 
999
595
        if (!$this->getUser()->checkEditable($displayGroup))
1000
596
            throw new AccessDeniedException();
1001
597
 
1002
598
        // Load the groups details
1003
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1004
599
        $displayGroup->load();
1005
600
 
1006
 
        $mediaIds = $this->getSanitizer()->getIntArray('mediaId');
 
601
        $mediaIds = Sanitize::getIntArray('mediaId');
1007
602
 
1008
603
        // Loop through all the media
1009
604
        foreach ($mediaIds as $mediaId) {
1010
605
 
1011
 
            $media = $this->mediaFactory->getById($mediaId);
 
606
            $media = MediaFactory::getById($mediaId);
1012
607
 
1013
608
            if (!$this->getUser()->checkViewable($media))
1014
609
                throw new AccessDeniedException(__('You have selected media that you no longer have permission to use. Please reload the form.'));
1017
612
        }
1018
613
 
1019
614
        // Check for unassign
1020
 
        foreach ($this->getSanitizer()->getIntArray('unassignMediaId') as $mediaId) {
 
615
        foreach (Sanitize::getIntArray('unassignMediaId') as $mediaId) {
1021
616
            // Get the media record
1022
 
            $media = $this->mediaFactory->getById($mediaId);
 
617
            $media = MediaFactory::getById($mediaId);
1023
618
 
1024
619
            if (!$this->getUser()->checkViewable($media))
1025
620
                throw new AccessDeniedException(__('You have selected media that you no longer have permission to use. Please reload the form.'));
1027
622
            $displayGroup->unassignMedia($media);
1028
623
        }
1029
624
 
1030
 
        $displayGroup->setCollectRequired(false);
1031
 
        $displayGroup->save(['validate' => false]);
 
625
        $displayGroup->save(false);
1032
626
 
1033
627
        // Return
1034
628
        $this->getState()->hydrate([
1070
664
     *      description="successful operation"
1071
665
     *  )
1072
666
     * )
1073
 
     *
1074
 
     * @throws XiboException
1075
667
     */
1076
668
    public function unassignMedia($displayGroupId)
1077
669
    {
1078
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
670
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
1079
671
 
1080
672
        if (!$this->getUser()->checkEditable($displayGroup))
1081
673
            throw new AccessDeniedException();
1082
674
 
1083
675
        // Load the groups details
1084
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1085
676
        $displayGroup->load();
1086
677
 
1087
 
        $mediaIds = $this->getSanitizer()->getIntArray('mediaId');
 
678
        $mediaIds = Sanitize::getIntArray('mediaIds');
1088
679
 
1089
680
        // Loop through all the media
1090
681
        foreach ($mediaIds as $mediaId) {
1091
682
 
1092
 
            $displayGroup->unassignMedia($this->mediaFactory->getById($mediaId));
 
683
            $displayGroup->unassignMedia(MediaFactory::getById($mediaId));
1093
684
        }
1094
685
 
1095
 
        $displayGroup->setCollectRequired(false);
1096
 
        $displayGroup->save(['validate' => false]);
 
686
        $displayGroup->save(false);
1097
687
 
1098
688
        // Return
1099
689
        $this->getState()->hydrate([
1104
694
    }
1105
695
 
1106
696
    /**
1107
 
     * Layouts Form (layouts linked to displays)
1108
 
     * @param int $displayGroupId
1109
 
     *
1110
 
     * @throws XiboException
1111
 
     */
1112
 
    public function LayoutsForm($displayGroupId)
1113
 
    {
1114
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1115
 
 
1116
 
        if (!$this->getUser()->checkEditable($displayGroup))
1117
 
            throw new AccessDeniedException();
1118
 
 
1119
 
        // Load the groups details
1120
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1121
 
        $displayGroup->load();
1122
 
 
1123
 
        $this->getState()->template = 'displaygroup-form-layouts';
1124
 
        $this->getState()->setData([
1125
 
            'displayGroup' => $displayGroup,
1126
 
            'modules' => $this->moduleFactory->query(null, ['regionSpecific' => 0]),
1127
 
            'layouts' => $this->layoutFactory->getByDisplayGroupId($displayGroup->displayGroupId),
1128
 
            'help' => $this->getHelp()->link('DisplayGroup', 'FileAssociations')
1129
 
        ]);
1130
 
    }
1131
 
 
1132
 
    /**
1133
 
     * Assign Layouts
1134
 
     * @param int $displayGroupId
1135
 
     *
1136
 
     * @SWG\Post(
1137
 
     *  path="/displaygroup/{displayGroupId}/layout/assign",
1138
 
     *  operationId="displayGroupLayoutsAssign",
1139
 
     *  tags={"displayGroup"},
1140
 
     *  summary="Assign one or more Layouts items to a Display Group",
1141
 
     *  description="Adds the provided Layouts to the Display Group",
1142
 
     *  @SWG\Parameter(
1143
 
     *      name="displayGroupId",
1144
 
     *      type="integer",
1145
 
     *      in="path",
1146
 
     *      description="The Display Group to assign to",
1147
 
     *      required=true
1148
 
     *  ),
1149
 
     *  @SWG\Parameter(
1150
 
     *      name="layoutId",
1151
 
     *      type="array",
1152
 
     *      in="formData",
1153
 
     *      description="The Layouts Ids to assign",
1154
 
     *      required=true,
1155
 
     *      @SWG\Items(
1156
 
     *          type="integer"
1157
 
     *      )
1158
 
     *  ),
1159
 
     *  @SWG\Parameter(
1160
 
     *      name="unassignLayoutId",
1161
 
     *      type="array",
1162
 
     *      in="formData",
1163
 
     *      description="Optional array of Layouts Id to unassign",
1164
 
     *      required=false,
1165
 
     *      @SWG\Items(
1166
 
     *          type="integer"
1167
 
     *      )
1168
 
     *  ),
1169
 
     *  @SWG\Response(
1170
 
     *      response=204,
1171
 
     *      description="successful operation"
1172
 
     *  )
1173
 
     * )
1174
 
     *
1175
 
     * @throws XiboException
1176
 
     */
1177
 
    public function assignLayouts($displayGroupId)
1178
 
    {
1179
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1180
 
 
1181
 
        if (!$this->getUser()->checkEditable($displayGroup))
1182
 
            throw new AccessDeniedException();
1183
 
 
1184
 
        // Load the groups details
1185
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1186
 
        $displayGroup->load();
1187
 
 
1188
 
        $layoutIds = $this->getSanitizer()->getIntArray('layoutId');
1189
 
 
1190
 
        // Loop through all the media
1191
 
        foreach ($layoutIds as $layoutId) {
1192
 
 
1193
 
            $layout = $this->layoutFactory->getById($layoutId);
1194
 
 
1195
 
            if (!$this->getUser()->checkViewable($layout))
1196
 
                throw new AccessDeniedException(__('You have selected a layout that you no longer have permission to use. Please reload the form.'));
1197
 
 
1198
 
            $displayGroup->assignLayout($layout);
1199
 
        }
1200
 
 
1201
 
        // Check for unassign
1202
 
        foreach ($this->getSanitizer()->getIntArray('unassignLayoutId') as $layoutId) {
1203
 
            // Get the layout record
1204
 
            $layout = $this->layoutFactory->getById($layoutId);
1205
 
 
1206
 
            if (!$this->getUser()->checkViewable($layout))
1207
 
                throw new AccessDeniedException(__('You have selected a layout that you no longer have permission to use. Please reload the form.'));
1208
 
 
1209
 
            $displayGroup->unassignLayout($layout);
1210
 
        }
1211
 
 
1212
 
        $displayGroup->setCollectRequired(false);
1213
 
        $displayGroup->save(['validate' => false]);
1214
 
 
1215
 
        // Return
1216
 
        $this->getState()->hydrate([
1217
 
            'httpStatus' => 204,
1218
 
            'message' => sprintf(__('Layouts assigned to %s'), $displayGroup->displayGroup),
1219
 
            'id' => $displayGroup->displayGroupId
1220
 
        ]);
1221
 
    }
1222
 
 
1223
 
    /**
1224
 
     * Unassign Layout
1225
 
     * @param int $displayGroupId
1226
 
     *
1227
 
     * @SWG\Post(
1228
 
     *  path="/displaygroup/{displayGroupId}/layout/unassign",
1229
 
     *  operationId="displayGroupLayoutUnassign",
1230
 
     *  tags={"displayGroup"},
1231
 
     *  summary="Unassign one or more Layout items from a Display Group",
1232
 
     *  description="Removes the provided from the Display Group",
1233
 
     *  @SWG\Parameter(
1234
 
     *      name="displayGroupId",
1235
 
     *      type="integer",
1236
 
     *      in="path",
1237
 
     *      description="The Display Group to unassign from",
1238
 
     *      required=true
1239
 
     *  ),
1240
 
     *  @SWG\Parameter(
1241
 
     *      name="layoutId",
1242
 
     *      type="array",
1243
 
     *      in="formData",
1244
 
     *      description="The Layout Ids to unassign",
1245
 
     *      required=true,
1246
 
     *      @SWG\Items(
1247
 
     *          type="integer"
1248
 
     *      )
1249
 
     *  ),
1250
 
     *  @SWG\Response(
1251
 
     *      response=204,
1252
 
     *      description="successful operation"
1253
 
     *  )
1254
 
     * )
1255
 
     *
1256
 
     * @throws XiboException
1257
 
     */
1258
 
    public function unassignLayouts($displayGroupId)
1259
 
    {
1260
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1261
 
 
1262
 
        if (!$this->getUser()->checkEditable($displayGroup))
1263
 
            throw new AccessDeniedException();
1264
 
 
1265
 
        // Load the groups details
1266
 
        $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1267
 
        $displayGroup->load();
1268
 
 
1269
 
        $layoutIds = $this->getSanitizer()->getIntArray('layoutId');
1270
 
 
1271
 
        // Loop through all the media
1272
 
        foreach ($layoutIds as $layoutId) {
1273
 
            $this->getLog()->debug('Unassign layoutId ' . $layoutId . ' from ' . $displayGroupId);
1274
 
            $displayGroup->unassignLayout($this->layoutFactory->getById($layoutId));
1275
 
        }
1276
 
 
1277
 
        $displayGroup->setCollectRequired(false);
1278
 
        $displayGroup->save(['validate' => false]);
1279
 
 
1280
 
        // Return
1281
 
        $this->getState()->hydrate([
1282
 
            'httpStatus' => 204,
1283
 
            'message' => sprintf(__('Layouts unassigned from %s'), $displayGroup->displayGroup),
1284
 
            'id' => $displayGroup->displayGroupId
1285
 
        ]);
1286
 
    }
1287
 
 
1288
 
    /**
1289
697
     * Version Form
1290
698
     * @param int $displayGroupId
1291
699
     */
1292
700
    public function versionForm($displayGroupId)
1293
701
    {
1294
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
 
702
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
1295
703
 
1296
704
        if (!$this->getUser()->checkEditable($displayGroup))
1297
705
            throw new AccessDeniedException();
1298
706
 
1299
707
        // List of effected displays
1300
 
        $displays = $this->displayFactory->getByDisplayGroupId($displayGroupId);
 
708
        $displays = DisplayFactory::getByDisplayGroupId($displayGroupId);
1301
709
 
1302
710
        // Possible media files to assign
1303
 
        $media = $this->mediaFactory->query(['name'], ['type' => 'genericfile']);
 
711
        $media = MediaFactory::query(['name'], ['type' => 'genericfile']);
1304
712
 
1305
713
        $this->getState()->template = 'displaygroup-form-version';
1306
714
        $this->getState()->setData([
1307
715
            'displayGroup' => $displayGroup,
1308
716
            'displays' => $displays,
1309
717
            'media' => $media,
1310
 
            'help' => $this->getHelp()->link('DisplayGroup', 'Version')
 
718
            'help' => Help::Link('DisplayGroup', 'Version')
1311
719
        ]);
1312
720
    }
1313
721
 
1340
748
     *      description="successful operation"
1341
749
     *  )
1342
750
     * )
1343
 
     *
1344
 
     * @throws XiboException
1345
751
     */
1346
752
    public function version($displayGroupId)
1347
753
    {
1348
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1349
 
         $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
 
754
        $displayGroup = DisplayGroupFactory::getById($displayGroupId);
1350
755
 
1351
756
        if (!$this->getUser()->checkEditable($displayGroup))
1352
757
            throw new AccessDeniedException();
1353
758
 
1354
 
        $media = $this->mediaFactory->getById($this->getSanitizer()->getInt('mediaId'));
 
759
        $media = MediaFactory::getById(Sanitize::getInt('mediaId'));
1355
760
 
1356
761
        if (!$this->getUser()->checkViewable($media))
1357
762
            throw new AccessDeniedException();
1358
763
 
1359
764
        // Assign the media file
1360
 
        $displayGroup->assignMedia($media);
1361
 
        $displayGroup->setCollectRequired(true);
 
765
        $displayGroup->assignMedia($media->mediaId);
1362
766
 
1363
767
        // Update each display in the group with the new version
1364
 
        foreach ($this->displayFactory->getByDisplayGroupId($displayGroupId) as $display) {
 
768
        foreach (DisplayFactory::getByDisplayGroupId($displayGroupId) as $display) {
1365
769
            /* @var Display $display */
1366
770
            $display->versionInstructions = json_encode(['id' => $media->mediaId, 'file' => $media->storedAs]);
1367
 
            $display->save(['validate' => false]);
 
771
            $display->save(false);
1368
772
        }
1369
773
 
1370
 
        // Save the group (for the file assignment)
1371
 
        $displayGroup->save(['manageDisplayLinks' => false]);
1372
 
 
1373
774
        // Return
1374
775
        $this->getState()->hydrate([
1375
776
            'httpStatus' => 204,
1377
778
            'id' => $displayGroup->displayGroupId
1378
779
        ]);
1379
780
    }
1380
 
 
1381
 
    /**
1382
 
     * @param int $displayGroupId
1383
 
     */
1384
 
    public function collectNowForm($displayGroupId)
1385
 
    {
1386
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1387
 
 
1388
 
        if (!$this->getUser()->checkEditable($displayGroup))
1389
 
            throw new AccessDeniedException();
1390
 
 
1391
 
        $this->getState()->template = 'displaygroup-form-collect-now';
1392
 
        $this->getState()->setData([
1393
 
            'displayGroup' => $displayGroup
1394
 
        ]);
1395
 
    }
1396
 
 
1397
 
    /**
1398
 
     * Cause the player to collect now
1399
 
     * @param int $displayGroupId
1400
 
     * @throws ConfigurationException when the message cannot be sent
1401
 
     *
1402
 
     * @SWG\Post(
1403
 
     *  path="/displaygroup/{displayGroupId}/action/collectNow",
1404
 
     *  operationId="displayGroupActionCollectNow",
1405
 
     *  tags={"displayGroup"},
1406
 
     *  summary="Action: Collect Now",
1407
 
     *  description="Send the collect now action to this DisplayGroup",
1408
 
     *  @SWG\Parameter(
1409
 
     *      name="displayGroupId",
1410
 
     *      in="path",
1411
 
     *      description="The display group id",
1412
 
     *      type="integer",
1413
 
     *      required=true
1414
 
     *   ),
1415
 
     *  @SWG\Response(
1416
 
     *      response=204,
1417
 
     *      description="successful operation"
1418
 
     *  )
1419
 
     * )
1420
 
     */
1421
 
    public function collectNow($displayGroupId)
1422
 
    {
1423
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1424
 
 
1425
 
        if (!$this->getUser()->checkEditable($displayGroup))
1426
 
            throw new AccessDeniedException();
1427
 
 
1428
 
        $this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), new CollectNowAction());
1429
 
 
1430
 
        // Return
1431
 
        $this->getState()->hydrate([
1432
 
            'httpStatus' => 204,
1433
 
            'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1434
 
            'id' => $displayGroup->displayGroupId
1435
 
        ]);
1436
 
    }
1437
 
 
1438
 
    /**
1439
 
     * Cause the player to collect now
1440
 
     * @param int $displayGroupId
1441
 
     * @throws ConfigurationException when the message cannot be sent
1442
 
     *
1443
 
     * @SWG\Post(
1444
 
     *  path="/displaygroup/{displayGroupId}/action/clearStatsAndLogs",
1445
 
     *  operationId="displayGroupActionClearStatsAndLogs",
1446
 
     *  tags={"displayGroup"},
1447
 
     *  summary="Action: Clear Stats and Logs",
1448
 
     *  description="Clear all stats and logs on this Group",
1449
 
     *  @SWG\Parameter(
1450
 
     *      name="displayGroupId",
1451
 
     *      in="path",
1452
 
     *      description="The display group id",
1453
 
     *      type="integer",
1454
 
     *      required=true
1455
 
     *   ),
1456
 
     *  @SWG\Response(
1457
 
     *      response=204,
1458
 
     *      description="successful operation"
1459
 
     *  )
1460
 
     * )
1461
 
     */
1462
 
    public function clearStatsAndLogs($displayGroupId)
1463
 
    {
1464
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1465
 
 
1466
 
        if (!$this->getUser()->checkEditable($displayGroup))
1467
 
            throw new AccessDeniedException();
1468
 
 
1469
 
        $this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), new CollectNowAction());
1470
 
 
1471
 
        // Return
1472
 
        $this->getState()->hydrate([
1473
 
            'httpStatus' => 204,
1474
 
            'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1475
 
            'id' => $displayGroup->displayGroupId
1476
 
        ]);
1477
 
    }
1478
 
 
1479
 
    /**
1480
 
     * Change to a new Layout
1481
 
     * @param $displayGroupId
1482
 
     * @throws ConfigurationException
1483
 
     * @throws \Xibo\Exception\NotFoundException
1484
 
     *
1485
 
     * @SWG\Post(
1486
 
     *  path="/displaygroup/{displayGroupId}/action/changeLayout",
1487
 
     *  operationId="displayGroupActionChangeLayout",
1488
 
     *  tags={"displayGroup"},
1489
 
     *  summary="Action: Change Layout",
1490
 
     *  description="Send the change layout action to this DisplayGroup",
1491
 
     *  @SWG\Parameter(
1492
 
     *      name="displayGroupId",
1493
 
     *      in="path",
1494
 
     *      description="The Display Group Id",
1495
 
     *      type="integer",
1496
 
     *      required=true
1497
 
     *   ),
1498
 
     *  @SWG\Parameter(
1499
 
     *      name="layoutId",
1500
 
     *      in="formData",
1501
 
     *      description="The Layout Id",
1502
 
     *      type="integer",
1503
 
     *      required=true
1504
 
     *   ),
1505
 
     *  @SWG\Parameter(
1506
 
     *      name="duration",
1507
 
     *      in="formData",
1508
 
     *      description="The duration in seconds for this Layout change to remain in effect",
1509
 
     *      type="integer",
1510
 
     *      required=false
1511
 
     *   ),
1512
 
     *  @SWG\Parameter(
1513
 
     *      name="downloadRequired",
1514
 
     *      in="formData",
1515
 
     *      description="Flag indicating whether the player should perform a collect before playing the Layout",
1516
 
     *      type="integer",
1517
 
     *      required=false
1518
 
     *   ),
1519
 
     *  @SWG\Parameter(
1520
 
     *      name="changeMode",
1521
 
     *      in="formData",
1522
 
     *      description="Whether to queue or replace with this action",
1523
 
     *      type="string",
1524
 
     *      required=true
1525
 
     *   ),
1526
 
     *  @SWG\Response(
1527
 
     *      response=204,
1528
 
     *      description="successful operation"
1529
 
     *  )
1530
 
     * )
1531
 
     *
1532
 
     * @throws XiboException
1533
 
     */
1534
 
    public function changeLayout($displayGroupId)
1535
 
    {
1536
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1537
 
 
1538
 
        if (!$this->getUser()->checkEditable($displayGroup))
1539
 
            throw new AccessDeniedException();
1540
 
 
1541
 
        // Get the layoutId
1542
 
        $layoutId = $this->getSanitizer()->getInt('layoutId');
1543
 
        $downloadRequired = ($this->getSanitizer()->getCheckbox('downloadRequired') == 1);
1544
 
 
1545
 
        if ($layoutId == 0)
1546
 
            throw new \InvalidArgumentException(__('Please provide a Layout'));
1547
 
 
1548
 
        // Check that this user has permissions to see this layout
1549
 
        $layout = $this->layoutFactory->getById($layoutId);
1550
 
 
1551
 
        if (!$this->getUser()->checkViewable($layout))
1552
 
            throw new AccessDeniedException();
1553
 
 
1554
 
        // Check to see if this layout is assigned to this display group.
1555
 
        if (count($this->layoutFactory->query(null, ['disableUserCheck' => 1, 'layoutId' => $layoutId, 'displayGroupId' => $displayGroupId])) <= 0) {
1556
 
            // Assign
1557
 
            $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1558
 
            $displayGroup->load();
1559
 
            $displayGroup->assignLayout($layout);
1560
 
 
1561
 
            // Don't collect now, this player action will cause a download.
1562
 
            // notify will still occur if the layout isn't already assigned (which is shouldn't be)
1563
 
            $displayGroup->setCollectRequired(false);
1564
 
 
1565
 
            $displayGroup->save(['validate' => false]);
1566
 
 
1567
 
            // Convert into a download required
1568
 
            $downloadRequired = true;
1569
 
        } else {
1570
 
            // The layout may not be built at this point
1571
 
            if ($downloadRequired) {
1572
 
                // in this case we should build it and notify before we send the action
1573
 
                // notify should NOT collect now, as we will do that during our own action.
1574
 
                $layout->xlfToDisk(['notify' => true, 'collectNow' => false]);
1575
 
            }
1576
 
        }
1577
 
 
1578
 
        // Create and send the player action
1579
 
        $this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), (new ChangeLayoutAction())->setLayoutDetails(
1580
 
            $layoutId,
1581
 
            $this->getSanitizer()->getInt('duration'),
1582
 
            $downloadRequired,
1583
 
            $this->getSanitizer()->getString('changeMode', 'queue')
1584
 
        ));
1585
 
 
1586
 
        // Return
1587
 
        $this->getState()->hydrate([
1588
 
            'httpStatus' => 204,
1589
 
            'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1590
 
            'id' => $displayGroup->displayGroupId
1591
 
        ]);
1592
 
    }
1593
 
 
1594
 
    /**
1595
 
     * Cause the player to revert to its scheduled content
1596
 
     * @param int $displayGroupId
1597
 
     * @throws ConfigurationException when the message cannot be sent
1598
 
     *
1599
 
     * @SWG\Post(
1600
 
     *  path="/displaygroup/{displayGroupId}/action/revertToSchedule",
1601
 
     *  operationId="displayGroupActionRevertToSchedule",
1602
 
     *  tags={"displayGroup"},
1603
 
     *  summary="Action: Revert to Schedule",
1604
 
     *  description="Send the revert to schedule action to this DisplayGroup",
1605
 
     *  @SWG\Parameter(
1606
 
     *      name="displayGroupId",
1607
 
     *      in="path",
1608
 
     *      description="The display group id",
1609
 
     *      type="integer",
1610
 
     *      required=true
1611
 
     *   ),
1612
 
     *  @SWG\Response(
1613
 
     *      response=204,
1614
 
     *      description="successful operation"
1615
 
     *  )
1616
 
     * )
1617
 
     */
1618
 
    public function revertToSchedule($displayGroupId)
1619
 
    {
1620
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1621
 
 
1622
 
        if (!$this->getUser()->checkEditable($displayGroup))
1623
 
            throw new AccessDeniedException();
1624
 
 
1625
 
        $this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), new RevertToSchedule());
1626
 
 
1627
 
        // Return
1628
 
        $this->getState()->hydrate([
1629
 
            'httpStatus' => 204,
1630
 
            'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1631
 
            'id' => $displayGroup->displayGroupId
1632
 
        ]);
1633
 
    }
1634
 
 
1635
 
    /**
1636
 
     * Add an Overlay Layout
1637
 
     * @param $displayGroupId
1638
 
     * @throws ConfigurationException
1639
 
     * @throws \Xibo\Exception\NotFoundException
1640
 
     *
1641
 
     * @SWG\Post(
1642
 
     *  path="/displaygroup/{displayGroupId}/action/overlayLayout",
1643
 
     *  operationId="displayGroupActionOverlayLayout",
1644
 
     *  tags={"displayGroup"},
1645
 
     *  summary="Action: Overlay Layout",
1646
 
     *  description="Send the overlay layout action to this DisplayGroup",
1647
 
     *  @SWG\Parameter(
1648
 
     *      name="displayGroupId",
1649
 
     *      in="path",
1650
 
     *      description="The Display Group Id",
1651
 
     *      type="integer",
1652
 
     *      required=true
1653
 
     *   ),
1654
 
     *  @SWG\Parameter(
1655
 
     *      name="layoutId",
1656
 
     *      in="formData",
1657
 
     *      description="The Layout Id",
1658
 
     *      type="integer",
1659
 
     *      required=true
1660
 
     *   ),
1661
 
     *  @SWG\Parameter(
1662
 
     *      name="duration",
1663
 
     *      in="formData",
1664
 
     *      description="The duration in seconds for this Overlay to remain in effect",
1665
 
     *      type="integer",
1666
 
     *      required=false
1667
 
     *   ),
1668
 
     *  @SWG\Parameter(
1669
 
     *      name="downloadRequired",
1670
 
     *      in="formData",
1671
 
     *      description="Flag indicating whether the player should perform a collect before adding the Overlay",
1672
 
     *      type="integer",
1673
 
     *      required=false
1674
 
     *   ),
1675
 
     *  @SWG\Response(
1676
 
     *      response=204,
1677
 
     *      description="successful operation"
1678
 
     *  )
1679
 
     * )
1680
 
     *
1681
 
     * @throws XiboException
1682
 
     */
1683
 
    public function overlayLayout($displayGroupId)
1684
 
    {
1685
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1686
 
 
1687
 
        if (!$this->getUser()->checkEditable($displayGroup))
1688
 
            throw new AccessDeniedException();
1689
 
 
1690
 
        // Get the layoutId
1691
 
        $layoutId = $this->getSanitizer()->getInt('layoutId');
1692
 
        $downloadRequired = ($this->getSanitizer()->getCheckbox('downloadRequired') == 1);
1693
 
 
1694
 
        if ($layoutId == 0)
1695
 
            throw new \InvalidArgumentException(__('Please provide a Layout'));
1696
 
 
1697
 
        // Check that this user has permissions to see this layout
1698
 
        $layout = $this->layoutFactory->getById($layoutId);
1699
 
 
1700
 
        if (!$this->getUser()->checkViewable($layout))
1701
 
            throw new AccessDeniedException();
1702
 
 
1703
 
        // Check to see if this layout is assigned to this display group.
1704
 
        if (count($this->layoutFactory->query(null, ['disableUserCheck' => 1, 'layoutId' => $layoutId, 'displayGroupId' => $displayGroupId])) <= 0) {
1705
 
            // Assign
1706
 
            $displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1707
 
            $displayGroup->load();
1708
 
            $displayGroup->assignLayout($layout);
1709
 
            // Don't notify, this player action will cause a download.
1710
 
            $displayGroup->setCollectRequired(false);
1711
 
            $displayGroup->save(['validate' => false]);
1712
 
 
1713
 
            // Convert into a download required
1714
 
            $downloadRequired = true;
1715
 
        } else {
1716
 
            // The layout may not be built at this point
1717
 
            if ($downloadRequired) {
1718
 
                // in this case we should build it and notify before we send the action
1719
 
                // notify should NOT collect now, as we will do that during our own action.
1720
 
                $layout->xlfToDisk(['notify' => true, 'collectNow' => false]);
1721
 
            }
1722
 
        }
1723
 
 
1724
 
        $this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), (new OverlayLayoutAction())->setLayoutDetails(
1725
 
            $layoutId,
1726
 
            $this->getSanitizer()->getInt('duration'),
1727
 
            $downloadRequired
1728
 
        ));
1729
 
 
1730
 
        // Return
1731
 
        $this->getState()->hydrate([
1732
 
            'httpStatus' => 204,
1733
 
            'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1734
 
            'id' => $displayGroup->displayGroupId
1735
 
        ]);
1736
 
    }
1737
 
 
1738
 
    /**
1739
 
     * Command Form
1740
 
     * @param int $displayGroupId
1741
 
     * @throws \Xibo\Exception\NotFoundException
1742
 
     */
1743
 
    public function commandForm($displayGroupId)
1744
 
    {
1745
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1746
 
 
1747
 
        if (!$this->getUser()->checkEditable($displayGroup))
1748
 
            throw new AccessDeniedException();
1749
 
 
1750
 
        $this->getState()->template = 'displaygroup-form-command';
1751
 
        $this->getState()->setData([
1752
 
            'displayGroup' => $displayGroup,
1753
 
            'commands' => $this->commandFactory->query()
1754
 
        ]);
1755
 
    }
1756
 
 
1757
 
    /**
1758
 
     * @param $displayGroupId
1759
 
     * @throws ConfigurationException
1760
 
     * @throws \Xibo\Exception\NotFoundException
1761
 
     *
1762
 
     * @SWG\Post(
1763
 
     *  path="/displaygroup/{displayGroupId}/action/command",
1764
 
     *  operationId="displayGroupActionCommand",
1765
 
     *  tags={"displayGroup"},
1766
 
     *  summary="Send Command",
1767
 
     *  description="Send a predefined command to this Group of Displays",
1768
 
     *  @SWG\Parameter(
1769
 
     *      name="displayGroupId",
1770
 
     *      in="path",
1771
 
     *      description="The display group id",
1772
 
     *      type="integer",
1773
 
     *      required=true
1774
 
     *   ),
1775
 
     *  @SWG\Parameter(
1776
 
     *      name="commandId",
1777
 
     *      in="formData",
1778
 
     *      description="The Command Id",
1779
 
     *      type="integer",
1780
 
     *      required=true
1781
 
     *   ),
1782
 
     *  @SWG\Response(
1783
 
     *      response=204,
1784
 
     *      description="successful operation"
1785
 
     *  )
1786
 
     * )
1787
 
     */
1788
 
    public function command($displayGroupId)
1789
 
    {
1790
 
        $displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1791
 
 
1792
 
        if (!$this->getUser()->checkEditable($displayGroup))
1793
 
            throw new AccessDeniedException();
1794
 
 
1795
 
        $command = $this->commandFactory->getById($this->getSanitizer()->getInt('commandId'));
1796
 
        $displays = $this->displayFactory->getByDisplayGroupId($displayGroupId);
1797
 
 
1798
 
        $this->playerAction->sendAction($displays, (new CommandAction())->setCommandCode($command->code));
1799
 
 
1800
 
        // Update the flag
1801
 
        foreach ($displays as $display) {
1802
 
            /* @var \Xibo\Entity\Display $display */
1803
 
            $display->lastCommandSuccess = 0;
1804
 
            $display->save(['validate' => false, 'audit' => false]);
1805
 
        }
1806
 
 
1807
 
        // Return
1808
 
        $this->getState()->hydrate([
1809
 
            'httpStatus' => 204,
1810
 
            'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1811
 
            'id' => $displayGroup->displayGroupId
1812
 
        ]);
1813
 
    }
1814
781
}