~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Entity/Command.php

  • Committer: Dan Garner
  • Date: 2016-02-18 16:07:16 UTC
  • mfrom: (454.4.137)
  • Revision ID: git-v1:8867f12675bc9e0e67e7e622c80da7471b9f294a
Merge pull request #139 from dasgarner/feature/nested-display-groups

Feature/nested display groups

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
namespace Xibo\Entity;
10
10
 
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;
17
14
 
18
15
/**
19
16
 * Class Command
88
85
    private $displayProfiles = [];
89
86
 
90
87
    /**
91
 
     * @var DisplayProfileFactory
92
 
     */
93
 
    private $displayProfileFactory;
94
 
 
95
 
    /**
96
 
     * Command constructor.
97
 
     * @param StorageServiceInterface $store
98
 
     * @param LogServiceInterface $log
99
 
     */
100
 
    public function __construct($store, $log)
101
 
    {
102
 
        $this->setCommonDependencies($store, $log);
103
 
    }
104
 
 
105
 
    /**
106
 
     * @param DisplayProfileFactory $displayProfileFactory
107
 
     */
108
 
    public function setChildObjectDependencies($displayProfileFactory)
109
 
    {
110
 
        $this->displayProfileFactory = $displayProfileFactory;
111
 
    }
112
 
 
113
 
    /**
114
88
     * Get Id
115
89
     * @return int
116
90
     */
130
104
 
131
105
    /**
132
106
     * Validate
133
 
     * @throws InvalidArgumentException
134
107
     */
135
108
    public function validate()
136
109
    {
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');
139
 
 
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');
142
 
 
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'));
 
112
 
 
113
        if (!v::string()->notEmpty()->length(1, 50)->validate($this->code))
 
114
            throw new \InvalidArgumentException(__('Please enter a code between 1 and 50 characters'));
 
115
 
 
116
        if (!v::string()->notEmpty()->length(1, 1000)->validate($this->description))
 
117
            throw new \InvalidArgumentException(__('Please enter a description between 1 and 1000 characters'));
145
118
    }
146
119
 
147
120
    /**
148
121
     * Load
149
 
     * @throws NotFoundException
 
122
     * @param array $options
150
123
     */
151
 
    public function load()
 
124
    public function load($options = [])
152
125
    {
153
126
        if ($this->loaded || $this->commandId == null)
154
127
            return;
155
128
 
156
 
        $this->displayProfiles = $this->displayProfileFactory->getByCommandId($this->commandId);
 
129
        $this->displayProfiles = DisplayProfileFactory::getByCommandId($this->commandId);
157
130
    }
158
131
 
159
132
    /**
160
133
     * Save
161
134
     * @param array $options
162
 
     *
163
 
     * @throws InvalidArgumentException
164
135
     */
165
136
    public function save($options = [])
166
137
    {
190
161
            $profile->save(['validate' => false]);
191
162
        }
192
163
 
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]);
194
165
    }
195
166
 
196
167
    private function add()
197
168
    {
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,
205
176
 
206
177
    private function edit()
207
178
    {
208
 
        $this->getStore()->update('
 
179
        PDOConnect::update('
209
180
            UPDATE `command` SET
210
181
              `command` = :command,
211
182
              `code` = :code,