3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
9
namespace Xibo\Controller;
12
use Xibo\Exception\AccessDeniedException;
13
use Xibo\Exception\XiboException;
14
use Xibo\Factory\CommandFactory;
15
use Xibo\Factory\DisplayProfileFactory;
16
use Xibo\Service\ConfigServiceInterface;
17
use Xibo\Service\DateServiceInterface;
18
use Xibo\Service\LogServiceInterface;
19
use Xibo\Service\SanitizerServiceInterface;
24
* @package Xibo\Controller
26
class Command extends Base
31
private $commandFactory;
34
* @var DisplayProfileFactory
36
private $displayProfileFactory;
39
* Set common dependencies.
40
* @param LogServiceInterface $log
41
* @param SanitizerServiceInterface $sanitizerService
42
* @param \Xibo\Helper\ApplicationState $state
43
* @param \Xibo\Entity\User $user
44
* @param \Xibo\Service\HelpServiceInterface $help
45
* @param DateServiceInterface $date
46
* @param ConfigServiceInterface $config
47
* @param CommandFactory $commandFactory
48
* @param DisplayProfileFactory $displayProfileFactory
50
public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $commandFactory, $displayProfileFactory)
52
$this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
54
$this->commandFactory = $commandFactory;
55
$this->displayProfileFactory = $displayProfileFactory;
58
public function displayPage()
60
$this->getState()->template = 'command-page';
66
* operationId="commandSearch",
68
* summary="Command Search",
69
* description="Search this users Commands",
73
* description="Filter by Command Id",
80
* description="Filter by Command Name",
87
* description="Filter by Command Code",
93
* description="successful operation",
96
* @SWG\Items(ref="#/definitions/Command")
104
'commandId' => $this->getSanitizer()->getInt('commandId'),
105
'command' => $this->getSanitizer()->getString('command'),
106
'code' => $this->getSanitizer()->getString('code')
109
$commands = $this->commandFactory->query($this->gridRenderSort(), $this->gridRenderFilter($filter));
111
foreach ($commands as $command) {
112
/* @var \Xibo\Entity\Command $command */
117
$command->includeProperty('buttons');
120
$command->buttons[] = array(
121
'id' => 'command_button_edit',
122
'url' => $this->urlFor('command.edit.form', ['id' => $command->commandId]),
126
if ($this->getUser()->checkDeleteable($command)) {
127
$command->buttons[] = array(
128
'id' => 'command_button_delete',
129
'url' => $this->urlFor('command.delete.form', ['id' => $command->commandId]),
130
'text' => __('Delete'),
131
'multi-select' => true,
132
'dataAttributes' => array(
133
array('name' => 'commit-url', 'value' => $this->urlFor('command.delete', ['id' => $command->commandId])),
134
array('name' => 'commit-method', 'value' => 'delete'),
135
array('name' => 'id', 'value' => 'command_button_delete'),
136
array('name' => 'text', 'value' => __('Delete')),
137
array('name' => 'rowtitle', 'value' => $command->command)
143
$this->getState()->template = 'grid';
144
$this->getState()->recordsTotal = $this->commandFactory->countLast();
145
$this->getState()->setData($commands);
151
public function addForm()
153
$this->getState()->template = 'command-form-add';
158
* @param int $commandId
159
* @throws XiboException
161
public function editForm($commandId)
163
$command = $this->commandFactory->getById($commandId);
165
if ($command->getOwnerId() != $this->getUser()->userId && $this->getUser()->userTypeId != 1)
166
throw new AccessDeniedException();
168
$this->getState()->template = 'command-form-edit';
169
$this->getState()->setData([
170
'command' => $command
176
* @param int $commandId
177
* @throws XiboException
179
public function deleteForm($commandId)
181
$command = $this->commandFactory->getById($commandId);
183
if ($command->getOwnerId() != $this->getUser()->userId && $this->getUser()->userTypeId != 1)
184
throw new AccessDeniedException();
186
$this->getState()->template = 'command-form-delete';
187
$this->getState()->setData([
188
'command' => $command
197
* operationId="commandAdd",
199
* summary="Command Add",
200
* description="Add a Command",
204
* description="The Command Name",
209
* name="description",
211
* description="A description for the command",
218
* description="A unique code for this command",
224
* description="successful operation",
225
* @SWG\Schema(ref="#/definitions/Command"),
228
* description="Location of the new record",
234
public function add()
236
$command = $this->commandFactory->create();
237
$command->command = $this->getSanitizer()->getString('command');
238
$command->description = $this->getSanitizer()->getString('description');
239
$command->code = $this->getSanitizer()->getString('code');
240
$command->userId = $this->getUser()->userId;
244
$this->getState()->hydrate([
246
'message' => sprintf(__('Added %s'), $command->command),
247
'id' => $command->commandId,
254
* @param int $commandId
257
* path="/command/{commandId}",
258
* operationId="commandEdit",
260
* summary="Edit Command",
261
* description="Edit the provided command",
265
* description="The Command Id to Edit",
272
* description="The Command Name",
277
* name="description",
279
* description="A description for the command",
285
* description="successful operation",
286
* @SWG\Schema(ref="#/definitions/Command")
290
* @throws XiboException
292
public function edit($commandId)
294
$command = $this->commandFactory->getById($commandId);
296
if ($command->getOwnerId() != $this->getUser()->userId && $this->getUser()->userTypeId != 1)
297
throw new AccessDeniedException();
299
$command->command = $this->getSanitizer()->getString('command');
300
$command->description = $this->getSanitizer()->getString('description');
304
$this->getState()->hydrate([
306
'message' => sprintf(__('Edited %s'), $command->command),
307
'id' => $command->commandId,
314
* @param int $commandId
317
* path="/command/{commandId}",
318
* operationId="commandDelete",
320
* summary="Delete Command",
321
* description="Delete the provided command",
325
* description="The Command Id to Delete",
331
* description="successful operation"
335
public function delete($commandId)
337
$command = $this->commandFactory->getById($commandId);
339
if ($command->getOwnerId() != $this->getUser()->userId && $this->getUser()->userTypeId != 1)
340
throw new AccessDeniedException();
342
$command->setChildObjectDependencies($this->displayProfileFactory);
346
$this->getState()->hydrate([
348
'message' => sprintf(__('Deleted %s'), $command->command)
b'\\ No newline at end of file'