ILIAS  Release_5_0_x_branch Revision 61816
 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  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  return true;
108  }
109 
110  function getUser($a_usr_id)
111  {
112  return $this->participants[$a_usr_id] ? $this->participants[$a_usr_id] : array();
113  }
114 
115  function getParticipants()
116  {
117  return $this->participants ? $this->participants : array();
118  }
119 
120  function isRegistered($a_usr_id)
121  {
122  return $this->participants[$a_usr_id]['registered'] ? true : false;
123  }
124 
125  function hasParticipated($a_usr_id)
126  {
127  return $this->participants[$a_usr_id]['participated'] ? true : false;
128  }
129 
130  function updateParticipation($a_usr_id,$a_status)
131  {
132  ilEventParticipants::_updateParticipation($a_usr_id,$this->getEventId(),$a_status);
133  }
134 
135  function _updateParticipation($a_usr_id,$a_event_id,$a_status)
136  {
137  global $ilDB;
138 
139  $query = "SELECT * FROM event_participants ".
140  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
141  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
142  $res = $ilDB->query($query);
143  if($res->numRows())
144  {
145  $query = "UPDATE event_participants ".
146  "SET participated = ".$ilDB->quote($a_status ,'integer')." ".
147  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
148  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
149  $res = $ilDB->manipulate($query);
150  }
151  else
152  {
153  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) ".
154  "VALUES( ".
155  $ilDB->quote(0 ,'integer').", ".
156  $ilDB->quote($a_status ,'integer').", ".
157  $ilDB->quote($a_event_id ,'integer').", ".
158  $ilDB->quote($a_usr_id ,'integer')." ".
159  ")";
160  $res = $ilDB->manipulate($query);
161  }
162 
163  // refresh learning progress status after updating participant
164  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
165  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
166 
167  return true;
168  }
169 
170  function _getRegistered($a_event_id)
171  {
172  global $ilDB;
173 
174  $query = "SELECT * FROM event_participants ".
175  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
176  "AND registered = ".$ilDB->quote(1 ,'integer');
177  $res = $ilDB->query($query);
178  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
179  {
180  $user_ids[] = $row->usr_id;
181  }
182  return $user_ids ? $user_ids : array();
183  }
184 
185  function _getParticipated($a_event_id)
186  {
187  global $ilDB;
188 
189  $query = "SELECT * FROM event_participants ".
190  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
191  "AND participated = 1";
192  $res = $ilDB->query($query);
193  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
194  {
195  $user_ids[] = $row->usr_id;
196  }
197  return $user_ids ? $user_ids : array();
198  }
199 
200  public static function _hasParticipated($a_usr_id,$a_event_id)
201  {
202  global $ilDB;
203 
204  $query = "SELECT participated FROM event_participants ".
205  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
206  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
207  $res = $ilDB->query($query);
208  if ($rec = $ilDB->fetchAssoc($res))
209  {
210  return (bool) $rec["participated"];
211  }
212  return false;
213  }
214 
215  public static function _isRegistered($a_usr_id,$a_event_id)
216  {
217  global $ilDB;
218 
219  $query = "SELECT * FROM event_participants ".
220  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
221  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
222  $res = $ilDB->query($query);
223  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
224  {
225  return (bool) $row->registered;
226  }
227  return false;
228  }
229 
230  function _register($a_usr_id,$a_event_id)
231  {
232  global $ilDB;
233 
234  $query = "SELECT * FROM event_participants ".
235  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
236  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
237  $res = $ilDB->query($query);
238  if($res->numRows())
239  {
240  $query = "UPDATE event_participants ".
241  "SET registered = '1' ".
242  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
243  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
244  $res = $ilDB->manipulate($query);
245  }
246  else
247  {
248  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) ".
249  "VALUES( ".
250  "1, ".
251  "0, ".
252  $ilDB->quote($a_event_id ,'integer').", ".
253  $ilDB->quote($a_usr_id ,'integer')." ".
254  ")";
255  $res = $ilDB->manipulate($query);
256  }
257 
258  // refresh learning progress status after updating participant
259  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
260  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
261 
262  return true;
263  }
264  function register($a_usr_id)
265  {
266  return ilEventParticipants::_register($a_usr_id,$this->getEventId());
267  }
268 
269  function _unregister($a_usr_id,$a_event_id)
270  {
271  global $ilDB;
272 
273  $query = "SELECT * FROM event_participants ".
274  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
275  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
276  $res = $ilDB->query($query);
277  if($res->numRows())
278  {
279  $query = "UPDATE event_participants ".
280  "SET registered = 0 ".
281  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
282  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
283  $res = $ilDB->manipulate($query);
284  }
285  else
286  {
287  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) ".
288  "VALUES( ".
289  "0, ".
290  "0, ".
291  $ilDB->quote($a_event_id ,'integer').", ".
292  $ilDB->quote($a_usr_id ,'integer')." ".
293  ")";
294  $res = $ilDB->manipulate($query);
295  }
296 
297  // refresh learning progress status after updating participant
298  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
299  ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
300 
301  return true;
302  }
303  function unregister($a_usr_id)
304  {
305  return ilEventParticipants::_unregister($a_usr_id,$this->getEventId());
306  }
307 
308  function _lookupMark($a_event_id,$a_usr_id)
309  {
310  include_once "Services/Tracking/classes/class.ilLPMarks.php";
311  $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
312  return $lp_mark->getMark();
313 
314  /*
315  global $ilDB;
316 
317  $query = "SELECT * FROM event_participants ".
318  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
319  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
320  $res = $ilDB->query($query);
321  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
322  {
323  return $row->mark;
324  }
325  return '';
326  */
327  }
328 
329  function _lookupComment($a_event_id,$a_usr_id)
330  {
331  include_once "Services/Tracking/classes/class.ilLPMarks.php";
332  $lp_mark = new ilLPMarks($a_event_id, $a_usr_id);
333  return $lp_mark->getComment();
334 
335  /*
336  global $ilDB;
337 
338  $query = "SELECT * FROM event_participants ".
339  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
340  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
341  $res = $ilDB->query($query);
342  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
343  {
344  return $row->e_comment;
345  }
346  return '';
347  */
348  }
349 
350 
351  function getEventId()
352  {
353  return $this->event_id;
354  }
355  function setEventId($a_event_id)
356  {
357  $this->event_id = $a_event_id;
358  }
359 
360  function _deleteByEvent($a_event_id)
361  {
362  global $ilDB;
363 
364  $query = "DELETE FROM event_participants ".
365  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ";
366  $res = $ilDB->manipulate($query);
367 
368  include_once "Services/Tracking/classes/class.ilLPMarks.php";
369  ilLPMarks::deleteObject($a_event_id);
370 
371  return true;
372  }
373  function _deleteByUser($a_usr_id)
374  {
375  global $ilDB;
376 
377  $query = "DELETE FROM event_participants ".
378  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
379  $res = $ilDB->manipulate($query);
380  return true;
381  }
382 
383 
384  // Private
385  function __read()
386  {
387  global $ilDB;
388 
389  include_once "Services/Tracking/classes/class.ilLPMarks.php";
390 
391 
392 
393  $query = "SELECT * FROM event_participants ".
394  "WHERE event_id = ".$ilDB->quote($this->getEventId())." ";
395  $res = $this->db->query($query);
396  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
397  {
398  $this->participants[$row->usr_id]['usr_id'] = $row->usr_id;
399  $this->participants[$row->usr_id]['registered'] = $row->registered;
400  $this->participants[$row->usr_id]['participated'] = $row->participated;
401  /*
402  $this->participants[$row->usr_id]['mark'] = $row->mark;
403  $this->participants[$row->usr_id]['comment'] = $row->e_comment;
404  */
405 
406  $lp_mark = new ilLPMarks($this->getEventId(), $row->usr_id);
407  $this->participants[$row->usr_id]['mark'] = $lp_mark->getMark();
408  $this->participants[$row->usr_id]['comment'] = $lp_mark->getComment();
409 
410 
411  if($row->registered)
412  {
413  $this->registered[] = $row->usr_id;
414  }
415  if($row->participated)
416  {
417  $this->participated[] = $row->usr_id;
418  }
419  }
420  }
421 }
422 ?>