ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $ilDB;
56
57 $this->calendar_id = $a_calendar_id;
58 $this->db = $ilDB;
59 $this->read();
60 }
read()
read shared calendars
global $ilDB

References $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 70 of file class.ilCalendarShared.php.

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 }

References $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 87 of file class.ilCalendarShared.php.

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 }

References $ilDB, $query, and $res.

◆ getCalendarId()

ilCalendarShared::getCalendarId ( )

get calendar id

@access public

Returns
int calendar id

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

209 {
210 return $this->calendar_id;
211 }

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 241 of file class.ilCalendarShared.php.

242 {
243 return $this->shared_roles ? $this->shared_roles : array();
244 }

◆ getShared()

ilCalendarShared::getShared ( )

get shared

@access public

Returns
array

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

220 {
221 return $this->shared ? $this->shared : array();
222 }

◆ 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 148 of file class.ilCalendarShared.php.

149 {
150 global $ilDB,$ilUser,$rbacreview;
151
152 if(!$a_usr_id)
153 {
154 $a_usr_id = $ilUser->getId();
155 }
156
157 $query = "SELECT * FROM cal_shared ".
158 "WHERE obj_type = ".$ilDB->quote(self::TYPE_USR ,'integer')." ".
159 "AND obj_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
160 "ORDER BY create_date";
161 $res = $ilDB->query($query);
162 $calendars = array();
163 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
164 {
165 $calendars[] = $row->cal_id;
166
167 $shared[$row->cal_id]['cal_id'] = $row->cal_id;
168 $shared[$row->cal_id]['create_date'] = $row->create_date;
169 $shared[$row->cal_id]['obj_type'] = $row->obj_type;
170 }
171
172 $assigned_roles = $rbacreview->assignedRoles($ilUser->getId());
173
174 $query = "SELECT * FROM cal_shared ".
175 "WHERE obj_type = ".$ilDB->quote(self::TYPE_ROLE ,'integer')." ".
176 "AND ".$ilDB->in('obj_id',$assigned_roles,false ,'integer');
177
178 $res = $ilDB->query($query);
179 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
180 {
181 if(in_array($row->cal_id,$calendars))
182 {
183 continue;
184 }
185 if(ilCalendarCategories::_isOwner($ilUser->getId(),$row->cal_id))
186 {
187 continue;
188 }
189
190 $shared[$row->cal_id]['cal_id'] = $row->cal_id;
191 $shared[$row->cal_id]['create_date'] = $row->create_date;
192 $shared[$row->cal_id]['obj_type'] = $row->obj_type;
193 }
194
195
196
197 return $shared ? $shared : array();
198 // TODO: return also role calendars
199
200 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _isOwner($a_usr_id, $a_cal_id)
check if user is owner of a category
global $ilUser
Definition: imgupload.php:15

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

Referenced by ilCalendarInboxGUI\inbox(), 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 230 of file class.ilCalendarShared.php.

231 {
232 return $this->shared_users ? $this->shared_users : array();
233 }

◆ isEditableForUser()

ilCalendarShared::isEditableForUser (   $a_user_id)

Check if calendar is editable for user.

Parameters
type$a_user_id

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

263 {
264 foreach((array) $this->shared as $info)
265 {
266 $GLOBALS['ilLog']->write(__METHOD__.': Calendar info:' . print_r($info,true));
267 $GLOBALS['ilLog']->write(__METHOD__.': Current user:' . $a_user_id);
268 if(!$info['writable'])
269 {
270 continue;
271 }
272
273 switch($info['obj_type'])
274 {
275 case self::TYPE_USR:
276 if($info['obj_id'] == $a_user_id)
277 {
278 $GLOBALS['ilLog']->write(__METHOD__.': Shared calendar is writable.');
279 return true;
280 }
281 break;
282
283 case self::TYPE_ROLE:
284 if($GLOBALS['rbacreview']->isAssigned($a_user_id,$info['obj_id']))
285 {
286 $GLOBALS['ilLog']->write(__METHOD__.': Shared calendar is writable.');
287 return true;
288 }
289 break;
290 }
291 }
292 $GLOBALS['ilLog']->write(__METHOD__.': Shared calendar is not writable.');
293 return false;
294 }
$info
Definition: example_052.php:80
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

References $GLOBALS, $info, 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 253 of file class.ilCalendarShared.php.

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

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 107 of file class.ilCalendarShared.php.

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(DB_FETCHMODE_OBJECT))
115 {
116 $obj_ids[$row->obj_id] = $row->obj_type;
117 }
118 $assigned_roles = $rbacreview->assignedRoles($a_usr_id);
119 foreach($obj_ids as $id => $type)
120 {
121 switch($type)
122 {
123 case self::TYPE_USR:
124 if($a_usr_id == $id)
125 {
126 return true;
127 }
128 break;
129 case self::TYPE_ROLE:
130 if(in_array($id,$assigned_roles))
131 {
132 return true;
133 }
134 break;
135 }
136 }
137 return false;
138 }

References $ilDB, $query, $res, $row, DB_FETCHMODE_OBJECT, TYPE_ROLE, and TYPE_USR.

Referenced by ilCalendarInboxGUI\acceptShared(), ilCalendarInboxGUI\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 360 of file class.ilCalendarShared.php.

361 {
362 global $ilDB;
363
364 $this->shared = $this->shared_users = $this->shared_roles = array();
365
366 $query = "SELECT * FROM cal_shared WHERE cal_id = ".$this->db->quote($this->getCalendarId() ,'integer');
367 $res = $this->db->query($query);
368 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
369 {
370 switch($row->obj_type)
371 {
372 case self::TYPE_USR:
373 $this->shared_users[$row->obj_id]['obj_id'] = $row->obj_id;
374 $this->shared_users[$row->obj_id]['obj_type'] = $row->obj_type;
375 $this->shared_users[$row->obj_id]['create_date'] = $row->create_date;
376 $this->shared_users[$row->obj_id]['writable'] = $row->writable;
377 break;
378
379
380 case self::TYPE_ROLE:
381 $this->shared_roles[$row->obj_id]['obj_id'] = $row->obj_id;
382 $this->shared_roles[$row->obj_id]['obj_type'] = $row->obj_type;
383 $this->shared_roles[$row->obj_id]['create_date'] = $row->create_date;
384 $this->shared_role[$row->obj_id]['writable'] = $row->writable;
385 break;
386
387 }
388
389 $this->shared[$row->obj_id]['obj_id'] = $row->obj_id;
390 $this->shared[$row->obj_id]['obj_type'] = $row->obj_type;
391 $this->shared[$row->obj_id]['create_date'] = $row->create_date;
392 $this->shared[$row->obj_id]['writable'] = $row->writable;
393 }
394 return true;
395 }
getCalendarId()
get calendar id

References $ilDB, $query, $res, $row, DB_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 304 of file class.ilCalendarShared.php.

305 {
306 global $ilDB;
307
308 if($this->isShared($a_obj_id))
309 {
310 return false;
311 }
312 $query = "INSERT INTO cal_shared (cal_id,obj_id,obj_type,create_date,writable) ".
313 "VALUES ( ".
314 $this->db->quote($this->getCalendarId() ,'integer').", ".
315 $this->db->quote($a_obj_id ,'integer').", ".
316 $this->db->quote($a_type ,'integer').", ".
317 $ilDB->now().", ".
318 $this->db->quote((int) $a_writable,'integer').' '.
319 ")";
320
321 $res = $ilDB->manipulate($query);
322
323 $this->read();
324 return true;
325 }
isShared($a_obj_id)
Check if calendar is already shared with specific user or role.

References $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 334 of file class.ilCalendarShared.php.

335 {
336 global $ilDB;
337
338 if(!$this->isShared($a_obj_id))
339 {
340 return false;
341 }
342 $query = "DELETE FROM cal_shared WHERE cal_id = ".$this->db->quote($this->getCalendarId() ,'integer')." ".
343 "AND obj_id = ".$this->db->quote($a_obj_id ,'integer')." ";
344 $res = $ilDB->manipulate($query);
345
346 include_once('./Services/Calendar/classes/class.ilCalendarSharedStatus.php');
348
349
350 $this->read();
351 return true;
352 }
static deleteStatus($a_id, $a_calendar_id)
delete status

References $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: