ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilEventParticipants.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 {
35  var $ilErr;
36  var $ilDB;
37  var $tree;
38  var $lng;
39 
40  var $event_id = null;
41 
42  function ilEventParticipants($a_event_id)
43  {
44  global $ilErr,$ilDB,$lng,$tree;
45 
46  $this->ilErr =& $ilErr;
47  $this->db =& $ilDB;
48  $this->lng =& $lng;
49 
50  $this->event_id = $a_event_id;
51  $this->__read();
52  }
53 
54  function setUserId($a_usr_id)
55  {
56  $this->user_id = $a_usr_id;
57  }
58  function getUserId()
59  {
60  return $this->user_id;
61  }
62  function setMark($a_mark)
63  {
64  $this->mark = $a_mark;
65  }
66  function getMark()
67  {
68  return $this->mark;
69  }
70  function setComment($a_comment)
71  {
72  $this->comment = $a_comment;
73  }
74  function getComment()
75  {
76  return $this->comment;
77  }
78  function setParticipated($a_status)
79  {
80  $this->participated = $a_status;
81  }
82  function getParticipated()
83  {
84  return $this->participated;
85  }
86  function setRegistered($a_status)
87  {
88  $this->registered = $a_status;
89  }
90  function getRegistered()
91  {
92  return $this->registered;
93  }
94  function updateUser()
95  {
96  global $ilDB;
97 
98  $query = "DELETE FROM event_participants ".
99  "WHERE event_id = ".$ilDB->quote($this->getEventId())." ".
100  "AND usr_id = ".$ilDB->quote($this->getUserId())." ";
101  $this->db->query($query);
102 
103  $query = "INSERT INTO event_participants ".
104  "SET event_id = ".$ilDB->quote($this->getEventId()).", ".
105  "usr_id = ".$ilDB->quote($this->getUserId()).", ".
106  "registered = ".$ilDB->quote($this->getRegistered()).", ".
107  "participated = ".$ilDB->quote($this->getParticipated()).", ".
108  "mark = ".$ilDB->quote($this->getMark()).", ".
109  "comment = ".$ilDB->quote($this->getComment())."";
110  $this->db->query($query);
111  return true;
112  }
113 
114  function getUser($a_usr_id)
115  {
116  return $this->participants[$a_usr_id] ? $this->participants[$a_usr_id] : array();
117  }
118 
119  function getParticipants()
120  {
121  return $this->participants ? $this->participants : array();
122  }
123 
124  function isRegistered($a_usr_id)
125  {
126  return $this->participants[$a_usr_id]['registered'] ? true : false;
127  }
128 
129  function hasParticipated($a_usr_id)
130  {
131  return $this->participants[$a_usr_id]['participated'] ? true : false;
132  }
133 
134  function updateParticipation($a_usr_id,$a_status)
135  {
136  ilEventParticipants::_updateParticipation($a_usr_id,$this->getEventId(),$a_status);
137  }
138 
139  function _updateParticipation($a_usr_id,$a_event_id,$a_status)
140  {
141  global $ilDB;
142 
143  $query = "SELECT * FROM event_participants ".
144  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
145  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
146  $res = $ilDB->query($query);
147  if($res->numRows())
148  {
149  $query = "UPDATE event_participants ".
150  "SET participated = ".$ilDB->quote($a_status)." ".
151  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
152  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
153  $ilDB->query($query);
154  }
155  else
156  {
157  $query = "INSERT INTO event_participants ".
158  "SET registered = '0', ".
159  "participated = ".$ilDB->quote($a_status).", ".
160  "event_id = ".$ilDB->quote($a_event_id).", ".
161  "usr_id = ".$ilDB->quote($a_usr_id)." ";
162  $ilDB->query($query);
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)." ".
173  "AND registered = '1'";
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)." ".
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  function _isRegistered($a_usr_id,$a_event_id)
198  {
199  global $ilDB;
200 
201  $query = "SELECT * FROM event_participants ".
202  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
203  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
204  $res = $ilDB->query($query);
205  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
206  {
207  return (bool) $row->registered;
208  }
209  return false;
210  }
211 
212  function _register($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)." ".
218  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
219  $res = $ilDB->query($query);
220  if($res->numRows())
221  {
222  $query = "UPDATE event_participants ".
223  "SET registered = '1' ".
224  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
225  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
226  $ilDB->query($query);
227  }
228  else
229  {
230  $query = "INSERT INTO event_participants ".
231  "SET registered = '1', ".
232  "participated = '0', ".
233  "event_id = ".$ilDB->quote($a_event_id).", ".
234  "usr_id = ".$ilDB->quote($a_usr_id)." ";
235  $ilDB->query($query);
236  }
237  return true;
238  }
239  function register($a_usr_id)
240  {
241  return ilEventParticipants::_register($a_usr_id,$this->getEventId());
242  }
243 
244  function _unregister($a_usr_id,$a_event_id)
245  {
246  global $ilDB;
247 
248  $query = "SELECT * FROM event_participants ".
249  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
250  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
251  $res = $ilDB->query($query);
252  if($res->numRows())
253  {
254  $query = "UPDATE event_participants ".
255  "SET registered = '0' ".
256  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
257  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
258  $ilDB->query($query);
259  }
260  else
261  {
262  $query = "INSERT INTO event_participants ".
263  "SET registered = '0', ".
264  "participated = '0', ".
265  "event_id = ".$ilDB->quote($a_event_id).", ".
266  "usr_id = ".$ilDB->quote($a_usr_id)." ";
267  $ilDB->query($query);
268  }
269  return true;
270  }
271  function unregister($a_usr_id)
272  {
273  return ilEventParticipants::_unregister($a_usr_id,$this->getEventId());
274  }
275 
276  function _lookupMark($a_event_id,$a_usr_id)
277  {
278  global $ilDB;
279 
280  $query = "SELECT * FROM event_participants ".
281  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
282  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
283  $res = $ilDB->query($query);
284  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
285  {
286  return $row->mark;
287  }
288  return '';
289  }
290 
291  function _lookupComment($a_event_id,$a_usr_id)
292  {
293  global $ilDB;
294 
295  $query = "SELECT * FROM event_participants ".
296  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
297  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
298  $res = $ilDB->query($query);
299  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
300  {
301  return $row->comment;
302  }
303  return '';
304  }
305 
306 
307  function getEventId()
308  {
309  return $this->event_id;
310  }
311  function setEventId($a_event_id)
312  {
313  $this->event_id = $a_event_id;
314  }
315 
316  function _deleteByEvent($a_event_id)
317  {
318  global $ilDB;
319 
320  $query = "DELETE FROM event_participants ".
321  "WHERE event_id = ".$ilDB->quote($a_event_id)." ";
322  $ilDB->query($query);
323  return true;
324  }
325  function _deleteByUser($a_usr_id)
326  {
327  global $ilDB;
328 
329  $query = "DELETE FROM event_participants ".
330  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ";
331  $ilDB->query($query);
332  return true;
333  }
334 
335 
336  // Private
337  function __read()
338  {
339  global $ilDB;
340 
341  $query = "SELECT * FROM event_participants ".
342  "WHERE event_id = ".$ilDB->quote($this->getEventId())." ";
343  $res = $this->db->query($query);
344  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
345  {
346  $this->participants[$row->usr_id]['usr_id'] = $row->usr_id;
347  $this->participants[$row->usr_id]['registered'] = $row->registered;
348  $this->participants[$row->usr_id]['participated'] = $row->participated;
349  $this->participants[$row->usr_id]['mark'] = $row->mark;
350  $this->participants[$row->usr_id]['comment'] = $row->comment;
351  }
352  }
353 }
354 ?>