ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
20 
28  public function assignMembers(array $a_usr_ids,$a_type)
29  {
30  global $rbacsystem, $ilErr;
31 
32 
33  if(!$GLOBALS['ilAccess']->checkAccess('manage_members','', $this->getParentObject()->getRefId()))
34  {
35  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->FATAL);
36  }
37 
38  if(!count($a_usr_ids))
39  {
40  ilUtil::sendFailure($this->lng->txt("crs_no_users_selected"),true);
41  return false;
42  }
43 
44  $added_users = 0;
45  foreach($a_usr_ids as $user_id)
46  {
47  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id,false))
48  {
49  continue;
50  }
51  if($this->getMembersObject()->isAssigned($user_id))
52  {
53  continue;
54  }
55  switch($a_type)
56  {
57  case $this->getParentObject()->getDefaultMemberRole():
58  $this->getMembersObject()->add($user_id,IL_CRS_MEMBER);
59  break;
60  case $this->getParentObject()->getDefaultTutorRole():
61  $this->getMembersObject()->add($user_id,IL_CRS_TUTOR);
62  break;
63  case $this->getParentObject()->getDefaultAdminRole():
64  $this->getMembersObject()->add($user_id,IL_CRS_ADMIN);
65  break;
66  default:
67  if(in_array($a_type,$this->getParentObject()->getLocalCourseRoles(true)))
68  {
69  $this->getMembersObject()->add($user_id,IL_CRS_MEMBER);
70  $this->getMembersObject()->updateRoleAssignments($user_id,(array)$a_type);
71  }
72  else
73  {
74  ilLoggerFactory::getLogger('crs')->notice('Can\'t find role with id .' . $a_type. ' to assign users.');
75  ilUtil::sendFailure($this->lng->txt("crs_cannot_find_role"),true);
76  return false;
77  }
78  break;
79  }
80  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_ACCEPT_USER,$user_id);
81 
82  $this->getParentObject()->checkLPStatusSync($user_id);
83 
84  ++$added_users;
85  }
86  if($added_users)
87  {
88  ilUtil::sendSuccess($this->lng->txt("crs_users_added"),true);
89  $this->ctrl->redirect($this,'participants');
90  }
91  ilUtil::sendFailure($this->lng->txt("crs_users_already_assigned"),true);
92  return false;
93  }
94 
98  protected function updateParticipantsStatus()
99  {
100  global $ilAccess,$ilErr,$ilUser,$rbacadmin;
101 
102  $visible_members = (array) $_POST['visible_member_ids'];
103  $passed = (array) $_POST['passed'];
104  $blocked = (array) $_POST['blocked'];
105  $contact = (array) $_POST['contact'];
106  $notification = (array) $_POST['notification'];
107 
108  foreach($visible_members as $member_id)
109  {
110  $this->getMembersObject()->updatePassed($member_id,in_array($member_id,$passed),true);
111  $this->updateLPFromStatus($member_id, in_array($member_id, $passed));
112 
113  if($this->getMembersObject()->isAdmin($member_id) or $this->getMembersObject()->isTutor($member_id))
114  {
115  // remove blocked
116  $this->getMembersObject()->updateBlocked($member_id, 0);
117  $this->getMembersObject()->updateNotification($member_id, in_array($member_id, $notification));
118  $this->getMembersObject()->updateContact($member_id, in_array($member_id, $contact));
119  }
120  else
121  {
122  // send notifications => unblocked
123  if($this->getMembersObject()->isBlocked($member_id) && !in_array($member_id,$blocked))
124  {
125  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_UNBLOCK_MEMBER,$member_id);
126  }
127  // => blocked
128  if(!$this->getMembersObject()->isBlocked($member_id) && in_array($member_id, $blocked))
129  {
130  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_BLOCK_MEMBER,$member_id);
131  }
132 
133  // normal member => remove notification, contact
134  $this->getMembersObject()->updateNotification($member_id, false);
135  $this->getMembersObject()->updateContact($member_id, false);
136  $this->getMembersObject()->updateBlocked($member_id, in_array($member_id, $blocked));
137  }
138  }
139 
140 
141  ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
142  $this->ctrl->redirect($this, 'participants');
143  }
144 
145 
149  protected function initParticipantTableGUI()
150  {
151  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
152  $show_tracking =
154  ;
155  if($show_tracking)
156  {
157  include_once('./Services/Object/classes/class.ilObjectLP.php');
158  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
159  $show_tracking = $olp->isActive();
160  }
161 
162  include_once('./Services/Object/classes/class.ilObjectActivation.php');
163  $timings_enabled =
164  (ilObjectActivation::hasTimings($this->getParentObject()->getRefId()) && ($this->getParentObject()->getViewMode() == IL_CRS_VIEW_TIMING))
165  ;
166 
167 
168  include_once './Modules/Course/classes/class.ilCourseParticipantsTableGUI.php';
169  return new ilCourseParticipantsTableGUI(
170  $this,
171  $this->getParentObject(),
172  $show_tracking,
173  $timings_enabled,
174  $this->getParentObject()->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP
175  );
176  }
177 
183  protected function initEditParticipantTableGUI(array $participants)
184  {
185  include_once './Modules/Course/classes/class.ilCourseEditParticipantsTableGUI.php';
186  $table = new ilCourseEditParticipantsTableGUI($this, $this->getParentObject());
187  $table->setTitle($this->lng->txt($this->getParentObject()->getType().'_header_edit_members'));
188  $table->setData($this->getParentGUI()->readMemberData($participants));
189 
190  return $table;
191  }
192 
196  protected function initParticipantTemplate()
197  {
198  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.crs_edit_members.html','Modules/Course');
199  }
200 
204  public function getLocalTypeRole($a_translation = false)
205  {
206  return $this->getParentObject()->getLocalCourseRoles($a_translation);
207  }
208 
212  protected function updateLPFromStatus($a_member_id, $a_passed)
213  {
214  return $this->getParentGUI()->updateLPFromStatus($a_member_id, $a_passed);
215  }
216 
221  protected function initWaitingList()
222  {
223  include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
224  $wait = new ilCourseWaitingList($this->getParentObject()->getId());
225  return $wait;
226  }
227 
231  protected function getDefaultRole()
232  {
233  return $this->getParentGUI()->object->getDefaultMemberRole();
234  }
235 
240  protected function deliverCertificate()
241  {
242  return $this->getParentGUI()->deliverCertificateObject($user_id);
243  }
244 
249  protected function getPrintMemberData($a_members)
250  {
251  global $ilAccess,$lng;
252 
253  $lng->loadLanguageModule('trac');
254 
255  $is_admin = true;
256  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
257  $privacy = ilPrivacySettings::_getInstance();
258 
259  if($privacy->enabledCourseAccessTimes())
260  {
261  include_once('./Services/Tracking/classes/class.ilLearningProgress.php');
262  $progress = ilLearningProgress::_lookupProgressByObjId($this->getParentObject()->getId());
263  }
264 
265  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
266  $show_tracking =
268  if($show_tracking)
269  {
270  include_once('./Services/Object/classes/class.ilObjectLP.php');
271  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
272  $show_tracking = $olp->isActive();
273  }
274 
275  if($show_tracking)
276  {
277  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
278  $completed = ilLPStatusWrapper::_lookupCompletedForObject($this->getParentObject()->getId());
279  $in_progress = ilLPStatusWrapper::_lookupInProgressForObject($this->getParentObject()->getId());
281  }
282 
283  $profile_data = ilObjUser::_readUsersProfileData($a_members);
284 
285  // course defined fields
286  include_once('Modules/Course/classes/Export/class.ilCourseUserData.php');
287  $cdfs = ilCourseUserData::_getValuesByObjId($this->getParentObject()->getId());
288 
289  foreach($a_members as $member_id)
290  {
291  // GET USER OBJ
292  if($tmp_obj = ilObjectFactory::getInstanceByObjId($member_id,false))
293  {
294  // udf
295  include_once './Services/User/classes/class.ilUserDefinedData.php';
296  $udf_data = new ilUserDefinedData($member_id);
297  foreach($udf_data->getAll() as $field => $value)
298  {
299  list($f,$field_id) = explode('_', $field);
300  $print_member[$member_id]['udf_'.$field_id] = (string) $value;
301  }
302 
303  foreach((array) $cdfs[$member_id] as $cdf_field => $cdf_value)
304  {
305  $print_member[$member_id]['cdf_'.$cdf_field] = (string) $cdf_value;
306  }
307 
308  foreach((array) $profile_data[$member_id] as $field => $value)
309  {
310  $print_member[$member_id][$field] = $value;
311  }
312 
313  $print_member[$member_id]['login'] = $tmp_obj->getLogin();
314  $print_member[$member_id]['name'] = $tmp_obj->getLastname().', '.$tmp_obj->getFirstname();
315 
316  if($this->getMembersObject()->isAdmin($member_id))
317  {
318  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_admin");
319  }
320  elseif($this->getMembersObject()->isTutor($member_id))
321  {
322  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_tutor");
323  }
324  elseif($this->getMembersObject()->isMember($member_id))
325  {
326  $print_member[$member_id]['role'] = $this->lng->txt("il_crs_member");
327  }
328  if($this->getMembersObject()->isAdmin($member_id) or $this->getMembersObject()->isTutor($member_id))
329  {
330  if($this->getMembersObject()->isNotificationEnabled($member_id))
331  {
332  $print_member[$member_id]['status'] = $this->lng->txt("crs_notify");
333  }
334  else
335  {
336  $print_member[$member_id]['status'] = $this->lng->txt("crs_no_notify");
337  }
338  }
339  else
340  {
341  if($this->getMembersObject()->isBlocked($member_id))
342  {
343  $print_member[$member_id]['status'] = $this->lng->txt("crs_blocked");
344  }
345  else
346  {
347  $print_member[$member_id]['status'] = $this->lng->txt("crs_unblocked");
348  }
349  }
350 
351  if($is_admin)
352  {
353  $print_member[$member_id]['passed'] = $this->getMembersObject()->hasPassed($member_id) ?
354  $this->lng->txt('crs_member_passed') :
355  $this->lng->txt('crs_member_not_passed');
356 
357  }
358  if($privacy->enabledCourseAccessTimes())
359  {
360  if(isset($progress[$member_id]['ts']) and $progress[$member_id]['ts'])
361  {
363  $print_member[$member_id]['access'] = ilDatePresentation::formatDate(new ilDateTime($progress[$member_id]['ts'],IL_CAL_UNIX));
365  }
366  else
367  {
368  $print_member[$member_id]['access'] = $this->lng->txt('no_date');
369  }
370  }
371  if($show_tracking)
372  {
373  if(in_array($member_id,$completed))
374  {
375  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_COMPLETED);
376  }
377  elseif(in_array($member_id,$in_progress))
378  {
379  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_IN_PROGRESS);
380  }
381  elseif(in_array($member_id,$failed))
382  {
383  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_FAILED);
384  }
385  else
386  {
387  $print_member[$member_id]['progress'] = $this->lng->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED);
388  }
389  }
390 
391  }
392  }
393  return ilUtil::sortArray($print_member,'name',$_SESSION['crs_print_order'], false, true);
394  }
395 
399  public function getAttendanceListUserData($a_user_id)
400  {
401  return $this->member_data[$a_user_id];
402  }
403 
404 }
405 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
readMemberData(array $usr_ids, array $columns)
Required for member table guis.
global $ilErr
Definition: raiseError.php:16
getLocalTypeRole($a_translation=false)
Base class for member tab content.
Class ilUserDefinedData.
$_SESSION["AccountId"]
getMembersObject()
Get member object.
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
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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
Add rich text string
The name of the decorator.
const IL_CAL_UNIX
const IL_CRS_VIEW_TIMING
const STATUS_DETERMINATION_LP
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
const LP_STATUS_IN_PROGRESS
const IL_CRS_MEMBER
deliverCertificate()
Deliver certificate for an user on the member list.
$a_type
Definition: workflow.php:93
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.
const LP_STATUS_FAILED
static _lookupProgressByObjId($a_obj_id)
lookup progress for a specific object
initParticipantTemplate()
Init participant view template.
static formatDate(ilDateTime $date)
Format a date public.
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.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$failed
Definition: Utf8Test.php:85
Create styles array
The data for the language used.
initEditParticipantTableGUI(array $participants)
init edit participants table gui
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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.
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"]