1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Event\AdminBlockEvent; |
8
|
|
|
use Chamilo\CoreBundle\Event\AbstractEvent; |
9
|
|
|
use Chamilo\CoreBundle\Event\Events; |
10
|
|
|
use Chamilo\CoreBundle\Event\NotificationContentEvent; |
11
|
|
|
use Chamilo\CoreBundle\Event\NotificationTitleEvent; |
12
|
|
|
use Chamilo\CoreBundle\Event\WSRegistrationEvent; |
13
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
14
|
|
|
|
15
|
|
|
class AdvancedSubscriptionEventSubscriber implements EventSubscriberInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @inheritDoc |
19
|
|
|
*/ |
20
|
|
|
public static function getSubscribedEvents(): array |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
Events::NOTIFICATION_CONTENT => 'onNotificationContent', |
24
|
|
|
Events::NOTIFICATION_TITLE => 'onNotificationTitle', |
25
|
|
|
|
26
|
|
|
Events::WS_REGISTRATION => 'onWSRegistration', |
27
|
|
|
|
28
|
|
|
Events::ADMIN_BLOCK => 'onAdminBlock', |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function onNotificationContent(NotificationContentEvent $event): void |
33
|
|
|
{ |
34
|
|
|
if (!AdvancedSubscriptionPlugin::create()->isEnabled(true)) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$data = $event->getData(); |
39
|
|
|
|
40
|
|
|
if (AbstractEvent::TYPE_PRE === $event->getType()) { |
41
|
|
|
$data['advanced_subscription_pre_content'] = $event->getContent(); |
42
|
|
|
|
43
|
|
|
$event->setData($data); |
44
|
|
|
} elseif (AbstractEvent::TYPE_POST === $event->getType()) { |
45
|
|
|
if (!empty($event->getContent()) && !empty($data['advanced_subscription_pre_content'])) { |
46
|
|
|
$content = str_replace( |
47
|
|
|
[ |
48
|
|
|
'<br /><hr>', |
49
|
|
|
'<br />', |
50
|
|
|
'<br/>', |
51
|
|
|
], |
52
|
|
|
'', |
53
|
|
|
$data['advanced_subscription_pre_content'] |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$event->setContent($content); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function onNotificationTitle(NotificationTitleEvent $event): void |
62
|
|
|
{ |
63
|
|
|
if (!AdvancedSubscriptionPlugin::create()->isEnabled(true)) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$data = $event->getData(); |
68
|
|
|
|
69
|
|
|
if (AbstractEvent::TYPE_PRE === $event->getType()) { |
70
|
|
|
$data['advanced_subscription_pre_title'] = $event->getTitle(); |
71
|
|
|
|
72
|
|
|
$event->setData($data); |
73
|
|
|
} elseif (AbstractEvent::TYPE_POST === $event->getType() |
74
|
|
|
&& !empty($data['advanced_subscription_pre_title']) |
75
|
|
|
) { |
76
|
|
|
$event->setTitle($data['advanced_subscription_pre_title']); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function onWSRegistration(WSRegistrationEvent $event): void |
81
|
|
|
{ |
82
|
|
|
if (!AdvancedSubscriptionPlugin::create()->isEnabled(true)) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (AbstractEvent::TYPE_POST === $event->getType()) { |
87
|
|
|
$server = $event->getServer(); |
88
|
|
|
|
89
|
|
|
/** WSSessionListInCategory */ |
90
|
|
|
|
91
|
|
|
// Output params for sessionBriefList WSSessionListInCategory |
92
|
|
|
$server->wsdl->addComplexType( |
93
|
|
|
'sessionBrief', |
94
|
|
|
'complexType', |
95
|
|
|
'struct', |
96
|
|
|
'all', |
97
|
|
|
'', |
98
|
|
|
[ |
99
|
|
|
// session.id |
100
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:int'], |
101
|
|
|
// session.name |
102
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], |
103
|
|
|
// session.short_description |
104
|
|
|
'short_description' => ['name' => 'short_description', 'type' => 'xsd:string'], |
105
|
|
|
// session.mode |
106
|
|
|
'mode' => ['name' => 'mode', 'type' => 'xsd:string'], |
107
|
|
|
// session.date_start |
108
|
|
|
'date_start' => ['name' => 'date_start', 'type' => 'xsd:string'], |
109
|
|
|
// session.date_end |
110
|
|
|
'date_end' => ['name' => 'date_end', 'type' => 'xsd:string'], |
111
|
|
|
// session.human_text_duration |
112
|
|
|
'human_text_duration' => ['name' => 'human_text_duration', 'type' => 'xsd:string'], |
113
|
|
|
// session.vacancies |
114
|
|
|
'vacancies' => ['name' => 'vacancies', 'type' => 'xsd:string'], |
115
|
|
|
// session.schedule |
116
|
|
|
'schedule' => ['name' => 'schedule', 'type' => 'xsd:string'], |
117
|
|
|
] |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
//Output params for WSSessionListInCategory |
121
|
|
|
$server->wsdl->addComplexType( |
122
|
|
|
'sessionBriefList', |
123
|
|
|
'complexType', |
124
|
|
|
'array', |
125
|
|
|
'', |
126
|
|
|
'SOAP-ENC:Array', |
127
|
|
|
[], |
128
|
|
|
[ |
129
|
|
|
['ref' => 'SOAP-ENC:arrayType', |
130
|
|
|
'wsdl:arrayType' => 'tns:sessionBrief[]', ], |
131
|
|
|
], |
132
|
|
|
'tns:sessionBrief' |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
// Input params for WSSessionListInCategory |
136
|
|
|
$server->wsdl->addComplexType( |
137
|
|
|
'sessionCategoryInput', |
138
|
|
|
'complexType', |
139
|
|
|
'struct', |
140
|
|
|
'all', |
141
|
|
|
'', |
142
|
|
|
[ |
143
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], // session_category.id |
144
|
|
|
'name' => ['name' => 'name', 'type' => 'xsd:string'], // session_category.name |
145
|
|
|
'target' => ['name' => 'target', 'type' => 'xsd:string'], // session.target |
146
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
147
|
|
|
] |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
// Input params for WSSessionGetDetailsByUser |
151
|
|
|
$server->wsdl->addComplexType( |
152
|
|
|
'advsubSessionDetailInput', |
153
|
|
|
'complexType', |
154
|
|
|
'struct', |
155
|
|
|
'all', |
156
|
|
|
'', |
157
|
|
|
[ |
158
|
|
|
// user_field_values.value |
159
|
|
|
'user_id' => ['name' => 'user_id', 'type' => 'xsd:int'], |
160
|
|
|
// user_field.user_id |
161
|
|
|
'user_field' => ['name' => 'user_field', 'type' => 'xsd:string'], |
162
|
|
|
// session.id |
163
|
|
|
'session_id' => ['name' => 'session_id', 'type' => 'xsd:int'], |
164
|
|
|
// user.profile_completes |
165
|
|
|
'profile_completed' => ['name' => 'profile_completed', 'type' => 'xsd:float'], |
166
|
|
|
// user.is_connected |
167
|
|
|
'is_connected' => ['name' => 'is_connected', 'type' => 'xsd:boolean'], |
168
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
169
|
|
|
] |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
// Output params for WSSessionGetDetailsByUser |
173
|
|
|
$server->wsdl->addComplexType( |
174
|
|
|
'advsubSessionDetail', |
175
|
|
|
'complexType', |
176
|
|
|
'struct', |
177
|
|
|
'all', |
178
|
|
|
'', |
179
|
|
|
[ |
180
|
|
|
// session.id |
181
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], |
182
|
|
|
// session.code |
183
|
|
|
'code' => ['name' => 'code', 'type' => 'xsd:string'], |
184
|
|
|
// session.place |
185
|
|
|
'cost' => ['name' => 'cost', 'type' => 'xsd:float'], |
186
|
|
|
// session.place |
187
|
|
|
'place' => ['name' => 'place', 'type' => 'xsd:string'], |
188
|
|
|
// session.allow_visitors |
189
|
|
|
'allow_visitors' => ['name' => 'allow_visitors', 'type' => 'xsd:string'], |
190
|
|
|
// session.teaching_hours |
191
|
|
|
'teaching_hours' => ['name' => 'teaching_hours', 'type' => 'xsd:int'], |
192
|
|
|
// session.brochure |
193
|
|
|
'brochure' => ['name' => 'brochure', 'type' => 'xsd:string'], |
194
|
|
|
// session.banner |
195
|
|
|
'banner' => ['name' => 'banner', 'type' => 'xsd:string'], |
196
|
|
|
// session.description |
197
|
|
|
'description' => ['name' => 'description', 'type' => 'xsd:string'], |
198
|
|
|
// status |
199
|
|
|
'status' => ['name' => 'status', 'type' => 'xsd:string'], |
200
|
|
|
// action_url |
201
|
|
|
'action_url' => ['name' => 'action_url', 'type' => 'xsd:string'], |
202
|
|
|
// message |
203
|
|
|
'message' => ['name' => 'error_message', 'type' => 'xsd:string'], |
204
|
|
|
] |
205
|
|
|
); |
206
|
|
|
|
207
|
|
|
/** WSListSessionsDetailsByCategory */ |
208
|
|
|
|
209
|
|
|
// Input params for WSListSessionsDetailsByCategory |
210
|
|
|
$server->wsdl->addComplexType( |
211
|
|
|
'listSessionsDetailsByCategory', |
212
|
|
|
'complexType', |
213
|
|
|
'struct', |
214
|
|
|
'all', |
215
|
|
|
'', |
216
|
|
|
[ |
217
|
|
|
// session_category.id |
218
|
|
|
'id' => ['name' => 'id', 'type' => 'xsd:string'], |
219
|
|
|
// session_category.access_url_id |
220
|
|
|
'access_url_id' => ['name' => 'access_url_id', 'type' => 'xsd:int'], |
221
|
|
|
// session_category.name |
222
|
|
|
'category_name' => ['name' => 'category_name', 'type' => 'xsd:string'], |
223
|
|
|
// secret key |
224
|
|
|
'secret_key' => ['name' => 'secret_key', 'type' => 'xsd:string'], |
225
|
|
|
], |
226
|
|
|
[], |
227
|
|
|
'tns:listSessionsDetailsByCategory' |
228
|
|
|
); |
229
|
|
|
|
230
|
|
|
// Output params for sessionDetailsCourseList WSListSessionsDetailsByCategory |
231
|
|
|
$server->wsdl->addComplexType( |
232
|
|
|
'sessionDetailsCourse', |
233
|
|
|
'complexType', |
234
|
|
|
'struct', |
235
|
|
|
'all', |
236
|
|
|
'', |
237
|
|
|
[ |
238
|
|
|
'course_id' => ['name' => 'course_id', 'type' => 'xsd:int'], // course.id |
239
|
|
|
'course_code' => ['name' => 'course_code', 'type' => 'xsd:string'], // course.code |
240
|
|
|
'course_title' => ['name' => 'course_title', 'type' => 'xsd:string'], // course.title |
241
|
|
|
'coach_username' => ['name' => 'coach_username', 'type' => 'xsd:string'], // user.username |
242
|
|
|
'coach_firstname' => ['name' => 'coach_firstname', 'type' => 'xsd:string'], // user.firstname |
243
|
|
|
'coach_lastname' => ['name' => 'coach_lastname', 'type' => 'xsd:string'], // user.lastname |
244
|
|
|
] |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
// Output array for sessionDetails WSListSessionsDetailsByCategory |
248
|
|
|
$server->wsdl->addComplexType( |
249
|
|
|
'sessionDetailsCourseList', |
250
|
|
|
'complexType', |
251
|
|
|
'array', |
252
|
|
|
'', |
253
|
|
|
'SOAP-ENC:Array', |
254
|
|
|
[], |
255
|
|
|
[ |
256
|
|
|
[ |
257
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
258
|
|
|
'wsdl:arrayType' => 'tns:sessionDetailsCourse[]', |
259
|
|
|
], |
260
|
|
|
], |
261
|
|
|
'tns:sessionDetailsCourse' |
262
|
|
|
); |
263
|
|
|
|
264
|
|
|
// Output params for sessionDetailsList WSListSessionsDetailsByCategory |
265
|
|
|
$server->wsdl->addComplexType( |
266
|
|
|
'sessionDetails', |
267
|
|
|
'complexType', |
268
|
|
|
'struct', |
269
|
|
|
'all', |
270
|
|
|
'', |
271
|
|
|
[ |
272
|
|
|
// session.id |
273
|
|
|
'id' => [ |
274
|
|
|
'name' => 'id', |
275
|
|
|
'type' => 'xsd:int', |
276
|
|
|
], |
277
|
|
|
// session.id_coach |
278
|
|
|
'coach_id' => [ |
279
|
|
|
'name' => 'coach_id', |
280
|
|
|
'type' => 'xsd:int', |
281
|
|
|
], |
282
|
|
|
// session.name |
283
|
|
|
'name' => [ |
284
|
|
|
'name' => 'name', |
285
|
|
|
'type' => 'xsd:string', |
286
|
|
|
], |
287
|
|
|
// session.nbr_courses |
288
|
|
|
'courses_num' => [ |
289
|
|
|
'name' => 'courses_num', |
290
|
|
|
'type' => 'xsd:int', |
291
|
|
|
], |
292
|
|
|
// session.nbr_users |
293
|
|
|
'users_num' => [ |
294
|
|
|
'name' => 'users_num', |
295
|
|
|
'type' => 'xsd:int', |
296
|
|
|
], |
297
|
|
|
// session.nbr_classes |
298
|
|
|
'classes_num' => [ |
299
|
|
|
'name' => 'classes_num', |
300
|
|
|
'type' => 'xsd:int', |
301
|
|
|
], |
302
|
|
|
// session.date_start |
303
|
|
|
'date_start' => [ |
304
|
|
|
'name' => 'date_start', |
305
|
|
|
'type' => 'xsd:string', |
306
|
|
|
], |
307
|
|
|
// session.date_end |
308
|
|
|
'date_end' => [ |
309
|
|
|
'name' => 'date_end', |
310
|
|
|
'type' => 'xsd:string', |
311
|
|
|
], |
312
|
|
|
// session.nb_days_access_before_beginning |
313
|
|
|
'access_days_before_num' => [ |
314
|
|
|
'name' => 'access_days_before_num', |
315
|
|
|
'type' => 'xsd:int', |
316
|
|
|
], |
317
|
|
|
// session.nb_days_access_after_end |
318
|
|
|
'access_days_after_num' => [ |
319
|
|
|
'name' => 'access_days_after_num', |
320
|
|
|
'type' => 'xsd:int', |
321
|
|
|
], |
322
|
|
|
// session.session_admin_id |
323
|
|
|
'session_admin_id' => [ |
324
|
|
|
'name' => 'session_admin_id', |
325
|
|
|
'type' => 'xsd:int', |
326
|
|
|
], |
327
|
|
|
// session.visibility |
328
|
|
|
'visibility' => [ |
329
|
|
|
'name' => 'visibility', |
330
|
|
|
'type' => 'xsd:int', |
331
|
|
|
], |
332
|
|
|
// session.session_category_id |
333
|
|
|
'session_category_id' => [ |
334
|
|
|
'name' => 'session_category_id', |
335
|
|
|
'type' => 'xsd:int', |
336
|
|
|
], |
337
|
|
|
// session.promotion_id |
338
|
|
|
'promotion_id' => [ |
339
|
|
|
'name' => 'promotion_id', |
340
|
|
|
'type' => 'xsd:int', |
341
|
|
|
], |
342
|
|
|
// session.number of registered users validated |
343
|
|
|
'validated_user_num' => [ |
344
|
|
|
'name' => 'validated_user_num', |
345
|
|
|
'type' => 'xsd:int', |
346
|
|
|
], |
347
|
|
|
// session.number of registered users from waiting queue |
348
|
|
|
'waiting_user_num' => [ |
349
|
|
|
'name' => 'waiting_user_num', |
350
|
|
|
'type' => 'xsd:int', |
351
|
|
|
], |
352
|
|
|
// extra fields |
353
|
|
|
// Array(field_name, field_value) |
354
|
|
|
'extra' => [ |
355
|
|
|
'name' => 'extra', |
356
|
|
|
'type' => 'tns:extrasList', |
357
|
|
|
], |
358
|
|
|
// course and coaches data |
359
|
|
|
// Array(course_id, course_code, course_title, coach_username, coach_firstname, coach_lastname) |
360
|
|
|
'course' => [ |
361
|
|
|
'name' => 'courses', |
362
|
|
|
'type' => 'tns:sessionDetailsCourseList', |
363
|
|
|
], |
364
|
|
|
] |
365
|
|
|
); |
366
|
|
|
|
367
|
|
|
// Output params for WSListSessionsDetailsByCategory |
368
|
|
|
$server->wsdl->addComplexType( |
369
|
|
|
'sessionDetailsList', |
370
|
|
|
'complexType', |
371
|
|
|
'array', |
372
|
|
|
'', |
373
|
|
|
'SOAP-ENC:Array', |
374
|
|
|
[], |
375
|
|
|
[ |
376
|
|
|
[ |
377
|
|
|
'ref' => 'SOAP-ENC:arrayType', |
378
|
|
|
'wsdl:arrayType' => 'tns:sessionDetails[]', |
379
|
|
|
], |
380
|
|
|
], |
381
|
|
|
'tns:sessionDetails' |
382
|
|
|
); |
383
|
|
|
|
384
|
|
|
// Register the method for WSSessionListInCategory |
385
|
|
|
$server->register( |
386
|
|
|
'HookAdvancedSubscription..WSSessionListInCategory', // method name |
387
|
|
|
['sessionCategoryInput' => 'tns:sessionCategoryInput'], // input parameters |
388
|
|
|
['return' => 'tns:sessionBriefList'], // output parameters |
389
|
|
|
'urn:WSRegistration', // namespace |
390
|
|
|
'urn:WSRegistration#WSSessionListInCategory', // soapaction |
391
|
|
|
'rpc', // style |
392
|
|
|
'encoded', // use |
393
|
|
|
'This service checks if user assigned to course' // documentation |
394
|
|
|
); |
395
|
|
|
|
396
|
|
|
// Register the method for WSSessionGetDetailsByUser |
397
|
|
|
$server->register( |
398
|
|
|
'HookAdvancedSubscription..WSSessionGetDetailsByUser', // method name |
399
|
|
|
['advsubSessionDetailInput' => 'tns:advsubSessionDetailInput'], // input parameters |
400
|
|
|
['return' => 'tns:advsubSessionDetail'], // output parameters |
401
|
|
|
'urn:WSRegistration', // namespace |
402
|
|
|
'urn:WSRegistration#WSSessionGetDetailsByUser', // soapaction |
403
|
|
|
'rpc', // style |
404
|
|
|
'encoded', // use |
405
|
|
|
'This service return session details to specific user' // documentation |
406
|
|
|
); |
407
|
|
|
|
408
|
|
|
// Register the method for WSListSessionsDetailsByCategory |
409
|
|
|
$server->register( |
410
|
|
|
'HookAdvancedSubscription..WSListSessionsDetailsByCategory', // method name |
411
|
|
|
['name' => 'tns:listSessionsDetailsByCategory'], // input parameters |
412
|
|
|
['return' => 'tns:sessionDetailsList'], // output parameters |
413
|
|
|
'urn:WSRegistration', // namespace |
414
|
|
|
'urn:WSRegistration#WSListSessionsDetailsByCategory', // soapaction |
415
|
|
|
'rpc', // style |
416
|
|
|
'encoded', // use |
417
|
|
|
'This service returns a list of detailed sessions by a category' // documentation |
418
|
|
|
); |
419
|
|
|
|
420
|
|
|
$event->setServer($server); |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
public function onAdminBlock(AdminBlockEvent $event): void |
425
|
|
|
{ |
426
|
|
|
$plugin = AdvancedSubscriptionPlugin::create(); |
427
|
|
|
|
428
|
|
|
if (!$plugin->isEnabled(true)) { |
429
|
|
|
return; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
if (AbstractEvent::TYPE_POST === $event->getType()) { |
433
|
|
|
$item = [ |
434
|
|
|
'url' => '../../plugin/advanced_subscription/src/admin_view.php', |
435
|
|
|
'label' => $plugin->get_lang('plugin_title'), |
436
|
|
|
]; |
437
|
|
|
|
438
|
|
|
$event->setItems('sessions', [$item]); |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
|