ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningSequenceRoles.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const ROLE_LS_ADMIN = "il_lso_admin";
27 public const ROLE_LS_MEMBER = "il_lso_member";
28
29 public const TYPE_PORTFOLIO = "prtf";
30
31 protected int $ref_id;
32 protected int $obj_id;
34 protected ilCtrl $ctrl;
38 protected ilObjUser $user;
39 protected ilLanguage $lng;
40
41 protected array $local_roles;
42
43 public function __construct(
44 int $ls_ref_id,
45 int $ls_obj_id,
53 ) {
54 $this->ref_id = $ls_ref_id;
55 $this->obj_id = $ls_obj_id;
56 $this->participants = $participants;
57 $this->ctrl = $ctrl;
58 $this->rbacadmin = $rbacadmin;
59 $this->rbacreview = $rbacreview;
60 $this->database = $database;
61 $this->user = $user;
62 $this->lng = $lng;
63
64 $this->local_roles = array();
65 }
66
67 public function initDefaultRoles(): void
68 {
70 self::ROLE_LS_ADMIN . '_' . $this->ref_id,
71 "LSO admin learning sequence obj_no." . $this->obj_id,
72 self::ROLE_LS_ADMIN,
73 $this->ref_id
74 );
75
77 self::ROLE_LS_MEMBER . '_' . $this->ref_id,
78 "LSO member of learning sequence obj_no." . $this->obj_id,
79 self::ROLE_LS_MEMBER,
80 $this->ref_id
81 );
82 }
83
87 public function getLocalLearningSequenceRoles(bool $translate = false): array
88 {
89 if (count($this->local_roles) == 0) {
90 $role_ids = $this->rbacreview->getRolesOfRoleFolder(
91 $this->ref_id
92 );
93
94 foreach ($role_ids as $role_id) {
95 if ($this->rbacreview->isAssignable($role_id, $this->ref_id) == true) {
96 $role = $this->getRoleObject($role_id);
97
98 if ($translate) {
99 $role_name = ilObjRole::_getTranslation($role->getTitle());
100 } else {
101 $role_name = $role->getTitle();
102 }
103
104 $this->local_roles[$role_name] = $role->getId();
105 }
106 }
107 }
108
109 return $this->local_roles;
110 }
111
112 public function getDefaultMemberRole(): int
113 {
114 $local_ls_roles = $this->getLocalLearningSequenceRoles();
115 return $local_ls_roles[self::ROLE_LS_MEMBER . "_" . $this->ref_id];
116 }
117
118 public function getDefaultAdminRole(): int
119 {
120 $local_ls_roles = $this->getLocalLearningSequenceRoles();
121 return $local_ls_roles[self::ROLE_LS_ADMIN . "_" . $this->ref_id];
122 }
123
124 public function addLSMember(int $user_id, int $role): bool
125 {
126 return $this->join($user_id, $role);
127 }
128
129 public function join(int $user_id, ?int $role = null): bool
130 {
131 if (is_null($role)) {
132 $role = $this->getDefaultMemberRole();
133 }
134 $this->rbacadmin->assignUser($role, $user_id);
135 return true;
136 }
137
138 public function leave(int $user_id): bool
139 {
140 $roles = $this->participants::getMemberRoles($this->ref_id);
141
142 foreach ($roles as $role) {
143 $this->rbacadmin->deassignUser($role, $user_id);
144 }
145
146 return true;
147 }
148
152 public function getLearningSequenceAdminIds(): array
153 {
154 $users = array();
155 foreach ($this->rbacreview->assignedUsers($this->getDefaultAdminRole()) as $admin_id) {
156 $users[] = (int) $admin_id;
157 }
158
159 return $users;
160 }
161
165 public function getDefaultLearningSequenceRoles(string $lso_id): array
166 {
167 if (strlen($lso_id) == 0) {
168 $lso_id = $this->ref_id;
169 }
170
171 $roles = $this->rbacreview->getRolesOfRoleFolder($lso_id);
172
173 $default_roles = array();
174 foreach ($roles as $role) {
175 $object = $this->getRoleObject($role);
176
177 $member = self::ROLE_LS_MEMBER . "_" . $lso_id;
178 $admin = self::ROLE_LS_ADMIN . "_" . $lso_id;
179
180 if (strcmp($object->getTitle(), $member) == 0) {
181 $default_roles["lso_member_role"] = $object->getId();
182 }
183
184 if (strcmp($object->getTitle(), $admin) == 0) {
185 $default_roles["lso_admin_role"] = $object->getId();
186 }
187 }
188
189 return $default_roles;
190 }
191
192 protected function getRoleObject(int $obj_id): ?\ilObject
193 {
195 }
196
202 public function readMemberData(array $user_ids, ?array $selected_columns = null): array
203 {
204 $portfolio_enabled = $this->isPortfolio($selected_columns);
205 $tracking_enabled = $this->isTrackingEnabled();
207
208 if ($tracking_enabled) {
209 $olp = ilObjectLP::getInstance($this->obj_id);
210 $tracking_enabled = $olp->isActive();
211
212 $completed = ilLPStatusWrapper::_lookupCompletedForObject($this->obj_id);
213 $in_progress = ilLPStatusWrapper::_lookupInProgressForObject($this->obj_id);
214 $failed = ilLPStatusWrapper::_lookupFailedForObject($this->obj_id);
215 }
216
217 if ($privacy->enabledLearningSequenceAccessTimes()) {
218 $progress = ilLearningProgress::_lookupProgressByObjId($this->obj_id);
219 }
220
221 if ($portfolio_enabled) {
223 $user_ids,
224 $this->ctrl->getLinkTargetByClass("ilLearningSequenceMembershipGUI", "members")
225 );
226 }
227
228 $members = array();
229 $profile_data = ilObjUser::_readUsersProfileData($user_ids);
230 foreach ($user_ids as $usr_id) {
231 $data = array();
232 $name = ilObjUser::_lookupName($usr_id);
233
234 $data['firstname'] = $name['firstname'];
235 $data['lastname'] = $name['lastname'];
236 $data['login'] = ilObjUser::_lookupLogin($usr_id);
237 $data['usr_id'] = $usr_id;
238
239 $data['notification'] = 0;
240 if ($this->participants->isNotificationEnabled($usr_id)) {
241 $data['notification'] = 1;
242 }
243
244 foreach ($profile_data[$usr_id] as $field => $value) {
245 $data[$field] = $value;
246 }
247
248 if ($tracking_enabled) {
249 if (in_array($usr_id, $completed)) {
251 } elseif (in_array($usr_id, $in_progress)) {
253 } elseif (in_array($usr_id, $failed)) {
255 } else {
257 }
258 }
259
260 if ($privacy->enabledLearningSequenceAccessTimes()) {
261 if (isset($progress[$usr_id]['ts']) && $progress[$usr_id]['ts']) {
262 $data['access_time'] = ilDatePresentation::formatDate(
263 $date = new ilDateTime($progress[$usr_id]['ts'], IL_CAL_UNIX)
264 );
265 $data['access_time_unix'] = $date->get(IL_CAL_UNIX);
266 } else {
267 $data['access_time'] = $this->lng->txt('no_date');
268 $data['access_time_unix'] = 0;
269 }
270 }
271
272 if ($portfolio_enabled && array_key_exists($usr_id, $portfolios)) {
273 $data['prtf'] = $portfolios[$usr_id];
274 }
275
276 $members[$usr_id] = $data;
277 }
278
279 return $members;
280 }
281
282 protected function isTrackingEnabled(): bool
283 {
284 return
287 ;
288 }
289
290 protected function isPortfolio(?array $columns = null): bool
291 {
292 if (is_null($columns)) {
293 return false;
294 }
295 return in_array(self::TYPE_PORTFOLIO, $columns);
296 }
297
298 public function isMember(int $usr_id): bool
299 {
300 return $this->participants->isMember($usr_id);
301 }
302
303 public function isCompletedByUser(int $usr_id): bool
304 {
305 ilLPStatusWrapper::_updateStatus($this->obj_id, $usr_id);
307 $user_completion = ilLPStatus::_hasUserCompleted($this->obj_id, $usr_id);
308 return ($tracking_active && $user_completion);
309 }
310}
const IL_CAL_UNIX
Class ilCtrl provides processing control methods.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
static _hasUserCompleted(int $a_obj_id, int $a_user_id)
Lookup user object completion.
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
language handling
static _lookupProgressByObjId(int $a_obj_id)
lookup progress for a specific object
addLSMember(int $user_id, int $role)
join(int $user_id, ?int $role=null)
readMemberData(array $user_ids, ?array $selected_columns=null)
ilLearningSequenceParticipants $participants
__construct(int $ls_ref_id, int $ls_obj_id, ilLearningSequenceParticipants $participants, ilCtrl $ctrl, ilRbacAdmin $rbacadmin, ilRbacReview $rbacreview, ilDBInterface $database, ilObjUser $user, ilLanguage $lng)
getLocalLearningSequenceRoles(bool $translate=false)
static getAvailablePortfolioLinksForUserIds(array $a_owner_ids, ?string $a_back_url=null)
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
static _getTranslation(string $a_role_title)
User class.
static _lookupName(int $a_user_id)
static _lookupLogin(int $a_user_id)
static _readUsersProfileData(array $a_user_ids)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
Interface ilDBInterface.