ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLearningSequenceParticipantsTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9{
14
18 protected $current_filter = array();
19
20 public function __construct(
22 ilObjLearningSequence $ls_object,
23 ilObjUserTracking $obj_user_tracking,
24 ilPrivacySettings $privacy_settings,
26 ilAccess $access,
27 ilRbacReview $rbac_review,
28 ilSetting $settings
29 ) {
30 $this->parent_gui = $parent_gui;
31 $this->rep_object = $ls_object;
32 $this->show_learning_progress = $show_learning_progress;
33
34 $this->obj_user_tracking = $obj_user_tracking;
35 $this->privacy_settings = $privacy_settings;
36 $this->lng = $lng;
37 $this->access = $access;
38 $this->rbac_review = $rbac_review;
39 $this->settings = $settings;
40
41 $this->lng->loadLanguageModule('lso');
42 $this->lng->loadLanguageModule('trac');
43 $this->lng->loadLanguageModule('rbac');
44 $this->lng->loadLanguageModule('mmbr');
45 $this->lng->loadLanguageModule('user');
46 $this->lng->loadLanguageModule('ps');
47
48 $this->participants = $ls_object->getLSParticipants();
49
50 $this->setPrefix('participants');
51
52 $this->setId('lso_' . $this->getRepositoryObject()->getId());
53 parent::__construct($parent_gui, 'participants');
54
55 $this->initSettings();
56 $this->initForm();
57 }
58
59 protected function initForm()
60 {
61 $this->setFormName('participants');
62 $this->setDefaultOrderField('roles');
63 $this->setRowTemplate("tpl.show_participants_row.html", "Modules/LearningSequence");
64 $this->setShowRowsSelector(true);
65 $this->setSelectAllCheckbox('participants');
66
67 $this->addColumn('', 'f', "1");
68 $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
69 $this->addColumn($this->lng->txt('login'), 'login');
70
71 $all_cols = $this->getSelectableColumns();
72 foreach ($this->getSelectedColumns() as $col) {
73 $this->addColumn($all_cols[$col]['txt'], $col);
74 }
75
76 if (
77 $this->obj_user_tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS) &&
79
80 ) {
81 $this->addColumn($this->lng->txt('first_access'), "first_access");
82 $this->addColumn($this->lng->txt('last_access'), "last_access");
83 }
84 $this->addColumn($this->lng->txt('completed_steps'), "completed_steps");
85 $this->addColumn($this->lng->txt('last_visited_step'), "last_visited_step");
86 $this->addColumn($this->lng->txt('lso_notification'), 'notification');
87 $this->addColumn($this->lng->txt(''), 'optional');
88
89 $this->enable('sort');
90 $this->enable('header');
91 $this->enable('numinfo');
92 $this->enable('select_all');
93
94 $this->initFilter();
95
96 $this->addMultiCommand('editParticipants', $this->lng->txt('edit'));
97 $this->addMultiCommand('confirmDeleteParticipants', $this->lng->txt('remove'));
98 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('mmbr_btn_mail_selected_users'));
99 $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
100 $this->addCommandButton('updateParticipantsStatus', $this->lng->txt('save'));
101 }
102
103 public function fillRow($set)
104 {
105 $this->tpl->setVariable('VAL_ID', $set['usr_id']);
106 $this->tpl->setVariable('VAL_NAME', $set['lastname'] . ', ' . $set['firstname']);
107 $this->tpl->setVariable('VAL_LOGIN', $set['login']);
108
109 if (
110 !$this->access->checkAccessOfUser($set['usr_id'], 'read', '', $this->getRepositoryObject()->getRefId()) &&
111 is_array($info = $this->access->getInfo())
112 ) {
113 $this->tpl->setCurrentBlock('access_warning');
114 $this->tpl->setVariable('PARENT_ACCESS', $info[0]['text']);
115 $this->tpl->parseCurrentBlock();
116 }
117
118 if (!ilObjUser::_lookupActive($set['usr_id'])) {
119 $this->tpl->setCurrentBlock('access_warning');
120 $this->tpl->setVariable('PARENT_ACCESS', $this->lng->txt('usr_account_inactive'));
121 $this->tpl->parseCurrentBlock();
122 }
123
124 foreach ($this->getSelectedColumns() as $field) {
125 switch ($field) {
126 case 'prtf':
127 $tmp = array();
128 if (is_array($set['prtf'])) {
129 foreach ($set['prtf'] as $prtf_url => $prtf_txt) {
130 $tmp[] = '<a href="' . $prtf_url . '">' . $prtf_txt . '</a>';
131 }
132 }
133 $this->tpl->setCurrentBlock('custom_fields');
134 $this->tpl->setVariable('VAL_CUST', (string) implode('<br />', $tmp));
135 $this->tpl->parseCurrentBlock();
136 break;
137 case 'roles':
138 $this->tpl->setCurrentBlock('custom_fields');
139 $this->tpl->setVariable('VAL_CUST', (string) $set['roles_label']);
140 $this->tpl->parseCurrentBlock();
141 break;
142 case 'org_units':
143 $this->tpl->setCurrentBlock('custom_fields');
144 $this->tpl->setVariable('VAL_CUST', (string) ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($set['usr_id']));
145 $this->tpl->parseCurrentBlock();
146 break;
147 default:
148 $this->tpl->setCurrentBlock('custom_fields');
149 $this->tpl->setVariable('VAL_CUST', isset($set[$field]) ? (string) $set[$field] : '');
150 $this->tpl->parseCurrentBlock();
151 break;
152 }
153 }
154
155 $this->tpl->setVariable('VAL_POSTNAME', 'participants');
156
157 if (
158 $this->obj_user_tracking->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS) &&
160
161 ) {
162 $this->tpl->setVariable('FIRST_ACCESS', $this->getFirstAccess((int) $set['usr_id']));
163 $this->tpl->setVariable('LAST_ACCESS', $this->getLastAccess((int) $set['usr_id']));
164 }
165
166 $this->tpl->setVariable('COMPLETED_STEPS', $this->getCompletedSteps((int) $set['usr_id']));
167 $this->tpl->setVariable('LAST_VISITED_STEP', $this->getLastVisitedStep((int) $set['usr_id']));
168
169 if ($this->getParticipants()->isAdmin($set['usr_id'])) {
170 $this->tpl->setVariable('VAL_NOTIFICATION_ID', $set['usr_id']);
171 $this->tpl->setVariable(
172 'VAL_NOTIFICATION_CHECKED',
173 $set['notification'] ? 'checked="checked"' : ''
174 );
175 }
176
177 $this->showActionLinks($set);
178 $this->tpl->setVariable('VAL_LOGIN', $set['login']);
179 }
180
181 protected function getFirstAccess(int $user_id)
182 {
183 $data = $this->getRepositoryObject()->getStateDB()->getFirstAccessFor(
184 (int) $this->getRepositoryObject()->getRefId(),
185 array($user_id)
186 );
187
188 if ($data[$user_id] === -1) {
189 return "-";
190 }
191
192 return $data[$user_id];
193 }
194
195 protected function getLastAccess(int $user_id)
196 {
197 $data = $this->getRepositoryObject()->getStateDB()->getLastAccessFor(
198 (int) $this->getRepositoryObject()->getRefId(),
199 array($user_id)
200 );
201
202 if ($data[$user_id] === -1) {
203 return "-";
204 }
205
206 return $data[$user_id];
207 }
208
209 protected function getCompletedSteps(int $user_id)
210 {
211 $passed = 0;
212 $learner_items = array();
213
214 $learner_items = $this->getRepositoryObject()->getLSLearnerItems(
215 $user_id
216 );
217
218 $completion_states = $this->rep_object->getLPCompletionStates();
219
220 foreach ($learner_items as $learner_item) {
221 if (in_array($learner_item->getLearningProgressStatus(), $completion_states)) {
222 $passed++;
223 }
224 }
225
226 return $passed . " / " . count($learner_items);
227 }
228
234 protected function getLastVisitedStep(int $user_id)
235 {
236 $data = $this->getRepositoryObject()->getStateDB()->getCurrentItemsFor(
237 (int) $this->getRepositoryObject()->getRefId(),
238 array($user_id)
239 );
240
241 if ($data[$user_id] === -1) {
242 return "-";
243 }
244
245 return $this->getTitleFor((int) $data[$user_id]);
246 }
247
248 protected function getTitleFor(int $ref_id) : string
249 {
251 }
252
253 public function parse()
254 {
255 $this->determineOffsetAndOrder(true);
256
257 $ls_participants = $this->participants->getParticipants();
258
259 $ls_participants = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
260 'manage_members',
261 'manage_members',
262 $this->getRepositoryObject()->getRefId(),
263 $ls_participants
264 );
265
266 if (!$ls_participants) {
267 $this->setData(array());
268 return;
269 }
270
271 $lso_user_data = $this->parent_gui->readMemberData(
272 $ls_participants,
273 $this->getSelectedColumns()
274 );
275
276 $additional_fields = $this->getSelectedColumns();
277 unset($additional_fields['prtf']);
278 unset($additional_fields['roles']);
279 unset($additional_fields['org_units']);
280
281 $udf_ids = $usr_data_fields = $odf_ids = array();
282 foreach ($additional_fields as $field) {
283 if (substr($field, 0, 3) == 'udf') {
284 $udf_ids[] = substr($field, 4);
285 continue;
286 }
287
288 if (substr($field, 0, 3) == 'odf') {
289 $odf_ids[] = substr($field, 4);
290 continue;
291 }
292
293 $usr_data_fields[] = $field;
294 }
295
297 $this->getOrderField(),
298 $this->getOrderDirection(),
299 0,
300 9999,
301 $this->current_filter['login'],
302 '',
303 null,
304 false,
305 false,
306 0,
307 0,
308 null,
309 $usr_data_fields,
310 $ls_participants
311 );
312
313 $user_data = array();
314 $filtered_user_ids = array();
315 $local_roles = $this->parent_gui->getLocalRoles();
316
317 foreach ($usr_data['set'] as $ud) {
318 $user_id = $ud['usr_id'];
319
320 if ($this->current_filter['roles']) {
321 if (!$this->rbac_review->isAssigned($user_id, $this->current_filter['roles'])) {
322 continue;
323 }
324 }
325
326 if ($this->current_filter['org_units']) {
327 $org_unit = $this->current_filter['org_units'];
328 $title = ilObjectFactory::getInstanceByRefId($org_unit)->getTitle();
329 $user_units = (string) ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
330 if (strpos($user_units, $title) === false) {
331 continue;
332 }
333 }
334
335 $filtered_user_ids[] = $user_id;
336 $user_data[$user_id] = array_merge($ud, (array) $lso_user_data[$user_id]);
337
338 $roles = array();
339 foreach ($local_roles as $role_id => $role_name) {
340 if ($this->rbac_review->isAssigned($user_id, $role_id)) {
341 $roles[] = $role_name;
342 }
343 }
344
345 $user_data[$user_id]['name'] = $user_data[$user_id]['lastname'] . ', ' . $user_data[$user_id]['firstname'];
346 $user_data[$user_id]['roles_label'] = implode('<br />', $roles);
347 $user_data[$user_id]['roles'] = $this->participants->setRoleOrderPosition($user_id);
348 }
349
350 // Custom user data fields
351 if ($udf_ids) {
352 $data = ilUserDefinedData::lookupData($ls_participants, $udf_ids);
353 foreach ($data as $usr_id => $fields) {
354 if (!$this->checkAcceptance($usr_id)) {
355 continue;
356 }
357
358 foreach ($fields as $field_id => $value) {
359 $user_data[$usr_id]['udf_' . $field_id] = $value;
360 }
361 }
362 }
363
364 $user_data = ilUtil::sortArray(
365 $user_data,
366 'name',
367 $this->getOrderDirection()
368 );
369
370 return $this->setData($user_data);
371 }
372
373 public function getSelectableColumns()
374 {
375 $ef = $this->getExportFieldsInfo();
376 $columns = array();
377 $columns = $ef->getSelectableFieldsInfo(
378 $this->getRepositoryObject()->getId()
379 );
380
381 if ($this->settings->get('user_portfolios')) {
382 $columns['prtf'] = array(
383 'txt' => $this->lng->txt('obj_prtf'),
384 'default' => false
385 );
386 }
387
388 $columns = array_merge(
389 array(
390 'roles' => array(
391 'txt' => $this->lng->txt('objs_role'),
392 'default' => true
393 )
394 ),
395 array(
396 'org_units' => array(
397 'txt' => $this->lng->txt("org_units"),
398 'default' => false
399 )
400 ),
402 );
403
404 return $columns;
405 }
406
407 protected function getExportFieldsInfo()
408 {
410 $this->getRepositoryObject()->getType()
411 );
412 }
413}
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
static _getInstanceByType($a_type)
Get Singleton Instance.
language handling
GUI class for learning sequence membership features.
__construct(ilLearningSequenceMembershipGUI $parent_gui, ilObjLearningSequence $ls_object, ilObjUserTracking $obj_user_tracking, ilPrivacySettings $privacy_settings, ilLanguage $lng, ilAccess $access, ilRbacReview $rbac_review, ilSetting $settings)
getLastVisitedStep(int $user_id)
Different to the concept we decide to use the title of the object instead of its actually number in t...
Class ilObjLearningSequence.
static _enabledLearningProgress()
check wether learing progress is enabled or not
static _lookupActive($a_usr_id)
Check user account active.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
showActionLinks($a_set)
show edit links
checkAcceptance($a_usr_id)
Check acceptance.
Singleton class that stores all privacy settings.
class ilRbacReview Contains Review functions of core Rbac.
ILIAS Setting Class.
getSelectedColumns()
Get selected columns.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setPrefix($a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
getId()
Get element id.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
getOrderDirection()
Get order direction.
enable($a_module_name)
enables particular modules of table
static lookupData($a_user_ids, $a_field_ids)
Lookup data.
static getUserListData( $a_order_field, $a_order_dir, $a_offset, $a_limit, $a_string_filter="", $a_activation_filter="", $a_last_login_filter=null, $a_limited_access_filter=false, $a_no_courses_filter=false, $a_course_group_filter=0, $a_role_filter=0, $a_user_folder_filter=null, $a_additional_fields='', $a_user_filter=null, $a_first_letter="", $a_authentication_filter=null)
Get data for user administration list.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
settings()
Definition: settings.php:2