ILIAS  release_8 Revision v8.24
class.ilTrObjectUsersPropsTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
36{
37 protected array $user_fields;
38 protected int $in_course = 0;
39 protected int $in_group = 0;
40 protected int $in_course_ref_id = 0;
41 protected int $in_group_ref_id = 0;
42 protected bool $has_edit = false;
43 protected bool $has_collection = false;
44 protected bool $has_multi = false;
45
46 protected int $obj_id;
47 protected int $ref_id;
48 protected string $type;
49
50 protected ilTree $tree;
54
58 public function __construct(
59 ?object $a_parent_obj,
60 string $a_parent_cmd,
61 int $a_obj_id,
62 int $a_ref_id,
63 bool $a_print_view = false
64 ) {
65 global $DIC;
66
67 $this->tree = $DIC->repositoryTree();
68 $this->rbacsystem = $DIC->rbac()->system();
69 $this->ilObjDataCache = $DIC['ilObjDataCache'];
70 $this->objDefinition = $DIC['objDefinition'];
71
72 $this->setId("troup");
73 $this->obj_id = $a_obj_id;
74 $this->ref_id = $a_ref_id;
75 $this->type = ilObject::_lookupType($a_obj_id);
76
77 $this->in_group_ref_id = $this->tree->checkForParentType($this->ref_id, "grp");
78 if ($this->in_group_ref_id) {
79 $this->in_group = ilObject::_lookupObjId($this->in_group_ref_id);
80 } else {
81 $this->in_course_ref_id = $this->tree->checkForParentType(
82 $this->ref_id,
83 "crs"
84 );
85 if ($this->in_course_ref_id) {
86 $this->in_course = ilObject::_lookupObjId($this->in_course_ref_id);
87 }
88 }
89 parent::__construct($a_parent_obj, $a_parent_cmd);
90 $this->parseTitle($a_obj_id, "trac_participants");
91
92 if ($a_print_view) {
93 $this->setPrintMode(true);
94 }
95
96 if (!$this->getPrintMode()) {
97 // see ilObjCourseGUI::addMailToMemberButton()
98 $mail = new ilMail($DIC->user()->getId());
99 if ($this->rbacsystem->checkAccess(
100 "internal_mail",
101 $mail->getMailObjectReferenceId()
102 )) {
103 $this->addMultiCommand(
104 "mailselectedusers",
105 $this->lng->txt("send_mail")
106 );
107 }
108 $this->lng->loadLanguageModule('user');
109 $this->addMultiCommand(
110 'addToClipboard',
111 $this->lng->txt('clipboard_add_btn')
112 );
113 $this->addColumn("", "", 1);
114 $this->has_multi = true;
115 }
116
117 $labels = $this->getSelectableColumns();
118 $first = false;
119 foreach ($this->getSelectedColumns() as $c) {
120 $first = $c;
121
122 // list cannot be sorted by udf fields (separate query)
123 // because of pagination only core fields can be sorted
124 $sort_id = (substr($c, 0, 4) == "udf_") ? "" : $c;
125
126 $this->addColumn($labels[$c]["txt"], $sort_id);
127 }
128
129 if (!$this->getPrintMode()) {
130 $this->addColumn($this->lng->txt("actions"), "");
131 }
132 $this->setSelectAllCheckbox('uid');
133 $this->setExternalSorting(true);
134 $this->setExternalSegmentation(true);
135 $this->setEnableHeader(true);
136 $this->setFormAction(
137 $this->ctrl->getFormActionByClass(get_class($this))
138 );
139 $this->setRowTemplate(
140 "tpl.object_users_props_row.html",
141 "Services/Tracking"
142 );
143 $this->setEnableTitle(true);
144 $this->setShowTemplates(true);
145 $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
146
147 if ($first) {
148 $this->setDefaultOrderField($first);
149 $this->setDefaultOrderDirection("asc");
150 }
151
152 $this->initFilter();
153
154 $this->getItems();
155
156 // #13807
158 'edit_learning_progress',
159 $this->ref_id
160 );
161 }
162
163 public function getSelectableColumns(): array
164 {
165 if ($this->selectable_columns) {
167 }
168
170 $this->in_course_ref_id,
171 $this->in_group_ref_id
172 );
173 $this->user_fields = $cols[1];
174 $this->selectable_columns = $cols[0];
175
177 }
178
182 public function getItems(): void
183 {
185 $additional_fields = $this->getSelectedColumns();
186
187 // only if object is [part of] course/group
188 $check_agreement = null;
189 if ($this->in_course) {
190 // privacy (if course agreement is activated)
192 if ($privacy->courseConfirmationRequired()) {
193 $check_agreement = $this->in_course;
194 }
195 } elseif ($this->in_group) {
196 // privacy (if group agreement is activated)
198 if ($privacy->groupConfirmationRequired()) {
199 $check_agreement = $this->in_group;
200 }
201 }
203 $this->ref_id,
208 $this->getCurrentFilter(),
209 $additional_fields,
210 $check_agreement,
211 $this->user_fields
212 );
213 if (count($tr_data["set"]) == 0 && $this->getOffset() > 0) {
214 $this->resetOffset();
216 $this->ref_id,
221 $this->getCurrentFilter(),
222 $additional_fields,
223 $check_agreement,
224 $this->user_fields
225 );
226 }
227
228 /*
229 * ilTrQuery does not read out any information about org units
230 * (nor should it), so it needs to be added here.
231 */
232 if (in_array('org_units', $additional_fields)) {
233 foreach (($tr_data['set'] ?? []) as $key => $data) {
234 if (!isset($data['usr_id'])) {
235 continue;
236 }
237 $usr_id = (int) $data['usr_id'];
238 $org_units = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($usr_id);
239 $tr_data["set"][$key]['org_units'] = $org_units;
240 }
241 }
242
243 $this->setMaxCount($tr_data["cnt"]);
244 $this->setData($tr_data["set"]);
245 }
246
247 public function initFilter(): void
248 {
249 foreach ($this->getSelectableColumns() as $column => $meta) {
250 // no udf!
251 switch ($column) {
252 case "firstname":
253 case "lastname":
254 case "mark":
255 case "u_comment":
256 case "institution":
257 case "department":
258 case "title":
259 case "street":
260 case "zipcode":
261 case "city":
262 case "country":
263 case "email":
264 case "matriculation":
265 case "login":
266 if ($column != "mark" ||
267 ilObjectLP::supportsMark($this->type)) {
268 $item = $this->addFilterItemByMetaType(
269 $column,
271 true,
272 $meta["txt"]
273 );
274 $this->filter[$column] = $item->getValue();
275 }
276 break;
277
278 case "first_access":
279 case "last_access":
280 case "create_date":
281 case 'status_changed':
282 $item = $this->addFilterItemByMetaType(
283 $column,
285 true,
286 $meta["txt"]
287 );
288 $this->filter[$column] = $item->getDate();
289 break;
290
291 case "birthday":
292 $item = $this->addFilterItemByMetaType(
293 $column,
295 true,
296 $meta["txt"]
297 );
298 $this->filter[$column] = $item->getDate();
299 break;
300
301 case "read_count":
302 case "percentage":
303 $item = $this->addFilterItemByMetaType(
304 $column,
306 true,
307 $meta["txt"]
308 );
309 $this->filter[$column] = $item->getValue();
310 break;
311
312 case "gender":
313 $item = $this->addFilterItemByMetaType(
314 "gender",
316 true,
317 $meta["txt"]
318 );
319 $item->setOptions(
320 array(
321 "" => $this->lng->txt("trac_all"),
322 "n" => $this->lng->txt("gender_n"),
323 "m" => $this->lng->txt("gender_m"),
324 "f" => $this->lng->txt("gender_f"),
325 )
326 );
327 $this->filter["gender"] = $item->getValue();
328 break;
329
330 case "sel_country":
331 $item = $this->addFilterItemByMetaType(
332 "sel_country",
334 true,
335 $meta["txt"]
336 );
337
338 $options = array();
339 foreach (ilCountry::getCountryCodes() as $c) {
340 $options[$c] = $this->lng->txt("meta_c_" . $c);
341 }
342 asort($options);
343 $item->setOptions(
344 array("" => $this->lng->txt("trac_all")) + $options
345 );
346
347 $this->filter["sel_country"] = $item->getValue();
348 break;
349
350 case "status":
351 $item = $this->addFilterItemByMetaType(
352 "status",
354 true,
355 $meta["txt"]
356 );
357 $item->setOptions(
358 array("" => $this->lng->txt("trac_all"),
359 ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM + 1 => $this->lng->txt(
361 ),
362 ilLPStatus::LP_STATUS_IN_PROGRESS_NUM + 1 => $this->lng->txt(
364 ),
365 ilLPStatus::LP_STATUS_COMPLETED_NUM + 1 => $this->lng->txt(
367 ),
368 ilLPStatus::LP_STATUS_FAILED_NUM + 1 => $this->lng->txt(
370 )
371 )
372 );
373 $this->filter["status"] = $item->getValue();
374 if (is_numeric($this->filter["status"])) {
375 $this->filter["status"]--;
376 }
377 break;
378
379 case "language":
380 $item = $this->addFilterItemByMetaType(
381 "language",
383 true
384 );
385 $this->filter["language"] = $item->getValue();
386 break;
387
388 case "spent_seconds":
389 if (ilObjectLP::supportsSpentSeconds($this->type)) {
390 $item = $this->addFilterItemByMetaType(
391 "spent_seconds",
393 true,
394 $meta["txt"]
395 );
396 $this->filter["spent_seconds"]["from"] = $item->getCombinationItem(
397 "from"
398 )->getValueInSeconds();
399 $this->filter["spent_seconds"]["to"] = $item->getCombinationItem(
400 "to"
401 )->getValueInSeconds();
402 }
403 break;
404 }
405 }
406 }
407
408 protected function fillRow(array $a_set): void
409 {
410 if ($this->has_multi) {
411 $this->tpl->setVariable("USER_ID", $a_set["usr_id"]);
412 }
413
414 foreach ($this->getSelectedColumns() as $c) {
415 if (!(bool) ($a_set["privacy_conflict"] ?? null)) {
416 if ($c == 'status' && $a_set[$c] != ilLPStatus::LP_STATUS_COMPLETED_NUM) {
417 $timing = $this->showTimingsWarning(
418 $this->ref_id,
419 $a_set["usr_id"]
420 );
421 if ($timing) {
422 if ($timing !== true) {
423 $timing = ": " . ilDatePresentation::formatDate(
424 new ilDate($timing, IL_CAL_UNIX)
425 );
426 } else {
427 $timing = "";
428 }
429 $this->tpl->setCurrentBlock('warning_img');
430 $this->tpl->setVariable(
431 'WARNING_IMG',
433 'time_warn.svg'
434 )
435 );
436 $this->tpl->setVariable(
437 'WARNING_ALT',
438 $this->lng->txt(
439 'trac_time_passed'
440 ) . $timing
441 );
442 $this->tpl->parseCurrentBlock();
443 }
444 }
445
446 // #7694
447 if ($c == 'login' && !$a_set["active"]) {
448 $this->tpl->setCurrentBlock('inactive_bl');
449 $this->tpl->setVariable(
450 'TXT_INACTIVE',
451 $this->lng->txt("inactive")
452 );
453 $this->tpl->parseCurrentBlock();
454 }
455
456 $val = $this->parseValue($c, $a_set[$c] ?? '', $this->type);
457 } else {
458 if ($c == 'login') {
459 $this->tpl->setCurrentBlock('inactive_bl');
460 $this->tpl->setVariable(
461 'TXT_INACTIVE',
462 $this->lng->txt(
463 "status_no_permission"
464 )
465 );
466 $this->tpl->parseCurrentBlock();
467 }
468
469 $val = "&nbsp;";
470 }
471
472 $this->tpl->setCurrentBlock("user_field");
473 $this->tpl->setVariable("VAL_UF", $val);
474 $this->tpl->parseCurrentBlock();
475 }
476
477 $this->ctrl->setParameterByClass(
478 "illplistofobjectsgui",
479 "user_id",
480 $a_set["usr_id"]
481 );
482
483 if (!$this->getPrintMode() && !(bool) ($a_set["privacy_conflict"] ?? null)) {
484 // details for containers and collections
485 if ($this->has_collection ||
486 $this->objDefinition->isContainer($this->type)) {
487 $this->tpl->setCurrentBlock("item_command");
488 $this->tpl->setVariable(
489 "HREF_COMMAND",
490 $this->ctrl->getLinkTargetByClass(
491 "illplistofobjectsgui",
492 "userdetails"
493 )
494 );
495 $this->tpl->setVariable(
496 "TXT_COMMAND",
497 $this->lng->txt('details')
498 );
499 $this->tpl->parseCurrentBlock();
500 }
501
502 if ($this->has_edit) {
503 $this->tpl->setCurrentBlock("item_command");
504 $this->tpl->setVariable(
505 "HREF_COMMAND",
506 $this->ctrl->getLinkTargetByClass(
507 "illplistofobjectsgui",
508 "edituser"
509 )
510 );
511 $this->tpl->setVariable("TXT_COMMAND", $this->lng->txt('edit'));
512 $this->tpl->parseCurrentBlock();
513 }
514 }
515
516 $this->ctrl->setParameterByClass("illplistofobjectsgui", 'user_id', '');
517 }
518
519 protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
520 {
521 $labels = $this->getSelectableColumns();
522 $cnt = 0;
523 foreach ($this->getSelectedColumns() as $c) {
524 $a_excel->setCell($a_row, $cnt++, $labels[$c]["txt"]);
525 }
526
527 $a_excel->setBold(
528 "A" . $a_row . ":" . $a_excel->getColumnCoord($cnt - 1) . $a_row
529 );
530 }
531
532 protected function fillRowExcel(
533 ilExcel $a_excel,
534 int &$a_row,
535 array $a_set
536 ): void {
537 $cnt = 0;
538 foreach ($this->getSelectedColumns() as $c) {
539 if ($c != 'status') {
540 $val = $this->parseValue($c, $a_set[$c], $this->type);
541 } else {
543 (int) $a_set[$c]
544 );
545 }
546 $a_excel->setCell($a_row, $cnt++, $val);
547 }
548 }
549
550 protected function fillHeaderCSV(ilCSVWriter $a_csv): void
551 {
552 $labels = $this->getSelectableColumns();
553 foreach ($this->getSelectedColumns() as $c) {
554 $a_csv->addColumn($labels[$c]["txt"]);
555 }
556
557 $a_csv->addRow();
558 }
559
560 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
561 {
562 foreach ($this->getSelectedColumns() as $c) {
563 if ($c != 'status') {
564 $val = $this->parseValue($c, $a_set[$c], $this->type);
565 } else {
567 (int) $a_set[$c]
568 );
569 }
570 $a_csv->addColumn($val);
571 }
572
573 $a_csv->addRow();
574 }
575}
const IL_CAL_UNIX
addColumn(string $a_col)
static getCountryCodes()
Get country codes (DIN EN 3166-1)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
Class for single dates.
setBold(string $a_coords)
Set cell(s) to bold.
getColumnCoord(int $a_col)
Get column "name" from number.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
TableGUI class for learning progress.
showTimingsWarning(int $a_ref_id, int $a_user_id)
getCurrentFilter(bool $as_query=false)
parseValue(string $id, ?string $value, string $type)
parseTitle(int $a_obj_id, string $action, int $a_user_id=0)
getSelectableUserColumns(int $a_in_course=0, int $a_in_group=0)
static checkPermission(string $a_permission, int $a_ref_id, ?int $a_user_id=null)
wrapper for rbac access checks
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parses the objects.xml it handles the xml-description of all ilias objects
static supportsSpentSeconds(string $obj_type)
static supportsMark(string $obj_type)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
determineOffsetAndOrder(bool $a_omit_offset=false)
setExportFormats(array $formats)
Set available export formats.
setExternalSegmentation(bool $a_val)
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
setShowTemplates(bool $a_value)
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setFormAction(string $a_form_action, bool $a_multipart=false)
resetOffset(bool $a_in_determination=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setDefaultOrderField(string $a_defaultorderfield)
setPrintMode(bool $a_value=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setExternalSorting(bool $a_val)
array $selectable_columns
const FILTER_DURATION_RANGE
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
const FILTER_NUMBER_RANGE
const FILTER_DATETIME_RANGE
setMaxCount(int $a_max_count)
set max.
Learning progress table: One object, rows: users, columns: properties Example: A course,...
fillRow(array $a_set)
Standard Version of Fill Row.
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
fillHeaderExcel(ilExcel $a_excel, int &$a_row)
Excel Version of Fill Header.
__construct(?object $a_parent_obj, string $a_parent_cmd, int $a_obj_id, int $a_ref_id, bool $a_print_view=false)
Constructor.
fillHeaderCSV(ilCSVWriter $a_csv)
CSV Version of Fill Header.
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
static getUserDataForObject(int $a_ref_id, string $a_order_field="", string $a_order_dir="", int $a_offset=0, int $a_limit=9999, ?array $a_filters=null, ?array $a_additional_fields=null, ?int $check_agreement=null, ?array $privacy_fields=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$cols
Definition: xhr_table.php:11