ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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

public

Parameters
intcalendar id

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

References $ilDB, and read().

54  {
55  global $ilDB;
56 
57  $this->calendar_id = $a_calendar_id;
58  $this->db = $ilDB;
59  $this->read();
60  }
global $ilDB
read()
read shared calendars
+ 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.

public

Parameters

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

References $ilDB, $query, and $res.

71  {
72  global $ilDB;
73 
74  $query = "DELETE FROM cal_shared WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer') . " ";
75  $res = $ilDB->manipulate($query);
76  return true;
77  }
foreach($_POST as $key=> $value) $res
$query
global $ilDB

◆ deleteByUser()

static ilCalendarShared::deleteByUser (   $a_user_id)
static

Delete all entries for a specific user.

public

Parameters
intusr_id
Returns

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

References $ilDB, $query, and $res.

88  {
89  global $ilDB;
90 
91  $query = "DELETE FROM cal_shared WHERE obj_id = " . $ilDB->quote($a_user_id, 'integer') . " ";
92  $res = $ilDB->manipulate($query);
93  return true;
94 
95  // TODO: delete also cal_shared_user_status
96  }
foreach($_POST as $key=> $value) $res
$query
global $ilDB

◆ getCalendarId()

ilCalendarShared::getCalendarId ( )

get calendar id

public

Returns
int calendar id

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

References $calendar_id.

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

198  {
199  return $this->calendar_id;
200  }
+ Here is the caller graph for this function:

◆ getRoles()

ilCalendarShared::getRoles ( )

get roles

public

Returns
array

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

References array.

231  {
232  return $this->shared_roles ? $this->shared_roles : array();
233  }
Create styles array
The data for the language used.

◆ getShared()

ilCalendarShared::getShared ( )

get shared

public

Returns
array

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

References array.

209  {
210  return $this->shared ? $this->shared : array();
211  }
Create styles array
The data for the language used.

◆ getSharedCalendarsForUser()

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

get shared calendars of user

public

Parameters
intuser id
Returns
array shared calendar info

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

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

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

144  {
145  global $ilDB,$ilUser,$rbacreview;
146 
147  if (!$a_usr_id) {
148  $a_usr_id = $ilUser->getId();
149  }
150 
151  $query = "SELECT * FROM cal_shared " .
152  "WHERE obj_type = " . $ilDB->quote(self::TYPE_USR, 'integer') . " " .
153  "AND obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
154  "ORDER BY create_date";
155  $res = $ilDB->query($query);
156  $calendars = array();
157  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158  $calendars[] = $row->cal_id;
159 
160  $shared[$row->cal_id]['cal_id'] = $row->cal_id;
161  $shared[$row->cal_id]['create_date'] = $row->create_date;
162  $shared[$row->cal_id]['obj_type'] = $row->obj_type;
163  }
164 
165  $assigned_roles = $rbacreview->assignedRoles($ilUser->getId());
166 
167  $query = "SELECT * FROM cal_shared " .
168  "WHERE obj_type = " . $ilDB->quote(self::TYPE_ROLE, 'integer') . " " .
169  "AND " . $ilDB->in('obj_id', $assigned_roles, false, 'integer');
170 
171  $res = $ilDB->query($query);
172  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
173  if (in_array($row->cal_id, $calendars)) {
174  continue;
175  }
176  if (ilCalendarCategories::_isOwner($ilUser->getId(), $row->cal_id)) {
177  continue;
178  }
179 
180  $shared[$row->cal_id]['cal_id'] = $row->cal_id;
181  $shared[$row->cal_id]['create_date'] = $row->create_date;
182  $shared[$row->cal_id]['obj_type'] = $row->obj_type;
183  }
184 
185 
186 
187  return $shared ? $shared : array();
188  // TODO: return also role calendars
189  }
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUsers()

ilCalendarShared::getUsers ( )

get users

public

Returns
array

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

References array.

220  {
221  return $this->shared_users ? $this->shared_users : array();
222  }
Create styles array
The data for the language used.

◆ isEditableForUser()

ilCalendarShared::isEditableForUser (   $a_user_id)

Check if calendar is editable for user.

Parameters
type$a_user_id

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

References $GLOBALS, $info, and array.

252  {
253  foreach ((array) $this->shared as $info) {
254  $GLOBALS['ilLog']->write(__METHOD__ . ': Calendar info:' . print_r($info, true));
255  $GLOBALS['ilLog']->write(__METHOD__ . ': Current user:' . $a_user_id);
256  if (!$info['writable']) {
257  continue;
258  }
259 
260  switch ($info['obj_type']) {
261  case self::TYPE_USR:
262  if ($info['obj_id'] == $a_user_id) {
263  $GLOBALS['ilLog']->write(__METHOD__ . ': Shared calendar is writable.');
264  return true;
265  }
266  break;
267 
268  case self::TYPE_ROLE:
269  if ($GLOBALS['rbacreview']->isAssigned($a_user_id, $info['obj_id'])) {
270  $GLOBALS['ilLog']->write(__METHOD__ . ': Shared calendar is writable.');
271  return true;
272  }
273  break;
274  }
275  }
276  $GLOBALS['ilLog']->write(__METHOD__ . ': Shared calendar is not writable.');
277  return false;
278  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Create styles array
The data for the language used.
$info
Definition: index.php:5

◆ isShared()

ilCalendarShared::isShared (   $a_obj_id)

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

public

Parameters
intobj_id
Returns
bool

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

Referenced by share(), and stopSharing().

243  {
244  return isset($this->shared[$a_obj_id]);
245  }
+ Here is the caller graph for this function:

◆ isSharedWithUser()

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

is shared with user

public

Parameters
intusr_id
intcalendar id
Returns
bool

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

References $id, $ilDB, $query, $res, $row, $type, and ilDBConstants\FETCHMODE_OBJECT.

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

108  {
109  global $ilDB,$rbacreview;
110 
111  $query = 'SELECT * FROM cal_shared ' .
112  "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
113  $res = $ilDB->query($query);
114  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
115  $obj_ids[$row->obj_id] = $row->obj_type;
116  }
117  $assigned_roles = $rbacreview->assignedRoles($a_usr_id);
118  foreach ($obj_ids as $id => $type) {
119  switch ($type) {
120  case self::TYPE_USR:
121  if ($a_usr_id == $id) {
122  return true;
123  }
124  break;
125  case self::TYPE_ROLE:
126  if (in_array($id, $assigned_roles)) {
127  return true;
128  }
129  break;
130  }
131  }
132  return false;
133  }
$type
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res
$query
global $ilDB
+ Here is the caller graph for this function:

◆ read()

ilCalendarShared::read ( )
protected

read shared calendars

protected

Returns

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

References $ilDB, $query, $res, $row, array, ilDBConstants\FETCHMODE_OBJECT, and getCalendarId().

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

343  {
344  global $ilDB;
345 
346  $this->shared = $this->shared_users = $this->shared_roles = array();
347 
348  $query = "SELECT * FROM cal_shared WHERE cal_id = " . $this->db->quote($this->getCalendarId(), 'integer');
349  $res = $this->db->query($query);
350  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
351  switch ($row->obj_type) {
352  case self::TYPE_USR:
353  $this->shared_users[$row->obj_id]['obj_id'] = $row->obj_id;
354  $this->shared_users[$row->obj_id]['obj_type'] = $row->obj_type;
355  $this->shared_users[$row->obj_id]['create_date'] = $row->create_date;
356  $this->shared_users[$row->obj_id]['writable'] = $row->writable;
357  break;
358 
359 
360  case self::TYPE_ROLE:
361  $this->shared_roles[$row->obj_id]['obj_id'] = $row->obj_id;
362  $this->shared_roles[$row->obj_id]['obj_type'] = $row->obj_type;
363  $this->shared_roles[$row->obj_id]['create_date'] = $row->create_date;
364  $this->shared_role[$row->obj_id]['writable'] = $row->writable;
365  break;
366 
367  }
368 
369  $this->shared[$row->obj_id]['obj_id'] = $row->obj_id;
370  $this->shared[$row->obj_id]['obj_type'] = $row->obj_type;
371  $this->shared[$row->obj_id]['create_date'] = $row->create_date;
372  $this->shared[$row->obj_id]['writable'] = $row->writable;
373  }
374  return true;
375  }
getCalendarId()
get calendar id
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
global $ilDB
+ 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

public

Parameters
intobj_id
inttype
Returns
bool

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

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

289  {
290  global $ilDB;
291 
292  if ($this->isShared($a_obj_id)) {
293  return false;
294  }
295  $query = "INSERT INTO cal_shared (cal_id,obj_id,obj_type,create_date,writable) " .
296  "VALUES ( " .
297  $this->db->quote($this->getCalendarId(), 'integer') . ", " .
298  $this->db->quote($a_obj_id, 'integer') . ", " .
299  $this->db->quote($a_type, 'integer') . ", " .
300  $ilDB->now() . ", " .
301  $this->db->quote((int) $a_writable, 'integer') . ' ' .
302  ")";
303 
304  $res = $ilDB->manipulate($query);
305 
306  $this->read();
307  return true;
308  }
$a_type
Definition: workflow.php:92
getCalendarId()
get calendar id
foreach($_POST as $key=> $value) $res
$query
global $ilDB
isShared($a_obj_id)
Check if calendar is already shared with specific user or role.
read()
read shared calendars
+ Here is the call graph for this function:

◆ stopSharing()

ilCalendarShared::stopSharing (   $a_obj_id)

stop sharing

public

Parameters
intobj_id
Returns
bool

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

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

318  {
319  global $ilDB;
320 
321  if (!$this->isShared($a_obj_id)) {
322  return false;
323  }
324  $query = "DELETE FROM cal_shared WHERE cal_id = " . $this->db->quote($this->getCalendarId(), 'integer') . " " .
325  "AND obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
326  $res = $ilDB->manipulate($query);
327 
328  include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
330 
331 
332  $this->read();
333  return true;
334  }
getCalendarId()
get calendar id
foreach($_POST as $key=> $value) $res
$query
static deleteStatus($a_id, $a_calendar_id)
delete status
global $ilDB
isShared($a_obj_id)
Check if calendar is already shared with specific user or role.
read()
read shared calendars
+ 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

const ilCalendarShared::TYPE_ROLE = 2

◆ TYPE_USR

const ilCalendarShared::TYPE_USR = 1

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