ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
56
57 $ilDB = $DIC['ilDB'];
58
59 $this->usr_id = $a_usr_id;
60 $this->db = $ilDB;
61
62 $this->read();
63 }
64
72 public function isAccepted($a_cal_id)
73 {
74 return isset($this->calendars[$a_cal_id]) and $this->calendars[$a_cal_id] == self::STATUS_ACCEPTED;
75 }
76
84 public function isDeclined($a_cal_id)
85 {
86 return isset($this->calendars[$a_cal_id]) and $this->calendars[$a_cal_id] == self::STATUS_DECLINED;
87 }
88
96 public static function getAcceptedCalendars($a_usr_id)
97 {
98 global $DIC;
99
100 $ilDB = $DIC['ilDB'];
101
102 $query = "SELECT cal_id FROM cal_shared_status " .
103 "WHERE status = " . $ilDB->quote(self::STATUS_ACCEPTED, 'integer') . " " .
104 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
105 $res = $ilDB->query($query);
106 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
107 $cal_ids[] = $row->cal_id;
108 }
109 return $cal_ids ? $cal_ids : array();
110 }
111
121 public static function hasStatus($a_usr_id, $a_calendar_id)
122 {
123 global $DIC;
124
125 $ilDB = $DIC['ilDB'];
126
127 $query = "SELECT * FROM cal_shared_status " .
128 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
129 "AND cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
130 $res = $ilDB->query($query);
131 return $res->numRows() ? true : false;
132 }
133
142 public static function deleteUser($a_usr_id)
143 {
144 global $DIC;
145
146 $ilUser = $DIC['ilUser'];
147 $ilDB = $DIC['ilDB'];
148
149 $query = "DELETE FROM cal_shared_status " .
150 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
151 $res = $ilDB->manipulate($query);
152 return true;
153 }
154
163 public static function deleteCalendar($a_calendar_id)
164 {
165 global $DIC;
166
167 $ilDB = $DIC['ilDB'];
168
169 $query = "DELETE FROM cal_shared_status " .
170 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
171 $res = $ilDB->manipulate($query);
172 return true;
173 }
174
184 public static function deleteStatus($a_id, $a_calendar_id)
185 {
186 global $DIC;
187
188 $ilDB = $DIC['ilDB'];
189 $rbacreview = $DIC['rbacreview'];
190
191
192 if (ilObject::_lookupType($a_id) == 'usr') {
193 $query = "DELETE FROM cal_shared_status " .
194 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " " .
195 "AND usr_id = " . $ilDB->quote($a_id, 'integer') . " ";
196 $res = $ilDB->manipulate($query);
197 } elseif (ilObject::_lookupType($a_id) == 'role') {
198 $assigned_users = $rbacreview->assignedUsers($a_id);
199
200 if (!count($assigned_users)) {
201 return true;
202 }
203
204 $query = "DELETE FROM cal_shared_status " .
205 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " " .
206 "AND " . $ilDB->in('usr_id', $assigned_users, false, 'integer');
207 $res = $ilDB->manipulate($query);
208 }
209
210 return true;
211 }
212
213
214
222 public function accept($a_calendar_id)
223 {
224 global $DIC;
225
226 $ilDB = $DIC['ilDB'];
227
228 self::deleteStatus($this->usr_id, $a_calendar_id);
229
230 $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) " .
231 "VALUES ( " .
232 $this->db->quote($a_calendar_id, 'integer') . ", " .
233 $this->db->quote($this->usr_id, 'integer') . ", " .
234 $this->db->quote(self::STATUS_ACCEPTED, 'integer') . " " .
235 ")";
236 $res = $ilDB->manipulate($query);
237
238 $this->calendars[$a_calendar_id] = self::STATUS_ACCEPTED;
239
240 return true;
241 }
242
250 public function decline($a_calendar_id)
251 {
252 global $DIC;
253
254 $ilDB = $DIC['ilDB'];
255
256 self::deleteStatus($this->usr_id, $a_calendar_id);
257
258 $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) " .
259 "VALUES ( " .
260 $this->db->quote($a_calendar_id, 'integer') . ", " .
261 $this->db->quote($this->usr_id, 'integer') . ", " .
262 $this->db->quote(self::STATUS_DECLINED, 'integer') . " " .
263 ")";
264 $res = $ilDB->manipulate($query);
265
266 $this->calendars[$a_calendar_id] = self::STATUS_DECLINED;
267
268 return true;
269 }
270
277 protected function read()
278 {
279 global $DIC;
280
281 $ilDB = $DIC['ilDB'];
282
283 $query = "SELECT * FROM cal_shared_status " .
284 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " ";
285 $res = $this->db->query($query);
286 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
287 $this->calendars[$row->cal_id] = $row->status;
288 }
289 }
290
296 public function getOpenInvitations()
297 {
298 include_once('./Services/Calendar/classes/class.ilCalendarShared.php');
299 $shared = ilCalendarShared::getSharedCalendarsForUser($this->usr_id);
300
301 $invitations = array();
302
303 foreach ($shared as $data) {
304 if ($this->isDeclined($data['cal_id']) || $this->isAccepted($data['cal_id'])) {
305 continue;
306 }
307
308 $tmp_calendar = new ilCalendarCategory($data['cal_id']);
309
310 $invitations[] = array(
311 'cal_id' => $data['cal_id'],
312 'create_date' => $data['create_date'],
313 'obj_type' => $data['obj_type'],
314 'name' => $tmp_calendar->getTitle(),
315 'owner' => $tmp_calendar->getObjId(),
316 'apps' => count(ilCalendarCategoryAssignments::_getAssignedAppointments(array($data['cal_id']))),
317 'accepted' => $this->isAccepted($data['cal_id']),
318 'declined' => $this->isDeclined($data['cal_id'])
319 );
320 }
321
322 return $invitations;
323 }
324}
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
Stores calendar categories.
Stores status (accepted/declined) of shared calendars.
decline($a_calendar_id)
decline calendar
__construct($a_usr_id)
Constructor.
static deleteStatus($a_id, $a_calendar_id)
delete status
static hasStatus($a_usr_id, $a_calendar_id)
check if a status is set for an calendar
getOpenInvitations()
Get open invitations.
accept($a_calendar_id)
accept calendar
static deleteUser($a_usr_id)
Delete by user.
static getAcceptedCalendars($a_usr_id)
get accepted shared calendars
static deleteCalendar($a_calendar_id)
Delete calendar.
static getSharedCalendarsForUser($a_usr_id=0)
get shared calendars of user
static _lookupType($a_id, $a_reference=false)
lookup object type
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23