ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCalendarShared.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
34{
35 const TYPE_USR = 1;
36 const TYPE_ROLE = 2;
37
38 private $calendar_id;
39
40 private $shared = array();
41 private $shared_users = array();
42 private $shared_roles = array();
43
44 protected $db;
45
46
53 public function __construct($a_calendar_id)
54 {
55 global $DIC;
56
57 $ilDB = $DIC['ilDB'];
58
59 $this->calendar_id = $a_calendar_id;
60 $this->db = $ilDB;
61 $this->read();
62 }
63
72 public static function deleteByCalendar($a_cal_id)
73 {
74 global $DIC;
75
76 $ilDB = $DIC['ilDB'];
77
78 $query = "DELETE FROM cal_shared WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer') . " ";
79 $res = $ilDB->manipulate($query);
80 return true;
81 }
82
91 public static function deleteByUser($a_user_id)
92 {
93 global $DIC;
94
95 $ilDB = $DIC['ilDB'];
96
97 $query = "DELETE FROM cal_shared WHERE obj_id = " . $ilDB->quote($a_user_id, 'integer') . " ";
98 $res = $ilDB->manipulate($query);
99 return true;
100
101 // TODO: delete also cal_shared_user_status
102 }
103
113 public static function isSharedWithUser($a_usr_id, $a_calendar_id)
114 {
115 global $DIC;
116
117 $ilDB = $DIC['ilDB'];
118 $rbacreview = $DIC['rbacreview'];
119
120 $query = 'SELECT * FROM cal_shared ' .
121 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
122 $res = $ilDB->query($query);
123 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
124 $obj_ids[$row->obj_id] = $row->obj_type;
125 }
126 $assigned_roles = $rbacreview->assignedRoles($a_usr_id);
127 foreach ($obj_ids as $id => $type) {
128 switch ($type) {
129 case self::TYPE_USR:
130 if ($a_usr_id == $id) {
131 return true;
132 }
133 break;
134 case self::TYPE_ROLE:
135 if (in_array($id, $assigned_roles)) {
136 return true;
137 }
138 break;
139 }
140 }
141 return false;
142 }
143
152 public static function getSharedCalendarsForUser($a_usr_id = 0)
153 {
154 global $DIC;
155
156 $ilDB = $DIC['ilDB'];
157 $ilUser = $DIC['ilUser'];
158 $rbacreview = $DIC['rbacreview'];
159
160 if (!$a_usr_id) {
161 $a_usr_id = $ilUser->getId();
162 }
163
164 $query = "SELECT * FROM cal_shared " .
165 "WHERE obj_type = " . $ilDB->quote(self::TYPE_USR, 'integer') . " " .
166 "AND obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
167 "ORDER BY create_date";
168 $res = $ilDB->query($query);
169 $calendars = array();
170 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
171 $calendars[] = $row->cal_id;
172
173 $shared[$row->cal_id]['cal_id'] = $row->cal_id;
174 $shared[$row->cal_id]['create_date'] = $row->create_date;
175 $shared[$row->cal_id]['obj_type'] = $row->obj_type;
176 }
177
178 $assigned_roles = $rbacreview->assignedRoles($ilUser->getId());
179
180 $query = "SELECT * FROM cal_shared " .
181 "WHERE obj_type = " . $ilDB->quote(self::TYPE_ROLE, 'integer') . " " .
182 "AND " . $ilDB->in('obj_id', $assigned_roles, false, 'integer');
183
184 $res = $ilDB->query($query);
185 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
186 if (in_array($row->cal_id, $calendars)) {
187 continue;
188 }
189 if (ilCalendarCategories::_isOwner($ilUser->getId(), $row->cal_id)) {
190 continue;
191 }
192
193 $shared[$row->cal_id]['cal_id'] = $row->cal_id;
194 $shared[$row->cal_id]['create_date'] = $row->create_date;
195 $shared[$row->cal_id]['obj_type'] = $row->obj_type;
196 }
197
198
199
200 return $shared ? $shared : array();
201 // TODO: return also role calendars
202 }
203
210 public function getCalendarId()
211 {
212 return $this->calendar_id;
213 }
214
221 public function getShared()
222 {
223 return $this->shared ? $this->shared : array();
224 }
225
232 public function getUsers()
233 {
234 return $this->shared_users ? $this->shared_users : array();
235 }
236
243 public function getRoles()
244 {
245 return $this->shared_roles ? $this->shared_roles : array();
246 }
247
255 public function isShared($a_obj_id)
256 {
257 return isset($this->shared[$a_obj_id]);
258 }
259
264 public function isEditableForUser($a_user_id)
265 {
266 foreach ((array) $this->shared as $info) {
267 if (!$info['writable']) {
268 continue;
269 }
270
271 switch ($info['obj_type']) {
272 case self::TYPE_USR:
273 if ($info['obj_id'] == $a_user_id) {
274 return true;
275 }
276 break;
277
278 case self::TYPE_ROLE:
279 if ($GLOBALS['DIC']['rbacreview']->isAssigned($a_user_id, $info['obj_id'])) {
280 return true;
281 }
282 break;
283 }
284 }
285 return false;
286 }
287
296 public function share($a_obj_id, $a_type, $a_writable = false)
297 {
298 global $DIC;
299
300 $ilDB = $DIC['ilDB'];
301
302 if ($this->isShared($a_obj_id)) {
303 return false;
304 }
305 $query = "INSERT INTO cal_shared (cal_id,obj_id,obj_type,create_date,writable) " .
306 "VALUES ( " .
307 $this->db->quote($this->getCalendarId(), 'integer') . ", " .
308 $this->db->quote($a_obj_id, 'integer') . ", " .
309 $this->db->quote($a_type, 'integer') . ", " .
310 $ilDB->now() . ", " .
311 $this->db->quote((int) $a_writable, 'integer') . ' ' .
312 ")";
313
314 $res = $ilDB->manipulate($query);
315
316 $this->read();
317 return true;
318 }
319
327 public function stopSharing($a_obj_id)
328 {
329 global $DIC;
330
331 $ilDB = $DIC['ilDB'];
332
333 if (!$this->isShared($a_obj_id)) {
334 return false;
335 }
336 $query = "DELETE FROM cal_shared WHERE cal_id = " . $this->db->quote($this->getCalendarId(), 'integer') . " " .
337 "AND obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
338 $res = $ilDB->manipulate($query);
339
340 include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
342
343
344 $this->read();
345 return true;
346 }
347
354 protected function read()
355 {
356 global $DIC;
357
358 $ilDB = $DIC['ilDB'];
359
360 $this->shared = $this->shared_users = $this->shared_roles = array();
361
362 $query = "SELECT * FROM cal_shared WHERE cal_id = " . $this->db->quote($this->getCalendarId(), 'integer');
363 $res = $this->db->query($query);
364 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
365 switch ($row->obj_type) {
366 case self::TYPE_USR:
367 $this->shared_users[$row->obj_id]['obj_id'] = $row->obj_id;
368 $this->shared_users[$row->obj_id]['obj_type'] = $row->obj_type;
369 $this->shared_users[$row->obj_id]['create_date'] = $row->create_date;
370 $this->shared_users[$row->obj_id]['writable'] = $row->writable;
371 break;
372
373
374 case self::TYPE_ROLE:
375 $this->shared_roles[$row->obj_id]['obj_id'] = $row->obj_id;
376 $this->shared_roles[$row->obj_id]['obj_type'] = $row->obj_type;
377 $this->shared_roles[$row->obj_id]['create_date'] = $row->create_date;
378 $this->shared_role[$row->obj_id]['writable'] = $row->writable;
379 break;
380
381 }
382
383 $this->shared[$row->obj_id]['obj_id'] = $row->obj_id;
384 $this->shared[$row->obj_id]['obj_type'] = $row->obj_type;
385 $this->shared[$row->obj_id]['create_date'] = $row->create_date;
386 $this->shared[$row->obj_id]['writable'] = $row->writable;
387 }
388 return true;
389 }
390}
An exception for terminatinating execution or to throw for unit testing.
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
static deleteStatus($a_id, $a_calendar_id)
delete status
Handles shared calendars.
static isSharedWithUser($a_usr_id, $a_calendar_id)
is shared with user
static getSharedCalendarsForUser($a_usr_id=0)
get shared calendars of user
static deleteByUser($a_user_id)
Delete all entries for a specific user.
isShared($a_obj_id)
Check if calendar is already shared with specific user or role.
isEditableForUser($a_user_id)
Check if calendar is editable for user.
__construct($a_calendar_id)
constructor
read()
read shared calendars
static deleteByCalendar($a_cal_id)
Delete all entries for a specific calendar id.
stopSharing($a_obj_id)
stop sharing
share($a_obj_id, $a_type, $a_writable=false)
share calendar
getCalendarId()
get calendar id
if(!array_key_exists('StateId', $_REQUEST)) $id
$info
Definition: index.php:5
$row
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$query
$type
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92