3
* Spring Signage Ltd - http://www.springsignage.com
4
* Copyright (C) 2016 Spring Signage Ltd
5
* (ApplicationScopeFactory.php)
9
namespace Xibo\Factory;
10
use Xibo\Entity\ApplicationScope;
11
use Xibo\Exception\NotFoundException;
12
use Xibo\Service\LogServiceInterface;
13
use Xibo\Service\SanitizerServiceInterface;
14
use Xibo\Storage\StorageServiceInterface;
17
* Class ApplicationScopeFactory
18
* @package Xibo\Factory
20
class ApplicationScopeFactory extends BaseFactory
24
* @param StorageServiceInterface $store
25
* @param LogServiceInterface $log
26
* @param SanitizerServiceInterface $sanitizerService
28
public function __construct($store, $log, $sanitizerService)
30
$this->setCommonDependencies($store, $log, $sanitizerService);
35
* @return ApplicationScope
37
public function create()
39
return new ApplicationScope($this->getStore(), $this->getLog());
45
* @return ApplicationScope
46
* @throws NotFoundException
48
public function getById($id)
50
$clientRedirectUri = $this->query(null, ['id' => $id]);
52
if (count($clientRedirectUri) <= 0)
53
throw new NotFoundException();
55
return $clientRedirectUri[0];
61
* @return array[ApplicationScope]
62
* @throws NotFoundException
64
public function getByClientId($clientId)
66
return $this->query(null, ['clientId' => $clientId]);
71
* @param null $sortOrder
72
* @param array $filterBy
75
public function query($sortOrder = null, $filterBy = [])
80
$select = 'SELECT `oauth_scopes`.id, `oauth_scopes`.description';
82
$body = ' FROM `oauth_scopes`';
84
if ($this->getSanitizer()->getString('clientId', $filterBy) != null) {
85
$body .= ' INNER JOIN `oauth_client_scopes`
86
ON `oauth_client_scopes`.scopeId = `oauth_scopes`.id ';
89
$body .= ' WHERE 1 = 1 ';
91
if ($this->getSanitizer()->getString('clientId', $filterBy) != null) {
92
$body .= ' AND `oauth_client_scopes`.clientId = :clientId ';
93
$params['clientId'] = $this->getSanitizer()->getString('clientId', $filterBy);
96
if ($this->getSanitizer()->getString('id', $filterBy) != null) {
97
$body .= ' AND `oauth_scopes`.id = :id ';
98
$params['id'] = $this->getSanitizer()->getString('id', $filterBy);
103
if (is_array($sortOrder))
104
$order .= 'ORDER BY ' . implode(',', $sortOrder);
108
if ($filterBy !== null && $this->getSanitizer()->getInt('start', $filterBy) !== null && $this->getSanitizer()->getInt('length', $filterBy) !== null) {
109
$limit = ' LIMIT ' . intval($this->getSanitizer()->getInt('start', $filterBy), 0) . ', ' . $this->getSanitizer()->getInt('length', 10, $filterBy);
112
// The final statements
113
$sql = $select . $body . $order . $limit;
115
foreach ($this->getStore()->select($sql, $params) as $row) {
116
$entries[] = $this->create()->hydrate($row, ['stringProperties' => ['id']]);
120
if ($limit != '' && count($entries) > 0) {
121
$results = $this->getStore()->select('SELECT COUNT(*) AS total ' . $body, $params);
122
$this->_countLast = intval($results[0]['total']);
b'\\ No newline at end of file'