ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
22  protected $registered = array();
23  protected $participated = array();
24 
28  protected $contacts = [];
29 
30  public $event_id = null;
31 
36  public function __construct($a_event_id)
37  {
38  global $DIC;
39 
40  $ilErr = $DIC['ilErr'];
41  $ilDB = $DIC['ilDB'];
42  $lng = $DIC['lng'];
43  $tree = $DIC['tree'];
44 
45  $this->ilErr = $ilErr;
46  $this->db = $ilDB;
47  $this->lng = $lng;
48 
49  $this->event_id = $a_event_id;
50  $this->__read();
51  }
52 
53  public function setUserId($a_usr_id)
54  {
55  $this->user_id = $a_usr_id;
56  }
57  public function getUserId()
58  {
59  return $this->user_id;
60  }
61  public function setMark($a_mark)
62  {
63  $this->mark = $a_mark;
64  }
65  public function getMark()
66  {
67  return $this->mark;
68  }
69  public function setComment($a_comment)
70  {
71  $this->comment = $a_comment;
72  }
73  public function getComment()
74  {
75  return $this->comment;
76  }
77  public function setParticipated($a_status)
78  {
79  $this->participated = $a_status;
80  }
81  public function getParticipated()
82  {
83  return $this->participated;
84  }
85  public function setRegistered($a_status)
86  {
87  $this->registered = $a_status;
88  }
89  public function getRegistered()
90  {
91  return $this->registered;
92  }
93 
97  public function setContact($a_status)
98  {
99  $this->contact = (int) $a_status;
100  }
101 
105  public function getContact()
106  {
107  return $this->contact;
108  }
109 
110 
111  public function updateUser()
112  {
113  global $DIC;
114 
115  $ilDB = $DIC['ilDB'];
116 
117  $query = "DELETE FROM event_participants " .
118  "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " " .
119  "AND usr_id = " . $ilDB->quote($this->getUserId(), 'integer') . " ";
120  $res = $ilDB->manipulate($query);
121 
122  $query = "INSERT INTO event_participants (event_id,usr_id,registered,participated,contact " .
123  ") VALUES( " .
124  $ilDB->quote($this->getEventId(), 'integer') . ", " .
125  $ilDB->quote($this->getUserId(), 'integer') . ", " .
126  $ilDB->quote($this->getRegistered(), 'integer') . ", " .
127  $ilDB->quote($this->getParticipated(), 'integer') . ', ' .
128  $ilDB->quote($this->getContact(), 'integer') . ' ' .
129  ")";
130  $res = $ilDB->manipulate($query);
131 
132  include_once "Services/Tracking/classes/class.ilLPMarks.php";
133  $lp_mark = new ilLPMarks($this->getEventId(), $this->getUserId());
134  $lp_mark->setComment($this->getComment());
135  $lp_mark->setMark($this->getMark());
136  $lp_mark->update();
137 
138  // refresh learning progress status after updating participant
139  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
141 
142  if (!$this->getRegistered()) {
143  self::handleAutoFill($this->getEventId());
144  }
145 
146  return true;
147  }
148 
149  public function getUser($a_usr_id)
150  {
151  return $this->participants[$a_usr_id] ? $this->participants[$a_usr_id] : array();
152  }
153 
154  public function getParticipants()
155  {
156  return $this->participants ? $this->participants : array();
157  }
158 
159  public function isRegistered($a_usr_id)
160  {
161  return $this->participants[$a_usr_id]['registered'] ? true : false;
162  }
163 
164  public function hasParticipated($a_usr_id)
165  {
166  return $this->participants[$a_usr_id]['participated'] ? true : false;
167  }
168 
175  public function isContact($a_usr_id)
176  {
177  return $this->participants[$a_usr_id]['contact'] ? true : false;
178  }
179 
180 
181  public function updateParticipation($a_usr_id, $a_status)
182  {
183  ilEventParticipants::_updateParticipation($a_usr_id, $this->getEventId(), $a_status);
184  }
185 
186  public static function _updateParticipation($a_usr_id, $a_event_id, $a_status)
187  {
188  global $DIC;
189 
190  $ilDB = $DIC['ilDB'];
191 
192  $query = "SELECT * FROM event_participants " .
193  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
194  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
195  $res = $ilDB->query($query);
196  if ($res->numRows()) {
197  $query = "UPDATE event_participants " .
198  "SET participated = " . $ilDB->quote($a_status, 'integer') . " " .
199  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
200  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
201  $res = $ilDB->manipulate($query);
202  } else {
203  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
204  "VALUES( " .
205  $ilDB->quote(0, 'integer') . ", " .
206  $ilDB->quote($a_status, 'integer') . ", " .
207  $ilDB->quote($a_event_id, 'integer') . ", " .
208  $ilDB->quote($a_usr_id, 'integer') . " " .
209  ")";
210  $res = $ilDB->manipulate($query);
211  }
212 
213  // refresh learning progress status after updating participant
214  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
215  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
216 
217  return true;
218  }
219 
220  public static function _getRegistered($a_event_id)
221  {
222  global $DIC;
223 
224  $ilDB = $DIC['ilDB'];
225 
226  $query = "SELECT * FROM event_participants " .
227  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
228  "AND registered = " . $ilDB->quote(1, 'integer');
229  $res = $ilDB->query($query);
230  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
231  $user_ids[] = $row->usr_id;
232  }
233  return $user_ids ? $user_ids : array();
234  }
235 
236  public static function _getParticipated($a_event_id)
237  {
238  global $DIC;
239 
240  $ilDB = $DIC['ilDB'];
241 
242  $query = "SELECT * FROM event_participants " .
243  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
244  "AND participated = 1";
245  $res = $ilDB->query($query);
246  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
247  $user_ids[] = $row->usr_id;
248  }
249  return $user_ids ? $user_ids : array();
250  }
251 
252  public static function _hasParticipated($a_usr_id, $a_event_id)
253  {
254  global $DIC;
255 
256  $ilDB = $DIC['ilDB'];
257 
258  $query = "SELECT participated 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 ($rec = $ilDB->fetchAssoc($res)) {
263  return (bool) $rec["participated"];
264  }
265  return false;
266  }
267 
268  public static function _isRegistered($a_usr_id, $a_event_id)
269  {
270  global $DIC;
271 
272  $ilDB = $DIC['ilDB'];
273 
274  $query = "SELECT * FROM event_participants " .
275  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
276  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
277  $res = $ilDB->query($query);
278  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
279  return (bool) $row->registered;
280  }
281  return false;
282  }
283 
284  public static function _register($a_usr_id, $a_event_id)
285  {
286  global $DIC;
287 
288  $ilDB = $DIC['ilDB'];
289 
290  $query = "SELECT * FROM event_participants " .
291  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
292  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
293  $res = $ilDB->query($query);
294  if ($res->numRows()) {
295  $query = "UPDATE event_participants " .
296  "SET registered = '1' " .
297  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
298  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
299  $res = $ilDB->manipulate($query);
300  } else {
301  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
302  "VALUES( " .
303  "1, " .
304  "0, " .
305  $ilDB->quote($a_event_id, 'integer') . ", " .
306  $ilDB->quote($a_usr_id, 'integer') . " " .
307  ")";
308  $res = $ilDB->manipulate($query);
309  }
310 
311  // refresh learning progress status after updating participant
312  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
313  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
314 
315  return true;
316  }
317  public function register($a_usr_id)
318  {
319  return ilEventParticipants::_register($a_usr_id, $this->getEventId());
320  }
321 
322  public static function _unregister($a_usr_id, $a_event_id)
323  {
324  global $DIC;
325 
326  $ilDB = $DIC['ilDB'];
327 
328  $query = "SELECT * FROM event_participants " .
329  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
330  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
331  $res = $ilDB->query($query);
332  if ($res->numRows()) {
333  $query = "UPDATE event_participants " .
334  "SET registered = 0 " .
335  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
336  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
337  $res = $ilDB->manipulate($query);
338  } else {
339  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
340  "VALUES( " .
341  "0, " .
342  "0, " .
343  $ilDB->quote($a_event_id, 'integer') . ", " .
344  $ilDB->quote($a_usr_id, 'integer') . " " .
345  ")";
346  $res = $ilDB->manipulate($query);
347  }
348 
349  // refresh learning progress status after updating participant
350  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
351  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
352 
353  self::handleAutoFill($a_event_id);
354 
355  return true;
356  }
357  public function unregister($a_usr_id)
358  {
359  return ilEventParticipants::_unregister($a_usr_id, $this->getEventId());
360  }
361 
362  public static function _lookupMark($a_event_id, $a_usr_id)
363  {
364  include_once "Services/Tracking/classes/class.ilLPMarks.php";
365  $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
366  return $lp_mark->getMark();
367  }
368 
369  public function _lookupComment($a_event_id, $a_usr_id)
370  {
371  include_once "Services/Tracking/classes/class.ilLPMarks.php";
372  $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
373  return $lp_mark->getComment();
374  }
375 
376 
377  public function getEventId()
378  {
379  return $this->event_id;
380  }
381  public function setEventId($a_event_id)
382  {
383  $this->event_id = $a_event_id;
384  }
385 
386  public static function _deleteByEvent($a_event_id)
387  {
388  global $DIC;
389 
390  $ilDB = $DIC['ilDB'];
391 
392  $query = "DELETE FROM event_participants " .
393  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
394  $res = $ilDB->manipulate($query);
395 
396  include_once "Services/Tracking/classes/class.ilLPMarks.php";
397  ilLPMarks::deleteObject($a_event_id);
398 
399  return true;
400  }
401  public static function _deleteByUser($a_usr_id)
402  {
403  global $DIC;
404 
405  $ilDB = $DIC['ilDB'];
406 
407  $query = "DELETE FROM event_participants " .
408  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
409  $res = $ilDB->manipulate($query);
410  return true;
411  }
412 
413 
414  // Private
415  public function __read()
416  {
417  global $DIC;
418 
419  $ilDB = $DIC['ilDB'];
420 
421  $query = "SELECT * FROM event_participants " .
422  "WHERE event_id = " . $ilDB->quote($this->getEventId()) . " ";
423  $res = $this->db->query($query);
424  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
425  $this->participants[$row->usr_id]['usr_id'] = $row->usr_id;
426  $this->participants[$row->usr_id]['registered'] = $row->registered;
427  $this->participants[$row->usr_id]['participated'] = $row->participated;
428  $this->participants[$row->usr_id]['contact'] = $row->contact;
429 
430  $lp_mark = new ilLPMarks($this->getEventId(), $row->usr_id);
431  $this->participants[$row->usr_id]['mark'] = $lp_mark->getMark();
432  $this->participants[$row->usr_id]['comment'] = $lp_mark->getComment();
433 
434 
435  if ($row->registered) {
436  $this->registered[] = $row->usr_id;
437  }
438  if ($row->participated) {
439  $this->participated[] = $row->usr_id;
440  }
441  }
442  }
443 
449  protected static function handleAutoFill($a_obj_id)
450  {
451  $sess = new ilObjSession($a_obj_id, false);
452  $sess->handleAutoFill();
453  }
454 }
static _getRegistered($a_event_id)
static _getParticipated($a_event_id)
updateParticipation($a_usr_id, $a_status)
static _unregister($a_usr_id, $a_event_id)
global $DIC
Definition: saml.php:7
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _lookupMark($a_event_id, $a_usr_id)
static _isRegistered($a_usr_id, $a_event_id)
static _hasParticipated($a_usr_id, $a_event_id)
foreach($_POST as $key=> $value) $res
comment()
Definition: comment.php:2
isContact($a_usr_id)
Check if user is contact.
static _register($a_usr_id, $a_event_id)
$query
static _deleteByEvent($a_event_id)
$comment
Definition: buildRTE.php:83
_lookupComment($a_event_id, $a_usr_id)
$row
static handleAutoFill($a_obj_id)
Trigger auto-fill from waiting list.
static deleteObject($a_obj_id)
Delete object.
__construct($a_event_id)
Constructor.
static _updateParticipation($a_usr_id, $a_event_id, $a_status)