ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilEventParticipants.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 protected ilDBInterface $db;
31 protected ilTree $tree;
32 protected int $contact = 0;
33 protected bool $registered = false;
34 protected bool $participated = false;
35 protected bool $excused = false;
36 protected int $event_id = 0;
37 protected bool $notificationEnabled = false;
38 protected int $user_id = 0;
39 protected string $mark = "";
40 protected string $comment = "";
41 protected array $participants = [];
42 protected array $participants_registered = [];
43 protected array $participants_participated = [];
44
45 public function __construct(int $a_event_id)
46 {
47 global $DIC;
48
49 $this->db = $DIC->database();
50 $this->tree = $DIC->repositoryTree();
51 $this->event_id = $a_event_id;
52 $this->__read();
53 }
54
55 public function setUserId(int $a_usr_id): void
56 {
57 $this->user_id = $a_usr_id;
58 }
59
60 public function getUserId(): int
61 {
62 return $this->user_id;
63 }
64
65 public function setMark(string $a_mark): void
66 {
67 $this->mark = $a_mark;
68 }
69
70 public function getMark(): string
71 {
72 return $this->mark;
73 }
74
75 public function setComment(string $a_comment): void
76 {
77 $this->comment = $a_comment;
78 }
79
80 public function getComment(): string
81 {
82 return $this->comment;
83 }
84
85 public function setParticipated(bool $a_status)
86 {
87 $this->participated = $a_status;
88 }
89
90 public function getParticipated(): bool
91 {
93 }
94
95 public function setRegistered(bool $a_status): void
96 {
97 $this->registered = $a_status;
98 }
99
100 public function getRegistered(): bool
101 {
102 return $this->registered;
103 }
104
105 public function setExcused(bool $a_stat): void
106 {
107 $this->excused = $a_stat;
108 }
109
110 public function getExcused(): bool
111 {
112 return $this->excused;
113 }
114
115 public function getEventId(): int
116 {
117 return $this->event_id;
118 }
119
120 public function setEventId(int $a_event_id): void
121 {
122 $this->event_id = $a_event_id;
123 }
124
125 public function setContact(bool $a_status): void
126 {
127 $this->contact = (int) $a_status;
128 }
129
130 public function getContact(): int
131 {
132 return $this->contact;
133 }
134
135 public function isNotificationEnabled(): bool
136 {
138 }
139
140 public function setNotificationEnabled(bool $value): void
141 {
142 $this->notificationEnabled = $value;
143 }
144
146 {
147 $this->participants_participated = $participants_participated;
148 }
149 public function getParticipatedParticipants(): array
150 {
152 }
153 public function setRegisteredParticipants(array $registered_participants): void
154 {
155 $this->participants_registered = $registered_participants;
156 }
157 public function getRegisteredParticipants(): array
158 {
160 }
161
162 public function updateExcusedForUser(int $a_usr_id, bool $a_status): void
163 {
164 if (!array_key_exists($a_usr_id, $this->participants)) {
165 $event_part = new \ilEventParticipants($this->event_id);
166 $event_part->setUserId($a_usr_id);
167 $event_part->setMark('');
168 $event_part->setComment('');
169 $event_part->setNotificationEnabled(false);
170 $event_part->setParticipated(false);
171 $event_part->setRegistered(false);
172 $event_part->setContact(false);
173 $event_part->setExcused($a_status);
174 $event_part->updateUser();
175 return;
176 }
177
178 $query = 'update event_participants set excused = ' . $this->db->quote($a_status, \ilDBConstants::T_INTEGER) . ' ' .
179 'where event_id = ' . $this->db->quote($this->event_id, \ilDBConstants::T_INTEGER) . ' and ' .
180 'usr_id = ' . $this->db->quote($a_usr_id, \ilDBConstants::T_INTEGER);
181 $this->db->manipulate($query);
182 }
183
184 public function updateUser(): bool
185 {
187
188 $query = "DELETE FROM event_participants " .
189 "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " " .
190 "AND usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " ";
191 $res = $ilDB->manipulate($query);
192
193 $query = "INSERT INTO event_participants (event_id,usr_id,registered,participated,contact,notification_enabled, excused " .
194 ") VALUES( " .
195 $ilDB->quote($this->getEventId(), 'integer') . ", " .
196 $ilDB->quote($this->getUserId(), 'integer') . ", " .
197 $ilDB->quote((int) $this->getRegistered(), 'integer') . ", " .
198 $ilDB->quote((int) $this->getParticipated(), 'integer') . ', ' .
199 $ilDB->quote($this->getContact(), 'integer') . ', ' .
200 $ilDB->quote((int) $this->isNotificationEnabled(), 'integer') . ', ' .
201 $ilDB->quote((int) $this->getExcused(), 'integer') .
202 ")";
203 $res = $ilDB->manipulate($query);
204
205 $lp_mark = new ilLPMarks($this->getEventId(), $this->getUserId());
206 $lp_mark->setComment($this->getComment());
207 $lp_mark->setMark($this->getMark());
208 $lp_mark->update();
209
210 // refresh learning progress status after updating participant
212 return true;
213 }
214
215 public function getUser(int $a_usr_id): array
216 {
217 return $this->participants[$a_usr_id] ?? [];
218 }
219
220 public function getParticipants(): array
221 {
222 return $this->participants;
223 }
224
225 public function isRegistered(int $a_usr_id): bool
226 {
227 return (bool) ($this->participants[$a_usr_id]['registered'] ?? false);
228 }
229
230 public function hasParticipated(int $a_usr_id): bool
231 {
232 return (bool) ($this->participants[$a_usr_id]['participated'] ?? false);
233 }
234
235 public function isExcused(int $a_usr_id): bool
236 {
237 return (bool) ($this->participants[$a_usr_id]['excused'] ?? false);
238 }
239
240 public function isContact(int $a_usr_id): bool
241 {
242 return (bool) ($this->participants[$a_usr_id]['contact'] ?? false);
243 }
244
245
246 public function updateParticipation(int $a_usr_id, bool $a_status): bool
247 {
248 return self::_updateParticipation($a_usr_id, $this->getEventId(), $a_status);
249 }
250
251 public static function _updateParticipation(int $a_usr_id, int $a_event_id, bool $a_status): bool
252 {
253 global $DIC;
254
255 $ilDB = $DIC->database();
256
257 $query = "SELECT * FROM event_participants " .
258 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
259 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
260 $res = $ilDB->query($query);
261 if ($res->numRows()) {
262 $query = "UPDATE event_participants " .
263 "SET participated = " . $ilDB->quote((int) $a_status, 'integer') . " " .
264 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
265 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
266 } else {
267 $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
268 "VALUES( " .
269 $ilDB->quote(0, 'integer') . ", " .
270 $ilDB->quote((int) $a_status, 'integer') . ", " .
271 $ilDB->quote($a_event_id, 'integer') . ", " .
272 $ilDB->quote($a_usr_id, 'integer') . " " .
273 ")";
274 }
275 $res = $ilDB->manipulate($query);
276
277 // refresh learning progress status after updating participant
278 ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
279
280 return true;
281 }
282
283 public static function _getRegistered(int $a_event_id): array
284 {
285 global $DIC;
286
287 $ilDB = $DIC->database();
288
289 $query = "SELECT * FROM event_participants " .
290 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
291 "AND registered = " . $ilDB->quote(1, 'integer');
292 $res = $ilDB->query($query);
293 $user_ids = [];
294 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
295 $user_ids[] = $row->usr_id;
296 }
297 return $user_ids;
298 }
299
300 public static function _getParticipated(int $a_event_id): array
301 {
302 global $DIC;
303
304 $ilDB = $DIC->database();
305
306 $query = "SELECT * FROM event_participants " .
307 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
308 "AND participated = 1";
309 $res = $ilDB->query($query);
310 $user_ids = [];
311 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
312 $user_ids[$row->usr_id] = $row->usr_id;
313 }
314 return $user_ids;
315 }
316
317 public static function _hasParticipated(int $a_usr_id, int $a_event_id): bool
318 {
319 global $DIC;
320
321 $ilDB = $DIC->database();
322
323 $query = "SELECT participated FROM event_participants " .
324 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
325 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
326 $res = $ilDB->query($query);
327 if ($rec = $ilDB->fetchAssoc($res)) {
328 return (bool) $rec["participated"];
329 }
330 return false;
331 }
332
333 public static function _isRegistered(int $a_usr_id, int $a_event_id): bool
334 {
335 global $DIC;
336
337 $ilDB = $DIC->database();
338
339 $query = "SELECT * FROM event_participants " .
340 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
341 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
342 $res = $ilDB->query($query);
343 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
344 return (bool) $row->registered;
345 }
346 return false;
347 }
348
349 public static function _register(int $a_usr_id, int $a_event_id): bool
350 {
351 global $DIC;
352
353 $ilDB = $DIC->database();
354
355 $query = "SELECT * FROM event_participants " .
356 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
357 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
358 $res = $ilDB->query($query);
359 if ($res->numRows()) {
360 $query = "UPDATE event_participants " .
361 "SET registered = '1' " .
362 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
363 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
364 } else {
365 $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
366 "VALUES( " .
367 "1, " .
368 "0, " .
369 $ilDB->quote($a_event_id, 'integer') . ", " .
370 $ilDB->quote($a_usr_id, 'integer') . " " .
371 ")";
372 }
373 $res = $ilDB->manipulate($query);
374
375 // refresh learning progress status after updating participant
376 ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
377
378 return true;
379 }
380
381 public function register(int $a_usr_id): bool
382 {
383 return ilEventParticipants::_register($a_usr_id, $this->getEventId());
384 }
385
386 public static function _unregister(int $a_usr_id, int $a_event_id): bool
387 {
388 global $DIC;
389
390 $ilDB = $DIC->database();
391
392 $query = "SELECT * FROM event_participants " .
393 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
394 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
395 $res = $ilDB->query($query);
396 if ($res->numRows()) {
397 $query = "UPDATE event_participants " .
398 "SET registered = 0 " .
399 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
400 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
401 } else {
402 $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
403 "VALUES( " .
404 "0, " .
405 "0, " .
406 $ilDB->quote($a_event_id, 'integer') . ", " .
407 $ilDB->quote($a_usr_id, 'integer') . " " .
408 ")";
409 }
410 $res = $ilDB->manipulate($query);
411
412 // refresh learning progress status after updating participant
413 ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
414 return true;
415 }
416
417 public function unregister(int $a_usr_id): bool
418 {
419 return self::_unregister($a_usr_id, $this->getEventId());
420 }
421
422 public static function _lookupMark(int $a_event_id, int $a_usr_id): string
423 {
424 $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
425 return $lp_mark->getMark();
426 }
427
428 public function _lookupComment(int $a_event_id, int $a_usr_id): string
429 {
430 $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
431 return $lp_mark->getComment();
432 }
433
434 public static function _deleteByEvent(int $a_event_id): bool
435 {
436 global $DIC;
437
438 $ilDB = $DIC->database();
439
440 $query = "DELETE FROM event_participants " .
441 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
442 $res = $ilDB->manipulate($query);
443
444 ilLPMarks::deleteObject($a_event_id);
445
446 return true;
447 }
448
449 public static function _deleteByUser(int $a_usr_id): bool
450 {
451 global $DIC;
452
453 $ilDB = $DIC->database();
454
455 $query = "DELETE FROM event_participants " .
456 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
457 $res = $ilDB->manipulate($query);
458
459 return true;
460 }
461
462 protected function __read(): void
463 {
464 global $DIC;
465
468
469 $query = "SELECT * FROM event_participants " .
470 "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " ";
471 $res = $this->db->query($query);
472
473 $parentRecipients = [];
474 $parentParticipants = [];
475 $session = ilObjectFactory::getInstanceByObjId($this->event_id);
476 $refIdArray = array_values(ilObject::_getAllReferences($this->event_id));
477 if (true === $session->isRegistrationNotificationEnabled()) {
478 if (ilSessionConstants::NOTIFICATION_INHERIT_OPTION === $session->getRegistrationNotificationOption()) {
479 $parentRefId = $tree->checkForParentType($refIdArray[0], 'grp');
480 if (!$parentRefId) {
481 $parentRefId = $tree->checkForParentType($refIdArray[0], 'crs');
482 }
483 if ($parentRefId) {
485 $parentRecipients = $participants->getNotificationRecipients();
486 $parentParticipants = $participants->getParticipants();
487 }
488 }
489 }
490 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
491 $this->participants[(int) $row->usr_id]['usr_id'] = (int) $row->usr_id;
492 $this->participants[(int) $row->usr_id]['registered'] = (bool) $row->registered;
493 $this->participants[(int) $row->usr_id]['participated'] = (bool) $row->participated;
494 $this->participants[(int) $row->usr_id]['excused'] = (bool) $row->excused;
495 $this->participants[(int) $row->usr_id]['contact'] = (bool) $row->contact;
496
497 $lp_mark = new ilLPMarks($this->getEventId(), (int) $row->usr_id);
498 $this->participants[(int) $row->usr_id]['mark'] = $lp_mark->getMark();
499 $this->participants[(int) $row->usr_id]['comment'] = $lp_mark->getComment();
500
501 if (
502 $session->isRegistrationNotificationEnabled() &&
503 $session->getRegistrationNotificationOption() === ilSessionConstants::NOTIFICATION_MANUAL_OPTION
504 ) {
505 $this->participants[(int) $row->usr_id]['notification_enabled'] = (bool) $row->notification_enabled;
506 } elseif (in_array((int) $row->usr_id, $parentRecipients)) {
507 $this->participants[(int) $row->usr_id]['notification_enabled'] = true;
508 } else {
509 $this->participants[(int) $row->usr_id]['notification_enabled'] = false;
510 }
511 if ($row->registered) {
512 $this->participants_registered[] = (int) $row->usr_id;
513 }
514 if ($row->participated) {
515 $this->participants_participated[] = (int) $row->usr_id;
516 }
517 }
518 // add defaults for parent participants
519 foreach ($parentParticipants as $usr_id) {
520 if (isset($this->participants[$usr_id])) {
521 continue;
522 }
523 $this->participants[$usr_id]['usr_id'] = (int) $usr_id;
524 $this->participants[$usr_id]['registered'] = false;
525 $this->participants[$usr_id]['participated'] = false;
526 $this->participants[$usr_id]['excused'] = false;
527 $this->participants[$usr_id]['contact'] = false;
528 $lp_mark = new ilLPMarks($this->getEventId(), $usr_id);
529 $this->participants[$usr_id]['mark'] = $lp_mark->getMark();
530 $this->participants[$usr_id]['comment'] = $lp_mark->getComment();
531 $this->participants[$usr_id]['notification_enabled'] = false;
532 if (in_array($usr_id, $parentRecipients)) {
533 $this->participants[$usr_id]['notification_enabled'] = true;
534 }
535 }
536 }
537}
class ilEventParticipants
setRegisteredParticipants(array $registered_participants)
static _isRegistered(int $a_usr_id, int $a_event_id)
_lookupComment(int $a_event_id, int $a_usr_id)
setParticipatedParticipants(array $participants_participated)
static _deleteByUser(int $a_usr_id)
static _lookupMark(int $a_event_id, int $a_usr_id)
static _unregister(int $a_usr_id, int $a_event_id)
updateExcusedForUser(int $a_usr_id, bool $a_status)
static _updateParticipation(int $a_usr_id, int $a_event_id, bool $a_status)
static _register(int $a_usr_id, int $a_event_id)
static _getParticipated(int $a_event_id)
static _deleteByEvent(int $a_event_id)
static _getRegistered(int $a_event_id)
static _hasParticipated(int $a_usr_id, int $a_event_id)
updateParticipation(int $a_usr_id, bool $a_status)
static deleteObject(int $a_obj_id)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _getAllReferences(int $id)
get all reference ids for object ID
static getInstance(int $a_ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
checkForParentType(int $a_ref_id, string $a_type, bool $a_exclude_source_check=false)
Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentTyp...
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26