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