9
9
namespace Xibo\Entity;
11
11
use Respect\Validation\Validator as v;
12
use Xibo\Exception\InvalidArgumentException;
13
use Xibo\Exception\NotFoundException;
14
12
use Xibo\Factory\DisplayProfileFactory;
15
use Xibo\Service\LogServiceInterface;
16
use Xibo\Storage\StorageServiceInterface;
13
use Xibo\Storage\PDOConnect;
88
85
private $displayProfiles = [];
91
* @var DisplayProfileFactory
93
private $displayProfileFactory;
96
* Command constructor.
97
* @param StorageServiceInterface $store
98
* @param LogServiceInterface $log
100
public function __construct($store, $log)
102
$this->setCommonDependencies($store, $log);
106
* @param DisplayProfileFactory $displayProfileFactory
108
public function setChildObjectDependencies($displayProfileFactory)
110
$this->displayProfileFactory = $displayProfileFactory;
133
* @throws InvalidArgumentException
135
108
public function validate()
137
if (!v::stringType()->notEmpty()->length(1, 254)->validate($this->command))
138
throw new InvalidArgumentException(__('Please enter a command name between 1 and 254 characters'), 'command');
140
if (!v::alpha()->NoWhitespace()->notEmpty()->length(1, 50)->validate($this->code))
141
throw new InvalidArgumentException(__('Please enter a code between 1 and 50 characters containing only alpha characters and no spaces'), 'code');
143
if (!v::stringType()->notEmpty()->length(1, 1000)->validate($this->description))
144
throw new InvalidArgumentException(__('Please enter a description between 1 and 1000 characters'), 'description');
110
if (!v::string()->notEmpty()->length(1, 254)->validate($this->command))
111
throw new \InvalidArgumentException(__('Please enter a command name between 1 and 254 characters'));
113
if (!v::string()->notEmpty()->length(1, 50)->validate($this->code))
114
throw new \InvalidArgumentException(__('Please enter a code between 1 and 50 characters'));
116
if (!v::string()->notEmpty()->length(1, 1000)->validate($this->description))
117
throw new \InvalidArgumentException(__('Please enter a description between 1 and 1000 characters'));
149
* @throws NotFoundException
122
* @param array $options
151
public function load()
124
public function load($options = [])
153
126
if ($this->loaded || $this->commandId == null)
156
$this->displayProfiles = $this->displayProfileFactory->getByCommandId($this->commandId);
129
$this->displayProfiles = DisplayProfileFactory::getByCommandId($this->commandId);
161
134
* @param array $options
163
* @throws InvalidArgumentException
165
136
public function save($options = [])
190
161
$profile->save(['validate' => false]);
193
$this->getStore()->update('DELETE FROM `command` WHERE `commandId` = :commandId', ['commandId' => $this->commandId]);
164
PDOConnect::update('DELETE FROM `command` WHERE `commandId` = :commandId', ['commandId' => $this->commandId]);
196
167
private function add()
198
$this->commandId = $this->getStore()->insert('INSERT INTO `command` (`command`, `code`, `description`, `userId`) VALUES (:command, :code, :description, :userId)', [
169
$this->commandId = PDOConnect::insert('INSERT INTO `command` (`command`, `code`, `description`, `userId`) VALUES (:command, :code, :description, :userId)', [
199
170
'command' => $this->command,
200
171
'code' => $this->code,
201
172
'description' => $this->description,