ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
33 abstract class ilWaitingList
34 {
35  private $db = null;
36  private $obj_id = 0;
37  private $user_ids = array();
38  private $users = array();
39 
40  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  {
72  return (int) $row->num;
73  }
74  return 0;
75  }
76 
84  public static function _deleteAll($a_obj_id)
85  {
86  global $ilDB;
87 
88  $query = "DELETE FROM crs_waiting_list WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
89  $res = $ilDB->manipulate($query);
90 
91  return true;
92  }
93 
101  public static function _deleteUser($a_usr_id)
102  {
103  global $ilDB;
104 
105  $query = "DELETE FROM crs_waiting_list WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer');
106  $res = $ilDB->manipulate($query);
107 
108  return true;
109  }
110 
117  public static function deleteUserEntry($a_usr_id, $a_obj_id)
118  {
119  global $ilDB;
120 
121  $query = "DELETE FROM crs_waiting_list ".
122  "WHERE usr_id = ".$ilDB->quote($a_usr_id,'integer').' '.
123  "AND obj_id = ".$ilDB->quote($a_obj_id,'integer');
124  $ilDB->query($query);
125  return true;
126  }
127 
128 
135  public function getObjId()
136  {
137  return $this->obj_id;
138  }
139 
146  public function addToList($a_usr_id)
147  {
148  global $ilDB;
149 
150  if($this->isOnList($a_usr_id))
151  {
152  return false;
153  }
154  $query = "INSERT INTO crs_waiting_list (obj_id,usr_id,sub_time) ".
155  "VALUES (".
156  $ilDB->quote($this->getObjId() ,'integer').", ".
157  $ilDB->quote($a_usr_id ,'integer').", ".
158  $ilDB->quote(time() ,'integer')." ".
159  ")";
160  $res = $ilDB->manipulate($query);
161  $this->read();
162 
163  return true;
164  }
165 
173  public function updateSubscriptionTime($a_usr_id,$a_subtime)
174  {
175  global $ilDB;
176 
177  $query = "UPDATE crs_waiting_list ".
178  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
179  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
180  "AND obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ";
181  $res = $ilDB->manipulate($query);
182  return true;
183  }
184 
192  public function removeFromList($a_usr_id)
193  {
194  global $ilDB;
195 
196  $query = "DELETE FROM crs_waiting_list ".
197  " WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ".
198  " AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
199  $res = $ilDB->manipulate($query);
200  $this->read();
201 
202  return true;
203  }
204 
212  public function isOnList($a_usr_id)
213  {
214  return isset($this->users[$a_usr_id]) ? true : false;
215  }
216 
225  public static function _isOnList($a_usr_id,$a_obj_id)
226  {
227  global $ilDB;
228 
229  if (isset(self::$is_on_list[$a_usr_id][$a_obj_id]))
230  {
231  return self::$is_on_list[$a_usr_id][$a_obj_id];
232  }
233 
234  $query = "SELECT usr_id ".
235  "FROM crs_waiting_list ".
236  "WHERE obj_id = ".$ilDB->quote($a_obj_id, 'integer')." ".
237  "AND usr_id = ".$ilDB->quote($a_usr_id, 'integer');
238  $res = $ilDB->query($query);
239  return $res->numRows() ? true : false;
240  }
241 
251  static function _preloadOnListInfo($a_usr_ids, $a_obj_ids)
252  {
253  global $ilDB;
254 
255  if (!is_array($a_usr_ids))
256  {
257  $a_usr_ids = array($a_usr_ids);
258  }
259  if (!is_array($a_obj_ids))
260  {
261  $a_obj_ids = array($a_obj_ids);
262  }
263  foreach ($a_usr_ids as $usr_id)
264  {
265  foreach ($a_obj_ids as $obj_id)
266  {
267  self::$is_on_list[$usr_id][$obj_id] = false;
268  }
269  }
270  $query = "SELECT usr_id, obj_id ".
271  "FROM crs_waiting_list ".
272  "WHERE ".
273  $ilDB->in("obj_id", $a_obj_ids, false, "integer")." AND ".
274  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
275  $res = $ilDB->query($query);
276  while ($rec = $ilDB->fetchAssoc($res))
277  {
278  self::$is_on_list[$rec["usr_id"]][$rec["obj_id"]] = true;
279  }
280  }
281 
282 
289  public function getCountUsers()
290  {
291  return count($this->users);
292  }
293 
301  public function getPosition($a_usr_id)
302  {
303  return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id]['position'] : -1;
304  }
305 
312  public function getAllUsers()
313  {
314  return $this->users ? $this->users : array();
315  }
316 
324  public function getUser($a_usr_id)
325  {
326  return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id] : false;
327  }
328 
334  public function getUserIds()
335  {
336  return $this->user_ids ? $this->user_ids : array();
337  }
338 
339 
347  private function read()
348  {
349  global $ilDB;
350 
351  $this->users = array();
352 
353  $query = "SELECT * FROM crs_waiting_list ".
354  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ORDER BY sub_time";
355 
356  $res = $this->db->query($query);
357  $counter = 0;
358  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
359  {
360  ++$counter;
361  $this->users[$row->usr_id]['position'] = $counter;
362  $this->users[$row->usr_id]['time'] = $row->sub_time;
363  $this->users[$row->usr_id]['usr_id'] = $row->usr_id;
364 
365  $this->user_ids[] = $row->usr_id;
366  }
367  return true;
368  }
369 
370 }
371 ?>
updateSubscriptionTime($a_usr_id, $a_subtime)
update subscription time
Base class for course and group waiting lists.
getUser($a_usr_id)
get user
removeFromList($a_usr_id)
remove usr from list
static _deleteUser($a_usr_id)
Delete user.
static _preloadOnListInfo($a_usr_ids, $a_obj_ids)
Preload on list info.
getUserIds()
Get all user ids of users on waiting list.
getCountUsers()
get number of users
read()
Read waiting list.
$counter
getAllUsers()
get all users on waiting list
static _isOnList($a_usr_id, $a_obj_id)
Check if a user on the waiting list.
Create styles array
The data for the language used.
getPosition($a_usr_id)
get position
static lookupListSize($a_obj_id)
Lookup waiting lit size.
getObjId()
get obj id
global $ilDB
__construct($a_obj_id)
Constructor.
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
static _deleteAll($a_obj_id)
delete all
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
addToList($a_usr_id)
add to list
isOnList($a_usr_id)
check if is on waiting list