3
* Xibo - Digital Signage - http://www.xibo.org.uk
4
* Copyright (C) 2012-2016 Spring Signage Ltd - http://www.springsignage.com
6
* This file is part of Xibo.
8
* Xibo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Affero General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
13
* Xibo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
18
* You should have received a copy of the GNU Affero General Public License
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
21
namespace Xibo\Controller;
23
use Xibo\Exception\AccessDeniedException;
24
use Xibo\Exception\XiboException;
25
use Xibo\Factory\DayPartFactory;
26
use Xibo\Factory\DisplayFactory;
27
use Xibo\Factory\DisplayGroupFactory;
28
use Xibo\Factory\LayoutFactory;
29
use Xibo\Factory\MediaFactory;
30
use Xibo\Factory\ScheduleFactory;
31
use Xibo\Service\ConfigServiceInterface;
32
use Xibo\Service\DateServiceInterface;
33
use Xibo\Service\LogServiceInterface;
34
use Xibo\Service\SanitizerServiceInterface;
38
* @package Xibo\Controller
40
class DayPart extends Base
42
/** @var DayPartFactory */
43
private $dayPartFactory;
45
/** @var DisplayGroupFactory */
46
private $displayGroupFactory;
48
/** @var DisplayFactory */
49
private $displayFactory;
51
/** @var LayoutFactory */
52
private $layoutFactory;
54
/** @var MediaFactory */
55
private $mediaFactory;
57
/** @var ScheduleFactory */
58
private $scheduleFactory;
61
* Set common dependencies.
62
* @param LogServiceInterface $log
63
* @param SanitizerServiceInterface $sanitizerService
64
* @param \Xibo\Helper\ApplicationState $state
65
* @param \Xibo\Entity\User $user
66
* @param \Xibo\Service\HelpServiceInterface $help
67
* @param DateServiceInterface $date
68
* @param ConfigServiceInterface $config
69
* @param DayPartFactory $dayPartFactory
70
* @param DisplayGroupFactory $displayGroupFactory
71
* @param DisplayFactory $displayFactory
72
* @param LayoutFactory $layoutFactory
73
* @param MediaFactory $mediaFactory
74
* @param ScheduleFactory $scheduleFactory
76
public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $dayPartFactory, $displayGroupFactory, $displayFactory, $layoutFactory, $mediaFactory, $scheduleFactory)
78
$this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
80
$this->dayPartFactory = $dayPartFactory;
81
$this->displayGroupFactory = $displayGroupFactory;
82
$this->displayFactory = $displayFactory;
83
$this->layoutFactory = $layoutFactory;
84
$this->mediaFactory = $mediaFactory;
85
$this->scheduleFactory = $scheduleFactory;
91
public function displayPage()
93
$this->getState()->template = 'daypart-page';
99
public function grid()
102
'dayPartId' => $this->getSanitizer()->getInt('dayPartId'),
103
'name' => $this->getSanitizer()->getString('name'),
108
$dayParts = $this->dayPartFactory->query($this->gridRenderSort(), $this->gridRenderFilter($filter));
110
foreach ($dayParts as $dayPart) {
111
/* @var \Xibo\Entity\DayPart $dayPart */
116
$dayPart->includeProperty('buttons');
119
$dayPart->buttons[] = array(
120
'id' => 'daypart_button_edit',
121
'url' => $this->urlFor('daypart.edit.form', ['id' => $dayPart->dayPartId]),
125
if ($this->getUser()->checkDeleteable($dayPart)) {
126
$dayPart->buttons[] = array(
127
'id' => 'daypart_button_delete',
128
'url' => $this->urlFor('daypart.delete.form', ['id' => $dayPart->dayPartId]),
129
'text' => __('Delete'),
130
'multi-select' => true,
131
'dataAttributes' => array(
132
array('name' => 'commit-url', 'value' => $this->urlFor('daypart.delete', ['id' => $dayPart->dayPartId])),
133
array('name' => 'commit-method', 'value' => 'delete'),
134
array('name' => 'id', 'value' => 'daypart_button_delete'),
135
array('name' => 'text', 'value' => __('Delete')),
136
array('name' => 'rowtitle', 'value' => $dayPart->name)
141
if ($this->getUser()->checkPermissionsModifyable($dayPart)) {
143
$dayPart->buttons[] = ['divider' => true];
146
$dayPart->buttons[] = array(
147
'id' => 'daypart_button_permissions',
148
'url' => $this->urlFor('user.permissions.form', ['entity' => 'DayPart', 'id' => $dayPart->dayPartId]),
149
'text' => __('Permissions')
154
$this->getState()->template = 'grid';
155
$this->getState()->recordsTotal = $this->dayPartFactory->countLast();
156
$this->getState()->setData($dayParts);
162
public function addForm()
164
$this->getState()->template = 'daypart-form-add';
165
$this->getState()->setData([
174
* @param int $dayPartId
176
public function editForm($dayPartId)
178
$dayPart = $this->dayPartFactory->getById($dayPartId);
180
if (!$this->getUser()->checkEditable($dayPart))
181
throw new AccessDeniedException();
183
if ($dayPart->isAlways === 1 || $dayPart->isCustom === 1)
184
throw new AccessDeniedException();
186
$this->getState()->template = 'daypart-form-edit';
187
$this->getState()->setData([
188
'dayPart' => $dayPart,
190
'exceptions' => $dayPart->exceptions
197
* @param int $dayPartId
199
public function deleteForm($dayPartId)
201
$dayPart = $this->dayPartFactory->getById($dayPartId);
203
if (!$this->getUser()->checkDeleteable($dayPart))
204
throw new AccessDeniedException();
206
if ($dayPart->isAlways === 1 || $dayPart->isCustom === 1)
207
throw new AccessDeniedException();
209
// Get a count of schedules for this day part
210
$schedules = $this->scheduleFactory->getByDayPartId($dayPartId);
212
$this->getState()->template = 'daypart-form-delete';
213
$this->getState()->setData([
214
'countSchedules' => count($schedules),
215
'dayPart' => $dayPart
223
* operationId="dayPartAdd",
225
* summary="Daypart Add",
226
* description="Add a Daypart",
230
* description="The Daypart Name",
235
* name="description",
237
* description="A description for the dayPart",
244
* description="The start time for this day part",
251
* description="The end time for this day part",
256
* name="exceptionDays",
258
* description="String array of exception days",
261
* @SWG\Items(type="string")
264
* name="exceptionStartTimes",
266
* description="String array of exception start times to match the exception days",
269
* @SWG\Items(type="string")
272
* name="exceptionEndTimes",
274
* description="String array of exception end times to match the exception days",
277
* @SWG\Items(type="string")
281
* description="successful operation",
282
* @SWG\Schema(ref="#/definitions/DayPart"),
285
* description="Location of the new record",
291
public function add()
293
$dayPart = $this->dayPartFactory->createEmpty();
294
$this->handleCommonInputs($dayPart);
297
->setScheduleFactory($this->scheduleFactory)
301
$this->getState()->hydrate([
303
'message' => sprintf(__('Added %s'), $dayPart->name),
304
'id' => $dayPart->dayPartId,
311
* @param int $dayPartId
314
* path="/daypart/{dayPartId}",
315
* operationId="dayPartAdd",
317
* summary="Daypart Add",
318
* description="Add a Daypart",
322
* description="The Daypart Id",
329
* description="The Daypart Name",
334
* name="description",
336
* description="A description for the dayPart",
343
* description="The start time for this day part",
350
* description="The end time for this day part",
355
* name="exceptionDays",
357
* description="String array of exception days",
360
* @SWG\Items(type="string")
363
* name="exceptionStartTimes",
365
* description="String array of exception start times to match the exception days",
368
* @SWG\Items(type="string")
371
* name="exceptionEndTimes",
373
* description="String array of exception end times to match the exception days",
376
* @SWG\Items(type="string")
380
* description="successful operation",
381
* @SWG\Schema(ref="#/definitions/DayPart")
385
* @throws XiboException
387
public function edit($dayPartId)
389
$dayPart = $this->dayPartFactory->getById($dayPartId)
390
->setDateService($this->getDate())
391
->setChildObjectDependencies($this->displayGroupFactory, $this->displayFactory, $this->layoutFactory, $this->mediaFactory, $this->scheduleFactory, $this->dayPartFactory)
394
if (!$this->getUser()->checkEditable($dayPart))
395
throw new AccessDeniedException();
397
if ($dayPart->isAlways === 1 || $dayPart->isCustom === 1)
398
throw new AccessDeniedException();
400
$this->handleCommonInputs($dayPart);
402
->setScheduleFactory($this->scheduleFactory)
406
$this->getState()->hydrate([
408
'message' => sprintf(__('Edited %s'), $dayPart->name),
409
'id' => $dayPart->dayPartId,
415
* Handle common inputs
418
private function handleCommonInputs($dayPart)
420
$dayPart->userId = $this->getUser()->userId;
421
$dayPart->name = $this->getSanitizer()->getString('name');
422
$dayPart->description = $this->getSanitizer()->getString('description');
423
$dayPart->isRetired = $this->getSanitizer()->getCheckbox('isRetired');
424
$dayPart->startTime = $this->getSanitizer()->getString('startTime');
425
$dayPart->endTime = $this->getSanitizer()->getString('endTime');
428
$exceptionDays = $this->getSanitizer()->getStringArray('exceptionDay');
429
$exceptionStartTimes = $this->getSanitizer()->getStringArray('exceptionStartTimes');
430
$exceptionEndTimes = $this->getSanitizer()->getStringArray('exceptionEndTimes');
432
// Clear down existing exceptions
433
$dayPart->exceptions = [];
436
foreach ($exceptionDays as $exceptionDay) {
437
// Pull the corrisponding start/end time out of the same position in the array
440
$exceptionDayStartTime = isset($exceptionStartTimes[$i]) ? $exceptionStartTimes[$i] : '';
441
$exceptionDayEndTime = isset($exceptionEndTimes[$i]) ? $exceptionEndTimes[$i] : '';
443
if ($exceptionDay == '' || $exceptionDayStartTime == '' || $exceptionDayEndTime == '')
446
// Is this already set?
448
foreach ($dayPart->exceptions as $exception) {
450
if ($exception['day'] == $exceptionDay) {
451
$exception['start'] = $exceptionDayStartTime;
452
$exception['end'] = $exceptionDayEndTime;
461
$dayPart->exceptions[] = [
462
'day' => $exceptionDay,
463
'start' => $exceptionDayStartTime,
464
'end' => $exceptionDayEndTime
472
* @param int $dayPartId
475
* path="/daypart/{dayPartId}",
476
* operationId="dayPartDelete",
478
* summary="Delete DayPart",
479
* description="Delete the provided dayPart",
483
* description="The Daypart Id to Delete",
489
* description="successful operation"
493
* @throws XiboException
495
public function delete($dayPartId)
497
$dayPart = $this->dayPartFactory->getById($dayPartId);
499
if (!$this->getUser()->checkDeleteable($dayPart))
500
throw new AccessDeniedException();
503
->setDateService($this->getDate())
504
->setScheduleFactory($this->scheduleFactory)
508
$this->getState()->hydrate([
510
'message' => sprintf(__('Deleted %s'), $dayPart->name)
b'\\ No newline at end of file'