ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
52
53 $this->db = $ilDB;
54 $this->obj_id = $a_obj_id;
55
56 $this->read();
57 }
58
63 public static function lookupListSize($a_obj_id)
64 {
65 global $ilDB;
66
67 $query = 'SELECT count(usr_id) num from crs_waiting_list WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
68 $res = $ilDB->query($query);
69
70 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
71 return (int) $row->num;
72 }
73 return 0;
74 }
75
83 public static function _deleteAll($a_obj_id)
84 {
85 global $ilDB;
86
87 $query = "DELETE FROM crs_waiting_list WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
88 $res = $ilDB->manipulate($query);
89
90 return true;
91 }
92
100 public static function _deleteUser($a_usr_id)
101 {
102 global $ilDB;
103
104 $query = "DELETE FROM crs_waiting_list WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer');
105 $res = $ilDB->manipulate($query);
106
107 return true;
108 }
109
116 public static function deleteUserEntry($a_usr_id, $a_obj_id)
117 {
118 global $ilDB;
119
120 $query = "DELETE FROM crs_waiting_list " .
121 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . ' ' .
122 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
123 $ilDB->query($query);
124 return true;
125 }
126
127
134 public function getObjId()
135 {
136 return $this->obj_id;
137 }
138
145 public function addToList($a_usr_id)
146 {
147 global $ilDB;
148
149 if ($this->isOnList($a_usr_id)) {
150 return false;
151 }
152 $query = "INSERT INTO crs_waiting_list (obj_id,usr_id,sub_time) " .
153 "VALUES (" .
154 $ilDB->quote($this->getObjId(), 'integer') . ", " .
155 $ilDB->quote($a_usr_id, 'integer') . ", " .
156 $ilDB->quote(time(), 'integer') . " " .
157 ")";
158 $res = $ilDB->manipulate($query);
159 $this->read();
160
161 return true;
162 }
163
171 public function updateSubscriptionTime($a_usr_id, $a_subtime)
172 {
173 global $ilDB;
174
175 $query = "UPDATE crs_waiting_list " .
176 "SET sub_time = " . $ilDB->quote($a_subtime, 'integer') . " " .
177 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
178 "AND obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
179 $res = $ilDB->manipulate($query);
180 return true;
181 }
182
190 public function removeFromList($a_usr_id)
191 {
192 global $ilDB;
193
194 $query = "DELETE FROM crs_waiting_list " .
195 " WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " " .
196 " AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
197 $res = $ilDB->manipulate($query);
198 $this->read();
199
200 return true;
201 }
202
210 public function isOnList($a_usr_id)
211 {
212 return isset($this->users[$a_usr_id]) ? true : false;
213 }
214
223 public static function _isOnList($a_usr_id, $a_obj_id)
224 {
225 global $ilDB;
226
227 if (isset(self::$is_on_list[$a_usr_id][$a_obj_id])) {
228 return self::$is_on_list[$a_usr_id][$a_obj_id];
229 }
230
231 $query = "SELECT usr_id " .
232 "FROM crs_waiting_list " .
233 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
234 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
235 $res = $ilDB->query($query);
236 return $res->numRows() ? true : false;
237 }
238
248 public static function _preloadOnListInfo($a_usr_ids, $a_obj_ids)
249 {
250 global $ilDB;
251
252 if (!is_array($a_usr_ids)) {
253 $a_usr_ids = array($a_usr_ids);
254 }
255 if (!is_array($a_obj_ids)) {
256 $a_obj_ids = array($a_obj_ids);
257 }
258 foreach ($a_usr_ids as $usr_id) {
259 foreach ($a_obj_ids as $obj_id) {
260 self::$is_on_list[$usr_id][$obj_id] = false;
261 }
262 }
263 $query = "SELECT usr_id, obj_id " .
264 "FROM crs_waiting_list " .
265 "WHERE " .
266 $ilDB->in("obj_id", $a_obj_ids, false, "integer") . " AND " .
267 $ilDB->in("usr_id", $a_usr_ids, false, "integer");
268 $res = $ilDB->query($query);
269 while ($rec = $ilDB->fetchAssoc($res)) {
270 self::$is_on_list[$rec["usr_id"]][$rec["obj_id"]] = true;
271 }
272 }
273
274
281 public function getCountUsers()
282 {
283 return count($this->users);
284 }
285
293 public function getPosition($a_usr_id)
294 {
295 return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id]['position'] : -1;
296 }
297
304 public function getAllUsers()
305 {
306 return $this->users ? $this->users : array();
307 }
308
316 public function getUser($a_usr_id)
317 {
318 return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id] : false;
319 }
320
326 public function getUserIds()
327 {
328 return $this->user_ids ? $this->user_ids : array();
329 }
330
331
339 private function read()
340 {
341 global $ilDB;
342
343 $this->users = array();
344
345 $query = "SELECT * FROM crs_waiting_list " .
346 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ORDER BY sub_time";
347
348 $res = $this->db->query($query);
349 $counter = 0;
350 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
351 ++$counter;
352 $this->users[$row->usr_id]['position'] = $counter;
353 $this->users[$row->usr_id]['time'] = $row->sub_time;
354 $this->users[$row->usr_id]['usr_id'] = $row->usr_id;
355
356 $this->user_ids[] = $row->usr_id;
357 }
358 return true;
359 }
360}
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
$counter
$query
foreach($_POST as $key=> $value) $res
global $ilDB