@@ -30,389 +30,389 @@ |
||
30 | 30 | |
31 | 31 | class Comment implements IComment { |
32 | 32 | |
33 | - protected $data = [ |
|
34 | - 'id' => '', |
|
35 | - 'parentId' => '0', |
|
36 | - 'topmostParentId' => '0', |
|
37 | - 'childrenCount' => '0', |
|
38 | - 'message' => '', |
|
39 | - 'verb' => '', |
|
40 | - 'actorType' => '', |
|
41 | - 'actorId' => '', |
|
42 | - 'objectType' => '', |
|
43 | - 'objectId' => '', |
|
44 | - 'creationDT' => null, |
|
45 | - 'latestChildDT' => null, |
|
46 | - ]; |
|
47 | - |
|
48 | - /** |
|
49 | - * Comment constructor. |
|
50 | - * |
|
51 | - * @param array $data optional, array with keys according to column names from |
|
52 | - * the comments database scheme |
|
53 | - */ |
|
54 | - public function __construct(array $data = null) { |
|
55 | - if(is_array($data)) { |
|
56 | - $this->fromArray($data); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * returns the ID of the comment |
|
62 | - * |
|
63 | - * It may return an empty string, if the comment was not stored. |
|
64 | - * It is expected that the concrete Comment implementation gives an ID |
|
65 | - * by itself (e.g. after saving). |
|
66 | - * |
|
67 | - * @return string |
|
68 | - * @since 9.0.0 |
|
69 | - */ |
|
70 | - public function getId() { |
|
71 | - return $this->data['id']; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * sets the ID of the comment and returns itself |
|
76 | - * |
|
77 | - * It is only allowed to set the ID only, if the current id is an empty |
|
78 | - * string (which means it is not stored in a database, storage or whatever |
|
79 | - * the concrete implementation does), or vice versa. Changing a given ID is |
|
80 | - * not permitted and must result in an IllegalIDChangeException. |
|
81 | - * |
|
82 | - * @param string $id |
|
83 | - * @return IComment |
|
84 | - * @throws IllegalIDChangeException |
|
85 | - * @since 9.0.0 |
|
86 | - */ |
|
87 | - public function setId($id) { |
|
88 | - if(!is_string($id)) { |
|
89 | - throw new \InvalidArgumentException('String expected.'); |
|
90 | - } |
|
91 | - |
|
92 | - $id = trim($id); |
|
93 | - if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
94 | - $this->data['id'] = $id; |
|
95 | - return $this; |
|
96 | - } |
|
97 | - |
|
98 | - throw new IllegalIDChangeException('Not allowed to assign a new ID to an already saved comment.'); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * returns the parent ID of the comment |
|
103 | - * |
|
104 | - * @return string |
|
105 | - * @since 9.0.0 |
|
106 | - */ |
|
107 | - public function getParentId() { |
|
108 | - return $this->data['parentId']; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * sets the parent ID and returns itself |
|
113 | - * |
|
114 | - * @param string $parentId |
|
115 | - * @return IComment |
|
116 | - * @since 9.0.0 |
|
117 | - */ |
|
118 | - public function setParentId($parentId) { |
|
119 | - if(!is_string($parentId)) { |
|
120 | - throw new \InvalidArgumentException('String expected.'); |
|
121 | - } |
|
122 | - $this->data['parentId'] = trim($parentId); |
|
123 | - return $this; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * returns the topmost parent ID of the comment |
|
128 | - * |
|
129 | - * @return string |
|
130 | - * @since 9.0.0 |
|
131 | - */ |
|
132 | - public function getTopmostParentId() { |
|
133 | - return $this->data['topmostParentId']; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * sets the topmost parent ID and returns itself |
|
139 | - * |
|
140 | - * @param string $id |
|
141 | - * @return IComment |
|
142 | - * @since 9.0.0 |
|
143 | - */ |
|
144 | - public function setTopmostParentId($id) { |
|
145 | - if(!is_string($id)) { |
|
146 | - throw new \InvalidArgumentException('String expected.'); |
|
147 | - } |
|
148 | - $this->data['topmostParentId'] = trim($id); |
|
149 | - return $this; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * returns the number of children |
|
154 | - * |
|
155 | - * @return int |
|
156 | - * @since 9.0.0 |
|
157 | - */ |
|
158 | - public function getChildrenCount() { |
|
159 | - return $this->data['childrenCount']; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * sets the number of children |
|
164 | - * |
|
165 | - * @param int $count |
|
166 | - * @return IComment |
|
167 | - * @since 9.0.0 |
|
168 | - */ |
|
169 | - public function setChildrenCount($count) { |
|
170 | - if(!is_int($count)) { |
|
171 | - throw new \InvalidArgumentException('Integer expected.'); |
|
172 | - } |
|
173 | - $this->data['childrenCount'] = $count; |
|
174 | - return $this; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * returns the message of the comment |
|
179 | - * |
|
180 | - * @return string |
|
181 | - * @since 9.0.0 |
|
182 | - */ |
|
183 | - public function getMessage() { |
|
184 | - return $this->data['message']; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * sets the message of the comment and returns itself |
|
189 | - * |
|
190 | - * @param string $message |
|
191 | - * @return IComment |
|
192 | - * @throws MessageTooLongException |
|
193 | - * @since 9.0.0 |
|
194 | - */ |
|
195 | - public function setMessage($message) { |
|
196 | - if(!is_string($message)) { |
|
197 | - throw new \InvalidArgumentException('String expected.'); |
|
198 | - } |
|
199 | - $message = trim($message); |
|
200 | - if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
201 | - throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); |
|
202 | - } |
|
203 | - $this->data['message'] = $message; |
|
204 | - return $this; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * returns an array containing mentions that are included in the comment |
|
209 | - * |
|
210 | - * @return array each mention provides a 'type' and an 'id', see example below |
|
211 | - * @since 11.0.0 |
|
212 | - * |
|
213 | - * The return array looks like: |
|
214 | - * [ |
|
215 | - * [ |
|
216 | - * 'type' => 'user', |
|
217 | - * 'id' => 'citizen4' |
|
218 | - * ], |
|
219 | - * [ |
|
220 | - * 'type' => 'group', |
|
221 | - * 'id' => 'media' |
|
222 | - * ], |
|
223 | - * … |
|
224 | - * ] |
|
225 | - * |
|
226 | - */ |
|
227 | - public function getMentions() { |
|
228 | - $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions); |
|
229 | - if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
230 | - return []; |
|
231 | - } |
|
232 | - $uids = array_unique($mentions[0]); |
|
233 | - $result = []; |
|
234 | - foreach ($uids as $uid) { |
|
235 | - $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; |
|
236 | - } |
|
237 | - return $result; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * returns the verb of the comment |
|
242 | - * |
|
243 | - * @return string |
|
244 | - * @since 9.0.0 |
|
245 | - */ |
|
246 | - public function getVerb() { |
|
247 | - return $this->data['verb']; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * sets the verb of the comment, e.g. 'comment' or 'like' |
|
252 | - * |
|
253 | - * @param string $verb |
|
254 | - * @return IComment |
|
255 | - * @since 9.0.0 |
|
256 | - */ |
|
257 | - public function setVerb($verb) { |
|
258 | - if(!is_string($verb) || !trim($verb)) { |
|
259 | - throw new \InvalidArgumentException('Non-empty String expected.'); |
|
260 | - } |
|
261 | - $this->data['verb'] = trim($verb); |
|
262 | - return $this; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * returns the actor type |
|
267 | - * |
|
268 | - * @return string |
|
269 | - * @since 9.0.0 |
|
270 | - */ |
|
271 | - public function getActorType() { |
|
272 | - return $this->data['actorType']; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * returns the actor ID |
|
277 | - * |
|
278 | - * @return string |
|
279 | - * @since 9.0.0 |
|
280 | - */ |
|
281 | - public function getActorId() { |
|
282 | - return $this->data['actorId']; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * sets (overwrites) the actor type and id |
|
287 | - * |
|
288 | - * @param string $actorType e.g. 'users' |
|
289 | - * @param string $actorId e.g. 'zombie234' |
|
290 | - * @return IComment |
|
291 | - * @since 9.0.0 |
|
292 | - */ |
|
293 | - public function setActor($actorType, $actorId) { |
|
294 | - if( |
|
295 | - !is_string($actorType) || !trim($actorType) |
|
296 | - || !is_string($actorId) || !trim($actorId) |
|
297 | - ) { |
|
298 | - throw new \InvalidArgumentException('String expected.'); |
|
299 | - } |
|
300 | - $this->data['actorType'] = trim($actorType); |
|
301 | - $this->data['actorId'] = trim($actorId); |
|
302 | - return $this; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * returns the creation date of the comment. |
|
307 | - * |
|
308 | - * If not explicitly set, it shall default to the time of initialization. |
|
309 | - * |
|
310 | - * @return \DateTime |
|
311 | - * @since 9.0.0 |
|
312 | - */ |
|
313 | - public function getCreationDateTime() { |
|
314 | - return $this->data['creationDT']; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * sets the creation date of the comment and returns itself |
|
319 | - * |
|
320 | - * @param \DateTime $timestamp |
|
321 | - * @return IComment |
|
322 | - * @since 9.0.0 |
|
323 | - */ |
|
324 | - public function setCreationDateTime(\DateTime $timestamp) { |
|
325 | - $this->data['creationDT'] = $timestamp; |
|
326 | - return $this; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * returns the DateTime of the most recent child, if set, otherwise null |
|
331 | - * |
|
332 | - * @return \DateTime|null |
|
333 | - * @since 9.0.0 |
|
334 | - */ |
|
335 | - public function getLatestChildDateTime() { |
|
336 | - return $this->data['latestChildDT']; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * sets the date of the most recent child |
|
341 | - * |
|
342 | - * @param \DateTime $dateTime |
|
343 | - * @return IComment |
|
344 | - * @since 9.0.0 |
|
345 | - */ |
|
346 | - public function setLatestChildDateTime(\DateTime $dateTime = null) { |
|
347 | - $this->data['latestChildDT'] = $dateTime; |
|
348 | - return $this; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * returns the object type the comment is attached to |
|
353 | - * |
|
354 | - * @return string |
|
355 | - * @since 9.0.0 |
|
356 | - */ |
|
357 | - public function getObjectType() { |
|
358 | - return $this->data['objectType']; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * returns the object id the comment is attached to |
|
363 | - * |
|
364 | - * @return string |
|
365 | - * @since 9.0.0 |
|
366 | - */ |
|
367 | - public function getObjectId() { |
|
368 | - return $this->data['objectId']; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * sets (overwrites) the object of the comment |
|
373 | - * |
|
374 | - * @param string $objectType e.g. 'files' |
|
375 | - * @param string $objectId e.g. '16435' |
|
376 | - * @return IComment |
|
377 | - * @since 9.0.0 |
|
378 | - */ |
|
379 | - public function setObject($objectType, $objectId) { |
|
380 | - if( |
|
381 | - !is_string($objectType) || !trim($objectType) |
|
382 | - || !is_string($objectId) || !trim($objectId) |
|
383 | - ) { |
|
384 | - throw new \InvalidArgumentException('String expected.'); |
|
385 | - } |
|
386 | - $this->data['objectType'] = trim($objectType); |
|
387 | - $this->data['objectId'] = trim($objectId); |
|
388 | - return $this; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * sets the comment data based on an array with keys as taken from the |
|
393 | - * database. |
|
394 | - * |
|
395 | - * @param array $data |
|
396 | - * @return IComment |
|
397 | - */ |
|
398 | - protected function fromArray($data) { |
|
399 | - foreach(array_keys($data) as $key) { |
|
400 | - // translate DB keys to internal setter names |
|
401 | - $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
402 | - $setter = str_replace('Timestamp', 'DateTime', $setter); |
|
403 | - |
|
404 | - if(method_exists($this, $setter)) { |
|
405 | - $this->$setter($data[$key]); |
|
406 | - } |
|
407 | - } |
|
408 | - |
|
409 | - foreach(['actor', 'object'] as $role) { |
|
410 | - if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
411 | - $setter = 'set' . ucfirst($role); |
|
412 | - $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - return $this; |
|
417 | - } |
|
33 | + protected $data = [ |
|
34 | + 'id' => '', |
|
35 | + 'parentId' => '0', |
|
36 | + 'topmostParentId' => '0', |
|
37 | + 'childrenCount' => '0', |
|
38 | + 'message' => '', |
|
39 | + 'verb' => '', |
|
40 | + 'actorType' => '', |
|
41 | + 'actorId' => '', |
|
42 | + 'objectType' => '', |
|
43 | + 'objectId' => '', |
|
44 | + 'creationDT' => null, |
|
45 | + 'latestChildDT' => null, |
|
46 | + ]; |
|
47 | + |
|
48 | + /** |
|
49 | + * Comment constructor. |
|
50 | + * |
|
51 | + * @param array $data optional, array with keys according to column names from |
|
52 | + * the comments database scheme |
|
53 | + */ |
|
54 | + public function __construct(array $data = null) { |
|
55 | + if(is_array($data)) { |
|
56 | + $this->fromArray($data); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * returns the ID of the comment |
|
62 | + * |
|
63 | + * It may return an empty string, if the comment was not stored. |
|
64 | + * It is expected that the concrete Comment implementation gives an ID |
|
65 | + * by itself (e.g. after saving). |
|
66 | + * |
|
67 | + * @return string |
|
68 | + * @since 9.0.0 |
|
69 | + */ |
|
70 | + public function getId() { |
|
71 | + return $this->data['id']; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * sets the ID of the comment and returns itself |
|
76 | + * |
|
77 | + * It is only allowed to set the ID only, if the current id is an empty |
|
78 | + * string (which means it is not stored in a database, storage or whatever |
|
79 | + * the concrete implementation does), or vice versa. Changing a given ID is |
|
80 | + * not permitted and must result in an IllegalIDChangeException. |
|
81 | + * |
|
82 | + * @param string $id |
|
83 | + * @return IComment |
|
84 | + * @throws IllegalIDChangeException |
|
85 | + * @since 9.0.0 |
|
86 | + */ |
|
87 | + public function setId($id) { |
|
88 | + if(!is_string($id)) { |
|
89 | + throw new \InvalidArgumentException('String expected.'); |
|
90 | + } |
|
91 | + |
|
92 | + $id = trim($id); |
|
93 | + if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
94 | + $this->data['id'] = $id; |
|
95 | + return $this; |
|
96 | + } |
|
97 | + |
|
98 | + throw new IllegalIDChangeException('Not allowed to assign a new ID to an already saved comment.'); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * returns the parent ID of the comment |
|
103 | + * |
|
104 | + * @return string |
|
105 | + * @since 9.0.0 |
|
106 | + */ |
|
107 | + public function getParentId() { |
|
108 | + return $this->data['parentId']; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * sets the parent ID and returns itself |
|
113 | + * |
|
114 | + * @param string $parentId |
|
115 | + * @return IComment |
|
116 | + * @since 9.0.0 |
|
117 | + */ |
|
118 | + public function setParentId($parentId) { |
|
119 | + if(!is_string($parentId)) { |
|
120 | + throw new \InvalidArgumentException('String expected.'); |
|
121 | + } |
|
122 | + $this->data['parentId'] = trim($parentId); |
|
123 | + return $this; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * returns the topmost parent ID of the comment |
|
128 | + * |
|
129 | + * @return string |
|
130 | + * @since 9.0.0 |
|
131 | + */ |
|
132 | + public function getTopmostParentId() { |
|
133 | + return $this->data['topmostParentId']; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * sets the topmost parent ID and returns itself |
|
139 | + * |
|
140 | + * @param string $id |
|
141 | + * @return IComment |
|
142 | + * @since 9.0.0 |
|
143 | + */ |
|
144 | + public function setTopmostParentId($id) { |
|
145 | + if(!is_string($id)) { |
|
146 | + throw new \InvalidArgumentException('String expected.'); |
|
147 | + } |
|
148 | + $this->data['topmostParentId'] = trim($id); |
|
149 | + return $this; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * returns the number of children |
|
154 | + * |
|
155 | + * @return int |
|
156 | + * @since 9.0.0 |
|
157 | + */ |
|
158 | + public function getChildrenCount() { |
|
159 | + return $this->data['childrenCount']; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * sets the number of children |
|
164 | + * |
|
165 | + * @param int $count |
|
166 | + * @return IComment |
|
167 | + * @since 9.0.0 |
|
168 | + */ |
|
169 | + public function setChildrenCount($count) { |
|
170 | + if(!is_int($count)) { |
|
171 | + throw new \InvalidArgumentException('Integer expected.'); |
|
172 | + } |
|
173 | + $this->data['childrenCount'] = $count; |
|
174 | + return $this; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * returns the message of the comment |
|
179 | + * |
|
180 | + * @return string |
|
181 | + * @since 9.0.0 |
|
182 | + */ |
|
183 | + public function getMessage() { |
|
184 | + return $this->data['message']; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * sets the message of the comment and returns itself |
|
189 | + * |
|
190 | + * @param string $message |
|
191 | + * @return IComment |
|
192 | + * @throws MessageTooLongException |
|
193 | + * @since 9.0.0 |
|
194 | + */ |
|
195 | + public function setMessage($message) { |
|
196 | + if(!is_string($message)) { |
|
197 | + throw new \InvalidArgumentException('String expected.'); |
|
198 | + } |
|
199 | + $message = trim($message); |
|
200 | + if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
201 | + throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); |
|
202 | + } |
|
203 | + $this->data['message'] = $message; |
|
204 | + return $this; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * returns an array containing mentions that are included in the comment |
|
209 | + * |
|
210 | + * @return array each mention provides a 'type' and an 'id', see example below |
|
211 | + * @since 11.0.0 |
|
212 | + * |
|
213 | + * The return array looks like: |
|
214 | + * [ |
|
215 | + * [ |
|
216 | + * 'type' => 'user', |
|
217 | + * 'id' => 'citizen4' |
|
218 | + * ], |
|
219 | + * [ |
|
220 | + * 'type' => 'group', |
|
221 | + * 'id' => 'media' |
|
222 | + * ], |
|
223 | + * … |
|
224 | + * ] |
|
225 | + * |
|
226 | + */ |
|
227 | + public function getMentions() { |
|
228 | + $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions); |
|
229 | + if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
230 | + return []; |
|
231 | + } |
|
232 | + $uids = array_unique($mentions[0]); |
|
233 | + $result = []; |
|
234 | + foreach ($uids as $uid) { |
|
235 | + $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; |
|
236 | + } |
|
237 | + return $result; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * returns the verb of the comment |
|
242 | + * |
|
243 | + * @return string |
|
244 | + * @since 9.0.0 |
|
245 | + */ |
|
246 | + public function getVerb() { |
|
247 | + return $this->data['verb']; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * sets the verb of the comment, e.g. 'comment' or 'like' |
|
252 | + * |
|
253 | + * @param string $verb |
|
254 | + * @return IComment |
|
255 | + * @since 9.0.0 |
|
256 | + */ |
|
257 | + public function setVerb($verb) { |
|
258 | + if(!is_string($verb) || !trim($verb)) { |
|
259 | + throw new \InvalidArgumentException('Non-empty String expected.'); |
|
260 | + } |
|
261 | + $this->data['verb'] = trim($verb); |
|
262 | + return $this; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * returns the actor type |
|
267 | + * |
|
268 | + * @return string |
|
269 | + * @since 9.0.0 |
|
270 | + */ |
|
271 | + public function getActorType() { |
|
272 | + return $this->data['actorType']; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * returns the actor ID |
|
277 | + * |
|
278 | + * @return string |
|
279 | + * @since 9.0.0 |
|
280 | + */ |
|
281 | + public function getActorId() { |
|
282 | + return $this->data['actorId']; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * sets (overwrites) the actor type and id |
|
287 | + * |
|
288 | + * @param string $actorType e.g. 'users' |
|
289 | + * @param string $actorId e.g. 'zombie234' |
|
290 | + * @return IComment |
|
291 | + * @since 9.0.0 |
|
292 | + */ |
|
293 | + public function setActor($actorType, $actorId) { |
|
294 | + if( |
|
295 | + !is_string($actorType) || !trim($actorType) |
|
296 | + || !is_string($actorId) || !trim($actorId) |
|
297 | + ) { |
|
298 | + throw new \InvalidArgumentException('String expected.'); |
|
299 | + } |
|
300 | + $this->data['actorType'] = trim($actorType); |
|
301 | + $this->data['actorId'] = trim($actorId); |
|
302 | + return $this; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * returns the creation date of the comment. |
|
307 | + * |
|
308 | + * If not explicitly set, it shall default to the time of initialization. |
|
309 | + * |
|
310 | + * @return \DateTime |
|
311 | + * @since 9.0.0 |
|
312 | + */ |
|
313 | + public function getCreationDateTime() { |
|
314 | + return $this->data['creationDT']; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * sets the creation date of the comment and returns itself |
|
319 | + * |
|
320 | + * @param \DateTime $timestamp |
|
321 | + * @return IComment |
|
322 | + * @since 9.0.0 |
|
323 | + */ |
|
324 | + public function setCreationDateTime(\DateTime $timestamp) { |
|
325 | + $this->data['creationDT'] = $timestamp; |
|
326 | + return $this; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * returns the DateTime of the most recent child, if set, otherwise null |
|
331 | + * |
|
332 | + * @return \DateTime|null |
|
333 | + * @since 9.0.0 |
|
334 | + */ |
|
335 | + public function getLatestChildDateTime() { |
|
336 | + return $this->data['latestChildDT']; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * sets the date of the most recent child |
|
341 | + * |
|
342 | + * @param \DateTime $dateTime |
|
343 | + * @return IComment |
|
344 | + * @since 9.0.0 |
|
345 | + */ |
|
346 | + public function setLatestChildDateTime(\DateTime $dateTime = null) { |
|
347 | + $this->data['latestChildDT'] = $dateTime; |
|
348 | + return $this; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * returns the object type the comment is attached to |
|
353 | + * |
|
354 | + * @return string |
|
355 | + * @since 9.0.0 |
|
356 | + */ |
|
357 | + public function getObjectType() { |
|
358 | + return $this->data['objectType']; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * returns the object id the comment is attached to |
|
363 | + * |
|
364 | + * @return string |
|
365 | + * @since 9.0.0 |
|
366 | + */ |
|
367 | + public function getObjectId() { |
|
368 | + return $this->data['objectId']; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * sets (overwrites) the object of the comment |
|
373 | + * |
|
374 | + * @param string $objectType e.g. 'files' |
|
375 | + * @param string $objectId e.g. '16435' |
|
376 | + * @return IComment |
|
377 | + * @since 9.0.0 |
|
378 | + */ |
|
379 | + public function setObject($objectType, $objectId) { |
|
380 | + if( |
|
381 | + !is_string($objectType) || !trim($objectType) |
|
382 | + || !is_string($objectId) || !trim($objectId) |
|
383 | + ) { |
|
384 | + throw new \InvalidArgumentException('String expected.'); |
|
385 | + } |
|
386 | + $this->data['objectType'] = trim($objectType); |
|
387 | + $this->data['objectId'] = trim($objectId); |
|
388 | + return $this; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * sets the comment data based on an array with keys as taken from the |
|
393 | + * database. |
|
394 | + * |
|
395 | + * @param array $data |
|
396 | + * @return IComment |
|
397 | + */ |
|
398 | + protected function fromArray($data) { |
|
399 | + foreach(array_keys($data) as $key) { |
|
400 | + // translate DB keys to internal setter names |
|
401 | + $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
402 | + $setter = str_replace('Timestamp', 'DateTime', $setter); |
|
403 | + |
|
404 | + if(method_exists($this, $setter)) { |
|
405 | + $this->$setter($data[$key]); |
|
406 | + } |
|
407 | + } |
|
408 | + |
|
409 | + foreach(['actor', 'object'] as $role) { |
|
410 | + if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
411 | + $setter = 'set' . ucfirst($role); |
|
412 | + $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + return $this; |
|
417 | + } |
|
418 | 418 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * the comments database scheme |
53 | 53 | */ |
54 | 54 | public function __construct(array $data = null) { |
55 | - if(is_array($data)) { |
|
55 | + if (is_array($data)) { |
|
56 | 56 | $this->fromArray($data); |
57 | 57 | } |
58 | 58 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * @since 9.0.0 |
86 | 86 | */ |
87 | 87 | public function setId($id) { |
88 | - if(!is_string($id)) { |
|
88 | + if (!is_string($id)) { |
|
89 | 89 | throw new \InvalidArgumentException('String expected.'); |
90 | 90 | } |
91 | 91 | |
92 | 92 | $id = trim($id); |
93 | - if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
93 | + if ($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
94 | 94 | $this->data['id'] = $id; |
95 | 95 | return $this; |
96 | 96 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @since 9.0.0 |
117 | 117 | */ |
118 | 118 | public function setParentId($parentId) { |
119 | - if(!is_string($parentId)) { |
|
119 | + if (!is_string($parentId)) { |
|
120 | 120 | throw new \InvalidArgumentException('String expected.'); |
121 | 121 | } |
122 | 122 | $this->data['parentId'] = trim($parentId); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @since 9.0.0 |
143 | 143 | */ |
144 | 144 | public function setTopmostParentId($id) { |
145 | - if(!is_string($id)) { |
|
145 | + if (!is_string($id)) { |
|
146 | 146 | throw new \InvalidArgumentException('String expected.'); |
147 | 147 | } |
148 | 148 | $this->data['topmostParentId'] = trim($id); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @since 9.0.0 |
168 | 168 | */ |
169 | 169 | public function setChildrenCount($count) { |
170 | - if(!is_int($count)) { |
|
170 | + if (!is_int($count)) { |
|
171 | 171 | throw new \InvalidArgumentException('Integer expected.'); |
172 | 172 | } |
173 | 173 | $this->data['childrenCount'] = $count; |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | * @since 9.0.0 |
194 | 194 | */ |
195 | 195 | public function setMessage($message) { |
196 | - if(!is_string($message)) { |
|
196 | + if (!is_string($message)) { |
|
197 | 197 | throw new \InvalidArgumentException('String expected.'); |
198 | 198 | } |
199 | 199 | $message = trim($message); |
200 | - if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
201 | - throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); |
|
200 | + if (mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
201 | + throw new MessageTooLongException('Comment message must not exceed '.IComment::MAX_MESSAGE_LENGTH.' characters'); |
|
202 | 202 | } |
203 | 203 | $this->data['message'] = $message; |
204 | 204 | return $this; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function getMentions() { |
228 | 228 | $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions); |
229 | - if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
229 | + if (!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
230 | 230 | return []; |
231 | 231 | } |
232 | 232 | $uids = array_unique($mentions[0]); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @since 9.0.0 |
256 | 256 | */ |
257 | 257 | public function setVerb($verb) { |
258 | - if(!is_string($verb) || !trim($verb)) { |
|
258 | + if (!is_string($verb) || !trim($verb)) { |
|
259 | 259 | throw new \InvalidArgumentException('Non-empty String expected.'); |
260 | 260 | } |
261 | 261 | $this->data['verb'] = trim($verb); |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | * @since 9.0.0 |
292 | 292 | */ |
293 | 293 | public function setActor($actorType, $actorId) { |
294 | - if( |
|
294 | + if ( |
|
295 | 295 | !is_string($actorType) || !trim($actorType) |
296 | - || !is_string($actorId) || !trim($actorId) |
|
296 | + || !is_string($actorId) || !trim($actorId) |
|
297 | 297 | ) { |
298 | 298 | throw new \InvalidArgumentException('String expected.'); |
299 | 299 | } |
@@ -377,9 +377,9 @@ discard block |
||
377 | 377 | * @since 9.0.0 |
378 | 378 | */ |
379 | 379 | public function setObject($objectType, $objectId) { |
380 | - if( |
|
380 | + if ( |
|
381 | 381 | !is_string($objectType) || !trim($objectType) |
382 | - || !is_string($objectId) || !trim($objectId) |
|
382 | + || !is_string($objectId) || !trim($objectId) |
|
383 | 383 | ) { |
384 | 384 | throw new \InvalidArgumentException('String expected.'); |
385 | 385 | } |
@@ -396,20 +396,20 @@ discard block |
||
396 | 396 | * @return IComment |
397 | 397 | */ |
398 | 398 | protected function fromArray($data) { |
399 | - foreach(array_keys($data) as $key) { |
|
399 | + foreach (array_keys($data) as $key) { |
|
400 | 400 | // translate DB keys to internal setter names |
401 | - $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
401 | + $setter = 'set'.implode('', array_map('ucfirst', explode('_', $key))); |
|
402 | 402 | $setter = str_replace('Timestamp', 'DateTime', $setter); |
403 | 403 | |
404 | - if(method_exists($this, $setter)) { |
|
404 | + if (method_exists($this, $setter)) { |
|
405 | 405 | $this->$setter($data[$key]); |
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | - foreach(['actor', 'object'] as $role) { |
|
410 | - if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
411 | - $setter = 'set' . ucfirst($role); |
|
412 | - $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
409 | + foreach (['actor', 'object'] as $role) { |
|
410 | + if (isset($data[$role.'_type']) && isset($data[$role.'_id'])) { |
|
411 | + $setter = 'set'.ucfirst($role); |
|
412 | + $this->$setter($data[$role.'_type'], $data[$role.'_id']); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 |
@@ -35,126 +35,126 @@ |
||
35 | 35 | use OCP\Share; |
36 | 36 | |
37 | 37 | class UserPlugin implements ISearchPlugin { |
38 | - /* @var bool */ |
|
39 | - protected $shareWithGroupOnly; |
|
40 | - protected $shareeEnumeration; |
|
41 | - |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - /** @var IGroupManager */ |
|
45 | - private $groupManager; |
|
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
48 | - /** @var IUserManager */ |
|
49 | - private $userManager; |
|
50 | - |
|
51 | - public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
52 | - $this->config = $config; |
|
53 | - |
|
54 | - $this->groupManager = $groupManager; |
|
55 | - $this->userSession = $userSession; |
|
56 | - $this->userManager = $userManager; |
|
57 | - |
|
58 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
59 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
60 | - } |
|
61 | - |
|
62 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
63 | - $result = ['wide' => [], 'exact' => []]; |
|
64 | - $users = []; |
|
65 | - $hasMoreResults = false; |
|
66 | - |
|
67 | - $userGroups = []; |
|
68 | - if ($this->shareWithGroupOnly) { |
|
69 | - // Search in all the groups this user is part of |
|
70 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
71 | - foreach ($userGroups as $userGroup) { |
|
72 | - $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); |
|
73 | - foreach ($usersTmp as $uid => $userDisplayName) { |
|
74 | - $users[$uid] = $userDisplayName; |
|
75 | - } |
|
76 | - } |
|
77 | - } else { |
|
78 | - // Search in all users |
|
79 | - $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); |
|
80 | - |
|
81 | - foreach ($usersTmp as $user) { |
|
82 | - $users[$user->getUID()] = $user->getDisplayName(); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - $this->takeOutCurrentUser($users); |
|
87 | - |
|
88 | - if (!$this->shareeEnumeration || sizeof($users) < $limit) { |
|
89 | - $hasMoreResults = true; |
|
90 | - } |
|
91 | - |
|
92 | - $foundUserById = false; |
|
93 | - $lowerSearch = strtolower($search); |
|
94 | - foreach ($users as $uid => $userDisplayName) { |
|
95 | - if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
96 | - if (strtolower($uid) === $lowerSearch) { |
|
97 | - $foundUserById = true; |
|
98 | - } |
|
99 | - $result['exact'][] = [ |
|
100 | - 'label' => $userDisplayName, |
|
101 | - 'value' => [ |
|
102 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
103 | - 'shareWith' => $uid, |
|
104 | - ], |
|
105 | - ]; |
|
106 | - } else { |
|
107 | - $result['wide'][] = [ |
|
108 | - 'label' => $userDisplayName, |
|
109 | - 'value' => [ |
|
110 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
111 | - 'shareWith' => $uid, |
|
112 | - ], |
|
113 | - ]; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - if ($offset === 0 && !$foundUserById) { |
|
118 | - // On page one we try if the search result has a direct hit on the |
|
119 | - // user id and if so, we add that to the exact match list |
|
120 | - $user = $this->userManager->get($search); |
|
121 | - if ($user instanceof IUser) { |
|
122 | - $addUser = true; |
|
123 | - |
|
124 | - if ($this->shareWithGroupOnly) { |
|
125 | - // Only add, if we have a common group |
|
126 | - $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
127 | - $addUser = !empty($commonGroups); |
|
128 | - } |
|
129 | - |
|
130 | - if ($addUser) { |
|
131 | - array_push($result['exact'], [ |
|
132 | - 'label' => $user->getDisplayName(), |
|
133 | - 'value' => [ |
|
134 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
135 | - 'shareWith' => $user->getUID(), |
|
136 | - ], |
|
137 | - ]); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - if (!$this->shareeEnumeration) { |
|
143 | - $result['wide'] = []; |
|
144 | - } |
|
145 | - |
|
146 | - $type = new SearchResultType('users'); |
|
147 | - $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
148 | - |
|
149 | - return $hasMoreResults; |
|
150 | - } |
|
151 | - |
|
152 | - public function takeOutCurrentUser(array &$users) { |
|
153 | - $currentUser = $this->userSession->getUser(); |
|
154 | - if(!is_null($currentUser)) { |
|
155 | - if (isset($users[$currentUser->getUID()])) { |
|
156 | - unset($users[$currentUser->getUID()]); |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
38 | + /* @var bool */ |
|
39 | + protected $shareWithGroupOnly; |
|
40 | + protected $shareeEnumeration; |
|
41 | + |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + /** @var IGroupManager */ |
|
45 | + private $groupManager; |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | + /** @var IUserManager */ |
|
49 | + private $userManager; |
|
50 | + |
|
51 | + public function __construct(IConfig $config, IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
52 | + $this->config = $config; |
|
53 | + |
|
54 | + $this->groupManager = $groupManager; |
|
55 | + $this->userSession = $userSession; |
|
56 | + $this->userManager = $userManager; |
|
57 | + |
|
58 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
59 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
60 | + } |
|
61 | + |
|
62 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
63 | + $result = ['wide' => [], 'exact' => []]; |
|
64 | + $users = []; |
|
65 | + $hasMoreResults = false; |
|
66 | + |
|
67 | + $userGroups = []; |
|
68 | + if ($this->shareWithGroupOnly) { |
|
69 | + // Search in all the groups this user is part of |
|
70 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
71 | + foreach ($userGroups as $userGroup) { |
|
72 | + $usersTmp = $this->groupManager->displayNamesInGroup($userGroup, $search, $limit, $offset); |
|
73 | + foreach ($usersTmp as $uid => $userDisplayName) { |
|
74 | + $users[$uid] = $userDisplayName; |
|
75 | + } |
|
76 | + } |
|
77 | + } else { |
|
78 | + // Search in all users |
|
79 | + $usersTmp = $this->userManager->searchDisplayName($search, $limit, $offset); |
|
80 | + |
|
81 | + foreach ($usersTmp as $user) { |
|
82 | + $users[$user->getUID()] = $user->getDisplayName(); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + $this->takeOutCurrentUser($users); |
|
87 | + |
|
88 | + if (!$this->shareeEnumeration || sizeof($users) < $limit) { |
|
89 | + $hasMoreResults = true; |
|
90 | + } |
|
91 | + |
|
92 | + $foundUserById = false; |
|
93 | + $lowerSearch = strtolower($search); |
|
94 | + foreach ($users as $uid => $userDisplayName) { |
|
95 | + if (strtolower($uid) === $lowerSearch || strtolower($userDisplayName) === $lowerSearch) { |
|
96 | + if (strtolower($uid) === $lowerSearch) { |
|
97 | + $foundUserById = true; |
|
98 | + } |
|
99 | + $result['exact'][] = [ |
|
100 | + 'label' => $userDisplayName, |
|
101 | + 'value' => [ |
|
102 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
103 | + 'shareWith' => $uid, |
|
104 | + ], |
|
105 | + ]; |
|
106 | + } else { |
|
107 | + $result['wide'][] = [ |
|
108 | + 'label' => $userDisplayName, |
|
109 | + 'value' => [ |
|
110 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
111 | + 'shareWith' => $uid, |
|
112 | + ], |
|
113 | + ]; |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + if ($offset === 0 && !$foundUserById) { |
|
118 | + // On page one we try if the search result has a direct hit on the |
|
119 | + // user id and if so, we add that to the exact match list |
|
120 | + $user = $this->userManager->get($search); |
|
121 | + if ($user instanceof IUser) { |
|
122 | + $addUser = true; |
|
123 | + |
|
124 | + if ($this->shareWithGroupOnly) { |
|
125 | + // Only add, if we have a common group |
|
126 | + $commonGroups = array_intersect($userGroups, $this->groupManager->getUserGroupIds($user)); |
|
127 | + $addUser = !empty($commonGroups); |
|
128 | + } |
|
129 | + |
|
130 | + if ($addUser) { |
|
131 | + array_push($result['exact'], [ |
|
132 | + 'label' => $user->getDisplayName(), |
|
133 | + 'value' => [ |
|
134 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
135 | + 'shareWith' => $user->getUID(), |
|
136 | + ], |
|
137 | + ]); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + if (!$this->shareeEnumeration) { |
|
143 | + $result['wide'] = []; |
|
144 | + } |
|
145 | + |
|
146 | + $type = new SearchResultType('users'); |
|
147 | + $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
148 | + |
|
149 | + return $hasMoreResults; |
|
150 | + } |
|
151 | + |
|
152 | + public function takeOutCurrentUser(array &$users) { |
|
153 | + $currentUser = $this->userSession->getUser(); |
|
154 | + if(!is_null($currentUser)) { |
|
155 | + if (isset($users[$currentUser->getUID()])) { |
|
156 | + unset($users[$currentUser->getUID()]); |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | 160 | } |
@@ -151,7 +151,7 @@ |
||
151 | 151 | |
152 | 152 | public function takeOutCurrentUser(array &$users) { |
153 | 153 | $currentUser = $this->userSession->getUser(); |
154 | - if(!is_null($currentUser)) { |
|
154 | + if (!is_null($currentUser)) { |
|
155 | 155 | if (isset($users[$currentUser->getUID()])) { |
156 | 156 | unset($users[$currentUser->getUID()]); |
157 | 157 | } |
@@ -31,68 +31,68 @@ |
||
31 | 31 | use OCP\Share; |
32 | 32 | |
33 | 33 | class Search implements ISearch { |
34 | - /** @var IContainer */ |
|
35 | - private $c; |
|
34 | + /** @var IContainer */ |
|
35 | + private $c; |
|
36 | 36 | |
37 | - protected $pluginList = []; |
|
37 | + protected $pluginList = []; |
|
38 | 38 | |
39 | - public function __construct(IContainer $c) { |
|
40 | - $this->c = $c; |
|
41 | - } |
|
39 | + public function __construct(IContainer $c) { |
|
40 | + $this->c = $c; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $search |
|
45 | - * @param array $shareTypes |
|
46 | - * @param bool $lookup |
|
47 | - * @param int|null $limit |
|
48 | - * @param int|null $offset |
|
49 | - * @return array |
|
50 | - * @throws \OCP\AppFramework\QueryException |
|
51 | - */ |
|
52 | - public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
53 | - $hasMoreResults = false; |
|
43 | + /** |
|
44 | + * @param string $search |
|
45 | + * @param array $shareTypes |
|
46 | + * @param bool $lookup |
|
47 | + * @param int|null $limit |
|
48 | + * @param int|null $offset |
|
49 | + * @return array |
|
50 | + * @throws \OCP\AppFramework\QueryException |
|
51 | + */ |
|
52 | + public function search($search, array $shareTypes, $lookup, $limit, $offset) { |
|
53 | + $hasMoreResults = false; |
|
54 | 54 | |
55 | - /** @var ISearchResult $searchResult */ |
|
56 | - $searchResult = $this->c->resolve(SearchResult::class); |
|
55 | + /** @var ISearchResult $searchResult */ |
|
56 | + $searchResult = $this->c->resolve(SearchResult::class); |
|
57 | 57 | |
58 | - foreach ($shareTypes as $type) { |
|
59 | - if(!isset($this->pluginList[$type])) { |
|
60 | - continue; |
|
61 | - } |
|
62 | - foreach ($this->pluginList[$type] as $plugin) { |
|
63 | - /** @var ISearchPlugin $searchPlugin */ |
|
64 | - $searchPlugin = $this->c->resolve($plugin); |
|
65 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
66 | - } |
|
67 | - } |
|
58 | + foreach ($shareTypes as $type) { |
|
59 | + if(!isset($this->pluginList[$type])) { |
|
60 | + continue; |
|
61 | + } |
|
62 | + foreach ($this->pluginList[$type] as $plugin) { |
|
63 | + /** @var ISearchPlugin $searchPlugin */ |
|
64 | + $searchPlugin = $this->c->resolve($plugin); |
|
65 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - // Get from lookup server, not a separate share type |
|
70 | - if ($lookup) { |
|
71 | - $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
72 | - $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
73 | - } |
|
69 | + // Get from lookup server, not a separate share type |
|
70 | + if ($lookup) { |
|
71 | + $searchPlugin = $this->c->resolve(LookupPlugin::class); |
|
72 | + $hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult); |
|
73 | + } |
|
74 | 74 | |
75 | - // sanitizing, could go into the plugins as well |
|
75 | + // sanitizing, could go into the plugins as well |
|
76 | 76 | |
77 | - // if we have a exact match, either for the federated cloud id or for the |
|
78 | - // email address we only return the exact match. It is highly unlikely |
|
79 | - // that the exact same email address and federated cloud id exists |
|
80 | - $emailType = new SearchResultType('emails'); |
|
81 | - $remoteType = new SearchResultType('remotes'); |
|
82 | - if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
83 | - $searchResult->unsetResult($remoteType); |
|
84 | - } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
85 | - $searchResult->unsetResult($emailType); |
|
86 | - } |
|
77 | + // if we have a exact match, either for the federated cloud id or for the |
|
78 | + // email address we only return the exact match. It is highly unlikely |
|
79 | + // that the exact same email address and federated cloud id exists |
|
80 | + $emailType = new SearchResultType('emails'); |
|
81 | + $remoteType = new SearchResultType('remotes'); |
|
82 | + if($searchResult->hasExactIdMatch($emailType) && !$searchResult->hasExactIdMatch($remoteType)) { |
|
83 | + $searchResult->unsetResult($remoteType); |
|
84 | + } elseif (!$searchResult->hasExactIdMatch($emailType) && $searchResult->hasExactIdMatch($remoteType)) { |
|
85 | + $searchResult->unsetResult($emailType); |
|
86 | + } |
|
87 | 87 | |
88 | - return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
89 | - } |
|
88 | + return [$searchResult->asArray(), (bool)$hasMoreResults]; |
|
89 | + } |
|
90 | 90 | |
91 | - public function registerPlugin(array $pluginInfo) { |
|
92 | - $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
93 | - if($shareType === null) { |
|
94 | - throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
95 | - } |
|
96 | - $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
97 | - } |
|
91 | + public function registerPlugin(array $pluginInfo) { |
|
92 | + $shareType = constant(Share::class . '::' . $pluginInfo['shareType']); |
|
93 | + if($shareType === null) { |
|
94 | + throw new \InvalidArgumentException('Provided ShareType is invalid'); |
|
95 | + } |
|
96 | + $this->pluginList[$shareType][] = $pluginInfo['class']; |
|
97 | + } |
|
98 | 98 | } |