21
21
namespace Xibo\Controller;
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;
49
* @package Xibo\Controller
30
use Xibo\Factory\PermissionFactory;
32
use Xibo\Helper\Sanitize;
51
35
class DisplayGroup extends Base
54
* @var PlayerActionServiceInterface
56
private $playerAction;
59
* @var DisplayGroupFactory
61
private $displayGroupFactory;
66
private $displayFactory;
71
private $moduleFactory;
76
private $mediaFactory;
81
private $layoutFactory;
86
private $commandFactory;
89
* @var ScheduleFactory
91
private $scheduleFactory;
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
117
public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $playerAction, $displayFactory, $displayGroupFactory, $layoutFactory, $moduleFactory, $mediaFactory, $commandFactory, $scheduleFactory, $tagFactory)
119
$this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
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;
133
38
* Display Group Page Render
135
40
public function displayPage()
137
42
$this->getState()->template = 'displaygroup-page';
138
$this->getState()->setData([
139
'displays' => $this->displayFactory->query()
621
424
* description="successful operation"
625
* @throws XiboException
627
428
public function assignDisplay($displayGroupId)
629
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
631
if ($displayGroup->isDisplaySpecific == 1)
632
throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
634
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
430
$displayGroup = DisplayGroupFactory::getById($displayGroupId);
636
432
if (!$this->getUser()->checkEditable($displayGroup))
637
433
throw new AccessDeniedException();
639
if ($displayGroup->isDynamic == 1)
640
throw new \InvalidArgumentException(__('Displays cannot be manually assigned to a Dynamic Group'));
642
$modifiedDisplays = [];
644
$displays = $this->getSanitizer()->getIntArray('displayId');
435
$displays = Sanitize::getIntArray('displayId');
646
437
foreach ($displays as $displayId) {
647
$display = $this->displayFactory->getById($displayId);
438
$display = DisplayFactory::getById($displayId);
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'));
652
443
$displayGroup->assignDisplay($display);
654
// Store so that we can flag as incomplete
655
if (!in_array($display, $modifiedDisplays))
656
$modifiedDisplays[] = $display;
659
446
// Have we been provided with unassign id's as well?
660
$displays = $this->getSanitizer()->getIntArray('unassignDisplayId');
447
$displays = Sanitize::getIntArray('unassignDisplayId');
662
449
foreach ($displays as $displayId) {
663
$display = $this->displayFactory->getById($displayId);
450
$display = DisplayFactory::getById($displayId);
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'));
668
455
$displayGroup->unassignDisplay($display);
670
// Store so that we can flag as incomplete
671
if (!in_array($display, $modifiedDisplays))
672
$modifiedDisplays[] = $display;
675
458
// Save the result
676
$displayGroup->save(['validate' => false]);
678
// Save the displays themselves
679
foreach ($modifiedDisplays as $display) {
680
/** @var Display $display */
459
$displayGroup->save(false);
685
462
$this->getState()->hydrate([
767
* Sets the Members of a group
768
* @param int $displayGroupId
769
* @throws InvalidArgumentException
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",
778
* name="displayGroupId",
781
* description="The Display Group to assign to",
785
* name="displayGroupId",
788
* description="The displayGroup Ids to assign",
795
* name="unassignDisplayGroupId",
797
* description="An optional array of displayGroup IDs to unassign",
800
* @SWG\Items(type="integer")
804
* description="successful operation"
808
* @throws XiboException
810
public function assignDisplayGroup($displayGroupId)
812
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
814
if ($displayGroup->isDisplaySpecific == 1)
815
throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
817
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
819
if (!$this->getUser()->checkEditable($displayGroup))
820
throw new AccessDeniedException();
822
if ($displayGroup->isDynamic == 1)
823
throw new \InvalidArgumentException(__('DisplayGroups cannot be manually assigned to a Dynamic Group'));
825
$displayGroups = $this->getSanitizer()->getIntArray('displayGroupId');
827
foreach ($displayGroups as $assignDisplayGroupId) {
828
$displayGroupAssign = $this->displayGroupFactory->getById($assignDisplayGroupId);
830
if (!$this->getUser()->checkViewable($displayGroupAssign))
831
throw new AccessDeniedException(__('Access Denied to DisplayGroup'));
833
$displayGroup->assignDisplayGroup($displayGroupAssign);
836
// Have we been provided with unassign id's as well?
837
$displayGroups = $this->getSanitizer()->getIntArray('unassignDisplayGroupId');
839
foreach ($displayGroups as $assignDisplayGroupId) {
840
$displayGroupUnassign = $this->displayGroupFactory->getById($assignDisplayGroupId);
842
if (!$this->getUser()->checkViewable($displayGroupUnassign))
843
throw new AccessDeniedException(__('Access Denied to DisplayGroup'));
845
$displayGroup->unassignDisplayGroup($displayGroupUnassign);
849
$displayGroup->save(['validate' => false]);
852
$this->getState()->hydrate([
854
'message' => sprintf(__('DisplayGroups assigned to %s'), $displayGroup->displayGroup),
855
'id' => $displayGroup->displayGroupId
860
* Unassign DisplayGroups from a Display Group
861
* @param int $displayGroupId
862
* @throws InvalidArgumentException
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",
871
* name="displayGroupId",
874
* description="The Display Group to unassign from",
878
* name="displayGroupId",
881
* description="The DisplayGroup Ids to unassign",
889
* description="successful operation"
893
* @throws XiboException
895
public function unassignDisplayGroup($displayGroupId)
897
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
899
if ($displayGroup->isDisplaySpecific == 1)
900
throw new InvalidArgumentException(__('This is a Display specific Display Group and its assignments cannot be modified.'), 'displayGroupId');
902
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
903
if (!$this->getUser()->checkEditable($displayGroup))
904
throw new AccessDeniedException();
906
if ($displayGroup->isDynamic == 1)
907
throw new \InvalidArgumentException(__('DisplayGroups cannot be manually unassigned to a Dynamic Group'));
909
$displayGroups = $this->getSanitizer()->getIntArray('displayGroupId');
911
foreach ($displayGroups as $assignDisplayGroupId) {
912
$displayGroup->unassignDisplayGroup($this->displayGroupFactory->getById($assignDisplayGroupId));
915
$displayGroup->save(['validate' => false]);
918
$this->getState()->hydrate([
920
'message' => sprintf(__('DisplayGroups unassigned from %s'), $displayGroup->displayGroup),
921
'id' => $displayGroup->displayGroupId
926
526
* Media Form (media linked to displays)
927
527
* @param int $displayGroupId
928
* @throws XiboException
930
529
public function mediaForm($displayGroupId)
932
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
531
$displayGroup = DisplayGroupFactory::getById($displayGroupId);
934
533
if (!$this->getUser()->checkEditable($displayGroup))
935
534
throw new AccessDeniedException();
937
536
// Load the groups details
938
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
939
537
$displayGroup->load();
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')
1107
* Layouts Form (layouts linked to displays)
1108
* @param int $displayGroupId
1110
* @throws XiboException
1112
public function LayoutsForm($displayGroupId)
1114
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1116
if (!$this->getUser()->checkEditable($displayGroup))
1117
throw new AccessDeniedException();
1119
// Load the groups details
1120
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1121
$displayGroup->load();
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')
1134
* @param int $displayGroupId
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",
1143
* name="displayGroupId",
1146
* description="The Display Group to assign to",
1153
* description="The Layouts Ids to assign",
1160
* name="unassignLayoutId",
1163
* description="Optional array of Layouts Id to unassign",
1171
* description="successful operation"
1175
* @throws XiboException
1177
public function assignLayouts($displayGroupId)
1179
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1181
if (!$this->getUser()->checkEditable($displayGroup))
1182
throw new AccessDeniedException();
1184
// Load the groups details
1185
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1186
$displayGroup->load();
1188
$layoutIds = $this->getSanitizer()->getIntArray('layoutId');
1190
// Loop through all the media
1191
foreach ($layoutIds as $layoutId) {
1193
$layout = $this->layoutFactory->getById($layoutId);
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.'));
1198
$displayGroup->assignLayout($layout);
1201
// Check for unassign
1202
foreach ($this->getSanitizer()->getIntArray('unassignLayoutId') as $layoutId) {
1203
// Get the layout record
1204
$layout = $this->layoutFactory->getById($layoutId);
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.'));
1209
$displayGroup->unassignLayout($layout);
1212
$displayGroup->setCollectRequired(false);
1213
$displayGroup->save(['validate' => false]);
1216
$this->getState()->hydrate([
1217
'httpStatus' => 204,
1218
'message' => sprintf(__('Layouts assigned to %s'), $displayGroup->displayGroup),
1219
'id' => $displayGroup->displayGroupId
1225
* @param int $displayGroupId
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",
1234
* name="displayGroupId",
1237
* description="The Display Group to unassign from",
1244
* description="The Layout Ids to unassign",
1252
* description="successful operation"
1256
* @throws XiboException
1258
public function unassignLayouts($displayGroupId)
1260
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1262
if (!$this->getUser()->checkEditable($displayGroup))
1263
throw new AccessDeniedException();
1265
// Load the groups details
1266
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1267
$displayGroup->load();
1269
$layoutIds = $this->getSanitizer()->getIntArray('layoutId');
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));
1277
$displayGroup->setCollectRequired(false);
1278
$displayGroup->save(['validate' => false]);
1281
$this->getState()->hydrate([
1282
'httpStatus' => 204,
1283
'message' => sprintf(__('Layouts unassigned from %s'), $displayGroup->displayGroup),
1284
'id' => $displayGroup->displayGroupId
1290
698
* @param int $displayGroupId
1292
700
public function versionForm($displayGroupId)
1294
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
702
$displayGroup = DisplayGroupFactory::getById($displayGroupId);
1296
704
if (!$this->getUser()->checkEditable($displayGroup))
1297
705
throw new AccessDeniedException();
1299
707
// List of effected displays
1300
$displays = $this->displayFactory->getByDisplayGroupId($displayGroupId);
708
$displays = DisplayFactory::getByDisplayGroupId($displayGroupId);
1302
710
// Possible media files to assign
1303
$media = $this->mediaFactory->query(['name'], ['type' => 'genericfile']);
711
$media = MediaFactory::query(['name'], ['type' => 'genericfile']);
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')
1377
778
'id' => $displayGroup->displayGroupId
1382
* @param int $displayGroupId
1384
public function collectNowForm($displayGroupId)
1386
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1388
if (!$this->getUser()->checkEditable($displayGroup))
1389
throw new AccessDeniedException();
1391
$this->getState()->template = 'displaygroup-form-collect-now';
1392
$this->getState()->setData([
1393
'displayGroup' => $displayGroup
1398
* Cause the player to collect now
1399
* @param int $displayGroupId
1400
* @throws ConfigurationException when the message cannot be sent
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",
1409
* name="displayGroupId",
1411
* description="The display group id",
1417
* description="successful operation"
1421
public function collectNow($displayGroupId)
1423
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1425
if (!$this->getUser()->checkEditable($displayGroup))
1426
throw new AccessDeniedException();
1428
$this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), new CollectNowAction());
1431
$this->getState()->hydrate([
1432
'httpStatus' => 204,
1433
'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1434
'id' => $displayGroup->displayGroupId
1439
* Cause the player to collect now
1440
* @param int $displayGroupId
1441
* @throws ConfigurationException when the message cannot be sent
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",
1450
* name="displayGroupId",
1452
* description="The display group id",
1458
* description="successful operation"
1462
public function clearStatsAndLogs($displayGroupId)
1464
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1466
if (!$this->getUser()->checkEditable($displayGroup))
1467
throw new AccessDeniedException();
1469
$this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), new CollectNowAction());
1472
$this->getState()->hydrate([
1473
'httpStatus' => 204,
1474
'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1475
'id' => $displayGroup->displayGroupId
1480
* Change to a new Layout
1481
* @param $displayGroupId
1482
* @throws ConfigurationException
1483
* @throws \Xibo\Exception\NotFoundException
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",
1492
* name="displayGroupId",
1494
* description="The Display Group Id",
1501
* description="The Layout Id",
1508
* description="The duration in seconds for this Layout change to remain in effect",
1513
* name="downloadRequired",
1515
* description="Flag indicating whether the player should perform a collect before playing the Layout",
1520
* name="changeMode",
1522
* description="Whether to queue or replace with this action",
1528
* description="successful operation"
1532
* @throws XiboException
1534
public function changeLayout($displayGroupId)
1536
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1538
if (!$this->getUser()->checkEditable($displayGroup))
1539
throw new AccessDeniedException();
1542
$layoutId = $this->getSanitizer()->getInt('layoutId');
1543
$downloadRequired = ($this->getSanitizer()->getCheckbox('downloadRequired') == 1);
1546
throw new \InvalidArgumentException(__('Please provide a Layout'));
1548
// Check that this user has permissions to see this layout
1549
$layout = $this->layoutFactory->getById($layoutId);
1551
if (!$this->getUser()->checkViewable($layout))
1552
throw new AccessDeniedException();
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) {
1557
$displayGroup->setChildObjectDependencies($this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory);
1558
$displayGroup->load();
1559
$displayGroup->assignLayout($layout);
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);
1565
$displayGroup->save(['validate' => false]);
1567
// Convert into a download required
1568
$downloadRequired = true;
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]);
1578
// Create and send the player action
1579
$this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), (new ChangeLayoutAction())->setLayoutDetails(
1581
$this->getSanitizer()->getInt('duration'),
1583
$this->getSanitizer()->getString('changeMode', 'queue')
1587
$this->getState()->hydrate([
1588
'httpStatus' => 204,
1589
'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1590
'id' => $displayGroup->displayGroupId
1595
* Cause the player to revert to its scheduled content
1596
* @param int $displayGroupId
1597
* @throws ConfigurationException when the message cannot be sent
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",
1606
* name="displayGroupId",
1608
* description="The display group id",
1614
* description="successful operation"
1618
public function revertToSchedule($displayGroupId)
1620
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1622
if (!$this->getUser()->checkEditable($displayGroup))
1623
throw new AccessDeniedException();
1625
$this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), new RevertToSchedule());
1628
$this->getState()->hydrate([
1629
'httpStatus' => 204,
1630
'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1631
'id' => $displayGroup->displayGroupId
1636
* Add an Overlay Layout
1637
* @param $displayGroupId
1638
* @throws ConfigurationException
1639
* @throws \Xibo\Exception\NotFoundException
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",
1648
* name="displayGroupId",
1650
* description="The Display Group Id",
1657
* description="The Layout Id",
1664
* description="The duration in seconds for this Overlay to remain in effect",
1669
* name="downloadRequired",
1671
* description="Flag indicating whether the player should perform a collect before adding the Overlay",
1677
* description="successful operation"
1681
* @throws XiboException
1683
public function overlayLayout($displayGroupId)
1685
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1687
if (!$this->getUser()->checkEditable($displayGroup))
1688
throw new AccessDeniedException();
1691
$layoutId = $this->getSanitizer()->getInt('layoutId');
1692
$downloadRequired = ($this->getSanitizer()->getCheckbox('downloadRequired') == 1);
1695
throw new \InvalidArgumentException(__('Please provide a Layout'));
1697
// Check that this user has permissions to see this layout
1698
$layout = $this->layoutFactory->getById($layoutId);
1700
if (!$this->getUser()->checkViewable($layout))
1701
throw new AccessDeniedException();
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) {
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]);
1713
// Convert into a download required
1714
$downloadRequired = true;
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]);
1724
$this->playerAction->sendAction($this->displayFactory->getByDisplayGroupId($displayGroupId), (new OverlayLayoutAction())->setLayoutDetails(
1726
$this->getSanitizer()->getInt('duration'),
1731
$this->getState()->hydrate([
1732
'httpStatus' => 204,
1733
'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1734
'id' => $displayGroup->displayGroupId
1740
* @param int $displayGroupId
1741
* @throws \Xibo\Exception\NotFoundException
1743
public function commandForm($displayGroupId)
1745
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1747
if (!$this->getUser()->checkEditable($displayGroup))
1748
throw new AccessDeniedException();
1750
$this->getState()->template = 'displaygroup-form-command';
1751
$this->getState()->setData([
1752
'displayGroup' => $displayGroup,
1753
'commands' => $this->commandFactory->query()
1758
* @param $displayGroupId
1759
* @throws ConfigurationException
1760
* @throws \Xibo\Exception\NotFoundException
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",
1769
* name="displayGroupId",
1771
* description="The display group id",
1778
* description="The Command Id",
1784
* description="successful operation"
1788
public function command($displayGroupId)
1790
$displayGroup = $this->displayGroupFactory->getById($displayGroupId);
1792
if (!$this->getUser()->checkEditable($displayGroup))
1793
throw new AccessDeniedException();
1795
$command = $this->commandFactory->getById($this->getSanitizer()->getInt('commandId'));
1796
$displays = $this->displayFactory->getByDisplayGroupId($displayGroupId);
1798
$this->playerAction->sendAction($displays, (new CommandAction())->setCommandCode($command->code));
1801
foreach ($displays as $display) {
1802
/* @var \Xibo\Entity\Display $display */
1803
$display->lastCommandSuccess = 0;
1804
$display->save(['validate' => false, 'audit' => false]);
1808
$this->getState()->hydrate([
1809
'httpStatus' => 204,
1810
'message' => sprintf(__('Command Sent to %s'), $displayGroup->displayGroup),
1811
'id' => $displayGroup->displayGroupId