ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilEventParticipants.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
14 {
15  public $ilErr;
16  public $ilDB;
17  public $tree;
18  public $lng;
19 
20  protected $contact = 0;
21 
25  protected $registered = [];
26 
30  protected $participated = [];
31 
35  protected $excused = [];
36 
40  protected $contacts = [];
41 
42  public $event_id = null;
43 
48 
53  public function __construct($a_event_id)
54  {
55  global $DIC;
56 
57  $ilErr = $DIC['ilErr'];
58  $ilDB = $DIC->database();
59  $lng = $DIC->language();
60  $tree = $DIC->repositoryTree();
61 
62  $this->ilErr = $ilErr;
63  $this->db = $ilDB;
64  $this->lng = $lng;
65 
66  $this->event_id = $a_event_id;
67  $this->__read();
68  }
69 
70  public function setUserId($a_usr_id)
71  {
72  $this->user_id = $a_usr_id;
73  }
74  public function getUserId()
75  {
76  return $this->user_id;
77  }
78  public function setMark($a_mark)
79  {
80  $this->mark = $a_mark;
81  }
82  public function getMark()
83  {
84  return $this->mark;
85  }
86  public function setComment($a_comment)
87  {
88  $this->comment = $a_comment;
89  }
90  public function getComment()
91  {
92  return $this->comment;
93  }
94  public function setParticipated($a_status)
95  {
96  $this->participated = $a_status;
97  }
98  public function getParticipated()
99  {
100  return $this->participated;
101  }
102  public function setRegistered($a_status)
103  {
104  $this->registered = $a_status;
105  }
106  public function getRegistered()
107  {
108  return $this->registered;
109  }
110 
114  public function setExcused(bool $a_stat)
115  {
116  $this->excused = $a_stat;
117  }
118 
122  public function getExcused() : bool
123  {
124  return $this->excused;
125  }
126 
127 
133  public function updateExcusedForUser(int $a_usr_id, bool $a_status)
134  {
135  if (!is_array($this->participants) || !array_key_exists($a_usr_id, $this->participants)) {
136  $event_part = new \ilEventParticipants($this->event_id);
137  $event_part->setUserId($a_usr_id);
138  $event_part->setMark('');
139  $event_part->setComment('');
140  $event_part->setNotificationEnabled(false);
141  $event_part->setParticipated(false);
142  $event_part->setRegistered(false);
143  $event_part->setContact(false);
144  $event_part->setExcused($a_status);
145  $event_part->updateUser();
146  return;
147  }
148 
149  $query = 'update event_participants set excused = ' . $this->db->quote($a_status, \ilDBConstants::T_INTEGER) . ' ' .
150  'where event_id = ' . $this->db->quote($this->event_id, \ilDBConstants::T_INTEGER) . ' and ' .
151  'usr_id = ' . $this->db->quote($a_usr_id, \ilDBConstants::T_INTEGER);
152  $this->db->manipulate($query);
153  return;
154  }
155 
159  public function setContact($a_status)
160  {
161  $this->contact = (int) $a_status;
162  }
163 
167  public function getContact()
168  {
169  return $this->contact;
170  }
171 
175  public function isNotificationEnabled()
176  {
177  return (bool) $this->notificationEnabled;
178  }
179 
183  public function setNotificationEnabled($value)
184  {
185  $this->notificationEnabled = (bool) $value;
186  }
187 
188  public function updateUser()
189  {
190  global $DIC;
191 
192  $ilDB = $DIC['ilDB'];
193 
194  $query = "DELETE FROM event_participants " .
195  "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " " .
196  "AND usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " ";
197  $res = $ilDB->manipulate($query);
198 
199  $query = "INSERT INTO event_participants (event_id,usr_id,registered,participated,contact,notification_enabled, excused " .
200  ") VALUES( " .
201  $ilDB->quote($this->getEventId(), 'integer') . ", " .
202  $ilDB->quote($this->getUserId(), 'integer') . ", " .
203  $ilDB->quote($this->getRegistered(), 'integer') . ", " .
204  $ilDB->quote($this->getParticipated(), 'integer') . ', ' .
205  $ilDB->quote($this->getContact(), 'integer') . ', ' .
206  $ilDB->quote($this->isNotificationEnabled(), 'integer') . ', ' .
207  $ilDB->quote((int) $this->getExcused(), 'integer') .
208  ")";
209  $res = $ilDB->manipulate($query);
210 
211  include_once "Services/Tracking/classes/class.ilLPMarks.php";
212  $lp_mark = new ilLPMarks($this->getEventId(), $this->getUserId());
213  $lp_mark->setComment($this->getComment());
214  $lp_mark->setMark($this->getMark());
215  $lp_mark->update();
216 
217  // refresh learning progress status after updating participant
218  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
220 
221  if (!$this->getRegistered()) {
222  self::handleAutoFill($this->getEventId());
223  }
224 
225  return true;
226  }
227 
228  public function getUser($a_usr_id)
229  {
230  return $this->participants[$a_usr_id] ? $this->participants[$a_usr_id] : array();
231  }
232 
233  public function getParticipants()
234  {
235  return $this->participants ? $this->participants : array();
236  }
237 
238  public function isRegistered($a_usr_id)
239  {
240  return $this->participants[$a_usr_id]['registered'] ? true : false;
241  }
242 
243  public function hasParticipated($a_usr_id)
244  {
245  return $this->participants[$a_usr_id]['participated'] ? true : false;
246  }
247 
252  public function isExcused(int $a_usr_id) : bool
253  {
254  return $this->participants[$a_usr_id]['excused'] ? true : false;
255  }
256 
263  public function isContact($a_usr_id)
264  {
265  return $this->participants[$a_usr_id]['contact'] ? true : false;
266  }
267 
268 
269  public function updateParticipation($a_usr_id, $a_status)
270  {
271  ilEventParticipants::_updateParticipation($a_usr_id, $this->getEventId(), $a_status);
272  }
273 
274  public static function _updateParticipation($a_usr_id, $a_event_id, $a_status)
275  {
276  global $DIC;
277 
278  $ilDB = $DIC['ilDB'];
279 
280  $query = "SELECT * FROM event_participants " .
281  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
282  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
283  $res = $ilDB->query($query);
284  if ($res->numRows()) {
285  $query = "UPDATE event_participants " .
286  "SET participated = " . $ilDB->quote($a_status, 'integer') . " " .
287  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
288  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
289  $res = $ilDB->manipulate($query);
290  } else {
291  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
292  "VALUES( " .
293  $ilDB->quote(0, 'integer') . ", " .
294  $ilDB->quote($a_status, 'integer') . ", " .
295  $ilDB->quote($a_event_id, 'integer') . ", " .
296  $ilDB->quote($a_usr_id, 'integer') . " " .
297  ")";
298  $res = $ilDB->manipulate($query);
299  }
300 
301  // refresh learning progress status after updating participant
302  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
303  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
304 
305  return true;
306  }
307 
308  public static function _getRegistered($a_event_id)
309  {
310  global $DIC;
311 
312  $ilDB = $DIC['ilDB'];
313 
314  $query = "SELECT * FROM event_participants " .
315  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
316  "AND registered = " . $ilDB->quote(1, 'integer');
317  $res = $ilDB->query($query);
318  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
319  $user_ids[] = $row->usr_id;
320  }
321  return $user_ids ? $user_ids : array();
322  }
323 
324  public static function _getParticipated($a_event_id)
325  {
326  global $DIC;
327 
328  $ilDB = $DIC['ilDB'];
329 
330  $query = "SELECT * FROM event_participants " .
331  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
332  "AND participated = 1";
333  $res = $ilDB->query($query);
334  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
335  $user_ids[$row->usr_id] = $row->usr_id;
336  }
337  return $user_ids ? $user_ids : array();
338  }
339 
340  public static function _hasParticipated($a_usr_id, $a_event_id)
341  {
342  global $DIC;
343 
344  $ilDB = $DIC['ilDB'];
345 
346  $query = "SELECT participated FROM event_participants " .
347  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
348  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
349  $res = $ilDB->query($query);
350  if ($rec = $ilDB->fetchAssoc($res)) {
351  return (bool) $rec["participated"];
352  }
353  return false;
354  }
355 
356  public static function _isRegistered($a_usr_id, $a_event_id)
357  {
358  global $DIC;
359 
360  $ilDB = $DIC['ilDB'];
361 
362  $query = "SELECT * FROM event_participants " .
363  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
364  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
365  $res = $ilDB->query($query);
366  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
367  return (bool) $row->registered;
368  }
369  return false;
370  }
371 
372  public static function _register($a_usr_id, $a_event_id)
373  {
374  global $DIC;
375 
376  $ilDB = $DIC['ilDB'];
377 
378  $query = "SELECT * FROM event_participants " .
379  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
380  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
381  $res = $ilDB->query($query);
382  if ($res->numRows()) {
383  $query = "UPDATE event_participants " .
384  "SET registered = '1' " .
385  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
386  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
387  $res = $ilDB->manipulate($query);
388  } else {
389  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
390  "VALUES( " .
391  "1, " .
392  "0, " .
393  $ilDB->quote($a_event_id, 'integer') . ", " .
394  $ilDB->quote($a_usr_id, 'integer') . " " .
395  ")";
396  $res = $ilDB->manipulate($query);
397  }
398 
399  // refresh learning progress status after updating participant
400  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
401  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
402 
403  return true;
404  }
405  public function register($a_usr_id)
406  {
407  return ilEventParticipants::_register($a_usr_id, $this->getEventId());
408  }
409 
410  public static function _unregister($a_usr_id, $a_event_id)
411  {
412  global $DIC;
413 
414  $ilDB = $DIC['ilDB'];
415 
416  $query = "SELECT * FROM event_participants " .
417  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
418  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
419  $res = $ilDB->query($query);
420  if ($res->numRows()) {
421  $query = "UPDATE event_participants " .
422  "SET registered = 0 " .
423  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
424  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
425  $res = $ilDB->manipulate($query);
426  } else {
427  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
428  "VALUES( " .
429  "0, " .
430  "0, " .
431  $ilDB->quote($a_event_id, 'integer') . ", " .
432  $ilDB->quote($a_usr_id, 'integer') . " " .
433  ")";
434  $res = $ilDB->manipulate($query);
435  }
436 
437  // refresh learning progress status after updating participant
438  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
439  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
440 
441  self::handleAutoFill($a_event_id);
442 
443  return true;
444  }
445  public function unregister($a_usr_id)
446  {
447  return ilEventParticipants::_unregister($a_usr_id, $this->getEventId());
448  }
449 
450  public static function _lookupMark($a_event_id, $a_usr_id)
451  {
452  include_once "Services/Tracking/classes/class.ilLPMarks.php";
453  $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
454  return $lp_mark->getMark();
455  }
456 
457  public function _lookupComment($a_event_id, $a_usr_id)
458  {
459  include_once "Services/Tracking/classes/class.ilLPMarks.php";
460  $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
461  return $lp_mark->getComment();
462  }
463 
464 
465  public function getEventId()
466  {
467  return $this->event_id;
468  }
469  public function setEventId($a_event_id)
470  {
471  $this->event_id = $a_event_id;
472  }
473 
474  public static function _deleteByEvent($a_event_id)
475  {
476  global $DIC;
477 
478  $ilDB = $DIC['ilDB'];
479 
480  $query = "DELETE FROM event_participants " .
481  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
482  $res = $ilDB->manipulate($query);
483 
484  include_once "Services/Tracking/classes/class.ilLPMarks.php";
485  ilLPMarks::deleteObject($a_event_id);
486 
487  return true;
488  }
489  public static function _deleteByUser($a_usr_id)
490  {
491  global $DIC;
492 
493  $ilDB = $DIC['ilDB'];
494 
495  $query = "DELETE FROM event_participants " .
496  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
497  $res = $ilDB->manipulate($query);
498  return true;
499  }
500 
501 
502  // Private
503  public function __read()
504  {
505  global $DIC;
506 
507  $ilDB = $DIC['ilDB'];
508 
509  $query = "SELECT * FROM event_participants " .
510  "WHERE event_id = " . $ilDB->quote($this->getEventId()) . " ";
511  $res = $this->db->query($query);
512 
513  global $DIC;
514  $tree = $DIC->repositoryTree();
515 
516  $parentRecipients = [];
517  $parentParticipants = [];
519  $refIdArray = array_values(ilObject::_getAllReferences($this->event_id));
520  if (true === $session->isRegistrationNotificationEnabled()) {
521  if (ilSessionConstants::NOTIFICATION_INHERIT_OPTION === $session->getRegistrationNotificationOption()) {
522  $parentRefId = $tree->checkForParentType($refIdArray[0], 'grp');
523  if (!$parentRefId) {
524  $parentRefId = $tree->checkForParentType($refIdArray[0], 'crs');
525  }
526  if ($parentRefId) {
527  $participants = \ilParticipants::getInstance($parentRefId);
528  $parentRecipients = $participants->getNotificationRecipients();
529  $parentParticipants = $participants->getParticipants();
530  }
531  }
532  }
533  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
534  $this->participants[$row->usr_id]['usr_id'] = $row->usr_id;
535  $this->participants[$row->usr_id]['registered'] = $row->registered;
536  $this->participants[$row->usr_id]['participated'] = $row->participated;
537  $this->participants[$row->usr_id]['excused'] = $row->excused;
538  $this->participants[$row->usr_id]['contact'] = $row->contact;
539 
540  $lp_mark = new ilLPMarks($this->getEventId(), $row->usr_id);
541  $this->participants[$row->usr_id]['mark'] = $lp_mark->getMark();
542  $this->participants[$row->usr_id]['comment'] = $lp_mark->getComment();
543  $this->participants[$row->usr_id]['notification_enabled'] = false;
544  if (in_array($row->usr_id, $parentRecipients)) {
545  $this->participants[$row->usr_id]['notification_enabled'] = true;
546  }
547 
548  if ($row->registered) {
549  $this->registered[] = $row->usr_id;
550  }
551  if ($row->participated) {
552  $this->participated[] = $row->usr_id;
553  }
554  }
555  // add defaults for parent participants
556  foreach ($parentParticipants as $usr_id) {
557  if (isset($this->participants[$usr_id])) {
558  continue;
559  }
560  $this->participants[$usr_id]['usr_id'] = $usr_id;
561  $this->participants[$usr_id]['registered'] = false;
562  $this->participants[$usr_id]['participated'] = false;
563  $this->participants[$usr_id]['excused'] = false;
564  $this->participants[$usr_id]['contact'] = false;
565  $lp_mark = new ilLPMarks($this->getEventId(), $usr_id);
566  $this->participants[$usr_id]['mark'] = $lp_mark->getMark();
567  $this->participants[$usr_id]['comment'] = $lp_mark->getComment();
568  $this->participants[$usr_id]['notification_enabled'] = false;
569  if (in_array($usr_id, $parentRecipients)) {
570  $this->participants[$usr_id]['notification_enabled'] = true;
571  }
572 
573  }
574  }
575 
581  protected static function handleAutoFill($a_obj_id)
582  {
583  $sess = new ilObjSession($a_obj_id, false);
584  $sess->handleAutoFill();
585  }
586 }
static _getRegistered($a_event_id)
static _getParticipated($a_event_id)
updateParticipation($a_usr_id, $a_status)
static _unregister($a_usr_id, $a_event_id)
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
$session
static _lookupMark($a_event_id, $a_usr_id)
static _isRegistered($a_usr_id, $a_event_id)
static _getAllReferences($a_id)
get all reference ids of object
static _hasParticipated($a_usr_id, $a_event_id)
static getInstance($a_ref_id)
Get instance by ref_id.
foreach($_POST as $key=> $value) $res
comment()
Definition: comment.php:2
global $DIC
Definition: goto.php:24
isContact($a_usr_id)
Check if user is contact.
static _register($a_usr_id, $a_event_id)
$query
static _deleteByEvent($a_event_id)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$comment
Definition: buildRTE.php:83
_lookupComment($a_event_id, $a_usr_id)
static handleAutoFill($a_obj_id)
Trigger auto-fill from waiting list.
static deleteObject($a_obj_id)
Delete object.
updateExcusedForUser(int $a_usr_id, bool $a_status)
Update excused status.
__construct($a_event_id)
Constructor.
static _updateParticipation($a_usr_id, $a_event_id, $a_status)