ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceRoles.php
Go to the documentation of this file.
1 <?php
2 
3 declare(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  public function __construct(
55  ilCtrl $ctrl,
60  ) {
61  $this->object = $object;
62  $this->participants = $participants;
63  $this->ctrl = $ctrl;
64  $this->rbacadmin = $rbacadmin;
65  $this->rbacreview = $rbacreview;
66  $this->database = $database;
67  $this->user = $user;
68 
69  $this->local_roles = array();
70  }
71 
72  public function initDefaultRoles()
73  {
75  self::ROLE_LS_ADMIN . '_' . $this->object->getRefId(),
76  "LSO admin learning sequence obj_no." . $this->object->getId(),
77  self::ROLE_LS_ADMIN,
78  $this->object->getRefId()
79  );
80 
82  self::ROLE_LS_MEMBER . '_' . $this->object->getRefId(),
83  "LSO member of learning sequence obj_no." . $this->object->getId(),
84  self::ROLE_LS_MEMBER,
85  $this->object->getRefId()
86  );
87  }
88 
92  public function getLocalLearningSequenceRoles(bool $translate = false) : array
93  {
94  if (count($this->local_roles) == 0) {
95  $role_ids = $this->rbacreview->getRolesOfRoleFolder(
96  $this->object->getRefId()
97  );
98 
99  foreach ($role_ids as $role_id) {
100  if ($this->rbacreview->isAssignable(
101  $role_id,
102  $this->object->getRefId()
103  ) == true
104  ) {
105  $role = $this->getRoleObject((int) $role_id);
106 
107  if ($translate) {
108  $role_name = ilObjRole::_getTranslation($role->getTitle());
109  } else {
110  $role_name = $role->getTitle();
111  }
112 
113  $this->local_roles[$role_name] = (int) $role->getId();
114  }
115  }
116  }
117 
118  return $this->local_roles;
119  }
120 
121  public function getDefaultMemberRole() : int
122  {
123  $local_ls_roles = $this->getLocalLearningSequenceRoles();
124  return $local_ls_roles[self::ROLE_LS_MEMBER . "_" . $this->object->getRefId()];
125  }
126 
127  public function getDefaultAdminRole() : int
128  {
129  $local_ls_roles = $this->getLocalLearningSequenceRoles();
130  return $local_ls_roles[self::ROLE_LS_ADMIN . "_" . $this->object->getRefId()];
131  }
132 
133  public function addLSMember(int $user_id, int $role) : bool
134  {
135  return $this->join($user_id, $role);
136  }
137 
138  public function join(int $user_id, $roles) : bool
139  {
140  if (is_array($roles)) {
141  foreach ($roles as $role) {
142  $this->rbacadmin->assignUser($role, $user_id, false);
143  }
144  } else {
145  $this->rbacadmin->assignUser($roles, $user_id, false);
146  }
147 
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->object->getRefId());
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 
232  public function getLearningSequenceAdminIds()
233  {
234  $users = array();
235  $roles = $this->getDefaultLearningSequenceRoles((string) $this->object->getRefId());
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->object->getRefId();
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  {
273  return ilObjectFactory::getInstanceByObjId($obj_id);
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();
280  $privacy = ilPrivacySettings::_getInstance();
281 
282  if ($tracking_enabled) {
283  $olp = ilObjectLP::getInstance($this->object->getId());
284  $tracking_enabled = $olp->isActive();
285 
286  $completed = ilLPStatusWrapper::_lookupCompletedForObject($this->object->getId());
287  $in_progress = ilLPStatusWrapper::_lookupInProgressForObject($this->object->getId());
288  $failed = ilLPStatusWrapper::_lookupFailedForObject($this->object->getId());
289  }
290 
291  if ($privacy->enabledLearningSequenceAccessTimes()) {
292  $progress = ilLearningProgress::_lookupProgressByObjId($this->object->getId());
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->object->getLSParticipants()->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)) {
328  $data['progress'] = ilLPStatus::LP_STATUS_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 }
static _lookupLogin($a_user_id)
lookup login
__construct(ilObjLearningSequence $object, ilLearningSequenceParticipants $participants, ilCtrl $ctrl, ilRbacAdmin $rbacadmin, ilRbacReview $rbacreview, ilDBInterface $database, ilObjUser $user)
static _lookupName($a_user_id)
lookup user name
dropDesktopItem($a_item_id, $a_type)
drop an item from user&#39;s personal desktop
This class provides processing control methods.
$result
Class ilObjLearningSequence.
getLocalLearningSequenceRoles(bool $translate=false)
const LP_STATUS_NOT_ATTEMPTED
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
PHP_EOL
Definition: complexTest.php:5
getLearningSequenceMemberData(array $user_ids, int $active=1)
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
user()
Definition: user.php:4
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
const LP_STATUS_IN_PROGRESS
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
static _enabledUserRelatedData()
check wether user related tracking is enabled or not
static _enabledLearningProgress()
check wether learing progress is enabled or not
const LP_STATUS_FAILED
static _lookupProgressByObjId($a_obj_id)
lookup progress for a specific object
readMemberData(array $user_ids, array $selected_columns=null)
Date and time handling
$query
static getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url=null)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$failed
Definition: Utf8Test.php:85
static _getTranslation($a_role_title)
$users
Definition: authpage.php:44
$row
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
addLSMember(int $user_id, int $role)
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.
static _getInstance()
Get instance of ilPrivacySettings.
Class ilRbacAdmin Core functions for role based access control.
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
const LP_STATUS_COMPLETED
static getInstance($a_obj_id)
if(! $in) $columns
Definition: Utf8Test.php:45
$data
Definition: bench.php:6
class ilRbacReview Contains Review functions of core Rbac.