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