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