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