ILIAS  Release_4_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  +-----------------------------------------------------------------------------+
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() ,'integer')." ".
100  "AND usr_id = ".$ilDB->quote($this->getUserId() ,'integer')." ";
101  $res = $ilDB->manipulate($query);
102 
103  $query = "INSERT INTO event_participants (event_id,usr_id,registered,participated,mark,e_comment) ".
104  "VALUES( ".
105  $ilDB->quote($this->getEventId() ,'integer').", ".
106  $ilDB->quote($this->getUserId() ,'integer').", ".
107  $ilDB->quote($this->getRegistered() ,'integer').", ".
108  $ilDB->quote($this->getParticipated() ,'integer').", ".
109  $ilDB->quote($this->getMark() ,'text').", ".
110  $ilDB->quote($this->getComment() ,'text')." ".
111  ")";
112  $res = $ilDB->manipulate($query);
113  return true;
114  }
115 
116  function getUser($a_usr_id)
117  {
118  return $this->participants[$a_usr_id] ? $this->participants[$a_usr_id] : array();
119  }
120 
121  function getParticipants()
122  {
123  return $this->participants ? $this->participants : array();
124  }
125 
126  function isRegistered($a_usr_id)
127  {
128  return $this->participants[$a_usr_id]['registered'] ? true : false;
129  }
130 
131  function hasParticipated($a_usr_id)
132  {
133  return $this->participants[$a_usr_id]['participated'] ? true : false;
134  }
135 
136  function updateParticipation($a_usr_id,$a_status)
137  {
138  ilEventParticipants::_updateParticipation($a_usr_id,$this->getEventId(),$a_status);
139  }
140 
141  function _updateParticipation($a_usr_id,$a_event_id,$a_status)
142  {
143  global $ilDB;
144 
145  $query = "SELECT * FROM event_participants ".
146  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
147  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
148  $res = $ilDB->query($query);
149  if($res->numRows())
150  {
151  $query = "UPDATE event_participants ".
152  "SET participated = ".$ilDB->quote($a_status ,'integer')." ".
153  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
154  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
155  $res = $ilDB->manipulate($query);
156  }
157  else
158  {
159  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) ".
160  "VALUES( ".
161  $ilDB->quote(0 ,'integer').", ".
162  $ilDB->quote($a_status ,'integer').", ".
163  $ilDB->quote($a_event_id ,'integer').", ".
164  $ilDB->quote($a_usr_id ,'integer')." ".
165  ")";
166  $res = $ilDB->manipulate($query);
167  }
168  return true;
169  }
170 
171  function _getRegistered($a_event_id)
172  {
173  global $ilDB;
174 
175  $query = "SELECT * FROM event_participants ".
176  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
177  "AND registered = ".$ilDB->quote(1 ,'integer');
178  $res = $ilDB->query($query);
179  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
180  {
181  $user_ids[] = $row->usr_id;
182  }
183  return $user_ids ? $user_ids : array();
184  }
185 
186  function _getParticipated($a_event_id)
187  {
188  global $ilDB;
189 
190  $query = "SELECT * FROM event_participants ".
191  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
192  "AND participated = 1";
193  $res = $ilDB->query($query);
194  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
195  {
196  $user_ids[] = $row->usr_id;
197  }
198  return $user_ids ? $user_ids : array();
199  }
200 
201  public static function _isRegistered($a_usr_id,$a_event_id)
202  {
203  global $ilDB;
204 
205  $query = "SELECT * FROM event_participants ".
206  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
207  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
208  $res = $ilDB->query($query);
209  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
210  {
211  return (bool) $row->registered;
212  }
213  return false;
214  }
215 
216  function _register($a_usr_id,$a_event_id)
217  {
218  global $ilDB;
219 
220  $query = "SELECT * FROM event_participants ".
221  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
222  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
223  $res = $ilDB->query($query);
224  if($res->numRows())
225  {
226  $query = "UPDATE event_participants ".
227  "SET registered = '1' ".
228  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
229  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
230  $res = $ilDB->manipulate($query);
231  }
232  else
233  {
234  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) ".
235  "VALUES( ".
236  "1, ".
237  "0, ".
238  $ilDB->quote($a_event_id ,'integer').", ".
239  $ilDB->quote($a_usr_id ,'integer')." ".
240  ")";
241  $res = $ilDB->manipulate($query);
242  }
243  return true;
244  }
245  function register($a_usr_id)
246  {
247  return ilEventParticipants::_register($a_usr_id,$this->getEventId());
248  }
249 
250  function _unregister($a_usr_id,$a_event_id)
251  {
252  global $ilDB;
253 
254  $query = "SELECT * FROM event_participants ".
255  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
256  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
257  $res = $ilDB->query($query);
258  if($res->numRows())
259  {
260  $query = "UPDATE event_participants ".
261  "SET registered = 0 ".
262  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
263  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
264  $res = $ilDB->manipulate($query);
265  }
266  else
267  {
268  $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) ".
269  "VALUES( ".
270  "0, ".
271  "0, ".
272  $ilDB->quote($a_event_id ,'integer').", ".
273  $ilDB->quote($a_usr_id ,'integer')." ".
274  ")";
275  $res = $ilDB->manipulate($query);
276  }
277  return true;
278  }
279  function unregister($a_usr_id)
280  {
281  return ilEventParticipants::_unregister($a_usr_id,$this->getEventId());
282  }
283 
284  function _lookupMark($a_event_id,$a_usr_id)
285  {
286  global $ilDB;
287 
288  $query = "SELECT * FROM event_participants ".
289  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
290  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
291  $res = $ilDB->query($query);
292  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
293  {
294  return $row->mark;
295  }
296  return '';
297  }
298 
299  function _lookupComment($a_event_id,$a_usr_id)
300  {
301  global $ilDB;
302 
303  $query = "SELECT * FROM event_participants ".
304  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
305  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
306  $res = $ilDB->query($query);
307  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
308  {
309  return $row->e_comment;
310  }
311  return '';
312  }
313 
314 
315  function getEventId()
316  {
317  return $this->event_id;
318  }
319  function setEventId($a_event_id)
320  {
321  $this->event_id = $a_event_id;
322  }
323 
324  function _deleteByEvent($a_event_id)
325  {
326  global $ilDB;
327 
328  $query = "DELETE FROM event_participants ".
329  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ";
330  $res = $ilDB->manipulate($query);
331  return true;
332  }
333  function _deleteByUser($a_usr_id)
334  {
335  global $ilDB;
336 
337  $query = "DELETE FROM event_participants ".
338  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
339  $res = $ilDB->manipulate($query);
340  return true;
341  }
342 
343 
344  // Private
345  function __read()
346  {
347  global $ilDB;
348 
349  $query = "SELECT * FROM event_participants ".
350  "WHERE event_id = ".$ilDB->quote($this->getEventId())." ";
351  $res = $this->db->query($query);
352  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
353  {
354  $this->participants[$row->usr_id]['usr_id'] = $row->usr_id;
355  $this->participants[$row->usr_id]['registered'] = $row->registered;
356  $this->participants[$row->usr_id]['participated'] = $row->participated;
357  $this->participants[$row->usr_id]['mark'] = $row->mark;
358  $this->participants[$row->usr_id]['comment'] = $row->e_comment;
359  }
360  }
361 }
362 ?>