ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
66  public static function _deleteAll($a_obj_id)
67  {
68  global $ilDB;
69 
70  $query = "DELETE FROM crs_waiting_list WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
71  $res = $ilDB->manipulate($query);
72 
73  return true;
74  }
75 
83  public static function _deleteUser($a_usr_id)
84  {
85  global $ilDB;
86 
87  $query = "DELETE FROM crs_waiting_list WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer');
88  $res = $ilDB->manipulate($query);
89 
90  return true;
91  }
92 
99  public static function deleteUserEntry($a_usr_id, $a_obj_id)
100  {
101  global $ilDB;
102 
103  $query = "DELETE FROM crs_waiting_list ".
104  "WHERE usr_id = ".$ilDB->quote($a_usr_id,'integer').' '.
105  "AND obj_id = ".$ilDB->quote($a_obj_id,'integer');
106  $ilDB->query($query);
107  return true;
108  }
109 
110 
117  public function getObjId()
118  {
119  return $this->obj_id;
120  }
121 
128  public function addToList($a_usr_id)
129  {
130  global $ilDB;
131 
132  if($this->isOnList($a_usr_id))
133  {
134  return false;
135  }
136  $query = "INSERT INTO crs_waiting_list (obj_id,usr_id,sub_time) ".
137  "VALUES (".
138  $ilDB->quote($this->getObjId() ,'integer').", ".
139  $ilDB->quote($a_usr_id ,'integer').", ".
140  $ilDB->quote(time() ,'integer')." ".
141  ")";
142  $res = $ilDB->manipulate($query);
143  $this->read();
144 
145  return true;
146  }
147 
155  public function updateSubscriptionTime($a_usr_id,$a_subtime)
156  {
157  global $ilDB;
158 
159  $query = "UPDATE crs_waiting_list ".
160  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
161  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
162  "AND obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ";
163  $res = $ilDB->manipulate($query);
164  return true;
165  }
166 
174  public function removeFromList($a_usr_id)
175  {
176  global $ilDB;
177 
178  $query = "DELETE FROM crs_waiting_list ".
179  " WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ".
180  " AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
181  $res = $ilDB->manipulate($query);
182  $this->read();
183 
184  return true;
185  }
186 
194  public function isOnList($a_usr_id)
195  {
196  return isset($this->users[$a_usr_id]) ? true : false;
197  }
198 
207  public static function _isOnList($a_usr_id,$a_obj_id)
208  {
209  global $ilDB;
210 
211  if (isset(self::$is_on_list[$a_usr_id][$a_obj_id]))
212  {
213  return self::$is_on_list[$a_usr_id][$a_obj_id];
214  }
215 
216  $query = "SELECT usr_id ".
217  "FROM crs_waiting_list ".
218  "WHERE obj_id = ".$ilDB->quote($a_obj_id, 'integer')." ".
219  "AND usr_id = ".$ilDB->quote($a_usr_id, 'integer');
220  $res = $ilDB->query($query);
221  return $res->numRows() ? true : false;
222  }
223 
233  function _preloadOnListInfo($a_usr_ids, $a_obj_ids)
234  {
235  global $ilDB;
236 
237  if (!is_array($a_usr_ids))
238  {
239  $a_usr_ids = array($a_usr_ids);
240  }
241  if (!is_array($a_obj_ids))
242  {
243  $a_obj_ids = array($a_obj_ids);
244  }
245  foreach ($a_usr_ids as $usr_id)
246  {
247  foreach ($a_obj_ids as $obj_id)
248  {
249  self::$is_on_list[$usr_id][$obj_id] = false;
250  }
251  }
252  $query = "SELECT usr_id, obj_id ".
253  "FROM crs_waiting_list ".
254  "WHERE ".
255  $ilDB->in("obj_id", $a_obj_ids, false, "integer")." AND ".
256  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
257  $res = $ilDB->query($query);
258  while ($rec = $ilDB->fetchAssoc($res))
259  {
260  self::$is_on_list[$rec["usr_id"]][$rec["obj_id"]] = true;
261  }
262  }
263 
264 
271  public function getCountUsers()
272  {
273  return count($this->users);
274  }
275 
283  public function getPosition($a_usr_id)
284  {
285  return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id]['position'] : -1;
286  }
287 
294  public function getAllUsers()
295  {
296  return $this->users ? $this->users : array();
297  }
298 
306  public function getUser($a_usr_id)
307  {
308  return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id] : false;
309  }
310 
316  public function getUserIds()
317  {
318  return $this->user_ids ? $this->user_ids : array();
319  }
320 
321 
329  private function read()
330  {
331  global $ilDB;
332 
333  $this->users = array();
334 
335  $query = "SELECT * FROM crs_waiting_list ".
336  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ORDER BY sub_time";
337 
338  $res = $this->db->query($query);
339  $counter = 0;
340  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
341  {
342  ++$counter;
343  $this->users[$row->usr_id]['position'] = $counter;
344  $this->users[$row->usr_id]['time'] = $row->sub_time;
345  $this->users[$row->usr_id]['usr_id'] = $row->usr_id;
346 
347  $this->user_ids[] = $row->usr_id;
348  }
349  return true;
350  }
351 
352 }
353 ?>