ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseMembershipGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
22
32{
34 {
35 return new ilMailMemberCourseRoles();
36 }
37
43 public function filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids): array
44 {
45 return $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
46 'manage_members',
47 'manage_members',
48 $this->getParentObject()->getRefId(),
49 $a_user_ids
50 );
51 }
52
56 protected function getMailContextOptions(): array
57 {
58 return [
60 'ref_id' => $this->getParentObject()->getRefId(),
61 'ts' => time(),
63 $this->getParentObject()->getId(),
65 ''
66 ),
67 ];
68 }
69
75 {
76 $this->tpl->setOnScreenMessage('question', $this->lng->txt('crs_ref_delete_confirmation_info'));
77
79 $this,
80 $this->getParentObject(),
81 'confirmDeleteParticipants'
82 );
83 $table->init();
84 $table->setParticipants($participants);
85 $table->parse();
86
87 $this->tpl->setContent($table->getHTML());
88 }
89
90 protected function deleteParticipantsWithLinkedCourses(): void
91 {
93
94 if (!is_array($participants) || $participants === []) {
95 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
96 $this->ctrl->redirect($this, 'participants');
97 }
98
99 // If the user doesn't have the edit_permission and is not administrator, he may not remove
100 // members who have the course administrator role
101 if (
102 !$this->access->checkAccess('edit_permission', '', $this->getParentObject()->getRefId()) &&
103 !$this->getMembersObject()->isAdmin($this->user->getId())
104 ) {
105 foreach ($participants as $part) {
106 if ($this->getMembersObject()->isAdmin($part)) {
107 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_perm'), true);
108 $this->ctrl->redirect($this, 'participants');
109 }
110 }
111 }
112
114 $this->tpl->setOnScreenMessage('failure', 'Error deleting participants.', true);
115 $this->ctrl->redirect($this, 'participants');
116 } else {
117 foreach ($this->initParticipantsFromPost() as $usr_id) {
118 $mail_type = 0;
119 switch ($this->getParentObject()->getType()) {
120 case 'crs':
122 break;
123 }
124 $this->getMembersObject()->sendNotification($mail_type, $usr_id);
125 }
126 }
127
128 $refs = [];
129 if ($this->http->wrapper()->post()->has('refs')) {
130 $refs = $this->http->wrapper()->post()->retrieve(
131 'refs',
132 $this->refinery->kindlyTo()->dictOf(
133 $this->refinery->kindlyTo()->dictOf(
134 $this->refinery->kindlyTo()->int()
135 )
136 )
137 );
138 }
139
140 // Delete course reference assignments
141 foreach ($refs as $usr_id => $usr_info) {
142 foreach ((array) $usr_info as $course_ref_id => $tmp) {
143 $part = ilParticipants::getInstance($course_ref_id);
144 $part->delete($usr_id);
145 }
146 }
147 $this->tpl->setOnScreenMessage(
148 'success',
149 $this->lng->txt($this->getParentObject()->getType() . "_members_deleted"),
150 true
151 );
152 $this->ctrl->redirect($this, "participants");
153 }
154
158 public function assignMembers(array $a_usr_ids, string $a_type): bool
159 {
160 $a_type = (int) $a_type;
161 if (!$this->checkRbacOrPositionAccessBool('manage_members', 'manage_members')) {
162 $this->error->raiseError($this->lng->txt("msg_no_perm_read"), $this->error->FATAL);
163 }
164 if ($a_usr_ids === []) {
165 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_no_users_selected"), true);
166 return false;
167 }
168 $a_usr_ids = $this->filterUserIdsByRbacOrPositionOfCurrentUser($a_usr_ids);
169
170 $added_users = 0;
171 foreach ($a_usr_ids as $user_id) {
172 if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
173 continue;
174 }
175 if ($this->getMembersObject()->isAssigned($user_id)) {
176 continue;
177 }
178 switch ($a_type) {
179 case $this->getParentObject()->getDefaultMemberRole():
180 $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_MEMBER);
181 break;
182 case $this->getParentObject()->getDefaultTutorRole():
183 $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_TUTOR);
184 break;
185 case $this->getParentObject()->getDefaultAdminRole():
186 $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_ADMIN);
187 break;
188 default:
189 if (in_array($a_type, $this->getParentObject()->getLocalCourseRoles(true))) {
190 $this->getMembersObject()->add($user_id, ilParticipants::IL_CRS_MEMBER);
191 $this->getMembersObject()->updateRoleAssignments($user_id, (array) $a_type);
192 } else {
193 ilLoggerFactory::getLogger('crs')->notice('Can\'t find role with id .' . $a_type . ' to assign users.');
194 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_cannot_find_role"), true);
195 return false;
196 }
197 break;
198 }
200
201 $this->getParentObject()->checkLPStatusSync($user_id);
202
203 ++$added_users;
204 }
205 if ($added_users) {
206 $this->tpl->setOnScreenMessage('success', $this->lng->txt("crs_users_added"), true);
207 $this->ctrl->redirect($this, 'participants');
208 }
209 $this->tpl->setOnScreenMessage('info', $this->lng->txt("crs_users_already_assigned"), true);
210 return false;
211 }
212
213 protected function initParticipantStatusFromPostFor(string $item_key): array
214 {
215 if ($this->http->wrapper()->post()->has($item_key)) {
216 return $this->http->wrapper()->post()->retrieve(
217 $item_key,
218 $this->refinery->kindlyTo()->listOf(
219 $this->refinery->kindlyTo()->int()
220 )
221 );
222 }
223 return [];
224 }
225
226 protected function updateParticipantsStatus(): void
227 {
228 $visible_members = [];
229 if ($this->http->wrapper()->post()->has('visible_member_ids')) {
230 $visible_members = $this->http->wrapper()->post()->retrieve(
231 'visible_member_ids',
232 $this->refinery->kindlyTo()->listOf(
233 $this->refinery->kindlyTo()->int()
234 )
235 );
236 }
237 $passed = $this->initParticipantStatusFromPostFor('passed');
238 $blocked = $this->initParticipantStatusFromPostFor('blocked');
239 $contact = $this->initParticipantStatusFromPostFor('contact');
240 $notification = $this->initParticipantStatusFromPostFor('notification');
241
242 foreach ($visible_members as $member_id) {
243 if ($this->access->checkAccess("grade", "", $this->getParentObject()->getRefId())) {
244 $this->getMembersObject()->updatePassed($member_id, in_array($member_id, $passed), true);
245 $this->updateLPFromStatus($member_id, in_array($member_id, $passed));
246 }
247
248 if ($this->getMembersObject()->isAdmin($member_id) || $this->getMembersObject()->isTutor($member_id)) {
249 // remove blocked
250 $this->getMembersObject()->updateBlocked($member_id, false);
251 $this->getMembersObject()->updateNotification($member_id, in_array($member_id, $notification));
252 $this->getMembersObject()->updateContact($member_id, in_array($member_id, $contact));
253 } else {
254 // send notifications => unblocked
255 if ($this->getMembersObject()->isBlocked($member_id) && !in_array($member_id, $blocked)) {
256 $this->getMembersObject()->sendNotification(
258 $member_id
259 );
260 }
261 // => blocked
262 if (!$this->getMembersObject()->isBlocked($member_id) && in_array($member_id, $blocked)) {
263 $this->getMembersObject()->sendNotification(
265 $member_id
266 );
267 }
268
269 // normal member => remove notification, contact
270 $this->getMembersObject()->updateNotification($member_id, false);
271 $this->getMembersObject()->updateContact($member_id, false);
272 $this->getMembersObject()->updateBlocked($member_id, in_array($member_id, $blocked));
273 }
274 }
275 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
276 $this->ctrl->redirect($this, 'participants');
277 }
278
280 {
281 $show_tracking =
283 if ($show_tracking) {
285 $show_tracking = $olp->isActive();
286 }
287
288 $timings_enabled =
289 (ilObjectActivation::hasTimings($this->getParentObject()->getRefId()) && ($this->getParentObject()->getViewMode() == ilCourseConstants::IL_CRS_VIEW_TIMING));
290
292 $this,
293 $this->getParentObject(),
294 $show_tracking,
295 $timings_enabled,
296 $this->getParentObject()->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP
297 );
298 }
299
301 {
303 $table = new ilCourseEditParticipantsTableGUI($this, $this->getParentObject());
304 $table->setTitle($this->lng->txt($this->getParentObject()->getType() . '_header_edit_members'));
305 $table->setData($this->getParentGUI()->readMemberData($participants));
306
307 return $table;
308 }
309
310 protected function initParticipantTemplate(): void
311 {
312 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.crs_edit_members.html', 'components/ILIAS/Course');
313 }
314
318 public function getLocalTypeRole(bool $a_translation = false): array
319 {
320 return $this->getParentObject()->getLocalCourseRoles($a_translation);
321 }
322
323 public function readMemberData(array $usr_ids, array $columns, bool $skip_names = false): array
324 {
325 return $this->getParentGUI()->readMemberData($usr_ids, $columns, $skip_names);
326 }
327
328 protected function updateLPFromStatus(int $a_member_id, bool $a_passed): void
329 {
330 $this->getParentGUI()->updateLPFromStatus($a_member_id, $a_passed);
331 }
332
334 {
335 return new ilCourseWaitingList($this->getParentObject()->getId());
336 }
337
338 protected function getDefaultRole(): ?int
339 {
340 return $this->getParentGUI()->getObject()->getDefaultMemberRole();
341 }
342
343 protected function deliverCertificate(): void
344 {
345 $this->getParentGUI()->deliverCertificateObject();
346 }
347
348 protected function getPrintMemberData(array $a_members): array
349 {
350 $this->lng->loadLanguageModule('trac');
351
352 $is_admin = true;
354
355 if ($privacy->enabledCourseAccessTimes()) {
357 }
358
359 $show_tracking =
361 if ($show_tracking) {
363 $show_tracking = $olp->isActive();
364 }
365
366 if ($show_tracking) {
370 }
371
372 $profile_data = ilObjUser::_readUsersProfileData($a_members);
373
374 // course defined fields
376
377 $udf_data = $this->profile->getAllUserDefinedFields();
378 $print_member = [];
379 foreach ($a_members as $member_id) {
380 // GET USER OBJ
381 if ($tmp_obj = ilObjectFactory::getInstanceByObjId($member_id, false)) {
382 foreach ($udf_data->getAll() as $field) {
383 $print_member[$member_id]['udf_' . $field->getIdentifier()] = (string) $field->retrieveValueFromUser($tmp_obj);
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}
const IL_CAL_UNIX
error(string $a_errmsg)
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)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
showDeleteParticipantsConfirmationWithLinkedCourses(array $participants)
Show deletion confirmation with linked courses.
readMemberData(array $usr_ids, array $columns, bool $skip_names=false)
updateLPFromStatus(int $a_member_id, bool $a_passed)
getAttendanceListUserData(int $user_id, array $filters=[])
initEditParticipantTableGUI(array $participants)
assignMembers(array $a_usr_ids, string $a_type)
callback from repository search gui
initParticipantStatusFromPostFor(string $item_key)
filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids)
Filter user ids by access.
getLocalTypeRole(bool $a_translation=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getValuesByObjId(int $a_obj_id)
static setUseRelativeDates(bool $a_status)
set use relative dates
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)
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
static _lookupProgressByObjId(int $a_obj_id)
lookup progress for a specific object
static getLogger(string $a_component_id)
Get component logger.
final const string CONTEXT_KEY
Class ilMailMemberCourseRoles.
const string PROP_CONTEXT_SUBJECT_PREFIX
Base class for member tab content.
ilParticipants $participants
checkRbacOrPositionAccessBool(string $a_rbac_perm, string $a_pos_perm, int $a_ref_id=0)
const int STATUS_DETERMINATION_LP
static _readUsersProfileData(array $a_user_ids)
static hasTimings(int $ref_id)
Check if there is any active timing (in subtree)
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)
static getInstance(int $a_ref_id)
static get(string $a_var)
static http()
Fetches the global http state from ILIAS.
$GLOBALS["DIC"]
Definition: wac.php:54