Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
77.05% |
47 / 61 |
|
61.54% |
8 / 13 |
CRAP | |
0.00% |
0 / 1 |
GetTreeRequest | |
77.05% |
47 / 61 |
|
61.54% |
8 / 13 |
34.17 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
create | |
75.61% |
31 / 41 |
|
0.00% |
0 / 1 |
16.84 | |||
getClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLimit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOffset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isShowInstance | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isHideNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOpenNodes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getResourceUrisToShow | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFilters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setFilters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFiltersOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setFiltersOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace oat\tao\model\Tree; |
4 | |
5 | use common_Exception; |
6 | use core_kernel_classes_Class; |
7 | use oat\tao\helpers\TreeHelper; |
8 | use Request; |
9 | use tao_helpers_Uri; |
10 | use oat\generis\model\OntologyRdfs; |
11 | |
12 | class GetTreeRequest |
13 | { |
14 | public const DEFAULT_LIMIT = 10; |
15 | public const DEFAULT_ORDERDIR = 'asc'; |
16 | |
17 | /** @var core_kernel_classes_Class */ |
18 | protected $class; |
19 | |
20 | /** @var int */ |
21 | protected $limit; |
22 | |
23 | /** @var int */ |
24 | protected $offset; |
25 | |
26 | /** @var bool */ |
27 | protected $showInstance; |
28 | |
29 | /** @var bool */ |
30 | protected $hideNode; |
31 | |
32 | /** @var array */ |
33 | protected $openNodes; |
34 | |
35 | /** @var array */ |
36 | protected $resourceUrisToShow; |
37 | |
38 | /** @var array */ |
39 | protected $filters = []; |
40 | |
41 | /** @var array */ |
42 | protected $filtersOptions = []; |
43 | |
44 | /** |
45 | * GetTreeRequest constructor. |
46 | * @param core_kernel_classes_Class $class |
47 | * @param int $limit |
48 | * @param int $offset |
49 | * @param bool $showInstance |
50 | * @param bool $hideNode |
51 | * @param array $openNodes |
52 | * @param array $resourceUrisToShow |
53 | * @param array $filtersOptions |
54 | * @param \core_kernel_classes_Property[] $filters Properties to filter tree resources |
55 | */ |
56 | public function __construct( |
57 | $class, |
58 | $limit, |
59 | $offset, |
60 | $showInstance, |
61 | $hideNode, |
62 | array $openNodes, |
63 | array $resourceUrisToShow = [], |
64 | $filtersOptions = [], |
65 | array $filters = [] |
66 | ) { |
67 | $this->class = $class; |
68 | $this->limit = $limit; |
69 | $this->offset = $offset; |
70 | $this->showInstance = $showInstance; |
71 | $this->hideNode = $hideNode; |
72 | $this->openNodes = $openNodes; |
73 | $this->resourceUrisToShow = $resourceUrisToShow; |
74 | $this->filters = $filters; |
75 | $this->filtersOptions = $filtersOptions; |
76 | } |
77 | |
78 | /** |
79 | * @param Request $request |
80 | * @return GetTreeRequest |
81 | * |
82 | * @throws common_Exception |
83 | */ |
84 | public static function create(Request $request) |
85 | { |
86 | |
87 | if ($request->hasParameter('classUri')) { |
88 | $classUri = tao_helpers_Uri::decode($request->getParameter('classUri')); |
89 | $class = new core_kernel_classes_Class($classUri); |
90 | $hideNode = true; |
91 | } elseif ($request->hasParameter('rootNode')) { |
92 | $class = new core_kernel_classes_Class($request->getParameter('rootNode')); |
93 | $hideNode = false; |
94 | } else { |
95 | throw new common_Exception('Missing node information for ' . __FUNCTION__); |
96 | } |
97 | |
98 | $openNodes = [$class->getUri()]; |
99 | $openNodesParameter = $request->getParameter('openNodes'); |
100 | $openParentNodesParameter = $request->getParameter('openParentNodes'); |
101 | |
102 | if ($request->hasParameter('openNodes') && is_array($openNodesParameter)) { |
103 | $openNodes = array_merge($openNodes, $openNodesParameter); |
104 | } elseif ($request->hasParameter('openParentNodes') && is_array($openParentNodesParameter)) { |
105 | $childNodes = $openParentNodesParameter; |
106 | $openNodes = TreeHelper::getNodesToOpen($childNodes, $class); |
107 | } |
108 | |
109 | $limit = $request->hasParameter('limit') ? $request->getParameter('limit') : self::DEFAULT_LIMIT; |
110 | $offset = $request->hasParameter('offset') ? $request->getParameter('offset') : 0; |
111 | $showInstance = $request->hasParameter('hideInstances') ? !$request->getParameter('hideInstances') : true; |
112 | $orderProp = $request->hasParameter('order') ? $request->getParameter('order') : OntologyRdfs::RDFS_LABEL; |
113 | $orderDir = $request->hasParameter('orderdir') ? $request->getParameter('orderdir') : self::DEFAULT_ORDERDIR; |
114 | |
115 | $filterProperties = []; |
116 | if ($request->hasParameter('filterProperties')) { |
117 | $filterProperties = $request->getParameter('filterProperties'); |
118 | if (!is_array($filterProperties)) { |
119 | $filterProperties = []; |
120 | } |
121 | } |
122 | |
123 | return new self( |
124 | $class, |
125 | $limit, |
126 | $offset, |
127 | $showInstance, |
128 | $hideNode, |
129 | $openNodes, |
130 | [], |
131 | [ |
132 | 'order' => [ |
133 | $orderProp => $orderDir |
134 | ] |
135 | ], |
136 | $filterProperties |
137 | ); |
138 | } |
139 | |
140 | /** |
141 | * @return core_kernel_classes_Class |
142 | */ |
143 | public function getClass() |
144 | { |
145 | return $this->class; |
146 | } |
147 | |
148 | /** |
149 | * @return int |
150 | */ |
151 | public function getLimit() |
152 | { |
153 | return $this->limit; |
154 | } |
155 | |
156 | /** |
157 | * @return int |
158 | */ |
159 | public function getOffset() |
160 | { |
161 | return $this->offset; |
162 | } |
163 | |
164 | /** |
165 | * @return bool |
166 | */ |
167 | public function isShowInstance() |
168 | { |
169 | return $this->showInstance; |
170 | } |
171 | |
172 | /** |
173 | * @return bool |
174 | */ |
175 | public function isHideNode() |
176 | { |
177 | return $this->hideNode; |
178 | } |
179 | |
180 | /** |
181 | * @return array |
182 | */ |
183 | public function getOpenNodes() |
184 | { |
185 | return $this->openNodes; |
186 | } |
187 | |
188 | /** |
189 | * @return array |
190 | */ |
191 | public function getResourceUrisToShow() |
192 | { |
193 | return $this->resourceUrisToShow; |
194 | } |
195 | |
196 | /** |
197 | * @return array |
198 | */ |
199 | public function getFilters() |
200 | { |
201 | return $this->filters; |
202 | } |
203 | |
204 | /** |
205 | * @param array $filters |
206 | */ |
207 | public function setFilters($filters) |
208 | { |
209 | $this->filters = $filters; |
210 | } |
211 | |
212 | /** |
213 | * @return array |
214 | */ |
215 | public function getFiltersOptions() |
216 | { |
217 | return $this->filtersOptions; |
218 | } |
219 | |
220 | /** |
221 | * @param array $filtersOptions |
222 | */ |
223 | public function setFiltersOptions($filtersOptions) |
224 | { |
225 | $this->filtersOptions = $filtersOptions; |
226 | } |
227 | } |