ILIAS  eassessment Revision 61809
 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 
41 
48  public function __construct($a_obj_id)
49  {
50  global $ilDB;
51 
52  $this->db = $ilDB;
53  $this->obj_id = $a_obj_id;
54 
55  $this->read();
56  }
57 
65  public static function _deleteAll($a_obj_id)
66  {
67  global $ilDB;
68 
69  $query = "DELETE FROM crs_waiting_list WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
70  $res = $ilDB->manipulate($query);
71 
72  return true;
73  }
74 
82  public static function _deleteUser($a_usr_id)
83  {
84  global $ilDB;
85 
86  $query = "DELETE FROM crs_waiting_list WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer');
87  $res = $ilDB->manipulate($query);
88 
89  return true;
90  }
91 
98  public static function deleteUserEntry($a_usr_id, $a_obj_id)
99  {
100  global $ilDB;
101 
102  $query = "DELETE FROM crs_waiting_list ".
103  "WHERE usr_id = ".$ilDB->quote($a_usr_id,'integer').' '.
104  "AND obj_id = ".$ilDB->quote($a_obj_id,'integer');
105  $ilDB->query($query);
106  return true;
107  }
108 
109 
116  public function getObjId()
117  {
118  return $this->obj_id;
119  }
120 
127  public function addToList($a_usr_id)
128  {
129  global $ilDB;
130 
131  if($this->isOnList($a_usr_id))
132  {
133  return false;
134  }
135  $query = "INSERT INTO crs_waiting_list (obj_id,usr_id,sub_time) ".
136  "VALUES (".
137  $ilDB->quote($this->getObjId() ,'integer').", ".
138  $ilDB->quote($a_usr_id ,'integer').", ".
139  $ilDB->quote(time() ,'integer')." ".
140  ")";
141  $res = $ilDB->manipulate($query);
142  $this->read();
143 
144  return true;
145  }
146 
154  public function updateSubscriptionTime($a_usr_id,$a_subtime)
155  {
156  global $ilDB;
157 
158  $query = "UPDATE crs_waiting_list ".
159  "SET sub_time = ".$ilDB->quote($a_subtime ,'integer')." ".
160  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
161  "AND obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ";
162  $res = $ilDB->manipulate($query);
163  return true;
164  }
165 
173  public function removeFromList($a_usr_id)
174  {
175  global $ilDB;
176 
177  $query = "DELETE FROM crs_waiting_list ".
178  " WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ".
179  " AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
180  $res = $ilDB->manipulate($query);
181  $this->read();
182 
183  return true;
184  }
185 
193  public function isOnList($a_usr_id)
194  {
195  return isset($this->users[$a_usr_id]) ? true : false;
196  }
197 
206  public static function _isOnList($a_usr_id,$a_obj_id)
207  {
208  global $ilDB;
209 
210  $query = "SELECT usr_id ".
211  "FROM crs_waiting_list ".
212  "WHERE obj_id = ".$ilDB->quote($a_obj_id, 'integer')." ".
213  "AND usr_id = ".$ilDB->quote($a_usr_id, 'integer');
214  $res = $ilDB->query($query);
215  return $res->numRows() ? true : false;
216  }
217 
224  public function getCountUsers()
225  {
226  return count($this->users);
227  }
228 
236  public function getPosition($a_usr_id)
237  {
238  return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id]['position'] : -1;
239  }
240 
247  public function getAllUsers()
248  {
249  return $this->users ? $this->users : array();
250  }
251 
259  public function getUser($a_usr_id)
260  {
261  return isset($this->users[$a_usr_id]) ? $this->users[$a_usr_id] : false;
262  }
263 
269  public function getUserIds()
270  {
271  return $this->user_ids ? $this->user_ids : array();
272  }
273 
274 
282  private function read()
283  {
284  global $ilDB;
285 
286  $this->users = array();
287 
288  $query = "SELECT * FROM crs_waiting_list ".
289  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ORDER BY sub_time";
290 
291  $res = $this->db->query($query);
292  $counter = 0;
293  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
294  {
295  ++$counter;
296  $this->users[$row->usr_id]['position'] = $counter;
297  $this->users[$row->usr_id]['time'] = $row->sub_time;
298  $this->users[$row->usr_id]['usr_id'] = $row->usr_id;
299 
300  $this->user_ids[] = $row->usr_id;
301  }
302  return true;
303  }
304 
305 }
306 ?>