ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarSharedStatus.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 {
34  const STATUS_ACCEPTED = 1;
35  const STATUS_DECLINED = 2;
36  const STATUS_DELETED = 3;
37 
38  protected $db = null;
39 
40  private $usr_id = 0;
41 
42  private $calendars = array();
43 
44 
52  public function __construct($a_usr_id)
53  {
54  global $ilDB;
55 
56  $this->usr_id = $a_usr_id;
57  $this->db = $ilDB;
58 
59  $this->read();
60  }
61 
69  public function isAccepted($a_cal_id)
70  {
71  return isset($this->calendars[$a_cal_id]) and $this->calendars[$a_cal_id] == self::STATUS_ACCEPTED;
72  }
73 
81  public function isDeclined($a_cal_id)
82  {
83  return isset($this->calendars[$a_cal_id]) and $this->calendars[$a_cal_id] == self::STATUS_DECLINED;
84  }
85 
93  public function getAcceptedCalendars($a_usr_id)
94  {
95  global $ilDB;
96 
97  $query = "SELECT cal_id FROM cal_shared_status ".
98  "WHERE status = ".$ilDB->quote(self::STATUS_ACCEPTED ,'integer')." ".
99  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
100  $res = $ilDB->query($query);
101  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
102  {
103  $cal_ids[] = $row->cal_id;
104  }
105  return $cal_ids ? $cal_ids : array();
106  }
107 
117  public static function hasStatus($a_usr_id,$a_calendar_id)
118  {
119  global $ilDB;
120 
121  $query = "SELECT * FROM cal_shared_status ".
122  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
123  "AND cal_id = ".$ilDB->quote($a_calendar_id ,'integer')." ";
124  $res = $ilDB->query($query);
125  return $res->numRows() ? true : false;
126  }
127 
136  public static function deleteUser($a_usr_id)
137  {
138  global $ilUser,$ilDB;
139 
140  $query = "DELETE FROM cal_shared_status ".
141  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ";
142  $res = $ilDB->manipulate($query);
143  return true;
144  }
145 
154  public static function deleteCalendar($a_calendar_id)
155  {
156  global $ilDB;
157 
158  $query = "DELETE FROM cal_shared_status ".
159  "WHERE cal_id = ".$ilDB->quote($a_calendar_id ,'integer')." ";
160  $res = $ilDB->manipulate($query);
161  return true;
162  }
163 
173  public static function deleteStatus($a_id,$a_calendar_id)
174  {
175  global $ilDB,$rbacreview;
176 
177 
178  if(ilObject::_lookupType($a_id) == 'usr')
179  {
180  $query = "DELETE FROM cal_shared_status ".
181  "WHERE cal_id = ".$ilDB->quote($a_calendar_id ,'integer')." ".
182  "AND usr_id = ".$ilDB->quote($a_id ,'integer')." ";
183  $res = $ilDB->manipulate($query);
184 
185  }
186  elseif(ilObject::_lookupType($a_id) == 'role')
187  {
188  $assigned_users = $rbacreview->assignedUsers($a_id);
189 
190  if(!count($assigned_users))
191  {
192  return true;
193  }
194 
195  $query = "DELETE FROM cal_shared_status ".
196  "WHERE cal_id = ".$ilDB->quote($a_calendar_id ,'integer')." ".
197  "AND ".$ilDB->in('usr_id',$assigned_users,false,'integer');
198  $res = $ilDB->manipulate($query);
199 
200  }
201 
202  return true;
203  }
204 
205 
206 
214  public function accept($a_calendar_id)
215  {
216  global $ilDB;
217 
218  self::deleteStatus($this->usr_id,$a_calendar_id);
219 
220  $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) ".
221  "VALUES ( ".
222  $this->db->quote($a_calendar_id ,'integer').", ".
223  $this->db->quote($this->usr_id ,'integer').", ".
224  $this->db->quote(self::STATUS_ACCEPTED ,'integer')." ".
225  ")";
226  $res = $ilDB->manipulate($query);
227 
228  $this->calendars[$a_calendar_id] = self::STATUS_ACCEPTED;
229 
230  return true;
231  }
232 
240  public function decline($a_calendar_id)
241  {
242  global $ilDB;
243 
244  self::deleteStatus($this->usr_id,$a_calendar_id);
245 
246  $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) ".
247  "VALUES ( ".
248  $this->db->quote($a_calendar_id ,'integer').", ".
249  $this->db->quote($this->usr_id ,'integer').", ".
250  $this->db->quote(self::STATUS_DECLINED ,'integer')." ".
251  ")";
252  $res = $ilDB->manipulate($query);
253 
254  $this->calendars[$a_calendar_id] = self::STATUS_DECLINED;
255 
256  return true;
257 
258  }
259 
266  protected function read()
267  {
268  global $ilDB;
269 
270  $query = "SELECT * FROM cal_shared_status ".
271  "WHERE usr_id = ".$this->db->quote($this->usr_id ,'integer')." ";
272  $res = $this->db->query($query);
273  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
274  {
275  $this->calendars[$row->cal_id] = $row->status;
276  }
277  }
278 
279 }
280 ?>