ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 static 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(ilDBConstants::FETCHMODE_OBJECT)) {
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  $query = "DELETE FROM cal_shared_status " .
180  "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " " .
181  "AND usr_id = " . $ilDB->quote($a_id, 'integer') . " ";
182  $res = $ilDB->manipulate($query);
183  } elseif (ilObject::_lookupType($a_id) == 'role') {
184  $assigned_users = $rbacreview->assignedUsers($a_id);
185 
186  if (!count($assigned_users)) {
187  return true;
188  }
189 
190  $query = "DELETE FROM cal_shared_status " .
191  "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " " .
192  "AND " . $ilDB->in('usr_id', $assigned_users, false, 'integer');
193  $res = $ilDB->manipulate($query);
194  }
195 
196  return true;
197  }
198 
199 
200 
208  public function accept($a_calendar_id)
209  {
210  global $ilDB;
211 
212  self::deleteStatus($this->usr_id, $a_calendar_id);
213 
214  $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) " .
215  "VALUES ( " .
216  $this->db->quote($a_calendar_id, 'integer') . ", " .
217  $this->db->quote($this->usr_id, 'integer') . ", " .
218  $this->db->quote(self::STATUS_ACCEPTED, 'integer') . " " .
219  ")";
220  $res = $ilDB->manipulate($query);
221 
222  $this->calendars[$a_calendar_id] = self::STATUS_ACCEPTED;
223 
224  return true;
225  }
226 
234  public function decline($a_calendar_id)
235  {
236  global $ilDB;
237 
238  self::deleteStatus($this->usr_id, $a_calendar_id);
239 
240  $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) " .
241  "VALUES ( " .
242  $this->db->quote($a_calendar_id, 'integer') . ", " .
243  $this->db->quote($this->usr_id, 'integer') . ", " .
244  $this->db->quote(self::STATUS_DECLINED, 'integer') . " " .
245  ")";
246  $res = $ilDB->manipulate($query);
247 
248  $this->calendars[$a_calendar_id] = self::STATUS_DECLINED;
249 
250  return true;
251  }
252 
259  protected function read()
260  {
261  global $ilDB;
262 
263  $query = "SELECT * FROM cal_shared_status " .
264  "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " ";
265  $res = $this->db->query($query);
266  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
267  $this->calendars[$row->cal_id] = $row->status;
268  }
269  }
270 
276  public function getOpenInvitations()
277  {
278  include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
279  $shared = ilCalendarShared::getSharedCalendarsForUser($this->usr_id);
280 
281  $invitations = array();
282 
283  foreach ($shared as $data) {
284  if ($this->isDeclined($data['cal_id']) || $this->isAccepted($data['cal_id'])) {
285  continue;
286  }
287 
288  $tmp_calendar = new ilCalendarCategory($data['cal_id']);
289 
290  $invitations[] = array(
291  'cal_id' => $data['cal_id'],
292  'create_date' => $data['create_date'],
293  'obj_type' => $data['obj_type'],
294  'name' => $tmp_calendar->getTitle(),
295  'owner' => $tmp_calendar->getObjId(),
296  'apps' => count(ilCalendarCategoryAssignments::_getAssignedAppointments(array($data['cal_id']))),
297  'accepted' => $this->isAccepted($data['cal_id']),
298  'declined' => $this->isDeclined($data['cal_id'])
299  );
300  }
301 
302  return $invitations;
303  }
304 }
decline($a_calendar_id)
decline calendar
static getAcceptedCalendars($a_usr_id)
get accepted shared calendars
static getSharedCalendarsForUser($a_usr_id=0)
get shared calendars of user
static deleteCalendar($a_calendar_id)
Delete calendar.
Stores status (accepted/declined) of shared calendars.
Stores calendar categories.
__construct($a_usr_id)
Constructor.
foreach($_POST as $key=> $value) $res
static deleteUser($a_usr_id)
Delete by user.
accept($a_calendar_id)
accept calendar
$ilUser
Definition: imgupload.php:18
$query
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
getOpenInvitations()
Get open invitations.
static deleteStatus($a_id, $a_calendar_id)
delete status
global $ilDB
static hasStatus($a_usr_id, $a_calendar_id)
check if a status is set for an calendar