ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCalendarShared Class Reference

Handles shared calendars. More...

+ Collaboration diagram for ilCalendarShared:

Public Member Functions

 __construct ($a_calendar_id)
 constructor More...
 
 getCalendarId ()
 get calendar id More...
 
 getShared ()
 get shared More...
 
 getUsers ()
 get users More...
 
 getRoles ()
 get roles More...
 
 isShared ($a_obj_id)
 Check if calendar is already shared with specific user or role. More...
 
 isEditableForUser ($a_user_id)
 Check if calendar is editable for user. More...
 
 share ($a_obj_id, $a_type, $a_writable=false)
 share calendar More...
 
 stopSharing ($a_obj_id)
 stop sharing More...
 

Static Public Member Functions

static deleteByCalendar ($a_cal_id)
 Delete all entries for a specific calendar id. More...
 
static deleteByUser ($a_user_id)
 Delete all entries for a specific user. More...
 
static isSharedWithUser ($a_usr_id, $a_calendar_id)
 is shared with user More...
 
static getSharedCalendarsForUser ($a_usr_id=0)
 get shared calendars of user More...
 

Data Fields

const TYPE_USR = 1
 
const TYPE_ROLE = 2
 

Protected Member Functions

 read ()
 read shared calendars More...
 

Protected Attributes

 $db
 

Private Attributes

 $calendar_id
 
 $shared = array()
 
 $shared_users = array()
 
 $shared_roles = array()
 

Detailed Description

Handles shared calendars.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 33 of file class.ilCalendarShared.php.

Constructor & Destructor Documentation

◆ __construct()

ilCalendarShared::__construct (   $a_calendar_id)

constructor

@access public

Parameters
intcalendar id

Definition at line 53 of file class.ilCalendarShared.php.

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 }
read()
read shared calendars
global $DIC
Definition: goto.php:24
global $ilDB

References $DIC, $ilDB, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteByCalendar()

static ilCalendarShared::deleteByCalendar (   $a_cal_id)
static

Delete all entries for a specific calendar id.

@access public

Parameters

return

Definition at line 72 of file class.ilCalendarShared.php.

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 }
$query
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $query, and $res.

◆ deleteByUser()

static ilCalendarShared::deleteByUser (   $a_user_id)
static

Delete all entries for a specific user.

@access public

Parameters
intusr_id
Returns

Definition at line 91 of file class.ilCalendarShared.php.

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 }

References $DIC, $ilDB, $query, and $res.

◆ getCalendarId()

ilCalendarShared::getCalendarId ( )

get calendar id

@access public

Returns
int calendar id

Definition at line 210 of file class.ilCalendarShared.php.

211 {
212 return $this->calendar_id;
213 }

References $calendar_id.

Referenced by read(), share(), and stopSharing().

+ Here is the caller graph for this function:

◆ getRoles()

ilCalendarShared::getRoles ( )

get roles

@access public

Returns
array

Definition at line 243 of file class.ilCalendarShared.php.

244 {
245 return $this->shared_roles ? $this->shared_roles : array();
246 }

◆ getShared()

ilCalendarShared::getShared ( )

get shared

@access public

Returns
array

Definition at line 221 of file class.ilCalendarShared.php.

222 {
223 return $this->shared ? $this->shared : array();
224 }

◆ getSharedCalendarsForUser()

static ilCalendarShared::getSharedCalendarsForUser (   $a_usr_id = 0)
static

get shared calendars of user

@access public

Parameters
intuser id
Returns
array shared calendar info

Definition at line 152 of file class.ilCalendarShared.php.

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 }
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
$ilUser
Definition: imgupload.php:18

References $DIC, $ilDB, $ilUser, $query, $res, $shared, ilCalendarCategories\_isOwner(), and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilCalendarSharedStatus\getOpenInvitations(), ilCalendarCategoryGUI\invitations(), and ilCalendarCategoryGUI\readPermissions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsers()

ilCalendarShared::getUsers ( )

get users

@access public

Returns
array

Definition at line 232 of file class.ilCalendarShared.php.

233 {
234 return $this->shared_users ? $this->shared_users : array();
235 }

◆ isEditableForUser()

ilCalendarShared::isEditableForUser (   $a_user_id)

Check if calendar is editable for user.

Parameters
type$a_user_id

Definition at line 264 of file class.ilCalendarShared.php.

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 }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64

References $GLOBALS, TYPE_ROLE, and TYPE_USR.

◆ isShared()

ilCalendarShared::isShared (   $a_obj_id)

Check if calendar is already shared with specific user or role.

@access public

Parameters
intobj_id
Returns
bool

Definition at line 255 of file class.ilCalendarShared.php.

256 {
257 return isset($this->shared[$a_obj_id]);
258 }

Referenced by share(), and stopSharing().

+ Here is the caller graph for this function:

◆ isSharedWithUser()

static ilCalendarShared::isSharedWithUser (   $a_usr_id,
  $a_calendar_id 
)
static

is shared with user

@access public

Parameters
intusr_id
intcalendar id
Returns
bool

Definition at line 113 of file class.ilCalendarShared.php.

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 }
$type

References $DIC, $ilDB, $query, $res, $type, ilDBConstants\FETCHMODE_OBJECT, TYPE_ROLE, and TYPE_USR.

Referenced by ilCalendarCategoryGUI\acceptShared(), ilCalendarCategoryGUI\declineShared(), and ilCalendarCategoryGUI\unshare().

+ Here is the caller graph for this function:

◆ read()

ilCalendarShared::read ( )
protected

read shared calendars

@access protected

Returns

Definition at line 354 of file class.ilCalendarShared.php.

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 }
getCalendarId()
get calendar id

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, getCalendarId(), TYPE_ROLE, and TYPE_USR.

Referenced by __construct(), share(), and stopSharing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ share()

ilCalendarShared::share (   $a_obj_id,
  $a_type,
  $a_writable = false 
)

share calendar

@access public

Parameters
intobj_id
inttype
Returns
bool

Definition at line 296 of file class.ilCalendarShared.php.

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 }
isShared($a_obj_id)
Check if calendar is already shared with specific user or role.

References $DIC, $ilDB, $query, $res, getCalendarId(), isShared(), and read().

+ Here is the call graph for this function:

◆ stopSharing()

ilCalendarShared::stopSharing (   $a_obj_id)

stop sharing

@access public

Parameters
intobj_id
Returns
bool

Definition at line 327 of file class.ilCalendarShared.php.

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 }
static deleteStatus($a_id, $a_calendar_id)
delete status

References $DIC, $ilDB, $query, $res, ilCalendarSharedStatus\deleteStatus(), getCalendarId(), isShared(), and read().

+ Here is the call graph for this function:

Field Documentation

◆ $calendar_id

ilCalendarShared::$calendar_id
private

Definition at line 38 of file class.ilCalendarShared.php.

Referenced by getCalendarId().

◆ $db

ilCalendarShared::$db
protected

Definition at line 44 of file class.ilCalendarShared.php.

◆ $shared

ilCalendarShared::$shared = array()
private

Definition at line 40 of file class.ilCalendarShared.php.

Referenced by getSharedCalendarsForUser().

◆ $shared_roles

ilCalendarShared::$shared_roles = array()
private

Definition at line 42 of file class.ilCalendarShared.php.

◆ $shared_users

ilCalendarShared::$shared_users = array()
private

Definition at line 41 of file class.ilCalendarShared.php.

◆ TYPE_ROLE

◆ TYPE_USR

const ilCalendarShared::TYPE_USR = 1

The documentation for this class was generated from the following file: