ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilLPProgressTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
20 
28 {
29  protected ?ilObjUser $tracked_user = null;
30  protected ?array $obj_ids = null;
31  protected bool $details = false;
32  protected int $mode = 0;
33  protected int $parent_obj_id = 0;
34  protected int $ref_id = 0;
35  protected int $obj_id = 0;
36  protected int $lp_context = 0;
37  protected bool $has_object_subitems = false;
38 
42  public function __construct(
43  ?object $a_parent_obj,
44  string $a_parent_cmd,
45  ?ilObjUser $a_user = null,
46  ?array $obj_ids = null,
47  bool $details = false,
48  ?int $mode = null,
49  bool $personal_only = false,
50  ?int $a_parent_id = null,
51  ?int $a_parent_ref_id = null,
52  ?int $lp_context = null
53  ) {
54  global $DIC;
55 
56  $ilCtrl = $DIC['ilCtrl'];
57  $lng = $DIC['lng'];
58 
59  $this->tracked_user = $a_user;
60  $this->obj_ids = $obj_ids;
61  $this->details = $details;
62  $this->mode = (int) $mode;
63  $this->parent_obj_id = (int) $a_parent_id;
64  $this->lp_context = (int) $lp_context;
65 
66  if ($a_parent_id) {
67  $this->obj_id = $this->parent_obj_id;
68  $this->ref_id = (int) $a_parent_ref_id;
69  }
70 
71  $this->setId("lpprgtbl");
72  parent::__construct($a_parent_obj, $a_parent_cmd);
73  $this->setLimit(9999);
74 
75  if (!$this->details) {
76  $this->has_object_subitems = true;
78  if (!$user) {
79  $user = $DIC->user();
80  }
81  $this->addColumn("", "", "1", true);
82  $this->addColumn($this->lng->txt("trac_title"), "title", "26%");
83  $this->addColumn($this->lng->txt("status"), "status", "7%");
84  $this->addColumn(
85  $this->lng->txt('trac_status_changed'),
86  'status_changed',
87  '10%'
88  );
89  $this->addColumn(
90  $this->lng->txt("trac_percentage"),
91  "percentage",
92  "7%"
93  );
94  $this->addColumn($this->lng->txt("trac_mark"), "", "5%");
95  $this->addColumn($this->lng->txt("comment"), "", "10%");
96  $this->addColumn($this->lng->txt("trac_mode"), "", "20%");
97  $this->addColumn($this->lng->txt("path"), "", "20%");
98  $this->addColumn($this->lng->txt("actions"), "", "5%");
99 
100  $this->setTitle(
101  sprintf(
102  $this->lng->txt("trac_learning_progress_of"),
103  $user->getFullName()
104  )
105  );
106  $this->initBaseFilter(
107  false,
108  true,
109  $obj_ids || $this->details
110  );
111 
112  $this->setSelectAllCheckbox("item_id");
113  $this->addMultiCommand(
114  "hideSelected",
115  $this->lng->txt("trac_hide_selected")
116  );
117  } else {
118  $olp = ilObjectLP::getInstance($this->parent_obj_id);
119  $collection = $olp->getCollectionInstance();
120  $this->has_object_subitems = ($collection instanceof ilLPCollectionOfRepositoryObjects);
121 
122  $this->setTitle($this->lng->txt("details")); // #15247
123 
124  $this->addColumn($this->lng->txt("trac_title"), "title", "31%");
125  $this->addColumn($this->lng->txt("status"), "status", "7%");
126 
127  if ($this->mode == ilLPObjSettings::LP_MODE_SCORM) {
128  $this->lng->loadLanguageModule('content');
129  $this->addColumn($this->lng->txt('cont_score'), 'score', '10%');
130  } elseif ($this->has_object_subitems) {
131  $this->addColumn(
132  $this->lng->txt('trac_status_changed'),
133  'status_changed',
134  '10%'
135  );
136  $this->addColumn(
137  $this->lng->txt("trac_percentage"),
138  "percentage",
139  "7%"
140  );
141  $this->addColumn($this->lng->txt("trac_mark"), "", "5%");
142  $this->addColumn($this->lng->txt("comment"), "", "10%");
143  $this->addColumn($this->lng->txt("trac_mode"), "", "20%");
144  $this->addColumn($this->lng->txt("path"), "", "20%");
145  }
146  }
147 
148  $this->setEnableHeader(true);
149  $this->setFormAction(
150  $this->ctrl->getFormActionByClass(get_class($this))
151  );
152  $this->setRowTemplate(
153  "tpl.lp_progress_list_row.html",
154  "components/ILIAS/Tracking"
155  );
156  $this->setEnableHeader(true);
157  $this->setEnableNumInfo(false);
158  $this->setEnableTitle(true);
159  $this->setDefaultOrderField("title");
160  $this->setDefaultOrderDirection("asc");
161 
162  if ($this->has_object_subitems) {
163  $this->setExportFormats(
164  array(self::EXPORT_CSV, self::EXPORT_EXCEL)
165  );
166  }
167 
168  // area selector gets in the way
169  if ($this->tracked_user) {
170  $this->getItems();
171  }
172  }
173 
174  public function numericOrdering(string $a_field): bool
175  {
176  return $a_field == "percentage";
177  }
178 
179  public function getItems(): void
180  {
181  $data = [];
182  $obj_ids = $this->obj_ids;
183  if (!$obj_ids && !$this->details) {
184  $filter = $this->getCurrentFilter(true);
185  // only courses in Achievements > Learning Progress (ILIAS 10 only) #43289
186  $filter['type'] = 'crs';
187  switch ($this->lp_context) {
189  $obj_ids = $this->searchObjects(
190  $filter,
191  ''
192  );
193  break;
194 
195  default:
196  $obj_ids = $this->searchObjects(
197  $filter,
198  "read"
199  );
200 
201  // check for LP relevance
203  $this->tracked_user->getId(),
204  $obj_ids,
205  null,
206  true
207  ) as $obj_id => $status) {
208  if (!$status) {
209  unset($obj_ids[$obj_id]);
210  }
211  }
212  break;
213  }
214  }
215  if ($obj_ids) {
216  switch ($this->mode) {
219  $this->tracked_user->getId(),
221  $obj_ids
222  );
223  break;
224 
227  $this->tracked_user->getId(),
229  $obj_ids
230  );
231  break;
232 
236  if ($this->tracked_user) {
238  $this->tracked_user->getId(),
240  $obj_ids
241  );
242  }
243  break;
244 
245  default:
247  $this->tracked_user->getId(),
248  $obj_ids
249  );
250  foreach ($data as $idx => $item) {
251  if (!($item["status"] ?? false) && !($this->filter["status"] ?? false) && !$this->details) {
252  unset($data[$idx]);
253  } else {
255  $item["obj_id"],
256  $item["type"]
257  );
258  }
259  }
260  break;
261  }
262 
263  // #15334
264  foreach ($data as $idx => $row) {
265  if (!$this->isPercentageAvailable($row["obj_id"] ?? 0)) {
266  // #17000 - enable proper (numeric) sorting
267  $data[$idx]["percentage"] = -1;
268  }
269  }
270  $this->setData($data);
271  }
272  }
273 
274  protected function fillRow(array $a_set): void
275  {
276  if (!$this->details) {
277  $this->tpl->setCurrentBlock("column_checkbox");
278  $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
279  $this->tpl->parseCurrentBlock();
280  }
281 
282  $this->tpl->setVariable(
283  "ICON_SRC",
284  ilObject::_getIcon(0, "tiny", $a_set["type"])
285  );
286  $this->tpl->setVariable("ICON_ALT", $this->lng->txt('obj_' . $a_set["type"]));
287  $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
288 
289  if ($a_set["offline"] ?? false) {
290  $this->tpl->setCurrentBlock("offline");
291  $this->tpl->setVariable("TEXT_STATUS", $this->lng->txt("status"));
292  $this->tpl->setVariable("TEXT_OFFLINE", $this->lng->txt("offline"));
293  $this->tpl->parseCurrentBlock();
294  }
295 
297  $this->tpl->setVariable(
298  "STATUS_ICON",
299  $icons->renderIconForStatus((int) $a_set["status"])
300  );
301 
302  if ($this->mode == ilLPObjSettings::LP_MODE_SCORM) {
303  $this->tpl->setVariable('SCORE_VAL', $a_set["score"]);
304  } elseif ($this->has_object_subitems) {
305  $this->tpl->setCurrentBlock("status_details");
306 
307  $this->tpl->setVariable(
308  'STATUS_CHANGED_VAL',
310  new ilDateTime(
311  $a_set['status_changed'],
313  )
314  )
315  );
316 
317  $olp = ilObjectLP::getInstance($a_set["obj_id"]);
318  $this->tpl->setVariable(
319  "MODE_TEXT",
320  $olp->getModeText($a_set["u_mode"])
321  );
322  $this->tpl->setVariable("MARK_VALUE", $a_set["mark"]);
323  $this->tpl->setVariable("COMMENT_TEXT", $a_set["comment"]);
324 
325  if ($a_set["percentage"] < 0) {
326  $this->tpl->setVariable("PERCENTAGE_VALUE", "");
327  } else {
328  $this->tpl->setVariable(
329  "PERCENTAGE_VALUE",
330  sprintf("%d%%", $a_set["percentage"])
331  );
332  }
333 
334  // path
335  $path = $this->buildPath($a_set["ref_ids"]);
336  if ($path) {
337  $this->tpl->setCurrentBlock("item_path");
338  foreach ($path as $path_item) {
339  $this->tpl->setVariable("PATH_ITEM", $path_item);
340  $this->tpl->parseCurrentBlock();
341  }
342  }
343 
344  $this->tpl->parseCurrentBlock();
345  }
346 
347  // not for objectives/scos
348  if (!$this->mode) {
349  // tlt warning
350  if ($a_set["status"] != ilLPStatus::LP_STATUS_COMPLETED_NUM && $a_set["ref_ids"]) {
351  $ref_id = $a_set["ref_ids"];
352  $ref_id = array_shift($ref_id);
353  $timing = $this->showTimingsWarning(
354  $ref_id,
355  $this->tracked_user->getId()
356  );
357  if ($timing) {
358  if ($timing !== true) {
359  $timing = ": " . ilDatePresentation::formatDate(
360  new ilDate($timing, IL_CAL_UNIX)
361  );
362  } else {
363  $timing = "";
364  }
365  $this->tpl->setCurrentBlock('warning_img');
366  $this->tpl->setVariable(
367  'WARNING_IMG',
369  'media/time_warn.svg'
370  )
371  );
372  $this->tpl->setVariable(
373  'WARNING_ALT',
374  $this->lng->txt(
375  'trac_time_passed'
376  ) . $timing
377  );
378  $this->tpl->parseCurrentBlock();
379  }
380  }
381 
382  // hide / unhide?!
383  if (!$this->details) {
384  $this->tpl->setCurrentBlock("item_command");
385  $this->ctrl->setParameterByClass(
386  get_class($this),
387  'hide',
388  $a_set["obj_id"]
389  );
390  $this->tpl->setVariable(
391  "HREF_COMMAND",
392  $this->ctrl->getLinkTargetByClass(
393  get_class($this),
394  'hide'
395  )
396  );
397  $this->tpl->setVariable(
398  "TXT_COMMAND",
399  $this->lng->txt('trac_hide')
400  );
401  $this->tpl->parseCurrentBlock();
402 
403  $olp = ilObjectLP::getInstance($a_set["obj_id"]);
404  if ($olp->getCollectionInstance() && $a_set["ref_ids"]) {
405  $ref_id = $a_set["ref_ids"];
406  $ref_id = array_shift($ref_id);
407  $this->ctrl->setParameterByClass(
408  $this->ctrl->getCmdClass(),
409  'details_id',
410  $ref_id
411  );
412  $this->tpl->setVariable(
413  "HREF_COMMAND",
414  $this->ctrl->getLinkTargetByClass(
415  $this->ctrl->getCmdClass(),
416  'details'
417  )
418  );
419  $this->ctrl->setParameterByClass(
420  $this->ctrl->getCmdClass(),
421  'details_id',
422  ''
423  );
424  $this->tpl->setVariable(
425  "TXT_COMMAND",
426  $this->lng->txt('trac_subitems')
427  );
428  $this->tpl->parseCurrentBlock();
429  }
430 
431  $this->tpl->setCurrentBlock("column_action");
432  $this->tpl->parseCurrentBlock();
433  }
434  }
435  }
436 
437  protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
438  {
439  $a_excel->setCell($a_row, 0, $this->lng->txt("type"));
440  $a_excel->setCell($a_row, 1, $this->lng->txt("trac_title"));
441  $a_excel->setCell($a_row, 2, $this->lng->txt("status"));
442  $a_excel->setCell($a_row, 3, $this->lng->txt("trac_status_changed"));
443  $a_excel->setCell($a_row, 4, $this->lng->txt("trac_percentage"));
444  $a_excel->setCell($a_row, 5, $this->lng->txt("trac_mark"));
445  $a_excel->setCell($a_row, 6, $this->lng->txt("comment"));
446  $a_excel->setCell($a_row, 7, $this->lng->txt("trac_mode"));
447  // $a_excel->setCell($a_row, 7, $this->lng->txt("path"));
448 
449  $a_excel->setBold("A" . $a_row . ":H" . $a_row);
450  }
451 
452  protected function fillRowExcel(
453  ilExcel $a_excel,
454  int &$a_row,
455  array $a_set
456  ): void {
457  $a_excel->setCell($a_row, 0, $this->lng->txt('obj_' . $a_set["type"]));
458  $a_excel->setCell($a_row, 1, $a_set["title"]);
459  $a_excel->setCell(
460  $a_row,
461  2,
463  $a_set["status"]
464  )
465  );
466 
467  $a_excel->setCell(
468  $a_row,
469  3,
470  new ilDateTime(
471  $a_set['status_changed'],
473  )
474  );
475 
476  if (!$this->isPercentageAvailable($a_set['obj_id'])) {
477  $a_excel->setCell($a_row, 4, '-');
478  } else {
479  $a_excel->setCell($a_row, 4, $a_set["percentage"] . "%");
480  }
481  $a_excel->setCell($a_row, 5, (string) $a_set["mark"]);
482  $a_excel->setCell($a_row, 6, (string) $a_set["comment"]);
483  $a_excel->setCell(
484  $a_row,
485  7,
486  ilLPObjSettings::_mode2Text($a_set["u_mode"])
487  );
488  }
489 
490  protected function fillHeaderCSV(ilCSVWriter $a_csv): void
491  {
492  $a_csv->addColumn($this->lng->txt("type"));
493  $a_csv->addColumn($this->lng->txt("trac_title"));
494  $a_csv->addColumn($this->lng->txt("status"));
495  $a_csv->addColumn($this->lng->txt("trac_status_changed"));
496  $a_csv->addColumn($this->lng->txt("trac_percentage"));
497  $a_csv->addColumn($this->lng->txt("trac_mark"));
498  $a_csv->addColumn($this->lng->txt("comment"));
499  $a_csv->addColumn($this->lng->txt("trac_mode"));
500  // $a_csv->addColumn($this->lng->txt("path"));
501  $a_csv->addRow();
502  }
503 
504  protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
505  {
506  $a_csv->addColumn($this->lng->txt('obj_' . $a_set["type"]));
507  $a_csv->addColumn($a_set["title"]);
508  $a_csv->addColumn(
510  );
511 
513  $a_csv->addColumn(
515  new ilDateTime(
516  $a_set['status_changed'],
518  )
519  )
520  );
522 
523  if (!$this->isPercentageAvailable($a_set['obj_id'])) {
524  $a_csv->addColumn('-');
525  } else {
526  $a_csv->addColumn(sprintf("%d%%", $a_set["percentage"]));
527  }
528  $a_csv->addColumn((string) $a_set["mark"]);
529  $a_csv->addColumn((string) $a_set["comment"]);
530  $a_csv->addColumn(ilLPObjSettings::_mode2Text($a_set["u_mode"]));
531 
532  $a_csv->addRow();
533  }
534 }
const LP_STATUS_COMPLETED_NUM
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
setData(array $a_data)
static array static setUseRelativeDates(bool $a_status)
set use relative dates
addColumn(string $a_col)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
getCurrentFilter(bool $as_query=false)
static getLPMemberships(int $usr_id, array $obj_ids, ?int $parent_ref_id=null, bool $mapped_ref_ids=false)
Get all objects where given user is member (from LP POV)
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)
static getSubItemsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_item_ids)
Get subitems status.
static getObjectivesStatusForUser(int $a_user_id, int $a_obj_id, array $a_objective_ids)
setEnableTitle(bool $a_enabletitle)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
searchObjects(array $filter, string $permission, ?array $preset_obj_ids=null, bool $a_check_lp_activation=true)
Search objects that match current filters.
static getSCOsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_sco_ids)
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
static resetToDefaults()
reset to defaults
__construct(?object $a_parent_obj, string $a_parent_cmd, ?ilObjUser $a_user=null, ?array $obj_ids=null, bool $details=false, ?int $mode=null, bool $personal_only=false, ?int $a_parent_id=null, ?int $a_parent_ref_id=null, ?int $lp_context=null)
Constructor.
const IL_CAL_UNIX
ilLanguage $lng
TableGUI class for learning progress.
setId(string $a_val)
$path
Definition: ltiservices.php:30
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
setBold(string $a_coords)
Set cell(s) to bold.
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.
global $DIC
Definition: shib_login.php:25
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setDefaultOrderDirection(string $a_defaultorderdirection)
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
initBaseFilter(bool $a_split_learning_resources=false, bool $a_include_no_status_filter=true, bool $show_type_filter=true)
Init filter.
static getObjectsStatusForUser(int $a_user_id, array $obj_refs)
setEnableNumInfo(bool $a_val)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
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)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static isObjectOffline(int $a_obj_id, string $a_type='')
showTimingsWarning(int $a_ref_id, int $a_user_id)
addMultiCommand(string $a_cmd, string $a_text)
static getInstance(int $obj_id)
setEnableHeader(bool $a_enableheader)
fillHeaderExcel(ilExcel $a_excel, int &$a_row)
static _mode2Text(int $a_mode)