ILIAS  Release_3_10_x_branch Revision 61812
 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)." ".
99  "AND usr_id = ".$ilDB->quote($a_usr_id)." ";
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)." ".
123  "AND cal_id = ".$ilDB->quote($a_calendar_id)." ";
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;
139 
140  $query = "DELETE FROM cal_shared_status ".
141  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ";
142  $ilDB->query($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)." ";
160  $ilDB->query($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)." ".
182  "AND usr_id = ".$ilDB->quote($a_id)." ";
183  $ilDB->query($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)." ".
197  "AND usr_id IN (".implode(',',ilUtil::quoteArray($assigned_users)).") ";
198  $ilDB->query($query);
199 
200  }
201 
202  return true;
203  }
204 
205 
206 
214  public function accept($a_calendar_id)
215  {
216  self::deleteStatus($this->usr_id,$a_calendar_id);
217 
218  $query = "INSERT INTO cal_shared_status ".
219  "SET cal_id = ".$this->db->quote($a_calendar_id).", ".
220  "usr_id = ".$this->db->quote($this->usr_id).", ".
221  "status = ".$this->db->quote(self::STATUS_ACCEPTED)." ";
222  $this->db->query($query);
223 
224  $this->calendars[$a_calendar_id] = self::STATUS_ACCEPTED;
225 
226  return true;
227  }
228 
236  public function decline($a_calendar_id)
237  {
238  self::deleteStatus($this->usr_id,$a_calendar_id);
239 
240  $query = "INSERT INTO cal_shared_status ".
241  "SET cal_id = ".$this->db->quote($a_calendar_id).", ".
242  "usr_id = ".$this->db->quote($this->usr_id).", ".
243  "status = ".$this->db->quote(self::STATUS_DECLINED)." ";
244  $this->db->query($query);
245 
246  $this->calendars[$a_calendar_id] = self::STATUS_DECLINED;
247 
248  return true;
249 
250  }
251 
258  protected function read()
259  {
260  $query = "SELECT * FROM cal_shared_status ".
261  "WHERE usr_id = ".$this->db->quote($this->usr_id)." ";
262  $res = $this->db->query($query);
263  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
264  {
265  $this->calendars[$row->cal_id] = $row->status;
266  }
267  }
268 
269 }
270 ?>