ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWaitingList.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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
33abstract class ilWaitingList
34{
35 private $db = null;
36 private $obj_id = 0;
37 private $user_ids = array();
38 private $users = array();
39
40 public static $is_on_list = array();
41
42
49 public function __construct($a_obj_id)
50 {
51 global $DIC;
52
53 $ilDB = $DIC['ilDB'];
54
55 $this->db = $ilDB;
56 $this->obj_id = $a_obj_id;
57
58 $this->read();
59 }
60
65 public static function lookupListSize($a_obj_id)
66 {
67 global $DIC;
68
69 $ilDB = $DIC['ilDB'];
70
71 $query = 'SELECT count(usr_id) num from crs_waiting_list WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
72 $res = $ilDB->query($query);
73
74 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
75 return (int) $row->num;
76 }
77 return 0;
78 }
79
87 public static function _deleteAll($a_obj_id)
88 {
89 global $DIC;
90
91 $ilDB = $DIC['ilDB'];
92
93 $query = "DELETE FROM crs_waiting_list WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
94 $res = $ilDB->manipulate($query);
95
96 return true;
97 }
98
106 public static function _deleteUser($a_usr_id)
107 {
108 global $DIC;
109
110 $ilDB = $DIC['ilDB'];
111
112 $query = "DELETE FROM crs_waiting_list WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer');
113 $res = $ilDB->manipulate($query);
114
115 return true;
116 }
117
124 public static function deleteUserEntry($a_usr_id, $a_obj_id)
125 {
126 global $DIC;
127
128 $ilDB = $DIC['ilDB'];
129
130 $query = "DELETE FROM crs_waiting_list " .
131 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . ' ' .
132 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
133 $ilDB->query($query);
134 return true;
135 }
136
137
144 public function getObjId()
145 {
146 return $this->obj_id;
147 }
148
155 public function addToList($a_usr_id)
156 {
157 global $DIC;
158
159 $ilDB = $DIC['ilDB'];
160
161 if ($this->isOnList($a_usr_id)) {
162 return false;
163 }
164 $query = "INSERT INTO crs_waiting_list (obj_id,usr_id,sub_time) " .
165 "VALUES (" .
166 $ilDB->quote($this->getObjId(), 'integer') . ", " .
167 $ilDB->quote($a_usr_id, 'integer') . ", " .
168 $ilDB->quote(time(), 'integer') . " " .
169 ")";
170 $res = $ilDB->manipulate($query);
171 $this->read();
172
173 return true;
174 }
175
183 public function updateSubscriptionTime($a_usr_id, $a_subtime)
184 {
185 global $DIC;
186
187 $ilDB = $DIC['ilDB'];
188
189 $query = "UPDATE crs_waiting_list " .
190 "SET sub_time = " . $ilDB->quote($a_subtime, 'integer') . " " .
191 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
192 "AND obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
193 $res = $ilDB->manipulate($query);
194 return true;
195 }
196
204 public function removeFromList($a_usr_id)
205 {
206 global $DIC;
207
208 $ilDB = $DIC['ilDB'];
209
210 $query = "DELETE FROM crs_waiting_list " .
211 " WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " " .
212 " AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
213 $res = $ilDB->manipulate($query);
214 $this->read();
215
216 return true;
217 }
218
226 public function isOnList($a_usr_id)
227 {
228 return isset($this->users[$a_usr_id]) ? true : false;
229 }
230
239 public static function _isOnList($a_usr_id, $a_obj_id)
240 {
241 global $DIC;
242
243 $ilDB = $DIC['ilDB'];
244
245 if (isset(self::$is_on_list[$a_usr_id][$a_obj_id])) {
246 return self::$is_on_list[$a_usr_id][$a_obj_id];
247 }
248
249 $query = "SELECT usr_id " .
250 "FROM crs_waiting_list " .
251 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
252 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
253 $res = $ilDB->query($query);
254 return $res->numRows() ? true : false;
255 }
256
266 public static function _preloadOnListInfo($a_usr_ids, $a_obj_ids)
267 {
268 global $DIC;
269
270 $ilDB = $DIC['ilDB'];
271
272 if (!is_array($a_usr_ids)) {
273 $a_usr_ids = array($a_usr_ids);
274 }
275 if (!is_array($a_obj_ids)) {
276 $a_obj_ids = array($a_obj_ids);
277 }
278 foreach ($a_usr_ids as $usr_id) {
279 foreach ($a_obj_ids as $obj_id) {
280 self::$is_on_list[$usr_id][$obj_id] = false;
281 }
282 }
283 $query = "SELECT usr_id, obj_id " .
284 "FROM crs_waiting_list " .
285 "WHERE " .
286 $ilDB->in("obj_id", $a_obj_ids, false, "integer") . " AND " .
287 $ilDB->in("usr_id", $a_usr_ids, false, "integer");
288 $res = $ilDB->query($query);
289 while ($rec = $ilDB->fetchAssoc($res)) {
290 self::$is_on_list[$rec["usr_id"]][$rec["obj_id"]] = true;
291 }
292 }
293
294
301 public function getCountUsers()
302 {
303 return count($this->users);
304 }
305
313 public function getPosition($a_usr_id)
314 {
315 return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id]['position'] : -1;
316 }
317
324 public function getAllUsers()
325 {
326 return $this->users ? $this->users : array();
327 }
328
336 public function getUser($a_usr_id)
337 {
338 return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id] : false;
339 }
340
346 public function getUserIds()
347 {
348 return $this->user_ids ? $this->user_ids : array();
349 }
350
351
359 private function read()
360 {
361 global $DIC;
362
363 $ilDB = $DIC['ilDB'];
364
365 $this->users = array();
366
367 $query = "SELECT * FROM crs_waiting_list " .
368 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ORDER BY sub_time";
369
370 $res = $this->db->query($query);
371 $counter = 0;
372 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
373 ++$counter;
374 $this->users[$row->usr_id]['position'] = $counter;
375 $this->users[$row->usr_id]['time'] = $row->sub_time;
376 $this->users[$row->usr_id]['usr_id'] = $row->usr_id;
377
378 $this->user_ids[] = $row->usr_id;
379 }
380 return true;
381 }
382}
An exception for terminatinating execution or to throw for unit testing.
Base class for course and group waiting lists.
static _deleteUser($a_usr_id)
Delete user.
read()
Read waiting list.
getUserIds()
Get all user ids of users on waiting list.
isOnList($a_usr_id)
check if is on waiting list
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
removeFromList($a_usr_id)
remove usr from list
addToList($a_usr_id)
add to list
updateSubscriptionTime($a_usr_id, $a_subtime)
update subscription time
getCountUsers()
get number of users
static _isOnList($a_usr_id, $a_obj_id)
Check if a user on the waiting list.
static _deleteAll($a_obj_id)
delete all
getAllUsers()
get all users on waiting list
static _preloadOnListInfo($a_usr_ids, $a_obj_ids)
Preload on list info.
getPosition($a_usr_id)
get position
static lookupListSize($a_obj_id)
Lookup waiting lit size.
__construct($a_obj_id)
Constructor.
getUser($a_usr_id)
get user
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46