ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTrUserObjectsPropsTableGUI.php
Go to the documentation of this file.
1 <?php
26 {
27  protected string $type;
28  protected int $ref_id;
29  protected int $obj_id;
30  protected int $user_id;
31 
34 
38  public function __construct(
39  ?object $a_parent_obj,
40  string $a_parent_cmd,
41  int $a_user_id,
42  int $a_obj_id,
43  int $a_ref_id,
44  bool $a_print_view = false
45  ) {
46  global $DIC;
47 
48  $this->setId("truop");
49  $this->user_id = $a_user_id;
50  $this->obj_id = $a_obj_id;
51  $this->type = ilObject::_lookupType($this->obj_id);
52  $this->ref_id = $a_ref_id;
53 
54  parent::__construct($a_parent_obj, $a_parent_cmd);
55  $this->setLimit(9999);
56 
57  $this->parseTitle($this->obj_id, "details", $this->user_id);
58 
59  if ($a_print_view) {
60  $this->setPrintMode(true);
61  }
62 
63  $this->addColumn($this->lng->txt("title"), "title");
64 
65  foreach ($this->getSelectedColumns() as $c) {
66  $l = $c;
67  if (in_array(
68  $l,
69  array("last_access",
70  "first_access",
71  "read_count",
72  "spent_seconds",
73  "mark",
74  "status",
75  "percentage"
76  )
77  )) {
78  $l = "trac_" . $l;
79  }
80  if ($l == "u_comment") {
81  $l = "trac_comment";
82  }
83  $this->addColumn($this->lng->txt($l), $c);
84  }
85 
86  if (!$this->getPrintMode()) {
87  $this->addColumn($this->lng->txt("actions"), "");
88  }
89 
90  $this->setExternalSorting(true);
91  $this->setExternalSegmentation(true);
92  $this->setEnableHeader(true);
93  $this->setFormAction(
94  $this->ctrl->getFormActionByClass(get_class($this))
95  );
96  $this->setRowTemplate(
97  "tpl.user_objects_props_row.html",
98  "Services/Tracking"
99  );
100  $this->setEnableTitle(true);
101  $this->setDefaultOrderField("title");
102  $this->setDefaultOrderDirection("asc");
103  $this->setShowTemplates(true);
104  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
105  $this->initFilter();
106  $this->getItems();
107  }
108 
109  public function getSelectableColumns(): array
110  {
111  // default fields
112  $cols = array();
113 
114  $tracking = new ilObjUserTracking();
115  if ($tracking->hasExtendedData(
117  )) {
118  $cols["first_access"] = array(
119  "txt" => $this->lng->txt("trac_first_access"),
120  "default" => true
121  );
122  $cols["last_access"] = array(
123  "txt" => $this->lng->txt("trac_last_access"),
124  "default" => true
125  );
126  }
127  if ($tracking->hasExtendedData(
129  )) {
130  $cols["read_count"] = array(
131  "txt" => $this->lng->txt("trac_read_count"),
132  "default" => true
133  );
134  }
135  if ($tracking->hasExtendedData(
137  )) {
138  $cols["spent_seconds"] = array(
139  "txt" => $this->lng->txt("trac_spent_seconds"),
140  "default" => true
141  );
142  }
143 
144  // #15334 - parent object does not matter, sub-objects may have percentage
145  $cols["percentage"] = array(
146  "txt" => $this->lng->txt("trac_percentage"),
147  "default" => true
148  );
149 
150  $cols["status"] = array(
151  "txt" => $this->lng->txt("trac_status"),
152  "default" => true
153  );
154  $cols["mark"] = array(
155  "txt" => $this->lng->txt("trac_mark"),
156  "default" => true
157  );
158  $cols["u_comment"] = array(
159  "txt" => $this->lng->txt("trac_comment"),
160  "default" => false
161  );
162 
163  return $cols;
164  }
165 
166  public function getItems()
167  {
168  $this->determineOffsetAndOrder();
169  $additional_fields = $this->getSelectedColumns();
170 
172  $this->user_id,
173  $this->obj_id,
174  $this->ref_id,
178  ilUtil::stripSlashes($this->getLimit()),
179  $this->filter,
180  $additional_fields,
181  $this->filter["view_mode"] ?? false
182  );
183 
184  if (count($tr_data["set"]) == 0 && $this->getOffset() > 0) {
185  $this->resetOffset();
187  $this->user_id,
188  $this->obj_id,
189  $this->ref_id,
193  ilUtil::stripSlashes($this->getLimit()),
194  $this->filter,
195  $additional_fields,
196  $this->filter["view_mode"] ?? false
197  );
198  }
199 
200  // #13807
201  foreach ($tr_data["set"] as $idx => $row) {
202  if (($row["ref_id"] ?? 0) &&
204  'read_learning_progress',
205  $row['ref_id']
206  )) {
207  foreach (array_keys($row) as $col_id) {
208  if (!in_array(
209  $col_id,
210  array("type",
211  "obj_id",
212  "ref_id",
213  "title",
214  "sort_title"
215  )
216  )) {
217  $tr_data["set"][$idx][$col_id] = null;
218  }
219  }
220  $tr_data["set"][$idx]["privacy_conflict"] = true;
221  }
222  }
223 
224  $this->setMaxCount($tr_data["cnt"]);
225 
226  if ($this->getOrderField() == "title") {
227  // sort alphabetically, move parent object to 1st position
228  $set = array();
229  $parent = false;
230  foreach ($tr_data["set"] as $idx => $row) {
231  if ($row['obj_id'] == $this->obj_id) {
232  $parent = $row;
233  } elseif (isset($row["sort_title"])) {
234  $set[strtolower($row["sort_title"]) . "__" . $idx] = $row;
235  } else {
236  $set[strtolower($row["title"]) . "__" . $idx] = $row;
237  }
238  }
239  unset($tr_data["set"]);
240  if ($this->getOrderDirection() == "asc") {
241  ksort($set);
242  } else {
243  krsort($set);
244  }
245  $set = array_values($set);
246  if ($parent) {
247  array_unshift($set, $parent);
248  }
249 
250  $this->setData($set);
251  } else {
252  $this->setData($tr_data["set"]);
253  }
254  }
255 
256  public function initFilter(): void
257  {
258  // for scorm and objectives this filter does not make sense / is not implemented
259  $olp = ilObjectLP::getInstance($this->obj_id);
260  $collection = $olp->getCollectionInstance();
261  if ($collection instanceof ilLPCollectionOfRepositoryObjects) {
262  // show collection only/all
263  $ti = new ilRadioGroupInputGUI(
264  $this->lng->txt("trac_view_mode"),
265  "view_mode"
266  );
267  $ti->addOption(
268  new ilRadioOption($this->lng->txt("trac_view_mode_all"), "")
269  );
270  $ti->addOption(
271  new ilRadioOption(
272  $this->lng->txt("trac_view_mode_collection"),
273  "coll"
274  )
275  );
276  $this->addFilterItem($ti);
277  $ti->readFromSession();
278  $this->filter["view_mode"] = $ti->getValue();
279  }
280  }
281 
282  protected function fillRow(array $a_set): void
283  {
284  global $DIC;
286 
287  if (!$this->isPercentageAvailable($a_set["obj_id"])) {
288  $a_set["percentage"] = null;
289  }
290 
291  foreach ($this->getSelectedColumns() as $c) {
292  if (!(bool) ($a_set["privacy_conflict"] ?? null)) {
293  $val = (trim(($a_set[$c] ?? '')) == "")
294  ? " "
295  : $a_set[$c];
296 
297  if (($a_set[$c] ?? '') != "" || $c == "status") {
298  switch ($c) {
299  case "first_access":
301  new ilDateTime(
302  $a_set[$c],
304  )
305  );
306  break;
307 
308  case "last_access":
310  new ilDateTime($a_set[$c], IL_CAL_UNIX)
311  );
312  break;
313 
314  case "status":
315  $val = $icons->renderIconForStatus($a_set[$c] ?? ilLPStatusIcons::ICON_VARIANT_LONG);
316 
317  if (($a_set["ref_id"] ?? 0) &&
318  $a_set["type"] != "lobj" &&
319  $a_set["type"] != "sco" &&
320  $a_set["type"] != "st" &&
321  $a_set["type"] != "mob") {
322  $timing = $this->showTimingsWarning(
323  $a_set["ref_id"],
324  $this->user_id
325  );
326  if ($timing) {
327  if ($timing !== true) {
328  $timing = ": " . ilDatePresentation::formatDate(
329  new ilDate(
330  $timing,
332  )
333  );
334  } else {
335  $timing = "";
336  }
337  $this->tpl->setCurrentBlock('warning_img');
338  $this->tpl->setVariable(
339  'WARNING_IMG',
341  'media/time_warn.svg'
342  )
343  );
344  $this->tpl->setVariable(
345  'WARNING_ALT',
346  $this->lng->txt(
347  'trac_time_passed'
348  ) . $timing
349  );
350  $this->tpl->parseCurrentBlock();
351  }
352  }
353  break;
354 
355  case "spent_seconds":
357  $a_set["type"]
358  )) {
359  $val = "-";
360  } else {
362  $a_set[$c],
363  ($a_set[$c] < 3600 ? true : false)
364  ); // #14858
365  }
366  break;
367 
368  case "percentage":
369  $val = $a_set[$c] . "%";
370  break;
371  }
372  }
373  if ($c == "mark" &&
374  !ilObjectLP::supportsMark($this->type)) {
375  $val = "-";
376  }
377  if ($c == "spent_seconds" &&
378  !ilObjectLP::supportsSpentSeconds($this->type)) {
379  $val = "-";
380  }
381  if ($c == "percentage" &&
382  !$this->isPercentageAvailable($a_set["obj_id"])) {
383  $val = "-";
384  }
385  } else {
386  $val = "&nbsp;";
387  }
388 
389  $this->tpl->setCurrentBlock("user_field");
390  $this->tpl->setVariable("VAL_UF", $val);
391  $this->tpl->parseCurrentBlock();
392  }
393 
394  if ($a_set["privacy_conflict"] ?? null) {
395  $this->tpl->setCurrentBlock("permission_bl");
396  $this->tpl->setVariable(
397  "TXT_NO_PERMISSION",
398  $this->lng->txt("status_no_permission")
399  );
400  $this->tpl->parseCurrentBlock();
401  }
402 
403  if ($a_set["title"] == "") {
404  $a_set["title"] = "--" . $this->lng->txt("none") . "--";
405  }
406 
407  $this->tpl->setVariable(
408  "ICON",
409  ilObject::_getIcon(0, "tiny", $a_set["type"])
410  );
411  $this->tpl->setVariable("ICON_ALT", $this->lng->txt($a_set["type"]));
412 
413  if (in_array(
414  $a_set['type'],
415  array('fold', 'grp')
416  ) && $a_set['obj_id'] != $this->obj_id) {
417  if ($a_set['type'] == 'fold') {
418  $object_gui = 'ilobjfoldergui';
419  } else {
420  $object_gui = 'ilobjgroupgui';
421  }
422  $this->tpl->setCurrentBlock('title_linked');
423 
424  $base_class = '';
425  if ($this->http->wrapper()->query()->has('baseClass')) {
426  $base_class = $this->http->wrapper()->query()->retrieve(
427  'baseClass',
428  $this->refinery->kindlyTo()->string()
429  );
430  }
431  // link structure gets too complicated
432  if ($base_class != "ilDashboardGUI" && $base_class != "ilAdministrationGUI") {
433  $old = $this->ctrl->getParameterArrayByClass(
434  'illplistofobjectsgui'
435  );
436  $this->ctrl->setParameterByClass(
437  'illplistofobjectsgui',
438  'ref_id',
439  $a_set["ref_id"]
440  );
441  $this->ctrl->setParameterByClass(
442  'illplistofobjectsgui',
443  'details_id',
444  $a_set["ref_id"]
445  );
446  $this->ctrl->setParameterByClass(
447  'illplistofobjectsgui',
448  'user_id',
449  $this->user_id
450  );
451  $url = $this->ctrl->getLinkTargetByClass(
452  array('ilrepositorygui',
453  $object_gui,
454  'illearningprogressgui',
455  'illplistofobjectsgui'
456  ),
457  'userdetails'
458  );
459  $this->ctrl->setParameterByClass(
460  'illplistofobjectsgui',
461  'ref_id',
462  $old["ref_id"] ?? null
463  );
464  $this->ctrl->setParameterByClass(
465  'illplistofobjectsgui',
466  'details_id',
467  $old["details_id"]
468  );
469  $this->ctrl->setParameterByClass(
470  'illplistofobjectsgui',
471  'user_id',
472  $old["user_id"]
473  );
474  } else {
475  $url = "#";
476  }
477 
478  $this->tpl->setVariable("URL_TITLE", $url);
479  $this->tpl->setVariable("VAL_TITLE", $a_set["title"]);
480  $this->tpl->parseCurrentBlock();
481  } else {
482  $this->tpl->setCurrentBlock('title_plain');
483  $this->tpl->setVariable("VAL_TITLE", $a_set["title"]);
484  $this->tpl->parseCurrentBlock();
485  }
486 
487  // #16453 / #17163
488  if (($a_set['ref_id'] ?? 0)) {
489  $path = new ilPathGUI();
490  $path = $path->getPath($this->ref_id, $a_set['ref_id']);
491  if ($path) {
492  $this->tpl->setVariable(
493  'COLL_PATH',
494  $this->lng->txt('path') . ': ' . $path
495  );
496  }
497  }
498 
499  // #13807 / #17069
500  if (($a_set["ref_id"] ?? 0) &&
502  'edit_learning_progress',
503  $a_set['ref_id']
504  )) {
505  if (!in_array(
506  $a_set["type"],
507  array("sco", "lobj")
508  ) && !$this->getPrintMode()) {
509  $this->tpl->setCurrentBlock("item_command");
510  $this->ctrl->setParameterByClass(
511  "illplistofobjectsgui",
512  "userdetails_id",
513  $a_set["ref_id"]
514  );
515  $this->tpl->setVariable(
516  "HREF_COMMAND",
517  $this->ctrl->getLinkTargetByClass(
518  "illplistofobjectsgui",
519  'edituser'
520  )
521  );
522  $this->tpl->setVariable("TXT_COMMAND", $this->lng->txt('edit'));
523  $this->ctrl->setParameterByClass(
524  "illplistofobjectsgui",
525  "userdetails_id",
526  ""
527  );
528  $this->tpl->parseCurrentBlock();
529  }
530  }
531  }
532 
533  protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
534  {
535  $a_excel->setCell($a_row, 0, $this->lng->txt("type"));
536  $a_excel->setCell($a_row, 1, $this->lng->txt("title"));
537 
538  $labels = $this->getSelectableColumns();
539  $cnt = 2;
540  foreach ($this->getSelectedColumns() as $c) {
541  $a_excel->setCell($a_row, $cnt++, $labels[$c]["txt"]);
542  }
543 
544  $a_excel->setBold(
545  "A" . $a_row . ":" . $a_excel->getColumnCoord($cnt - 1) . $a_row
546  );
547  }
548 
549  protected function fillRowExcel(
550  ilExcel $a_excel,
551  int &$a_row,
552  array $a_set
553  ): void {
554  $a_excel->setCell($a_row, 0, $this->lng->txt($a_set["type"]));
555  $a_excel->setCell($a_row, 1, $a_set["title"]);
556 
557  $cnt = 2;
558  foreach ($this->getSelectedColumns() as $c) {
559  if ($c != 'status') {
560  $val = $this->parseValue($c, $a_set[$c], $this->type);
561  } else {
563  (int) $a_set[$c]
564  );
565  }
566  $a_excel->setCell($a_row, $cnt++, $val);
567  }
568  }
569 
570  protected function fillHeaderCSV(ilCSVWriter $a_csv): void
571  {
572  $a_csv->addColumn($this->lng->txt("type"));
573  $a_csv->addColumn($this->lng->txt("title"));
574 
575  $labels = $this->getSelectableColumns();
576  foreach ($this->getSelectedColumns() as $c) {
577  $a_csv->addColumn($labels[$c]["txt"]);
578  }
579 
580  $a_csv->addRow();
581  }
582 
583  protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
584  {
585  $a_csv->addColumn($this->lng->txt($a_set["type"]));
586  $a_csv->addColumn($a_set["title"]);
587 
588  foreach ($this->getSelectedColumns() as $c) {
589  if ($c != 'status') {
590  $val = $this->parseValue($c, $a_set[$c], $this->type);
591  } else {
593  (int) $a_set[$c]
594  );
595  }
596  $a_csv->addColumn($val);
597  }
598 
599  $a_csv->addRow();
600  }
601 }
setData(array $a_data)
Creates a path for a start and endnode.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_col)
__construct(?object $a_parent_obj, string $a_parent_cmd, int $a_user_id, int $a_obj_id, int $a_ref_id, bool $a_print_view=false)
Constructor.
setExportFormats(array $formats)
Set available export formats.
const IL_CAL_DATETIME
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
getColumnCoord(int $a_col)
Get column "name" from number.
setShowTemplates(bool $a_value)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
setPrintMode(bool $a_value=false)
addOption(ilRadioOption $a_option)
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
fillHeaderExcel(ilExcel $a_excel, int &$a_row)
const IL_CAL_UNIX
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
setId(string $a_val)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
resetOffset(bool $a_in_determination=false)
setExternalSorting(bool $a_val)
setBold(string $a_coords)
Set cell(s) to bold.
static http()
Fetches the global http state from ILIAS.
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
TableGUI class for learning progress.
setDefaultOrderField(string $a_defaultorderfield)
isPercentageAvailable(int $a_obj_id)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
parseValue(string $id, ?string $value, string $type)
setDefaultOrderDirection(string $a_defaultorderdirection)
$url
Definition: ltiregstart.php:35
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...
static supportsSpentSeconds(string $obj_type)
setLimit(int $a_limit=0, int $a_default_limit=0)
static checkPermission(string $a_permission, int $a_ref_id, ?int $a_user_id=null)
wrapper for rbac access checks
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)
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static supportsMark(string $obj_type)
static _lookupType(int $id, bool $reference=false)
parseTitle(int $a_obj_id, string $action, int $a_user_id=0)
showTimingsWarning(int $a_ref_id, int $a_user_id)
static getInstance(int $obj_id)
static getObjectsDataForUser(int $a_user_id, int $a_parent_obj_id, int $a_parent_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, bool $use_collection=true)
Get all object-based tracking data for user and parent object.
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)
setMaxCount(int $a_max_count)
set max.
setExternalSegmentation(bool $a_val)