ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCourseMembershipGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once './Services/Membership/classes/class.ilMembershipGUI.php';
6
19{
23 protected function getMailMemberRoles()
24 {
25 return new ilMailMemberCourseRoles();
26 }
27
33 public function filterUserIdsByRbacOrPositionOfCurrentUser($a_user_ids)
34 {
35 return $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
36 'manage_members',
37 'manage_members',
38 $this->getParentObject()->getRefId(),
39 $a_user_ids
40 );
41 }
42
46 protected function getMailContextOptions() : array
47 {
48 $context_options = [
50 'ref_id' => $this->getParentObject()->getRefId(),
51 'ts' => time(),
53 $this->getParentObject()->getId(),
55 ''
56 ),
57 ];
58
59 return $context_options;
60 }
61
67 {
68 ilUtil::sendQuestion($this->lng->txt('crs_ref_delete_confirmation_info'));
69
70 $table = new ilCourseReferenceDeleteConfirmationTableGUI($this, $this->getParentObject(), 'confirmDeleteParticipants');
71 $table->init();
72 $table->setParticipants($participants);
73 $table->parse();
74
75 $this->tpl->setContent($table->getHTML());
76 }
77
78
83 {
84 global $DIC;
85
86 $ilAccess = $DIC['ilAccess'];
87
88 $participants = (array) $_POST['participants'];
89
90 if (!is_array($participants) or !count($participants)) {
91 ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
92 $this->ctrl->redirect($this, 'participants');
93 }
94
95 // If the user doesn't have the edit_permission and is not administrator, he may not remove
96 // members who have the course administrator role
97 if (
98 !$ilAccess->checkAccess('edit_permission', '', $this->getParentObject()->getRefId()) &&
99 !$this->getMembersObject()->isAdmin($GLOBALS['DIC']['ilUser']->getId())
100 ) {
101 foreach ($participants as $part) {
102 if ($this->getMembersObject()->isAdmin($part)) {
103 ilUtil::sendFailure($this->lng->txt('msg_no_perm_perm'), true);
104 $this->ctrl->redirect($this, 'participants');
105 }
106 }
107 }
108
109 if (!$this->getMembersObject()->deleteParticipants($participants)) {
110 ilUtil::sendFailure('Error deleting participants.', true);
111 $this->ctrl->redirect($this, 'participants');
112 } else {
113 foreach ((array) $_POST["participants"] as $usr_id) {
114 $mail_type = 0;
115 switch ($this->getParentObject()->getType()) {
116 case 'crs':
117 $mail_type = $this->getMembersObject()->NOTIFY_DISMISS_MEMBER;
118 break;
119 }
120 $this->getMembersObject()->sendNotification($mail_type, $usr_id);
121 }
122 }
123
124 // Delete course reference assignments
125 if (count((array) $_POST['refs'])) {
126 foreach ($_POST['refs'] as $usr_id => $usr_info) {
127 foreach ((array) $usr_info as $course_ref_id => $tmp) {
128 $part = ilParticipants::getInstance($course_ref_id);
129 $part->delete($usr_id);
130 }
131 }
132 }
133
134 ilUtil::sendSuccess($this->lng->txt($this->getParentObject()->getType() . "_members_deleted"), true);
135 $this->ctrl->redirect($this, "participants");
136
137 return true;
138 }
139
140
148 public function assignMembers(array $a_usr_ids, $a_type)
149 {
150 global $DIC;
151
152 $rbacsystem = $DIC['rbacsystem'];
153 $ilErr = $DIC['ilErr'];
154
155 if (!$this->checkRbacOrPositionAccessBool('manage_members', 'manage_members')) {
156 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
157 }
158
159 if (!count($a_usr_ids)) {
160 ilUtil::sendFailure($this->lng->txt("crs_no_users_selected"), true);
161 return false;
162 }
163
164 $a_usr_ids = $this->filterUserIdsByRbacOrPositionOfCurrentUser($a_usr_ids);
165
166 $added_users = 0;
167 foreach ($a_usr_ids as $user_id) {
168 if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
169 continue;
170 }
171 if ($this->getMembersObject()->isAssigned($user_id)) {
172 continue;
173 }
174 switch ($a_type) {
175 case $this->getParentObject()->getDefaultMemberRole():
176 $this->getMembersObject()->add($user_id, IL_CRS_MEMBER);
177 break;
178 case $this->getParentObject()->getDefaultTutorRole():
179 $this->getMembersObject()->add($user_id, IL_CRS_TUTOR);
180 break;
181 case $this->getParentObject()->getDefaultAdminRole():
182 $this->getMembersObject()->add($user_id, IL_CRS_ADMIN);
183 break;
184 default:
185 if (in_array($a_type, $this->getParentObject()->getLocalCourseRoles(true))) {
186 $this->getMembersObject()->add($user_id, IL_CRS_MEMBER);
187 $this->getMembersObject()->updateRoleAssignments($user_id, (array) $a_type);
188 } else {
189 ilLoggerFactory::getLogger('crs')->notice('Can\'t find role with id .' . $a_type . ' to assign users.');
190 ilUtil::sendFailure($this->lng->txt("crs_cannot_find_role"), true);
191 return false;
192 }
193 break;
194 }
195 $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_ACCEPT_USER, $user_id);
196
197 $this->getParentObject()->checkLPStatusSync($user_id);
198
199 ++$added_users;
200 }
201 if ($added_users) {
202 ilUtil::sendSuccess($this->lng->txt("crs_users_added"), true);
203 $this->ctrl->redirect($this, 'participants');
204 }
205 ilUtil::sendFailure($this->lng->txt("crs_users_already_assigned"), true);
206 return false;
207 }
208
212 protected function updateParticipantsStatus()
213 {
214 global $DIC;
215
216 $ilAccess = $DIC['ilAccess'];
217 $ilErr = $DIC['ilErr'];
218 $ilUser = $DIC['ilUser'];
219 $rbacadmin = $DIC['rbacadmin'];
220
221 $visible_members = (array) $_POST['visible_member_ids'];
222 $passed = (array) $_POST['passed'];
223 $blocked = (array) $_POST['blocked'];
224 $contact = (array) $_POST['contact'];
225 $notification = (array) $_POST['notification'];
226
227 foreach ($visible_members as $member_id) {
228 if ($ilAccess->checkAccess("grade", "", $this->getParentObject()->getRefId())) {
229 $this->getMembersObject()->updatePassed($member_id, in_array($member_id, $passed), true);
230 $this->updateLPFromStatus($member_id, in_array($member_id, $passed));
231 }
232
233 if ($this->getMembersObject()->isAdmin($member_id) or $this->getMembersObject()->isTutor($member_id)) {
234 // remove blocked
235 $this->getMembersObject()->updateBlocked($member_id, 0);
236 $this->getMembersObject()->updateNotification($member_id, in_array($member_id, $notification));
237 $this->getMembersObject()->updateContact($member_id, in_array($member_id, $contact));
238 } else {
239 // send notifications => unblocked
240 if ($this->getMembersObject()->isBlocked($member_id) && !in_array($member_id, $blocked)) {
241 $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_UNBLOCK_MEMBER, $member_id);
242 }
243 // => blocked
244 if (!$this->getMembersObject()->isBlocked($member_id) && in_array($member_id, $blocked)) {
245 $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_BLOCK_MEMBER, $member_id);
246 }
247
248 // normal member => remove notification, contact
249 $this->getMembersObject()->updateNotification($member_id, false);
250 $this->getMembersObject()->updateContact($member_id, false);
251 $this->getMembersObject()->updateBlocked($member_id, in_array($member_id, $blocked));
252 }
253 }
254
255
256 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
257 $this->ctrl->redirect($this, 'participants');
258 }
259
260
264 protected function initParticipantTableGUI()
265 {
266 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
267 $show_tracking =
269 ;
270 if ($show_tracking) {
271 include_once('./Services/Object/classes/class.ilObjectLP.php');
272 $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
273 $show_tracking = $olp->isActive();
274 }
275
276 include_once('./Services/Object/classes/class.ilObjectActivation.php');
277 $timings_enabled =
278 (ilObjectActivation::hasTimings($this->getParentObject()->getRefId()) && ($this->getParentObject()->getViewMode() == IL_CRS_VIEW_TIMING))
279 ;
280
281
282 include_once './Modules/Course/classes/class.ilCourseParticipantsTableGUI.php';
284 $this,
285 $this->getParentObject(),
286 $show_tracking,
287 $timings_enabled,
288 $this->getParentObject()->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP
289 );
290 }
291
297 protected function initEditParticipantTableGUI(array $participants)
298 {
299 include_once './Modules/Course/classes/class.ilCourseEditParticipantsTableGUI.php';
300 $table = new ilCourseEditParticipantsTableGUI($this, $this->getParentObject());
301 $table->setTitle($this->lng->txt($this->getParentObject()->getType() . '_header_edit_members'));
302 $table->setData($this->getParentGUI()->readMemberData($participants));
303
304 return $table;
305 }
306
310 protected function initParticipantTemplate()
311 {
312 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.crs_edit_members.html', 'Modules/Course');
313 }
314
318 public function getLocalTypeRole($a_translation = false)
319 {
320 return $this->getParentObject()->getLocalCourseRoles($a_translation);
321 }
322
323 public function readMemberData(array $usr_ids, array $columns, bool $skip_names = false)
324 {
325 return $this->getParentGUI()->readMemberData($usr_ids, $columns, $skip_names);
326 }
327
331 protected function updateLPFromStatus($a_member_id, $a_passed)
332 {
333 return $this->getParentGUI()->updateLPFromStatus($a_member_id, $a_passed);
334 }
335
340 protected function initWaitingList()
341 {
342 include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
343 $wait = new ilCourseWaitingList($this->getParentObject()->getId());
344 return $wait;
345 }
346
350 protected function getDefaultRole()
351 {
352 return $this->getParentGUI()->object->getDefaultMemberRole();
353 }
354
359 protected function deliverCertificate()
360 {
361 return $this->getParentGUI()->deliverCertificateObject();
362 }
363
368 protected function getPrintMemberData($a_members)
369 {
370 global $DIC;
371
372 $ilAccess = $DIC['ilAccess'];
373 $lng = $DIC['lng'];
374
375 $lng->loadLanguageModule('trac');
376
377 $is_admin = true;
378 include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
380
381 if ($privacy->enabledCourseAccessTimes()) {
382 include_once('./Services/Tracking/classes/class.ilLearningProgress.php');
383 $progress = ilLearningProgress::_lookupProgressByObjId($this->getParentObject()->getId());
384 }
385
386 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
387 $show_tracking =
389 if ($show_tracking) {
390 include_once('./Services/Object/classes/class.ilObjectLP.php');
391 $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
392 $show_tracking = $olp->isActive();
393 }
394
395 if ($show_tracking) {
396 include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
398 $in_progress = ilLPStatusWrapper::_lookupInProgressForObject($this->getParentObject()->getId());
400 }
401
402 $profile_data = ilObjUser::_readUsersProfileData($a_members);
403
404 // course defined fields
405 include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
406 $cdfs = ilCourseUserData::_getValuesByObjId($this->getParentObject()->getId());
407
408 $print_member = [];
409 foreach ($a_members as $member_id) {
410 // GET USER OBJ
411 if ($tmp_obj = ilObjectFactory::getInstanceByObjId($member_id, false)) {
412 // udf
413 include_once './Services/User/classes/class.ilUserDefinedData.php';
414 $udf_data = new ilUserDefinedData($member_id);
415 foreach ($udf_data->getAll() as $field => $value) {
416 list($f, $field_id) = explode('_', $field);
417 $print_member[$member_id]['udf_' . $field_id] = (string) $value;
418 }
419
420 foreach ((array) $cdfs[$member_id] as $cdf_field => $cdf_value) {
421 $print_member[$member_id]['cdf_' . $cdf_field] = (string) $cdf_value;
422 }
423
424 foreach ((array) $profile_data[$member_id] as $field => $value) {
425 $print_member[$member_id][$field] = $value;
426 }
427
428 $print_member[$member_id]['login'] = $tmp_obj->getLogin();
429 $print_member[$member_id]['name'] = $tmp_obj->getLastname() . ', ' . $tmp_obj->getFirstname();
430
431 if ($this->getMembersObject()->isAdmin($member_id)) {
432 $print_member[$member_id]['role'] = $this->lng->txt("il_crs_admin");
433 } elseif ($this->getMembersObject()->isTutor($member_id)) {
434 $print_member[$member_id]['role'] = $this->lng->txt("il_crs_tutor");
435 } elseif ($this->getMembersObject()->isMember($member_id)) {
436 $print_member[$member_id]['role'] = $this->lng->txt("il_crs_member");
437 }
438 if ($this->getMembersObject()->isAdmin($member_id) or $this->getMembersObject()->isTutor($member_id)) {
439 if ($this->getMembersObject()->isNotificationEnabled($member_id)) {
440 $print_member[$member_id]['status'] = $this->lng->txt("crs_notify");
441 } else {
442 $print_member[$member_id]['status'] = $this->lng->txt("crs_no_notify");
443 }
444 } else {
445 if ($this->getMembersObject()->isBlocked($member_id)) {
446 $print_member[$member_id]['status'] = $this->lng->txt("crs_blocked");
447 } else {
448 $print_member[$member_id]['status'] = $this->lng->txt("crs_unblocked");
449 }
450 }
451
452 if ($is_admin) {
453 $print_member[$member_id]['passed'] = $this->getMembersObject()->hasPassed($member_id) ?
454 $this->lng->txt('crs_member_passed') :
455 $this->lng->txt('crs_member_not_passed');
456 }
457 if ($privacy->enabledCourseAccessTimes()) {
458 if (isset($progress[$member_id]['ts']) and $progress[$member_id]['ts']) {
460 $print_member[$member_id]['access'] = ilDatePresentation::formatDate(new ilDateTime($progress[$member_id]['ts'], IL_CAL_UNIX));
462 } else {
463 $print_member[$member_id]['access'] = $this->lng->txt('no_date');
464 }
465 }
466 if ($show_tracking) {
467 if (in_array($member_id, $completed)) {
468 $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_COMPLETED);
469 } elseif (in_array($member_id, $in_progress)) {
470 $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_IN_PROGRESS);
471 } elseif (in_array($member_id, $failed)) {
472 $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_FAILED);
473 } else {
474 $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED);
475 }
476 }
477 }
478 }
479 return ilUtil::sortArray($print_member, 'name', $_SESSION['crs_print_order'], false, true);
480 }
481
486 public function getAttendanceListUserData($a_user_id)
487 {
488 if (is_array($this->member_data) && array_key_exists($a_user_id, $this->member_data)) {
489 return $this->member_data[$a_user_id];
490 }
491 return [];
492 }
493}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$failed
Definition: Utf8Test.php:85
if(! $in) $columns
Definition: Utf8Test.php:45
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_VIEW_TIMING
const IL_CAL_UNIX
const IL_CRS_ADMIN
Base class for course and group participants.
const IL_CRS_MEMBER
const IL_CRS_TUTOR
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
readMemberData(array $usr_ids, array $columns, bool $skip_names=false)
showDeleteParticipantsConfirmationWithLinkedCourses($participants)
Show deletion confirmation with linked courses.
getAttendanceListUserData($a_user_id)
Callback from attendance list.
filterUserIdsByRbacOrPositionOfCurrentUser($a_user_ids)
Filter user ids by access.
getPrintMemberData($a_members)
Get print member data.
initParticipantTemplate()
Init participant view template.
deliverCertificate()
Deliver certificate for an user on the member list.
updateParticipantsStatus()
=> save button in member table
initEditParticipantTableGUI(array $participants)
init edit participants table gui
getLocalTypeRole($a_translation=false)
assignMembers(array $a_usr_ids, $a_type)
callback from repository search gui @global ilRbacSystem $rbacsystem
updateLPFromStatus($a_member_id, $a_passed)
Update lp from status.
static _getValuesByObjId($a_obj_id)
Get values by obj_id (for all users)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
@classDescription Date and time handling
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
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
static _lookupProgressByObjId($a_obj_id)
lookup progress for a specific object
static getLogger($a_component_id)
Get component logger.
const CONTEXT_KEY
Session parameter for the context.
Class ilMailMemberCourseRoles.
const PROP_CONTEXT_SUBJECT_PREFIX
Base class for member tab content.
getParentGUI()
Get parent gui.
checkRbacOrPositionAccessBool($a_rbac_perm, $a_pos_perm, $a_ref_id=0)
Check if rbac or position access is granted.
getParentObject()
Get parent object.
getMembersObject()
Get member object.
const STATUS_DETERMINATION_LP
static _enabledLearningProgress()
check wether learing progress is enabled or not
static _enabledUserRelatedData()
check wether user related tracking is enabled or not
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
static hasTimings($a_ref_id)
Check if there is any active timing (in subtree)
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($a_ref_id)
Get instance by ref_id.
static _getInstance()
Get instance of ilPrivacySettings.
Class ilUserDefinedData.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$ilErr
Definition: raiseError.php:18