ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCalendarShared Class Reference

Handles shared calendars. More...

+ Collaboration diagram for ilCalendarShared:

Public Member Functions

 __construct (int $a_calendar_id)
 
 getCalendarId ()
 
 getShared ()
 
 getUsers ()
 
 getRoles ()
 
 isShared (int $a_obj_id)
 
 isEditableForUser (int $a_user_id)
 
 share (int $a_obj_id, int $a_type, bool $a_writable=false)
 
 stopSharing (int $a_obj_id)
 

Static Public Member Functions

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

Data Fields

const TYPE_USR = 1
 
const TYPE_ROLE = 2
 

Protected Member Functions

 read ()
 

Protected Attributes

ilDBInterface $db
 
ilRbacReview $rbacreview
 

Private Attributes

int $calendar_id
 
array $shared = array()
 
array $shared_users = array()
 
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

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

Constructor & Destructor Documentation

◆ __construct()

ilCalendarShared::__construct ( int  $a_calendar_id)

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

41 {
42 global $DIC;
43
44 $this->calendar_id = $a_calendar_id;
45 $this->db = $DIC->database();
46 $this->rbacreview = $DIC->rbac()->review();
47 $this->read();
48 }
global $DIC
Definition: shib_login.php:26

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteByCalendar()

static ilCalendarShared::deleteByCalendar ( int  $a_cal_id)
static

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

50 : void
51 {
52 global $DIC;
53
54 $ilDB = $DIC['ilDB'];
55 $query = "DELETE FROM cal_shared WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer') . " ";
56 $res = $ilDB->manipulate($query);
57 }
$res
Definition: ltiservices.php:69

References $DIC, $ilDB, and $res.

◆ deleteByUser()

static ilCalendarShared::deleteByUser ( int  $a_user_id)
static

Delete all entries for a specific user.

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

62 : void
63 {
64 global $DIC;
65
66 $ilDB = $DIC['ilDB'];
67 $query = "DELETE FROM cal_shared WHERE obj_id = " . $ilDB->quote($a_user_id, 'integer') . " ";
68 $res = $ilDB->manipulate($query);
69 }

References $DIC, $ilDB, and $res.

◆ getCalendarId()

ilCalendarShared::getCalendarId ( )

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

155 : int
156 {
157 return $this->calendar_id;
158 }

References $calendar_id.

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

+ Here is the caller graph for this function:

◆ getRoles()

ilCalendarShared::getRoles ( )

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

170 : array
171 {
172 return $this->shared_roles;
173 }

References $shared_roles.

◆ getShared()

ilCalendarShared::getShared ( )

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

160 : array
161 {
162 return $this->shared;
163 }

References $shared.

◆ getSharedCalendarsForUser()

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

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

106 : array
107 {
108 global $DIC;
109
110 $ilDB = $DIC['ilDB'];
111 $ilUser = $DIC['ilUser'];
112 $rbacreview = $DIC['rbacreview'];
113
114 if (!$a_usr_id) {
115 $a_usr_id = $ilUser->getId();
116 }
117
118 $query = "SELECT * FROM cal_shared " .
119 "WHERE obj_type = " . $ilDB->quote(self::TYPE_USR, 'integer') . " " .
120 "AND obj_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
121 "ORDER BY create_date";
122 $res = $ilDB->query($query);
123 $calendars = array();
124 $shared = [];
125 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
126 $calendars[] = (int) $row->cal_id;
127
128 $shared[(int) $row->cal_id]['cal_id'] = (int) $row->cal_id;
129 $shared[(int) $row->cal_id]['create_date'] = (string) $row->create_date;
130 $shared[(int) $row->cal_id]['obj_type'] = (string) $row->obj_type;
131 }
132
133 $assigned_roles = $rbacreview->assignedRoles($ilUser->getId());
134
135 $query = "SELECT * FROM cal_shared " .
136 "WHERE obj_type = " . $ilDB->quote(self::TYPE_ROLE, 'integer') . " " .
137 "AND " . $ilDB->in('obj_id', $assigned_roles, false, 'integer');
138
139 $res = $ilDB->query($query);
140 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
141 if (in_array($row->cal_id, $calendars)) {
142 continue;
143 }
144 if (ilCalendarCategories::_isOwner($ilUser->getId(), (int) $row->cal_id)) {
145 continue;
146 }
147
148 $shared[(int) $row->cal_id]['cal_id'] = (int) $row->cal_id;
149 $shared[(int) $row->cal_id]['create_date'] = (string) $row->create_date;
150 $shared[(int) $row->cal_id]['obj_type'] = (string) $row->obj_type;
151 }
152 return $shared;
153 }
static _isOwner(int $a_usr_id, int $a_cal_id)
check if user is owner of a category
assignedRoles(int $a_usr_id)
get all assigned roles to a given user

References $DIC, $ilDB, $rbacreview, $res, $shared, ilCalendarCategories\_isOwner(), ilRbacReview\assignedRoles(), ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

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 ( )

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

165 : array
166 {
167 return $this->shared_users;
168 }

References $shared_users.

◆ isEditableForUser()

ilCalendarShared::isEditableForUser ( int  $a_user_id)

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

180 : bool
181 {
182 foreach ($this->shared as $info) {
183 if (!$info['writable']) {
184 continue;
185 }
186
187 switch ($info['obj_type']) {
188 case self::TYPE_USR:
189 if ($info['obj_id'] == $a_user_id) {
190 return true;
191 }
192 break;
193
194 case self::TYPE_ROLE:
195 if ($this->rbacreview->isAssigned($a_user_id, $info['obj_id'])) {
196 return true;
197 }
198 break;
199 }
200 }
201 return false;
202 }
$info
Definition: entry_point.php:21

References $info, TYPE_ROLE, and TYPE_USR.

◆ isShared()

ilCalendarShared::isShared ( int  $a_obj_id)

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

175 : bool
176 {
177 return isset($this->shared[$a_obj_id]);
178 }

Referenced by share(), and stopSharing().

+ Here is the caller graph for this function:

◆ isSharedWithUser()

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

is shared with user

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

74 : bool
75 {
76 global $DIC;
77
78 $ilDB = $DIC['ilDB'];
79 $rbacreview = $DIC['rbacreview'];
80
81 $query = 'SELECT * FROM cal_shared ' .
82 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
83 $res = $ilDB->query($query);
84 $obj_ids = [];
85 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
86 $obj_ids[(int) $row->obj_id] = (string) $row->obj_type;
87 }
88 $assigned_roles = $rbacreview->assignedRoles($a_usr_id);
89 foreach ($obj_ids as $id => $type) {
90 switch ($type) {
91 case self::TYPE_USR:
92 if ($a_usr_id == $id) {
93 return true;
94 }
95 break;
96 case self::TYPE_ROLE:
97 if (in_array($id, $assigned_roles)) {
98 return true;
99 }
100 break;
101 }
102 }
103 return false;
104 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $DIC, $id, $ilDB, $rbacreview, $res, ilRbacReview\assignedRoles(), ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\int(), TYPE_ROLE, and TYPE_USR.

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

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

◆ read()

ilCalendarShared::read ( )
protected

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

235 : void
236 {
237 $this->shared = $this->shared_users = $this->shared_roles = array();
238 $query = "SELECT * FROM cal_shared WHERE cal_id = " . $this->db->quote($this->getCalendarId(), 'integer');
239 $res = $this->db->query($query);
240 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
241 switch ($row->obj_type) {
242 case self::TYPE_USR:
243 $this->shared_users[(int) $row->obj_id]['obj_id'] = (int) $row->obj_id;
244 $this->shared_users[(int) $row->obj_id]['obj_type'] = (string) $row->obj_type;
245 $this->shared_users[(int) $row->obj_id]['create_date'] = (string) $row->create_date;
246 $this->shared_users[(int) $row->obj_id]['writable'] = (bool) $row->writable;
247 break;
248
249 case self::TYPE_ROLE:
250 $this->shared_roles[(int) $row->obj_id]['obj_id'] = (int) $row->obj_id;
251 $this->shared_roles[(int) $row->obj_id]['obj_type'] = (string) $row->obj_type;
252 $this->shared_roles[(int) $row->obj_id]['create_date'] = (string) $row->create_date;
253 $this->shared_roles[(int) $row->obj_id]['writable'] = (bool) $row->writable;
254 break;
255 }
256
257 $this->shared[(int) $row->obj_id]['obj_id'] = (int) $row->obj_id;
258 $this->shared[(int) $row->obj_id]['obj_type'] = (string) $row->obj_type;
259 $this->shared[(int) $row->obj_id]['create_date'] = (string) $row->create_date;
260 $this->shared[(int) $row->obj_id]['writable'] = (bool) $row->writable;
261 }
262 }

References $res, ilDBConstants\FETCHMODE_OBJECT, getCalendarId(), ILIAS\Repository\int(), 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 ( int  $a_obj_id,
int  $a_type,
bool  $a_writable = false 
)

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

204 : void
205 {
206 if ($this->isShared($a_obj_id)) {
207 return;
208 }
209 $query = "INSERT INTO cal_shared (cal_id,obj_id,obj_type,create_date,writable) " .
210 "VALUES ( " .
211 $this->db->quote($this->getCalendarId(), 'integer') . ", " .
212 $this->db->quote($a_obj_id, 'integer') . ", " .
213 $this->db->quote($a_type, 'integer') . ", " .
214 $this->db->now() . ", " .
215 $this->db->quote((int) $a_writable, 'integer') . ' ' .
216 ")";
217
218 $res = $this->db->manipulate($query);
219 $this->read();
220 }

References $res, getCalendarId(), isShared(), and read().

+ Here is the call graph for this function:

◆ stopSharing()

ilCalendarShared::stopSharing ( int  $a_obj_id)

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

222 : void
223 {
224 if (!$this->isShared($a_obj_id)) {
225 return;
226 }
227 $query = "DELETE FROM cal_shared WHERE cal_id = " . $this->db->quote($this->getCalendarId(), 'integer') . " " .
228 "AND obj_id = " . $this->db->quote($a_obj_id, 'integer') . " ";
229 $res = $this->db->manipulate($query);
230
232 $this->read();
233 }
static deleteStatus(int $a_id, int $a_calendar_id)

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

+ Here is the call graph for this function:

Field Documentation

◆ $calendar_id

int ilCalendarShared::$calendar_id
private

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

Referenced by getCalendarId().

◆ $db

ilDBInterface ilCalendarShared::$db
protected

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

◆ $rbacreview

ilRbacReview ilCalendarShared::$rbacreview
protected

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

Referenced by getSharedCalendarsForUser(), and isSharedWithUser().

◆ $shared

array ilCalendarShared::$shared = array()
private

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

Referenced by getShared(), and getSharedCalendarsForUser().

◆ $shared_roles

array ilCalendarShared::$shared_roles = array()
private

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

Referenced by getRoles().

◆ $shared_users

array ilCalendarShared::$shared_users = array()
private

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

Referenced by getUsers().

◆ TYPE_ROLE

◆ TYPE_USR

const ilCalendarShared::TYPE_USR = 1

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