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