~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Factory/ApplicationScopeFactory.php

  • Committer: Dan Garner
  • Date: 2016-02-12 10:41:25 UTC
  • mto: (454.4.130)
  • mto: This revision was merged to the branch mainline in revision 484.
  • Revision ID: git-v1:ca673f8ea522eac5f311ed779b0fbfeb35a0e4dd
Handle duration changes in XLF generation. Fixed region option factory.
xibosignage/xibo#721

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2016 Spring Signage Ltd
5
 
 * (ApplicationScopeFactory.php)
6
 
 */
7
 
 
8
 
 
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;
15
 
 
16
 
/**
17
 
 * Class ApplicationScopeFactory
18
 
 * @package Xibo\Factory
19
 
 */
20
 
class ApplicationScopeFactory extends BaseFactory
21
 
{
22
 
    /**
23
 
     * Construct a factory
24
 
     * @param StorageServiceInterface $store
25
 
     * @param LogServiceInterface $log
26
 
     * @param SanitizerServiceInterface $sanitizerService
27
 
     */
28
 
    public function __construct($store, $log, $sanitizerService)
29
 
    {
30
 
        $this->setCommonDependencies($store, $log, $sanitizerService);
31
 
    }
32
 
 
33
 
    /**
34
 
     * Create Empty
35
 
     * @return ApplicationScope
36
 
     */
37
 
    public function create()
38
 
    {
39
 
        return new ApplicationScope($this->getStore(), $this->getLog());
40
 
    }
41
 
 
42
 
    /**
43
 
     * Get by ID
44
 
     * @param $id
45
 
     * @return ApplicationScope
46
 
     * @throws NotFoundException
47
 
     */
48
 
    public function getById($id)
49
 
    {
50
 
        $clientRedirectUri = $this->query(null, ['id' => $id]);
51
 
 
52
 
        if (count($clientRedirectUri) <= 0)
53
 
            throw new NotFoundException();
54
 
 
55
 
        return $clientRedirectUri[0];
56
 
    }
57
 
 
58
 
    /**
59
 
     * Get by Client Id
60
 
     * @param $clientId
61
 
     * @return array[ApplicationScope]
62
 
     * @throws NotFoundException
63
 
     */
64
 
    public function getByClientId($clientId)
65
 
    {
66
 
        return $this->query(null, ['clientId' => $clientId]);
67
 
    }
68
 
 
69
 
    /**
70
 
     * Query
71
 
     * @param null $sortOrder
72
 
     * @param array $filterBy
73
 
     * @return array
74
 
     */
75
 
    public function query($sortOrder = null, $filterBy = [])
76
 
    {
77
 
        $entries = array();
78
 
        $params = array();
79
 
 
80
 
        $select = 'SELECT `oauth_scopes`.id, `oauth_scopes`.description';
81
 
 
82
 
        $body = '  FROM `oauth_scopes`';
83
 
 
84
 
        if ($this->getSanitizer()->getString('clientId', $filterBy) != null) {
85
 
            $body .= ' INNER JOIN `oauth_client_scopes`
86
 
                ON `oauth_client_scopes`.scopeId = `oauth_scopes`.id ';
87
 
        }
88
 
 
89
 
        $body .= ' WHERE 1 = 1 ';
90
 
 
91
 
        if ($this->getSanitizer()->getString('clientId', $filterBy) != null) {
92
 
            $body .= ' AND `oauth_client_scopes`.clientId = :clientId  ';
93
 
            $params['clientId'] = $this->getSanitizer()->getString('clientId', $filterBy);
94
 
        }
95
 
 
96
 
        if ($this->getSanitizer()->getString('id', $filterBy) != null) {
97
 
            $body .= ' AND `oauth_scopes`.id = :id ';
98
 
            $params['id'] = $this->getSanitizer()->getString('id', $filterBy);
99
 
        }
100
 
 
101
 
        // Sorting?
102
 
        $order = '';
103
 
        if (is_array($sortOrder))
104
 
            $order .= 'ORDER BY ' . implode(',', $sortOrder);
105
 
 
106
 
        $limit = '';
107
 
        // Paging
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);
110
 
        }
111
 
 
112
 
        // The final statements
113
 
        $sql = $select . $body . $order . $limit;
114
 
 
115
 
        foreach ($this->getStore()->select($sql, $params) as $row) {
116
 
            $entries[] = $this->create()->hydrate($row, ['stringProperties' => ['id']]);
117
 
        }
118
 
 
119
 
        // Paging
120
 
        if ($limit != '' && count($entries) > 0) {
121
 
            $results = $this->getStore()->select('SELECT COUNT(*) AS total ' . $body, $params);
122
 
            $this->_countLast = intval($results[0]['total']);
123
 
        }
124
 
 
125
 
        return $entries;
126
 
    }
127
 
}
 
 
b'\\ No newline at end of file'