ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public $ilErr;
16 public $ilDB;
17 public $tree;
18 public $lng;
19
20 protected $registered = array();
21 protected $participated = array();
22
23 public $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 public function setUserId($a_usr_id)
42 {
43 $this->user_id = $a_usr_id;
44 }
45 public function getUserId()
46 {
47 return $this->user_id;
48 }
49 public function setMark($a_mark)
50 {
51 $this->mark = $a_mark;
52 }
53 public function getMark()
54 {
55 return $this->mark;
56 }
57 public function setComment($a_comment)
58 {
59 $this->comment = $a_comment;
60 }
61 public function getComment()
62 {
63 return $this->comment;
64 }
65 public function setParticipated($a_status)
66 {
67 $this->participated = $a_status;
68 }
69 public function getParticipated()
70 {
72 }
73 public function setRegistered($a_status)
74 {
75 $this->registered = $a_status;
76 }
77 public function getRegistered()
78 {
79 return $this->registered;
80 }
81 public 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()) {
113 }
114
115 return true;
116 }
117
118 public function getUser($a_usr_id)
119 {
120 return $this->participants[$a_usr_id] ? $this->participants[$a_usr_id] : array();
121 }
122
123 public function getParticipants()
124 {
125 return $this->participants ? $this->participants : array();
126 }
127
128 public function isRegistered($a_usr_id)
129 {
130 return $this->participants[$a_usr_id]['registered'] ? true : false;
131 }
132
133 public function hasParticipated($a_usr_id)
134 {
135 return $this->participants[$a_usr_id]['participated'] ? true : false;
136 }
137
138 public function updateParticipation($a_usr_id, $a_status)
139 {
140 ilEventParticipants::_updateParticipation($a_usr_id, $this->getEventId(), $a_status);
141 }
142
143 public static function _updateParticipation($a_usr_id, $a_event_id, $a_status)
144 {
145 global $ilDB;
146
147 $query = "SELECT * FROM event_participants " .
148 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
149 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
150 $res = $ilDB->query($query);
151 if ($res->numRows()) {
152 $query = "UPDATE event_participants " .
153 "SET participated = " . $ilDB->quote($a_status, 'integer') . " " .
154 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
155 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
156 $res = $ilDB->manipulate($query);
157 } else {
158 $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
159 "VALUES( " .
160 $ilDB->quote(0, 'integer') . ", " .
161 $ilDB->quote($a_status, 'integer') . ", " .
162 $ilDB->quote($a_event_id, 'integer') . ", " .
163 $ilDB->quote($a_usr_id, 'integer') . " " .
164 ")";
165 $res = $ilDB->manipulate($query);
166 }
167
168 // refresh learning progress status after updating participant
169 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
170 ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
171
172 return true;
173 }
174
175 public static function _getRegistered($a_event_id)
176 {
177 global $ilDB;
178
179 $query = "SELECT * FROM event_participants " .
180 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
181 "AND registered = " . $ilDB->quote(1, 'integer');
182 $res = $ilDB->query($query);
183 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
184 $user_ids[] = $row->usr_id;
185 }
186 return $user_ids ? $user_ids : array();
187 }
188
189 public static function _getParticipated($a_event_id)
190 {
191 global $ilDB;
192
193 $query = "SELECT * FROM event_participants " .
194 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
195 "AND participated = 1";
196 $res = $ilDB->query($query);
197 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
198 $user_ids[] = $row->usr_id;
199 }
200 return $user_ids ? $user_ids : array();
201 }
202
203 public static function _hasParticipated($a_usr_id, $a_event_id)
204 {
205 global $ilDB;
206
207 $query = "SELECT participated FROM event_participants " .
208 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
209 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
210 $res = $ilDB->query($query);
211 if ($rec = $ilDB->fetchAssoc($res)) {
212 return (bool) $rec["participated"];
213 }
214 return false;
215 }
216
217 public static function _isRegistered($a_usr_id, $a_event_id)
218 {
219 global $ilDB;
220
221 $query = "SELECT * FROM event_participants " .
222 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
223 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
224 $res = $ilDB->query($query);
225 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
226 return (bool) $row->registered;
227 }
228 return false;
229 }
230
231 public static function _register($a_usr_id, $a_event_id)
232 {
233 global $ilDB;
234
235 $query = "SELECT * FROM event_participants " .
236 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
237 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
238 $res = $ilDB->query($query);
239 if ($res->numRows()) {
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 } else {
246 $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
247 "VALUES( " .
248 "1, " .
249 "0, " .
250 $ilDB->quote($a_event_id, 'integer') . ", " .
251 $ilDB->quote($a_usr_id, 'integer') . " " .
252 ")";
253 $res = $ilDB->manipulate($query);
254 }
255
256 // refresh learning progress status after updating participant
257 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
258 ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
259
260 return true;
261 }
262 public function register($a_usr_id)
263 {
264 return ilEventParticipants::_register($a_usr_id, $this->getEventId());
265 }
266
267 public static function _unregister($a_usr_id, $a_event_id)
268 {
269 global $ilDB;
270
271 $query = "SELECT * FROM event_participants " .
272 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
273 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
274 $res = $ilDB->query($query);
275 if ($res->numRows()) {
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 } else {
282 $query = "INSERT INTO event_participants (registered,participated,event_id,usr_id) " .
283 "VALUES( " .
284 "0, " .
285 "0, " .
286 $ilDB->quote($a_event_id, 'integer') . ", " .
287 $ilDB->quote($a_usr_id, 'integer') . " " .
288 ")";
289 $res = $ilDB->manipulate($query);
290 }
291
292 // refresh learning progress status after updating participant
293 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
294 ilLPStatusWrapper::_updateStatus($a_event_id, $a_usr_id);
295
296 self::handleAutoFill($a_event_id);
297
298 return true;
299 }
300 public function unregister($a_usr_id)
301 {
302 return ilEventParticipants::_unregister($a_usr_id, $this->getEventId());
303 }
304
305 public static 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(ilDBConstants::FETCHMODE_OBJECT))
319 {
320 return $row->mark;
321 }
322 return '';
323 */
324 }
325
326 public 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(ilDBConstants::FETCHMODE_OBJECT))
340 {
341 return $row->e_comment;
342 }
343 return '';
344 */
345 }
346
347
348 public function getEventId()
349 {
350 return $this->event_id;
351 }
352 public function setEventId($a_event_id)
353 {
354 $this->event_id = $a_event_id;
355 }
356
357 public static 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 public static 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 public function __read()
383 {
384 global $ilDB;
385
386 $query = "SELECT * FROM event_participants " .
387 "WHERE event_id = " . $ilDB->quote($this->getEventId()) . " ";
388 $res = $this->db->query($query);
389 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
390 $this->participants[$row->usr_id]['usr_id'] = $row->usr_id;
391 $this->participants[$row->usr_id]['registered'] = $row->registered;
392 $this->participants[$row->usr_id]['participated'] = $row->participated;
393 /*
394 $this->participants[$row->usr_id]['mark'] = $row->mark;
395 $this->participants[$row->usr_id]['comment'] = $row->e_comment;
396 */
397
398 $lp_mark = new ilLPMarks($this->getEventId(), $row->usr_id);
399 $this->participants[$row->usr_id]['mark'] = $lp_mark->getMark();
400 $this->participants[$row->usr_id]['comment'] = $lp_mark->getComment();
401
402
403 if ($row->registered) {
404 $this->registered[] = $row->usr_id;
405 }
406 if ($row->participated) {
407 $this->participated[] = $row->usr_id;
408 }
409 }
410 }
411
417 protected static function handleAutoFill($a_obj_id)
418 {
419 $sess = new ilObjSession($a_obj_id, false);
420 $sess->handleAutoFill();
421 }
422}
$comment
Definition: buildRTE.php:83
An exception for terminatinating execution or to throw for unit testing.
static _updateParticipation($a_usr_id, $a_event_id, $a_status)
static _lookupMark($a_event_id, $a_usr_id)
static _isRegistered($a_usr_id, $a_event_id)
static _deleteByEvent($a_event_id)
static _hasParticipated($a_usr_id, $a_event_id)
_lookupComment($a_event_id, $a_usr_id)
static _getParticipated($a_event_id)
static _getRegistered($a_event_id)
__construct($a_event_id)
Constructor.
static _register($a_usr_id, $a_event_id)
static _unregister($a_usr_id, $a_event_id)
static handleAutoFill($a_obj_id)
Trigger auto-fill from waiting list.
updateParticipation($a_usr_id, $a_status)
static deleteObject($a_obj_id)
Delete object.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
comment()
Definition: comment.php:2
$query
foreach($_POST as $key=> $value) $res