1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | /** |
||
4 | * Hook Observer for Advanced subscription plugin. |
||
5 | * |
||
6 | * @author Daniel Alejandro Barreto Alva <[email protected]> |
||
7 | * |
||
8 | * @package chamilo.plugin.advanced_subscription |
||
9 | */ |
||
10 | require_once __DIR__.'/../config.php'; |
||
11 | |||
12 | /** |
||
13 | * Class HookAdvancedSubscription extends the HookObserver to implements |
||
14 | * specific behaviour when the AdvancedSubscription plugin is enabled. |
||
15 | */ |
||
16 | class HookAdvancedSubscription extends HookObserver implements HookAdminBlockObserverInterface, HookWSRegistrationObserverInterface, HookNotificationContentObserverInterface |
||
17 | { |
||
18 | public static $plugin; |
||
19 | |||
20 | /** |
||
21 | * Constructor. Calls parent, mainly. |
||
22 | */ |
||
23 | protected function __construct() |
||
24 | { |
||
25 | self::$plugin = AdvancedSubscriptionPlugin::create(); |
||
26 | parent::__construct( |
||
27 | 'plugin/advanced_subscription/src/HookAdvancedSubscription.class.php', |
||
28 | 'advanced_subscription' |
||
29 | ); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @return array |
||
34 | */ |
||
35 | public function hookAdminBlock(HookAdminBlockEventInterface $hook) |
||
36 | { |
||
37 | $data = $hook->getEventData(); |
||
38 | // if ($data['type'] === HOOK_EVENT_TYPE_PRE) // Nothing to do |
||
39 | if ($data['type'] === HOOK_EVENT_TYPE_POST) { |
||
40 | if (isset($data['blocks'])) { |
||
41 | $data['blocks']['sessions']['items'][] = [ |
||
42 | 'url' => '../../plugin/advanced_subscription/src/admin_view.php', |
||
43 | 'label' => get_plugin_lang('plugin_title', 'AdvancedSubscriptionPlugin'), |
||
44 | ]; |
||
45 | } |
||
46 | } // Else: Hook type is not valid, nothing to do |
||
47 | |||
48 | return $data; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Add Webservices to registration.soap.php. |
||
53 | * |
||
54 | * @return mixed (int or false) |
||
55 | */ |
||
56 | public function hookWSRegistration(HookWSRegistrationEventInterface $hook) |
||
57 | { |
||
58 | $data = $hook->getEventData(); |
||
59 | //if ($data['type'] === HOOK_EVENT_TYPE_PRE) // nothing to do |
||
60 | if ($data['type'] === HOOK_EVENT_TYPE_POST) { |
||
61 | /** @var \nusoap_server $server */ |
||
62 | $server = &$data['server']; |
||
63 | |||
64 | /** WSSessionListInCategory */ |
||
65 | |||
66 | // Output params for sessionBriefList WSSessionListInCategory |
||
67 | $server->wsdl->addComplexType( |
||
68 | 'sessionBrief', |
||
69 | 'complexType', |
||
70 | 'struct', |
||
71 | 'all', |
||
72 | '', |
||
73 | [ |
||
74 | // session.id |
||
75 | 'id' => ['name' => 'id', 'type' => 'xsd:int'], |
||
76 | // session.name |
||
77 | 'name' => ['name' => 'name', 'type' => 'xsd:string'], |
||
78 | // session.short_description |
||
79 | 'short_description' => ['name' => 'short_description', 'type' => 'xsd:string'], |
||
80 | // session.mode |
||
81 | 'mode' => ['name' => 'mode', 'type' => 'xsd:string'], |
||
82 | // session.date_start |
||
83 | 'date_start' => ['name' => 'date_start', 'type' => 'xsd:string'], |
||
84 | // session.date_end |
||
85 | 'date_end' => ['name' => 'date_end', 'type' => 'xsd:string'], |
||
86 | // session.human_text_duration |
||
87 | 'human_text_duration' => ['name' => 'human_text_duration', 'type' => 'xsd:string'], |
||
88 | // session.vacancies |
||
89 | 'vacancies' => ['name' => 'vacancies', 'type' => 'xsd:string'], |
||
90 | // session.schedule |
||
91 | 'schedule' => ['name' => 'schedule', 'type' => 'xsd:string'], |
||
92 | ] |
||
93 | ); |
||
94 | |||
95 | //Output params for WSSessionListInCategory |
||
96 | $server->wsdl->addComplexType( |
||
97 | 'sessionBriefList', |
||
98 | 'complexType', |
||
99 | 'array', |
||
100 | '', |
||
101 | 'SOAP-ENC:Array', |
||
102 | [], |
||
103 | [ |
||
104 | ['ref' => 'SOAP-ENC:arrayType', |
||
105 | 'wsdl:arrayType' => 'tns:sessionBrief[]', ], |
||
106 | ], |
||
107 | 'tns:sessionBrief' |
||
108 | ); |
||
109 | |||
110 | // Input params for WSSessionListInCategory |
||
111 | $server->wsdl->addComplexType( |
||
112 | 'sessionCategoryInput', |
||
113 | 'complexType', |
||
114 | 'struct', |
||
115 | 'all', |
||
116 | '', |
||
117 | [ |
||
118 | 'id' => ['name' => 'id', 'type' => 'xsd:string'], // session_category.id |
||
119 | 'name' => ['name' => 'name', 'type' => 'xsd:string'], // session_category.name |
||
120 | 'target' => ['name' => 'target', 'type' => 'xsd:string'], // session.target |
||
121 | 'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||
122 | ] |
||
123 | ); |
||
124 | |||
125 | // Input params for WSSessionGetDetailsByUser |
||
126 | $server->wsdl->addComplexType( |
||
127 | 'advsubSessionDetailInput', |
||
128 | 'complexType', |
||
129 | 'struct', |
||
130 | 'all', |
||
131 | '', |
||
132 | [ |
||
133 | // user_field_values.value |
||
134 | 'user_id' => ['name' => 'user_id', 'type' => 'xsd:int'], |
||
135 | // user_field.user_id |
||
136 | 'user_field' => ['name' => 'user_field', 'type' => 'xsd:string'], |
||
137 | // session.id |
||
138 | 'session_id' => ['name' => 'session_id', 'type' => 'xsd:int'], |
||
139 | // user.profile_completes |
||
140 | 'profile_completed' => ['name' => 'profile_completed', 'type' => 'xsd:float'], |
||
141 | // user.is_connected |
||
142 | 'is_connected' => ['name' => 'is_connected', 'type' => 'xsd:boolean'], |
||
143 | 'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||
144 | ] |
||
145 | ); |
||
146 | |||
147 | // Output params for WSSessionGetDetailsByUser |
||
148 | $server->wsdl->addComplexType( |
||
149 | 'advsubSessionDetail', |
||
150 | 'complexType', |
||
151 | 'struct', |
||
152 | 'all', |
||
153 | '', |
||
154 | [ |
||
155 | // session.id |
||
156 | 'id' => ['name' => 'id', 'type' => 'xsd:string'], |
||
157 | // session.code |
||
158 | 'code' => ['name' => 'code', 'type' => 'xsd:string'], |
||
159 | // session.place |
||
160 | 'cost' => ['name' => 'cost', 'type' => 'xsd:float'], |
||
161 | // session.place |
||
162 | 'place' => ['name' => 'place', 'type' => 'xsd:string'], |
||
163 | // session.allow_visitors |
||
164 | 'allow_visitors' => ['name' => 'allow_visitors', 'type' => 'xsd:string'], |
||
165 | // session.teaching_hours |
||
166 | 'teaching_hours' => ['name' => 'teaching_hours', 'type' => 'xsd:int'], |
||
167 | // session.brochure |
||
168 | 'brochure' => ['name' => 'brochure', 'type' => 'xsd:string'], |
||
169 | // session.banner |
||
170 | 'banner' => ['name' => 'banner', 'type' => 'xsd:string'], |
||
171 | // session.description |
||
172 | 'description' => ['name' => 'description', 'type' => 'xsd:string'], |
||
173 | // status |
||
174 | 'status' => ['name' => 'status', 'type' => 'xsd:string'], |
||
175 | // action_url |
||
176 | 'action_url' => ['name' => 'action_url', 'type' => 'xsd:string'], |
||
177 | // message |
||
178 | 'message' => ['name' => 'error_message', 'type' => 'xsd:string'], |
||
179 | ] |
||
180 | ); |
||
181 | |||
182 | /** WSListSessionsDetailsByCategory */ |
||
183 | |||
184 | // Input params for WSListSessionsDetailsByCategory |
||
185 | $server->wsdl->addComplexType( |
||
186 | 'listSessionsDetailsByCategory', |
||
187 | 'complexType', |
||
188 | 'struct', |
||
189 | 'all', |
||
190 | '', |
||
191 | [ |
||
192 | // session_category.id |
||
193 | 'id' => ['name' => 'id', 'type' => 'xsd:string'], |
||
194 | // session_category.access_url_id |
||
195 | 'access_url_id' => ['name' => 'access_url_id', 'type' => 'xsd:int'], |
||
196 | // session_category.name |
||
197 | 'category_name' => ['name' => 'category_name', 'type' => 'xsd:string'], |
||
198 | // secret key |
||
199 | 'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
||
200 | ], |
||
201 | [], |
||
202 | 'tns:listSessionsDetailsByCategory' |
||
203 | ); |
||
204 | |||
205 | // Output params for sessionDetailsCourseList WSListSessionsDetailsByCategory |
||
206 | $server->wsdl->addComplexType( |
||
207 | 'sessionDetailsCourse', |
||
208 | 'complexType', |
||
209 | 'struct', |
||
210 | 'all', |
||
211 | '', |
||
212 | [ |
||
213 | 'course_id' => ['name' => 'course_id', 'type' => 'xsd:int'], // course.id |
||
214 | 'course_code' => ['name' => 'course_code', 'type' => 'xsd:string'], // course.code |
||
215 | 'course_title' => ['name' => 'course_title', 'type' => 'xsd:string'], // course.title |
||
216 | 'coach_username' => ['name' => 'coach_username', 'type' => 'xsd:string'], // user.username |
||
217 | 'coach_firstname' => ['name' => 'coach_firstname', 'type' => 'xsd:string'], // user.firstname |
||
218 | 'coach_lastname' => ['name' => 'coach_lastname', 'type' => 'xsd:string'], // user.lastname |
||
219 | ] |
||
220 | ); |
||
221 | |||
222 | // Output array for sessionDetails WSListSessionsDetailsByCategory |
||
223 | $server->wsdl->addComplexType( |
||
224 | 'sessionDetailsCourseList', |
||
225 | 'complexType', |
||
226 | 'array', |
||
227 | '', |
||
228 | 'SOAP-ENC:Array', |
||
229 | [], |
||
230 | [ |
||
231 | [ |
||
232 | 'ref' => 'SOAP-ENC:arrayType', |
||
233 | 'wsdl:arrayType' => 'tns:sessionDetailsCourse[]', |
||
234 | ], |
||
235 | ], |
||
236 | 'tns:sessionDetailsCourse' |
||
237 | ); |
||
238 | |||
239 | // Output params for sessionDetailsList WSListSessionsDetailsByCategory |
||
240 | $server->wsdl->addComplexType( |
||
241 | 'sessionDetails', |
||
242 | 'complexType', |
||
243 | 'struct', |
||
244 | 'all', |
||
245 | '', |
||
246 | [ |
||
247 | // session.id |
||
248 | 'id' => [ |
||
249 | 'name' => 'id', |
||
250 | 'type' => 'xsd:int', |
||
251 | ], |
||
252 | // session.id_coach |
||
253 | 'coach_id' => [ |
||
254 | 'name' => 'coach_id', |
||
255 | 'type' => 'xsd:int', |
||
256 | ], |
||
257 | // session.name |
||
258 | 'name' => [ |
||
259 | 'name' => 'name', |
||
260 | 'type' => 'xsd:string', |
||
261 | ], |
||
262 | // session.nbr_courses |
||
263 | 'courses_num' => [ |
||
264 | 'name' => 'courses_num', |
||
265 | 'type' => 'xsd:int', |
||
266 | ], |
||
267 | // session.nbr_users |
||
268 | 'users_num' => [ |
||
269 | 'name' => 'users_num', |
||
270 | 'type' => 'xsd:int', |
||
271 | ], |
||
272 | // session.nbr_classes |
||
273 | 'classes_num' => [ |
||
274 | 'name' => 'classes_num', |
||
275 | 'type' => 'xsd:int', |
||
276 | ], |
||
277 | // session.date_start |
||
278 | 'date_start' => [ |
||
279 | 'name' => 'date_start', |
||
280 | 'type' => 'xsd:string', |
||
281 | ], |
||
282 | // session.date_end |
||
283 | 'date_end' => [ |
||
284 | 'name' => 'date_end', |
||
285 | 'type' => 'xsd:string', |
||
286 | ], |
||
287 | // session.nb_days_access_before_beginning |
||
288 | 'access_days_before_num' => [ |
||
289 | 'name' => 'access_days_before_num', |
||
290 | 'type' => 'xsd:int', |
||
291 | ], |
||
292 | // session.nb_days_access_after_end |
||
293 | 'access_days_after_num' => [ |
||
294 | 'name' => 'access_days_after_num', |
||
295 | 'type' => 'xsd:int', |
||
296 | ], |
||
297 | // session.session_admin_id |
||
298 | 'session_admin_id' => [ |
||
299 | 'name' => 'session_admin_id', |
||
300 | 'type' => 'xsd:int', |
||
301 | ], |
||
302 | // session.visibility |
||
303 | 'visibility' => [ |
||
304 | 'name' => 'visibility', |
||
305 | 'type' => 'xsd:int', |
||
306 | ], |
||
307 | // session.session_category_id |
||
308 | 'session_category_id' => [ |
||
309 | 'name' => 'session_category_id', |
||
310 | 'type' => 'xsd:int', |
||
311 | ], |
||
312 | // session.promotion_id |
||
313 | 'promotion_id' => [ |
||
314 | 'name' => 'promotion_id', |
||
315 | 'type' => 'xsd:int', |
||
316 | ], |
||
317 | // session.number of registered users validated |
||
318 | 'validated_user_num' => [ |
||
319 | 'name' => 'validated_user_num', |
||
320 | 'type' => 'xsd:int', |
||
321 | ], |
||
322 | // session.number of registered users from waiting queue |
||
323 | 'waiting_user_num' => [ |
||
324 | 'name' => 'waiting_user_num', |
||
325 | 'type' => 'xsd:int', |
||
326 | ], |
||
327 | // extra fields |
||
328 | // Array(field_name, field_value) |
||
329 | 'extra' => [ |
||
330 | 'name' => 'extra', |
||
331 | 'type' => 'tns:extrasList', |
||
332 | ], |
||
333 | // course and coaches data |
||
334 | // Array(course_id, course_code, course_title, coach_username, coach_firstname, coach_lastname) |
||
335 | 'course' => [ |
||
336 | 'name' => 'courses', |
||
337 | 'type' => 'tns:sessionDetailsCourseList', |
||
338 | ], |
||
339 | ] |
||
340 | ); |
||
341 | |||
342 | // Output params for WSListSessionsDetailsByCategory |
||
343 | $server->wsdl->addComplexType( |
||
344 | 'sessionDetailsList', |
||
345 | 'complexType', |
||
346 | 'array', |
||
347 | '', |
||
348 | 'SOAP-ENC:Array', |
||
349 | [], |
||
350 | [ |
||
351 | [ |
||
352 | 'ref' => 'SOAP-ENC:arrayType', |
||
353 | 'wsdl:arrayType' => 'tns:sessionDetails[]', |
||
354 | ], |
||
355 | ], |
||
356 | 'tns:sessionDetails' |
||
357 | ); |
||
358 | |||
359 | // Register the method for WSSessionListInCategory |
||
360 | $server->register( |
||
361 | 'HookAdvancedSubscription..WSSessionListInCategory', // method name |
||
362 | ['sessionCategoryInput' => 'tns:sessionCategoryInput'], // input parameters |
||
363 | ['return' => 'tns:sessionBriefList'], // output parameters |
||
364 | 'urn:WSRegistration', // namespace |
||
365 | 'urn:WSRegistration#WSSessionListInCategory', // soapaction |
||
366 | 'rpc', // style |
||
367 | 'encoded', // use |
||
368 | 'This service checks if user assigned to course' // documentation |
||
369 | ); |
||
370 | |||
371 | // Register the method for WSSessionGetDetailsByUser |
||
372 | $server->register( |
||
373 | 'HookAdvancedSubscription..WSSessionGetDetailsByUser', // method name |
||
374 | ['advsubSessionDetailInput' => 'tns:advsubSessionDetailInput'], // input parameters |
||
375 | ['return' => 'tns:advsubSessionDetail'], // output parameters |
||
376 | 'urn:WSRegistration', // namespace |
||
377 | 'urn:WSRegistration#WSSessionGetDetailsByUser', // soapaction |
||
378 | 'rpc', // style |
||
379 | 'encoded', // use |
||
380 | 'This service return session details to specific user' // documentation |
||
381 | ); |
||
382 | |||
383 | // Register the method for WSListSessionsDetailsByCategory |
||
384 | $server->register( |
||
385 | 'HookAdvancedSubscription..WSListSessionsDetailsByCategory', // method name |
||
386 | ['name' => 'tns:listSessionsDetailsByCategory'], // input parameters |
||
387 | ['return' => 'tns:sessionDetailsList'], // output parameters |
||
388 | 'urn:WSRegistration', // namespace |
||
389 | 'urn:WSRegistration#WSListSessionsDetailsByCategory', // soapaction |
||
390 | 'rpc', // style |
||
391 | 'encoded', // use |
||
392 | 'This service returns a list of detailed sessions by a category' // documentation |
||
393 | ); |
||
394 | |||
395 | return $data; |
||
0 ignored issues
–
show
|
|||
396 | } // Else: Nothing to do |
||
397 | |||
398 | return false; |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * @param $params |
||
403 | * |
||
404 | * @return soap_fault|null |
||
405 | */ |
||
406 | public static function WSSessionListInCategory($params) |
||
407 | { |
||
408 | global $debug; |
||
409 | |||
410 | if ($debug) { |
||
411 | error_log(__FUNCTION__); |
||
412 | error_log('Params '.print_r($params, 1)); |
||
413 | if (!WSHelperVerifyKey($params)) { |
||
414 | error_log(return_error(WS_ERROR_SECRET_KEY)); |
||
415 | } |
||
416 | } |
||
417 | // Check if category ID is set |
||
418 | if (!empty($params['id']) && empty($params['name'])) { |
||
419 | $sessionCategoryId = $params['id']; |
||
420 | } elseif (!empty($params['name'])) { |
||
421 | // Check if category name is set |
||
422 | $sessionCategoryId = SessionManager::getSessionCategoryIdByName($params['name']); |
||
423 | if (is_array($sessionCategoryId)) { |
||
424 | $sessionCategoryId = current($sessionCategoryId); |
||
425 | } |
||
426 | } else { |
||
427 | // Return soap fault Not valid input params |
||
428 | |||
429 | return return_error(WS_ERROR_INVALID_INPUT); |
||
430 | } |
||
431 | |||
432 | // Get the session brief List by category |
||
433 | $fields = [ |
||
434 | 'id', |
||
435 | 'short_description', |
||
436 | 'mode', |
||
437 | 'human_text_duration', |
||
438 | 'vacancies', |
||
439 | 'schedule', |
||
440 | ]; |
||
441 | $datePub = new DateTime(); |
||
442 | $sessionList = SessionManager::getShortSessionListAndExtraByCategory( |
||
443 | $sessionCategoryId, |
||
444 | $params['target'], |
||
445 | $fields, |
||
446 | $datePub |
||
447 | ); |
||
448 | |||
449 | return $sessionList; |
||
450 | } |
||
451 | |||
452 | /** |
||
453 | * @param $params |
||
454 | * |
||
455 | * @return soap_fault|null |
||
456 | */ |
||
457 | public static function WSSessionGetDetailsByUser($params) |
||
458 | { |
||
459 | global $debug; |
||
460 | |||
461 | if ($debug) { |
||
462 | error_log('WSUserSubscribedInCourse'); |
||
463 | error_log('Params '.print_r($params, 1)); |
||
464 | } |
||
465 | if (!WSHelperVerifyKey($params)) { |
||
466 | return return_error(WS_ERROR_SECRET_KEY); |
||
467 | } |
||
468 | // Check params |
||
469 | if (is_array($params) && !empty($params['session_id']) && !empty($params['user_id'])) { |
||
470 | $userId = UserManager::get_user_id_from_original_id($params['user_id'], $params['user_field']); |
||
471 | $sessionId = (int) $params['session_id']; |
||
472 | // Check if user exists |
||
473 | if (UserManager::is_user_id_valid($userId) && |
||
474 | SessionManager::isValidId($sessionId) |
||
475 | ) { |
||
476 | // Check if student is already subscribed |
||
477 | $plugin = AdvancedSubscriptionPlugin::create(); |
||
478 | $isOpen = $plugin->isSessionOpen($sessionId); |
||
479 | $status = $plugin->getQueueStatus($userId, $sessionId); |
||
480 | $vacancy = $plugin->getVacancy($sessionId); |
||
481 | $data = $plugin->getSessionDetails($sessionId); |
||
482 | $isUserInTargetGroup = $plugin->isUserInTargetGroup($userId, $sessionId); |
||
483 | if (!empty($data) && is_array($data)) { |
||
484 | $data['status'] = $status; |
||
485 | // Vacancy and queue status cases: |
||
486 | if ($isOpen) { |
||
487 | // Go to Course session |
||
488 | $data['action_url'] = self::$plugin->getOpenSessionUrl($userId, $params); |
||
489 | if (SessionManager::isUserSubscribedAsStudent($sessionId, $userId)) { |
||
490 | $data['status'] = 10; |
||
491 | } |
||
492 | } else { |
||
493 | if (!$isUserInTargetGroup) { |
||
494 | $data['status'] = -2; |
||
495 | } else { |
||
496 | try { |
||
497 | $isAllowed = self::$plugin->isAllowedToDoRequest($userId, $params); |
||
498 | $data['message'] = self::$plugin->getStatusMessage($status, $isAllowed); |
||
499 | } catch (\Exception $e) { |
||
500 | $data['message'] = $e->getMessage(); |
||
501 | } |
||
502 | $params['action'] = 'subscribe'; |
||
503 | $params['sessionId'] = intval($sessionId); |
||
504 | $params['currentUserId'] = 0; // No needed |
||
505 | $params['studentUserId'] = intval($userId); |
||
506 | $params['queueId'] = 0; // No needed |
||
507 | $params['newStatus'] = ADVANCED_SUBSCRIPTION_QUEUE_STATUS_START; |
||
508 | if ($vacancy > 0) { |
||
509 | // Check conditions |
||
510 | if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) { |
||
511 | // No in Queue, require queue subscription url action |
||
512 | $data['action_url'] = self::$plugin->getTermsUrl($params); |
||
513 | } elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) { |
||
514 | // send url action |
||
515 | $data['action_url'] = self::$plugin->getSessionUrl($sessionId); |
||
516 | } // Else: In queue, output status message, no more info. |
||
517 | } else { |
||
518 | if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) { |
||
519 | $data['action_url'] = self::$plugin->getSessionUrl($sessionId); |
||
520 | } elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) { |
||
521 | // in Queue or not, cannot be subscribed to session |
||
522 | $data['action_url'] = self::$plugin->getTermsUrl($params); |
||
523 | } // Else: In queue, output status message, no more info. |
||
524 | } |
||
525 | } |
||
526 | } |
||
527 | $result = $data; |
||
528 | } else { |
||
529 | // Return soap fault No result was found |
||
530 | $result = return_error(WS_ERROR_NOT_FOUND_RESULT); |
||
531 | } |
||
532 | } else { |
||
533 | // Return soap fault No result was found |
||
534 | $result = return_error(WS_ERROR_NOT_FOUND_RESULT); |
||
535 | } |
||
536 | } else { |
||
537 | // Return soap fault Not valid input params |
||
538 | $result = return_error(WS_ERROR_INVALID_INPUT); |
||
539 | } |
||
540 | |||
541 | return $result; |
||
0 ignored issues
–
show
|
|||
542 | } |
||
543 | |||
544 | /** |
||
545 | * Get a list of sessions (id, coach_id, name, courses_num, users_num, classes_num, |
||
546 | * access_start_date, access_end_date, access_days_before_num, session_admin_id, visibility, |
||
547 | * session_category_id, promotion_id, |
||
548 | * validated_user_num, waiting_user_num, |
||
549 | * extra, course) the validated_usernum and waiting_user_num are |
||
550 | * used when have the plugin for advance incsription enables. |
||
551 | * The extra data (field_name, field_value) |
||
552 | * The course data (course_id, course_code, course_title, |
||
553 | * coach_username, coach_firstname, coach_lastname). |
||
554 | * |
||
555 | * @param array $params List of parameters (id, category_name, access_url_id, secret_key) |
||
556 | * |
||
557 | * @return array|soap_fault Sessions list (id=>[title=>'title',url='http://...',date_start=>'...',date_end=>'']) |
||
558 | */ |
||
559 | public static function WSListSessionsDetailsByCategory($params) |
||
560 | { |
||
561 | global $debug; |
||
562 | |||
563 | if ($debug) { |
||
564 | error_log('WSListSessionsDetailsByCategory'); |
||
565 | error_log('Params '.print_r($params, 1)); |
||
566 | } |
||
567 | $secretKey = $params['secret_key']; |
||
568 | |||
569 | // Check if secret key is valid |
||
570 | if (!WSHelperVerifyKey($secretKey)) { |
||
571 | return return_error(WS_ERROR_SECRET_KEY); |
||
572 | } |
||
573 | |||
574 | // Check if category ID is set |
||
575 | if (!empty($params['id']) && empty($params['category_name'])) { |
||
576 | $sessionCategoryId = $params['id']; |
||
577 | } elseif (!empty($params['category_name'])) { |
||
578 | // Check if category name is set |
||
579 | $sessionCategoryId = SessionManager::getSessionCategoryIdByName($params['category_name']); |
||
580 | if (is_array($sessionCategoryId)) { |
||
581 | $sessionCategoryId = current($sessionCategoryId); |
||
582 | } |
||
583 | } else { |
||
584 | // Return soap fault Not valid input params |
||
585 | |||
586 | return return_error(WS_ERROR_INVALID_INPUT); |
||
587 | } |
||
588 | |||
589 | // Get the session List by category |
||
590 | $sessionList = SessionManager::getSessionListAndExtraByCategoryId($sessionCategoryId); |
||
591 | |||
592 | if (empty($sessionList)) { |
||
593 | // If not found any session, return error |
||
594 | |||
595 | return return_error(WS_ERROR_NOT_FOUND_RESULT); |
||
596 | } |
||
597 | |||
598 | // Get validated and waiting queue users count for each session |
||
599 | AdvancedSubscriptionPlugin::create(); |
||
600 | foreach ($sessionList as &$session) { |
||
601 | // Add validated and queue users count |
||
602 | $session['validated_user_num'] = self::$plugin->countQueueByParams( |
||
603 | [ |
||
604 | 'sessions' => [$session['id']], |
||
605 | 'status' => [ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED], |
||
606 | ] |
||
607 | ); |
||
608 | $session['waiting_user_num'] = self::$plugin->countQueueByParams( |
||
609 | [ |
||
610 | 'sessions' => [$session['id']], |
||
611 | 'status' => [ |
||
612 | ADVANCED_SUBSCRIPTION_QUEUE_STATUS_START, |
||
613 | ADVANCED_SUBSCRIPTION_QUEUE_STATUS_BOSS_APPROVED, |
||
614 | ], |
||
615 | ] |
||
616 | ); |
||
617 | } |
||
618 | |||
619 | return $sessionList; |
||
620 | } |
||
621 | |||
622 | /** |
||
623 | * Return notification content when the hook has been triggered. |
||
624 | * |
||
625 | * @return mixed (int or false) |
||
626 | */ |
||
627 | public function hookNotificationContent(HookNotificationContentEventInterface $hook) |
||
628 | { |
||
629 | $data = $hook->getEventData(); |
||
630 | if ($data['type'] === HOOK_EVENT_TYPE_PRE) { |
||
631 | $data['advanced_subscription_pre_content'] = $data['content']; |
||
632 | |||
633 | return $data; |
||
634 | } elseif ($data['type'] === HOOK_EVENT_TYPE_POST) { |
||
635 | if (isset($data['content']) && |
||
636 | !empty($data['content']) && |
||
637 | isset($data['advanced_subscription_pre_content']) && |
||
638 | !empty($data['advanced_subscription_pre_content']) |
||
639 | ) { |
||
640 | $data['content'] = str_replace( |
||
641 | [ |
||
642 | '<br /><hr>', |
||
643 | '<br />', |
||
644 | '<br/>', |
||
645 | ], |
||
646 | '', |
||
647 | $data['advanced_subscription_pre_content'] |
||
648 | ); |
||
649 | } |
||
650 | |||
651 | return $data; |
||
652 | } //Else hook type is not valid, nothing to do |
||
653 | |||
654 | return false; |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * Return the notification data title if the hook was triggered. |
||
659 | * |
||
660 | * @return array|bool |
||
661 | */ |
||
662 | public function hookNotificationTitle(HookNotificationTitleEventInterface $hook) |
||
663 | { |
||
664 | $data = $hook->getEventData(); |
||
665 | if ($data['type'] === HOOK_EVENT_TYPE_PRE) { |
||
666 | $data['advanced_subscription_pre_title'] = $data['title']; |
||
667 | |||
668 | return $data; |
||
669 | } elseif ($data['type'] === HOOK_EVENT_TYPE_POST) { |
||
670 | if (isset($data['advanced_subscription_pre_title']) && |
||
671 | !empty($data['advanced_subscription_pre_title']) |
||
672 | ) { |
||
673 | $data['title'] = $data['advanced_subscription_pre_title']; |
||
674 | } |
||
675 | |||
676 | return $data; |
||
677 | } // Else: hook type is not valid, nothing to do |
||
678 | |||
679 | return false; |
||
680 | } |
||
681 | } |
||
682 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: