3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2015 Spring Signage Ltd
5
* (DisplayProfileFactory.php)
9
namespace Xibo\Factory;
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
use Xibo\Entity\DisplayProfile;
14
use Xibo\Exception\NotFoundException;
15
use Xibo\Service\ConfigServiceInterface;
16
use Xibo\Service\LogServiceInterface;
17
use Xibo\Service\SanitizerServiceInterface;
18
use Xibo\Storage\StorageServiceInterface;
21
* Class DisplayProfileFactory
22
* @package Xibo\Factory
24
class DisplayProfileFactory extends BaseFactory
27
* @var ConfigServiceInterface
31
/** @var EventDispatcherInterface */
37
private $commandFactory;
41
* @param StorageServiceInterface $store
42
* @param LogServiceInterface $log
43
* @param SanitizerServiceInterface $sanitizerService
44
* @param ConfigServiceInterface $config
45
* @param EventDispatcherInterface $dispatcher
46
* @param CommandFactory $commandFactory
48
public function __construct($store, $log, $sanitizerService, $config, $dispatcher, $commandFactory)
50
$this->setCommonDependencies($store, $log, $sanitizerService);
52
$this->config = $config;
53
$this->dispatcher = $dispatcher;
54
$this->commandFactory = $commandFactory;
58
* @return DisplayProfile
60
public function createEmpty()
62
return new DisplayProfile(
72
* @param int $displayProfileId
73
* @return DisplayProfile
74
* @throws NotFoundException
76
public function getById($displayProfileId)
78
$profiles = $this->query(null, ['disableUserCheck' => 1, 'displayProfileId' => $displayProfileId]);
80
if (count($profiles) <= 0)
81
throw new NotFoundException();
83
$profile = $profiles[0];
84
/* @var DisplayProfile $profile */
92
* @return DisplayProfile
93
* @throws NotFoundException
95
public function getDefaultByType($type)
97
$profiles = $this->query(null, ['disableUserCheck' => 1, 'type' => $type, 'isDefault' => 1]);
99
if (count($profiles) <= 0)
100
throw new NotFoundException();
102
$profile = $profiles[0];
103
/* @var DisplayProfile $profile */
111
* @return DisplayProfile
113
public function getUnknownProfile($clientType)
115
$profile = $this->createEmpty();
116
$profile->type = 'unknown';
117
$profile->setClientType($clientType);
125
* @return array[DisplayProfile]
126
* @throws NotFoundException
128
public function getByCommandId($commandId)
130
return $this->query(null, ['disableUserCheck' => 1, 'commandId' => $commandId]);
134
* @param array $sortOrder
135
* @param array $filterBy
136
* @return DisplayProfile[]
137
* @throws NotFoundException
139
public function query($sortOrder = null, $filterBy = [])
145
$select = 'SELECT displayProfileId, name, type, config, isDefault, userId ';
147
$body = ' FROM `displayprofile` WHERE 1 = 1 ';
149
if ($this->getSanitizer()->getInt('displayProfileId', $filterBy) !== null) {
150
$body .= ' AND displayProfileId = :displayProfileId ';
151
$params['displayProfileId'] = $this->getSanitizer()->getInt('displayProfileId', $filterBy);
154
if ($this->getSanitizer()->getInt('isDefault', $filterBy) !== null) {
155
$body .= ' AND isDefault = :isDefault ';
156
$params['isDefault'] = $this->getSanitizer()->getInt('isDefault', $filterBy);
159
// Filter by DisplayProfile Name?
160
if ($this->getSanitizer()->getString('displayProfile', $filterBy) != null) {
161
// convert into a space delimited array
162
$names = explode(' ', $this->getSanitizer()->getString('displayProfile', $filterBy));
165
foreach ($names as $searchName) {
167
// Not like, or like?
168
if (substr($searchName, 0, 1) == '-') {
169
$body .= " AND `displayprofile`.name NOT LIKE :search$i ";
170
$params['search' . $i] = '%' . ltrim(($searchName), '-') . '%';
173
$body .= " AND `displayprofile`.name LIKE :search$i ";
174
$params['search' . $i] = '%' . $searchName . '%';
179
if ($this->getSanitizer()->getString('type', $filterBy) != null) {
180
$body .= ' AND type = :type ';
181
$params['type'] = $this->getSanitizer()->getString('type', $filterBy);
184
if ($this->getSanitizer()->getInt('commandId', $filterBy) !== null) {
186
AND `displayprofile`.displayProfileId IN (
187
SELECT `lkcommanddisplayprofile`.displayProfileId
188
FROM `lkcommanddisplayprofile`
189
WHERE `lkcommanddisplayprofile`.commandId = :commandId
193
$params['commandId'] = $this->getSanitizer()->getInt('commandId', $filterBy);
198
if (is_array($sortOrder))
199
$order .= 'ORDER BY ' . implode(',', $sortOrder);
203
if ($filterBy !== null && $this->getSanitizer()->getInt('start', $filterBy) !== null && $this->getSanitizer()->getInt('length', $filterBy) !== null) {
204
$limit = ' LIMIT ' . intval($this->getSanitizer()->getInt('start', $filterBy), 0) . ', ' . $this->getSanitizer()->getInt('length', 10, $filterBy);
207
$sql = $select . $body . $order . $limit;
211
foreach ($this->getStore()->select($sql, $params) as $row) {
212
$profiles[] = $this->createEmpty()->hydrate($row);
216
if ($limit != '' && count($profiles) > 0) {
217
$results = $this->getStore()->select('SELECT COUNT(*) AS total ' . $body, $params);
218
$this->_countLast = intval($results[0]['total']);
223
} catch (\Exception $e) {
225
$this->getLog()->error($e);
227
throw new NotFoundException();
b'\\ No newline at end of file'