ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLearningSequenceRoles.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
11{
12 const ROLE_LS_ADMIN = "il_lso_admin";
13 const ROLE_LS_MEMBER = "il_lso_member";
14
15 const TYPE_PORTFOLIO = "prtf";
16
20 protected $object;
21
25 protected $participants;
26
30 protected $rbacadmin;
31
35 protected $rbacreview;
36
40 protected $database;
41
45 protected $user;
46
50 protected $local_roles;
51
52
53 public function __construct(
54 int $ls_ref_id,
55 int $ls_obj_id,
57 ilCtrl $ctrl,
62 ) {
63 //$this->object = $object;
64 $this->ref_id = $ls_ref_id;
65 $this->obj_id = $ls_obj_id;
66 $this->participants = $participants;
67 $this->ctrl = $ctrl;
68 $this->rbacadmin = $rbacadmin;
69 $this->rbacreview = $rbacreview;
70 $this->database = $database;
71 $this->user = $user;
72
73 $this->local_roles = array();
74 }
75
76 public function initDefaultRoles()
77 {
79 self::ROLE_LS_ADMIN . '_' . $this->ref_id,
80 "LSO admin learning sequence obj_no." . $this->obj_id,
81 self::ROLE_LS_ADMIN,
82 $this->ref_id
83 );
84
86 self::ROLE_LS_MEMBER . '_' . $this->ref_id,
87 "LSO member of learning sequence obj_no." . $this->obj_id,
88 self::ROLE_LS_MEMBER,
89 $this->ref_id
90 );
91 }
92
96 public function getLocalLearningSequenceRoles(bool $translate = false) : array
97 {
98 if (count($this->local_roles) == 0) {
99 $role_ids = $this->rbacreview->getRolesOfRoleFolder(
100 $this->ref_id
101 );
102
103 foreach ($role_ids as $role_id) {
104 if ($this->rbacreview->isAssignable(
105 $role_id,
106 $this->ref_id
107 ) == true
108 ) {
109 $role = $this->getRoleObject((int) $role_id);
110
111 if ($translate) {
112 $role_name = ilObjRole::_getTranslation($role->getTitle());
113 } else {
114 $role_name = $role->getTitle();
115 }
116
117 $this->local_roles[$role_name] = (int) $role->getId();
118 }
119 }
120 }
121
122 return $this->local_roles;
123 }
124
125 public function getDefaultMemberRole() : int
126 {
127 $local_ls_roles = $this->getLocalLearningSequenceRoles();
128 return $local_ls_roles[self::ROLE_LS_MEMBER . "_" . $this->ref_id];
129 }
130
131 public function getDefaultAdminRole() : int
132 {
133 $local_ls_roles = $this->getLocalLearningSequenceRoles();
134 return $local_ls_roles[self::ROLE_LS_ADMIN . "_" . $this->ref_id];
135 }
136
137 public function addLSMember(int $user_id, int $role) : bool
138 {
139 return $this->join($user_id, $role);
140 }
141
142 public function join(int $user_id, int $role = null) : bool
143 {
144 if (is_null($role)) {
145 $role = $this->getDefaultMemberRole();
146 }
147 $this->rbacadmin->assignUser($role, $user_id);
148 return true;
149 }
150
151 public function leaveLearningSequence() : int
152 {
153 $member_ids = $this->getLearningSequenceMemberIds();
154
155 if (count($member_ids) <= 1 || !in_array($this->user->getId(), $member_ids)) {
156 return 2;
157 } else {
158 if (!$this->isAdmin($this->user->getId())) {
159 $this->leave($this->user->getId());
160 //$member = new ilObjUser($this->user->getId());
161 //$member->dropDesktopItem($this->getRefId(), "lso");
162 return 0;
163 } elseif (count($this->getLearningSequenceAdminIds()) == 1) {
164 return 1;
165 }
166 }
167 }
168
169 public function getLearningSequenceMemberIds() : array
170 {
171 $users = array();
172 $roles = $this->getLocalLearningSequenceRoles();
173
174 foreach ($roles as $role) {
175 foreach ($this->rbacreview->assignedUsers($role) as $member_id) {
176 array_push($users, $member_id);
177 }
178 }
179
180 $users = array_unique($users);
181
182 return $users;
183 }
184
185 public function leave(int $user_id) : bool
186 {
187 $roles = $this->participants::getMemberRoles($this->ref_id);
188
189 if (!is_array($roles)) {
190 return $this->rbacadmin->deassignUser($roles, $user_id);
191 }
192
193 foreach ($roles as $role) {
194 $this->rbacadmin->deassignUser($role, $user_id);
195 }
196
197 return true;
198 }
199
200 public function getLearningSequenceMemberData(array $user_ids, int $active = 1)
201 {
202 $users = array();
203 $additional_where = "";
204
205 if (is_numeric($active) && $active > -1) {
206 $additional_where = "AND active = '$active'" . PHP_EOL;
207 }
208
209 $query =
210 "SELECT login, firstname, lastname, title, usr_id, last_login" . PHP_EOL
211 . "FROM usr_data " . PHP_EOL
212 . "WHERE usr_id IN (" . implode(',', ilUtil::quoteArray($user_ids)) . ") " . PHP_EOL
213 . $additional_where . PHP_EOL
214 . "ORDER BY lastname, firstname" . PHP_EOL
215 ;
216
217 $result = $this->database->query($query);
218
219 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
220 $users[] = [
221 "id" => $row->usr_id,
222 "login" => $row->login,
223 "firstname" => $row->firstname,
224 "lastname" => $row->lastname,
225 "last_login" => $row->last_login
226 ];
227 }
228
229 return $users;
230 }
231
233 {
234 $users = array();
235 $roles = $this->getDefaultLearningSequenceRoles((string) $this->ref_id);
236
237 foreach ($this->rbacreview->assignedUsers($this->getDefaultAdminRole()) as $admin_id) {
238 array_push($users, $admin_id);
239 }
240
241 return $users;
242 }
243
244 public function getDefaultLearningSequenceRoles(string $lso_id) : array
245 {
246 if (strlen($lso_id) == 0) {
247 $lso_id = $this->ref_id;
248 }
249
250 $roles = $this->rbacreview->getRolesOfRoleFolder($lso_id);
251
252 $default_roles = array();
253 foreach ($roles as $role) {
254 $object = $this->getRoleObject((int) $role);
255
256 $member = self::ROLE_LS_MEMBER . "_" . $lso_id;
257 $admin = self::ROLE_LS_ADMIN . "_" . $lso_id;
258
259 if (strcmp($object->getTitle(), $member) == 0) {
260 $default_roles["lso_member_role"] = $object->getId();
261 }
262
263 if (strcmp($object->getTitle(), $admin) == 0) {
264 $default_roles["lso_admin_role"] = $object->getId();
265 }
266 }
267
268 return $default_roles;
269 }
270
271 protected function getRoleObject(int $obj_id)
272 {
274 }
275
276 public function readMemberData(array $user_ids, array $selected_columns = null) : array
277 {
278 $portfolio_enabled = $this->isPortfolio($selected_columns);
279 $tracking_enabled = $this->isTrackingEnabled();
281
282 if ($tracking_enabled) {
283 $olp = ilObjectLP::getInstance($this->obj_id);
284 $tracking_enabled = $olp->isActive();
285
286 $completed = ilLPStatusWrapper::_lookupCompletedForObject($this->obj_id);
287 $in_progress = ilLPStatusWrapper::_lookupInProgressForObject($this->obj_id);
289 }
290
291 if ($privacy->enabledLearningSequenceAccessTimes()) {
292 $progress = ilLearningProgress::_lookupProgressByObjId($this->obj_id);
293 }
294
295 if ($portfolio_enabled) {
297 $user_ids,
298 $this->ctrl->getLinkTargetByClass("ilLearningSequenceMembershipGUI", "members")
299 );
300 }
301
302 $members = array();
303 $profile_data = ilObjUser::_readUsersProfileData($user_ids);
304 foreach ($user_ids as $usr_id) {
305 $data = array();
306 $name = ilObjUser::_lookupName($usr_id);
307
308 $data['firstname'] = $name['firstname'];
309 $data['lastname'] = $name['lastname'];
310 $data['login'] = ilObjUser::_lookupLogin($usr_id);
311 $data['usr_id'] = $usr_id;
312
313 $data['notification'] = 0;
314 if ($this->participants->isNotificationEnabled($usr_id)) {
315 $data['notification'] = 1;
316 }
317
318 foreach ($profile_data[$usr_id] as $field => $value) {
319 $data[$field] = $value;
320 }
321
322 if ($tracking_enabled) {
323 if (in_array($usr_id, $completed)) {
325 } elseif (in_array($usr_id, $in_progress)) {
327 } elseif (in_array($usr_id, $failed)) {
329 } else {
331 }
332 }
333
334 if ($privacy->enabledLearningSequenceAccessTimes()) {
335 if (isset($progress[$usr_id]['ts']) and $progress[$usr_id]['ts']) {
336 $data['access_time'] = ilDatePresentation::formatDate(
337 $date = new ilDateTime($progress[$usr_id]['ts'], IL_CAL_UNIX)
338 );
339 $data['access_time_unix'] = $date->get(IL_CAL_UNIX);
340 } else {
341 $data['access_time'] = $this->lng->txt('no_date');
342 $data['access_time_unix'] = 0;
343 }
344 }
345
346 if ($portfolio_enabled) {
347 $data['prtf'] = $portfolios[$usr_id];
348 }
349
350 $members[$usr_id] = $data;
351 }
352
353 return $members;
354 }
355
356 protected function isTrackingEnabled() : bool
357 {
358 return
361 ;
362 }
363
364 protected function isPortfolio(array $columns = null) : bool
365 {
366 if (is_null($columns)) {
367 return false;
368 }
369 return in_array(self::TYPE_PORTFOLIO, $columns);
370 }
371
372 public function isMember(int $usr_id)
373 {
374 return $this->participants->isMember($usr_id);
375 }
376
377 public function isCompletedByUser(int $usr_id) : bool
378 {
379 \ilLPStatusWrapper::_updateStatus($this->obj_id, $usr_id);
381 $user_completion = ilLPStatus::_hasUserCompleted($this->obj_id, $usr_id);
382 return ($tracking_active && $user_completion);
383 }
384}
$result
user()
Definition: user.php:4
$failed
Definition: Utf8Test.php:85
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
This class provides processing control methods.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
static _lookupProgressByObjId($a_obj_id)
lookup progress for a specific object
__construct(int $ls_ref_id, int $ls_obj_id, ilLearningSequenceParticipants $participants, ilCtrl $ctrl, ilRbacAdmin $rbacadmin, ilRbacReview $rbacreview, ilDBInterface $database, ilObjUser $user)
addLSMember(int $user_id, int $role)
getLearningSequenceMemberData(array $user_ids, int $active=1)
readMemberData(array $user_ids, array $selected_columns=null)
join(int $user_id, int $role=null)
getLocalLearningSequenceRoles(bool $translate=false)
static getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url=null)
static _getTranslation($a_role_title)
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
static _enabledLearningProgress()
check wether learing progress is enabled or not
static _enabledUserRelatedData()
check wether user related tracking is enabled or not
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstance($a_obj_id)
static _getInstance()
Get instance of ilPrivacySettings.
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.
Interface ilDBInterface.
if($format !==null) $name
Definition: metadata.php:230
$query
$data
Definition: storeScorm.php:23