ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCourseMembershipGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
30 {
32  {
33  return new ilMailMemberCourseRoles();
34  }
35 
41  public function filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids): array
42  {
43  return $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
44  'manage_members',
45  'manage_members',
46  $this->getParentObject()->getRefId(),
47  $a_user_ids
48  );
49  }
50 
54  protected function getMailContextOptions(): array
55  {
56  return [
58  'ref_id' => $this->getParentObject()->getRefId(),
59  'ts' => time(),
61  $this->getParentObject()->getId(),
63  ''
64  ),
65  ];
66  }
67 
73  {
74  $this->tpl->setOnScreenMessage('question', $this->lng->txt('crs_ref_delete_confirmation_info'));
75 
77  $this,
78  $this->getParentObject(),
79  'confirmDeleteParticipants'
80  );
81  $table->init();
82  $table->setParticipants($participants);
83  $table->parse();
84 
85  $this->tpl->setContent($table->getHTML());
86  }
87 
88  protected function deleteParticipantsWithLinkedCourses(): void
89  {
91 
92  if (!is_array($participants) || $participants === []) {
93  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
94  $this->ctrl->redirect($this, 'participants');
95  }
96 
97  // If the user doesn't have the edit_permission and is not administrator, he may not remove
98  // members who have the course administrator role
99  if (
100  !$this->access->checkAccess('edit_permission', '', $this->getParentObject()->getRefId()) &&
101  !$this->getMembersObject()->isAdmin($this->user->getId())
102  ) {
103  foreach ($participants as $part) {
104  if ($this->getMembersObject()->isAdmin($part)) {
105  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_perm'), true);
106  $this->ctrl->redirect($this, 'participants');
107  }
108  }
109  }
110 
112  $this->tpl->setOnScreenMessage('failure', 'Error deleting participants.', true);
113  $this->ctrl->redirect($this, 'participants');
114  } else {
115  foreach ($this->initParticipantsFromPost() as $usr_id) {
116  $mail_type = 0;
117  switch ($this->getParentObject()->getType()) {
118  case 'crs':
120  break;
121  }
122  $this->getMembersObject()->sendNotification($mail_type, $usr_id);
123  }
124  }
125 
126  $refs = [];
127  if ($this->http->wrapper()->post()->has('refs')) {
128  $refs = $this->http->wrapper()->post()->retrieve(
129  'refs',
130  $this->refinery->kindlyTo()->dictOf(
131  $this->refinery->kindlyTo()->dictOf(
132  $this->refinery->kindlyTo()->int()
133  )
134  )
135  );
136  }
137 
138  // Delete course reference assignments
139  foreach ($refs as $usr_id => $usr_info) {
140  foreach ((array) $usr_info as $course_ref_id => $tmp) {
141  $part = ilParticipants::getInstance($course_ref_id);
142  $part->delete($usr_id);
143  }
144  }
145  $this->tpl->setOnScreenMessage(
146  'success',
147  $this->lng->txt($this->getParentObject()->getType() . "_members_deleted"),
148  true
149  );
150  $this->ctrl->redirect($this, "participants");
151  }
152 
156  public function assignMembers(array $a_usr_ids, string $a_type): bool
157  {
158  $a_type = (int) $a_type;
159  if (!$this->checkRbacOrPositionAccessBool('manage_members', 'manage_members')) {
160  $this->error->raiseError($this->lng->txt("msg_no_perm_read"), $this->error->FATAL);
161  }
162  if ($a_usr_ids === []) {
163  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_no_users_selected"), true);
164  return false;
165  }
166  $a_usr_ids = $this->filterUserIdsByRbacOrPositionOfCurrentUser($a_usr_ids);
167 
168  $added_users = 0;
169  foreach ($a_usr_ids as $user_id) {
170  if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
171  continue;
172  }
173  if ($this->getMembersObject()->isAssigned($user_id)) {
174  continue;
175  }
176  switch ($a_type) {
177  case $this->getParentObject()->getDefaultMemberRole():
178  $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_MEMBER);
179  break;
180  case $this->getParentObject()->getDefaultTutorRole():
181  $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_TUTOR);
182  break;
183  case $this->getParentObject()->getDefaultAdminRole():
184  $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_ADMIN);
185  break;
186  default:
187  if (in_array($a_type, $this->getParentObject()->getLocalCourseRoles(true))) {
188  $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_MEMBER);
189  $this->getMembersObject()->updateRoleAssignments($user_id, (array) $a_type);
190  } else {
191  ilLoggerFactory::getLogger('crs')->notice('Can\'t find role with id .' . $a_type . ' to assign users.');
192  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_cannot_find_role"), true);
193  return false;
194  }
195  break;
196  }
198 
199  $this->getParentObject()->checkLPStatusSync($user_id);
200 
201  ++$added_users;
202  }
203  if ($added_users) {
204  $this->tpl->setOnScreenMessage('success', $this->lng->txt("crs_users_added"), true);
205  $this->ctrl->redirect($this, 'participants');
206  }
207  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_users_already_assigned"), true);
208  return false;
209  }
210 
211  protected function initParticipantStatusFromPostFor(string $item_key): array
212  {
213  if ($this->http->wrapper()->post()->has($item_key)) {
214  return $this->http->wrapper()->post()->retrieve(
215  $item_key,
216  $this->refinery->kindlyTo()->listOf(
217  $this->refinery->kindlyTo()->int()
218  )
219  );
220  }
221  return [];
222  }
223 
224  protected function updateParticipantsStatus(): void
225  {
226  $visible_members = [];
227  if ($this->http->wrapper()->post()->has('visible_member_ids')) {
228  $visible_members = $this->http->wrapper()->post()->retrieve(
229  'visible_member_ids',
230  $this->refinery->kindlyTo()->listOf(
231  $this->refinery->kindlyTo()->int()
232  )
233  );
234  }
235  $passed = $this->initParticipantStatusFromPostFor('passed');
236  $blocked = $this->initParticipantStatusFromPostFor('blocked');
237  $contact = $this->initParticipantStatusFromPostFor('contact');
238  $notification = $this->initParticipantStatusFromPostFor('notification');
239 
240  foreach ($visible_members as $member_id) {
241  if ($this->access->checkAccess("grade", "", $this->getParentObject()->getRefId())) {
242  $this->getMembersObject()->updatePassed($member_id, in_array($member_id, $passed), true);
243  $this->updateLPFromStatus($member_id, in_array($member_id, $passed));
244  }
245 
246  if ($this->getMembersObject()->isAdmin($member_id) || $this->getMembersObject()->isTutor($member_id)) {
247  // remove blocked
248  $this->getMembersObject()->updateBlocked($member_id, false);
249  $this->getMembersObject()->updateNotification($member_id, in_array($member_id, $notification));
250  $this->getMembersObject()->updateContact($member_id, in_array($member_id, $contact));
251  } else {
252  // send notifications => unblocked
253  if ($this->getMembersObject()->isBlocked($member_id) && !in_array($member_id, $blocked)) {
254  $this->getMembersObject()->sendNotification(
256  $member_id
257  );
258  }
259  // => blocked
260  if (!$this->getMembersObject()->isBlocked($member_id) && in_array($member_id, $blocked)) {
261  $this->getMembersObject()->sendNotification(
263  $member_id
264  );
265  }
266 
267  // normal member => remove notification, contact
268  $this->getMembersObject()->updateNotification($member_id, false);
269  $this->getMembersObject()->updateContact($member_id, false);
270  $this->getMembersObject()->updateBlocked($member_id, in_array($member_id, $blocked));
271  }
272  }
273  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
274  $this->ctrl->redirect($this, 'participants');
275  }
276 
278  {
279  $show_tracking =
281  if ($show_tracking) {
282  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
283  $show_tracking = $olp->isActive();
284  }
285 
286  $timings_enabled =
287  (ilObjectActivation::hasTimings($this->getParentObject()->getRefId()) && ($this->getParentObject()->getViewMode() == ilCourseConstants::IL_CRS_VIEW_TIMING));
288 
289  return new ilCourseParticipantsTableGUI(
290  $this,
291  $this->getParentObject(),
292  $show_tracking,
293  $timings_enabled,
294  $this->getParentObject()->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP
295  );
296  }
297 
299  {
301  $table = new ilCourseEditParticipantsTableGUI($this, $this->getParentObject());
302  $table->setTitle($this->lng->txt($this->getParentObject()->getType() . '_header_edit_members'));
303  $table->setData($this->getParentGUI()->readMemberData($participants));
304 
305  return $table;
306  }
307 
308  protected function initParticipantTemplate(): void
309  {
310  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.crs_edit_members.html', 'Modules/Course');
311  }
312 
316  public function getLocalTypeRole(bool $a_translation = false): array
317  {
318  return $this->getParentObject()->getLocalCourseRoles($a_translation);
319  }
320 
321  public function readMemberData(array $usr_ids, array $columns, bool $skip_names = false): array
322  {
323  return $this->getParentGUI()->readMemberData($usr_ids, $columns, $skip_names);
324  }
325 
326  protected function updateLPFromStatus(int $a_member_id, bool $a_passed): void
327  {
328  $this->getParentGUI()->updateLPFromStatus($a_member_id, $a_passed);
329  }
330 
331  protected function initWaitingList(): ilCourseWaitingList
332  {
333  return new ilCourseWaitingList($this->getParentObject()->getId());
334  }
335 
336  protected function getDefaultRole(): ?int
337  {
338  return $this->getParentGUI()->getObject()->getDefaultMemberRole();
339  }
340 
341  protected function deliverCertificate(): void
342  {
343  $this->getParentGUI()->deliverCertificateObject();
344  }
345 
346  protected function getPrintMemberData(array $a_members): array
347  {
348  $this->lng->loadLanguageModule('trac');
349 
350  $is_admin = true;
351  $privacy = ilPrivacySettings::getInstance();
352 
353  if ($privacy->enabledCourseAccessTimes()) {
355  }
356 
357  $show_tracking =
359  if ($show_tracking) {
360  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
361  $show_tracking = $olp->isActive();
362  }
363 
364  if ($show_tracking) {
368  }
369 
370  $profile_data = ilObjUser::_readUsersProfileData($a_members);
371 
372  // course defined fields
374 
375  $print_member = [];
376  foreach ($a_members as $member_id) {
377  // GET USER OBJ
378  if ($tmp_obj = ilObjectFactory::getInstanceByObjId($member_id, false)) {
379  // udf
380  $udf_data = new ilUserDefinedData($member_id);
381  foreach ($udf_data->getAll() as $field => $value) {
382  list($f, $field_id) = explode('_', $field);
383  $print_member[$member_id]['udf_' . $field_id] = (string) $value;
384  }
385 
386  foreach ((array) ($cdfs[$member_id] ?? []) as $cdf_field => $cdf_value) {
387  $print_member[$member_id]['cdf_' . $cdf_field] = (string) $cdf_value;
388  }
389 
390  foreach ((array) $profile_data[$member_id] as $field => $value) {
391  $print_member[$member_id][$field] = $value;
392  }
393 
394  $print_member[$member_id]['login'] = $tmp_obj->getLogin();
395  $print_member[$member_id]['name'] = $tmp_obj->getLastname() . ', ' . $tmp_obj->getFirstname();
396 
397  if ($this->getMembersObject()->isAdmin($member_id)) {
398  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_admin");
399  } elseif ($this->getMembersObject()->isTutor($member_id)) {
400  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_tutor");
401  } elseif ($this->getMembersObject()->isMember($member_id)) {
402  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_member");
403  }
404  if ($this->getMembersObject()->isAdmin($member_id) || $this->getMembersObject()->isTutor($member_id)) {
405  if ($this->getMembersObject()->isNotificationEnabled($member_id)) {
406  $print_member[$member_id]['status'] = $this->lng->txt("crs_notify");
407  } else {
408  $print_member[$member_id]['status'] = $this->lng->txt("crs_no_notify");
409  }
410  } else {
411  if ($this->getMembersObject()->isBlocked($member_id)) {
412  $print_member[$member_id]['status'] = $this->lng->txt("crs_blocked");
413  } else {
414  $print_member[$member_id]['status'] = $this->lng->txt("crs_unblocked");
415  }
416  }
417 
418  if ($is_admin) {
419  $print_member[$member_id]['passed'] = $this->getMembersObject()->hasPassed($member_id) ?
420  $this->lng->txt('crs_member_passed') :
421  $this->lng->txt('crs_member_not_passed');
422  }
423  if ($privacy->enabledCourseAccessTimes()) {
424  if (isset($progress[$member_id]['ts']) && $progress[$member_id]['ts']) {
426  $print_member[$member_id]['access'] = ilDatePresentation::formatDate(new ilDateTime(
427  $progress[$member_id]['ts'],
429  ));
431  } else {
432  $print_member[$member_id]['access'] = $this->lng->txt('no_date');
433  }
434  }
435  if ($show_tracking) {
436  if (in_array($member_id, $completed)) {
437  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_COMPLETED);
438  } elseif (in_array($member_id, $in_progress)) {
439  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_IN_PROGRESS);
440  } elseif (in_array($member_id, $failed)) {
441  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_FAILED);
442  } else {
443  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED);
444  }
445  }
446  }
447  }
448  $print_order = (string) (ilSession::get('crs_print_order') ?? '');
449  return ilArrayUtil::sortArray($print_member, 'name', $print_order, false, true);
450  }
451 
452  public function getAttendanceListUserData(int $user_id, array $filters = []): array
453  {
454  if (is_array($this->member_data) && array_key_exists($user_id, $this->member_data)) {
455  return $this->member_data[$user_id];
456  }
457  return [];
458  }
459 }
static get(string $a_var)
Base class for member tab content.
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const LP_STATUS_NOT_ATTEMPTED
const PROP_CONTEXT_SUBJECT_PREFIX
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
static getInstance(int $a_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateLPFromStatus(int $a_member_id, bool $a_passed)
showDeleteParticipantsConfirmationWithLinkedCourses(array $participants)
Show deletion confirmation with linked courses.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _getValuesByObjId(int $a_obj_id)
initParticipantStatusFromPostFor(string $item_key)
const IL_CAL_UNIX
const STATUS_DETERMINATION_LP
const LP_STATUS_IN_PROGRESS
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
readMemberData(array $usr_ids, array $columns, bool $skip_names=false)
assignMembers(array $a_usr_ids, string $a_type)
callback from repository search gui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLocalTypeRole(bool $a_translation=false)
Class ilMailMemberCourseRoles.
static http()
Fetches the global http state from ILIAS.
const LP_STATUS_FAILED
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilParticipants $participants
getAttendanceListUserData(int $user_id, array $filters=[])
initEditParticipantTableGUI(array $participants)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _readUsersProfileData(array $a_user_ids)
static hasTimings(int $ref_id)
Check if there is any active timing (in subtree)
filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids)
Filter user ids by access.
static _lookupProgressByObjId(int $a_obj_id)
lookup progress for a specific object
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
checkRbacOrPositionAccessBool(string $a_rbac_perm, string $a_pos_perm, int $a_ref_id=0)
static setUseRelativeDates(bool $a_status)
set use relative dates
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const LP_STATUS_COMPLETED
static getInstance(int $obj_id)
Class ilAbstractMailMemberRoles.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)