ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_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()
47  {
48  $context_options = [];
49 
50  $context_options =
51  [
53  'ref_id' => $this->getParentObject()->getRefId(),
54  'ts' => time()
55  ];
56  return $context_options;
57  }
58 
59 
67  public function assignMembers(array $a_usr_ids, $a_type)
68  {
69  global $DIC;
70 
71  $rbacsystem = $DIC['rbacsystem'];
72  $ilErr = $DIC['ilErr'];
73 
74  if (!$this->checkRbacOrPositionAccessBool('manage_members', 'manage_members')) {
75  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
76  }
77 
78  if (!count($a_usr_ids)) {
79  ilUtil::sendFailure($this->lng->txt("crs_no_users_selected"), true);
80  return false;
81  }
82 
83  $a_usr_ids = $this->filterUserIdsByRbacOrPositionOfCurrentUser($a_usr_ids);
84 
85  $added_users = 0;
86  foreach ($a_usr_ids as $user_id) {
87  if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
88  continue;
89  }
90  if ($this->getMembersObject()->isAssigned($user_id)) {
91  continue;
92  }
93  switch ($a_type) {
94  case $this->getParentObject()->getDefaultMemberRole():
95  $this->getMembersObject()->add($user_id, IL_CRS_MEMBER);
96  break;
97  case $this->getParentObject()->getDefaultTutorRole():
98  $this->getMembersObject()->add($user_id, IL_CRS_TUTOR);
99  break;
100  case $this->getParentObject()->getDefaultAdminRole():
101  $this->getMembersObject()->add($user_id, IL_CRS_ADMIN);
102  break;
103  default:
104  if (in_array($a_type, $this->getParentObject()->getLocalCourseRoles(true))) {
105  $this->getMembersObject()->add($user_id, IL_CRS_MEMBER);
106  $this->getMembersObject()->updateRoleAssignments($user_id, (array) $a_type);
107  } else {
108  ilLoggerFactory::getLogger('crs')->notice('Can\'t find role with id .' . $a_type . ' to assign users.');
109  ilUtil::sendFailure($this->lng->txt("crs_cannot_find_role"), true);
110  return false;
111  }
112  break;
113  }
114  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_ACCEPT_USER, $user_id);
115 
116  $this->getParentObject()->checkLPStatusSync($user_id);
117 
118  ++$added_users;
119  }
120  if ($added_users) {
121  ilUtil::sendSuccess($this->lng->txt("crs_users_added"), true);
122  $this->ctrl->redirect($this, 'participants');
123  }
124  ilUtil::sendFailure($this->lng->txt("crs_users_already_assigned"), true);
125  return false;
126  }
127 
131  protected function updateParticipantsStatus()
132  {
133  global $DIC;
134 
135  $ilAccess = $DIC['ilAccess'];
136  $ilErr = $DIC['ilErr'];
137  $ilUser = $DIC['ilUser'];
138  $rbacadmin = $DIC['rbacadmin'];
139 
140  $visible_members = (array) $_POST['visible_member_ids'];
141  $passed = (array) $_POST['passed'];
142  $blocked = (array) $_POST['blocked'];
143  $contact = (array) $_POST['contact'];
144  $notification = (array) $_POST['notification'];
145 
146  foreach ($visible_members as $member_id) {
147  if ($ilAccess->checkAccess("grade", "", $this->getParentObject()->getRefId())) {
148  $this->getMembersObject()->updatePassed($member_id, in_array($member_id, $passed), true);
149  $this->updateLPFromStatus($member_id, in_array($member_id, $passed));
150  }
151 
152  if ($this->getMembersObject()->isAdmin($member_id) or $this->getMembersObject()->isTutor($member_id)) {
153  // remove blocked
154  $this->getMembersObject()->updateBlocked($member_id, 0);
155  $this->getMembersObject()->updateNotification($member_id, in_array($member_id, $notification));
156  $this->getMembersObject()->updateContact($member_id, in_array($member_id, $contact));
157  } else {
158  // send notifications => unblocked
159  if ($this->getMembersObject()->isBlocked($member_id) && !in_array($member_id, $blocked)) {
160  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_UNBLOCK_MEMBER, $member_id);
161  }
162  // => blocked
163  if (!$this->getMembersObject()->isBlocked($member_id) && in_array($member_id, $blocked)) {
164  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_BLOCK_MEMBER, $member_id);
165  }
166 
167  // normal member => remove notification, contact
168  $this->getMembersObject()->updateNotification($member_id, false);
169  $this->getMembersObject()->updateContact($member_id, false);
170  $this->getMembersObject()->updateBlocked($member_id, in_array($member_id, $blocked));
171  }
172  }
173 
174 
175  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
176  $this->ctrl->redirect($this, 'participants');
177  }
178 
179 
183  protected function initParticipantTableGUI()
184  {
185  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
186  $show_tracking =
188  ;
189  if ($show_tracking) {
190  include_once('./Services/Object/classes/class.ilObjectLP.php');
191  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
192  $show_tracking = $olp->isActive();
193  }
194 
195  include_once('./Services/Object/classes/class.ilObjectActivation.php');
196  $timings_enabled =
197  (ilObjectActivation::hasTimings($this->getParentObject()->getRefId()) && ($this->getParentObject()->getViewMode() == IL_CRS_VIEW_TIMING))
198  ;
199 
200 
201  include_once './Modules/Course/classes/class.ilCourseParticipantsTableGUI.php';
202  return new ilCourseParticipantsTableGUI(
203  $this,
204  $this->getParentObject(),
205  $show_tracking,
206  $timings_enabled,
207  $this->getParentObject()->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP
208  );
209  }
210 
216  protected function initEditParticipantTableGUI(array $participants)
217  {
218  include_once './Modules/Course/classes/class.ilCourseEditParticipantsTableGUI.php';
220  $table->setTitle($this->lng->txt($this->getParentObject()->getType() . '_header_edit_members'));
221  $table->setData($this->getParentGUI()->readMemberData($participants));
222 
223  return $table;
224  }
225 
229  protected function initParticipantTemplate()
230  {
231  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.crs_edit_members.html', 'Modules/Course');
232  }
233 
237  public function getLocalTypeRole($a_translation = false)
238  {
239  return $this->getParentObject()->getLocalCourseRoles($a_translation);
240  }
241 
245  protected function updateLPFromStatus($a_member_id, $a_passed)
246  {
247  return $this->getParentGUI()->updateLPFromStatus($a_member_id, $a_passed);
248  }
249 
254  protected function initWaitingList()
255  {
256  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
257  $wait = new ilCourseWaitingList($this->getParentObject()->getId());
258  return $wait;
259  }
260 
264  protected function getDefaultRole()
265  {
266  return $this->getParentGUI()->object->getDefaultMemberRole();
267  }
268 
273  protected function deliverCertificate()
274  {
275  return $this->getParentGUI()->deliverCertificateObject();
276  }
277 
282  protected function getPrintMemberData($a_members)
283  {
284  global $DIC;
285 
286  $ilAccess = $DIC['ilAccess'];
287  $lng = $DIC['lng'];
288 
289  $lng->loadLanguageModule('trac');
290 
291  $is_admin = true;
292  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
293  $privacy = ilPrivacySettings::_getInstance();
294 
295  if ($privacy->enabledCourseAccessTimes()) {
296  include_once('./Services/Tracking/classes/class.ilLearningProgress.php');
297  $progress = ilLearningProgress::_lookupProgressByObjId($this->getParentObject()->getId());
298  }
299 
300  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
301  $show_tracking =
303  if ($show_tracking) {
304  include_once('./Services/Object/classes/class.ilObjectLP.php');
305  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
306  $show_tracking = $olp->isActive();
307  }
308 
309  if ($show_tracking) {
310  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
311  $completed = ilLPStatusWrapper::_lookupCompletedForObject($this->getParentObject()->getId());
312  $in_progress = ilLPStatusWrapper::_lookupInProgressForObject($this->getParentObject()->getId());
314  }
315 
316  $profile_data = ilObjUser::_readUsersProfileData($a_members);
317 
318  // course defined fields
319  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
320  $cdfs = ilCourseUserData::_getValuesByObjId($this->getParentObject()->getId());
321 
322  foreach ($a_members as $member_id) {
323  // GET USER OBJ
324  if ($tmp_obj = ilObjectFactory::getInstanceByObjId($member_id, false)) {
325  // udf
326  include_once './Services/User/classes/class.ilUserDefinedData.php';
327  $udf_data = new ilUserDefinedData($member_id);
328  foreach ($udf_data->getAll() as $field => $value) {
329  list($f, $field_id) = explode('_', $field);
330  $print_member[$member_id]['udf_' . $field_id] = (string) $value;
331  }
332 
333  foreach ((array) $cdfs[$member_id] as $cdf_field => $cdf_value) {
334  $print_member[$member_id]['cdf_' . $cdf_field] = (string) $cdf_value;
335  }
336 
337  foreach ((array) $profile_data[$member_id] as $field => $value) {
338  $print_member[$member_id][$field] = $value;
339  }
340 
341  $print_member[$member_id]['login'] = $tmp_obj->getLogin();
342  $print_member[$member_id]['name'] = $tmp_obj->getLastname() . ', ' . $tmp_obj->getFirstname();
343 
344  if ($this->getMembersObject()->isAdmin($member_id)) {
345  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_admin");
346  } elseif ($this->getMembersObject()->isTutor($member_id)) {
347  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_tutor");
348  } elseif ($this->getMembersObject()->isMember($member_id)) {
349  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_member");
350  }
351  if ($this->getMembersObject()->isAdmin($member_id) or $this->getMembersObject()->isTutor($member_id)) {
352  if ($this->getMembersObject()->isNotificationEnabled($member_id)) {
353  $print_member[$member_id]['status'] = $this->lng->txt("crs_notify");
354  } else {
355  $print_member[$member_id]['status'] = $this->lng->txt("crs_no_notify");
356  }
357  } else {
358  if ($this->getMembersObject()->isBlocked($member_id)) {
359  $print_member[$member_id]['status'] = $this->lng->txt("crs_blocked");
360  } else {
361  $print_member[$member_id]['status'] = $this->lng->txt("crs_unblocked");
362  }
363  }
364 
365  if ($is_admin) {
366  $print_member[$member_id]['passed'] = $this->getMembersObject()->hasPassed($member_id) ?
367  $this->lng->txt('crs_member_passed') :
368  $this->lng->txt('crs_member_not_passed');
369  }
370  if ($privacy->enabledCourseAccessTimes()) {
371  if (isset($progress[$member_id]['ts']) and $progress[$member_id]['ts']) {
373  $print_member[$member_id]['access'] = ilDatePresentation::formatDate(new ilDateTime($progress[$member_id]['ts'], IL_CAL_UNIX));
375  } else {
376  $print_member[$member_id]['access'] = $this->lng->txt('no_date');
377  }
378  }
379  if ($show_tracking) {
380  if (in_array($member_id, $completed)) {
381  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_COMPLETED);
382  } elseif (in_array($member_id, $in_progress)) {
383  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_IN_PROGRESS);
384  } elseif (in_array($member_id, $failed)) {
385  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_FAILED);
386  } else {
387  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED);
388  }
389  }
390  }
391  }
392  return ilUtil::sortArray($print_member, 'name', $_SESSION['crs_print_order'], false, true);
393  }
394 
399  public function getAttendanceListUserData($a_user_id)
400  {
401  if (is_array($this->member_data) && array_key_exists($a_user_id, $this->member_data)) {
402  return $this->member_data[$a_user_id];
403  }
404  return [];
405  }
406 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
readMemberData(array $usr_ids, array $columns)
Required for member table guis.
getLocalTypeRole($a_translation=false)
Base class for member tab content.
Class ilUserDefinedData.
$_SESSION["AccountId"]
getMembersObject()
Get member object.
global $DIC
Definition: saml.php:7
static hasTimings($a_ref_id)
Check if there is any active timing (in subtree)
static _getValuesByObjId($a_obj_id)
Get values by obj_id (for all users)
const LP_STATUS_NOT_ATTEMPTED
updateParticipantsStatus()
=> save button in member table
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static setUseRelativeDates($a_status)
set use relative dates
const IL_CRS_TUTOR
const IL_CAL_UNIX
const IL_CRS_VIEW_TIMING
const STATUS_DETERMINATION_LP
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
$ilErr
Definition: raiseError.php:18
const LP_STATUS_IN_PROGRESS
const IL_CRS_MEMBER
deliverCertificate()
Deliver certificate for an user on the member list.
$a_type
Definition: workflow.php:92
static _enabledUserRelatedData()
check wether user related tracking is enabled or not
static _enabledLearningProgress()
check wether learing progress is enabled or not
updateLPFromStatus($a_member_id, $a_passed)
Update lp from status.
Class ilMailMemberCourseRoles.
const LP_STATUS_FAILED
static _lookupProgressByObjId($a_obj_id)
lookup progress for a specific object
initParticipantTemplate()
Init participant view template.
Date and time handling
$ilUser
Definition: imgupload.php:18
const IL_CRS_ADMIN
Base class for course and group participants.
assignMembers(array $a_usr_ids, $a_type)
callback from repository search gui ilRbacSystem $rbacsystem
getParentGUI()
Get parent gui.
filterUserIdsByRbacOrPositionOfCurrentUser($a_user_ids)
Filter user ids by access.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$failed
Definition: Utf8Test.php:85
initEditParticipantTableGUI(array $participants)
init edit participants table gui
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const CONTEXT_KEY
Session parameter for the context.
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
getPrintMemberData($a_members)
Get print member data.
getAttendanceListUserData($a_user_id)
Callback from attendance list.
static getLogger($a_component_id)
Get component logger.
static _getInstance()
Get instance of ilPrivacySettings.
getParentObject()
Get parent object.
if(empty($password)) $table
Definition: pwgen.php:24
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
const LP_STATUS_COMPLETED
static getInstance($a_obj_id)
$_POST["username"]
checkRbacOrPositionAccessBool($a_rbac_perm, $a_pos_perm, $a_ref_id=0)
Check if rbac or position access is granted.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.