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