ILIAS  release_8 Revision v8.24
class.ilLPProgressTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
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
108 $this->setSelectAllCheckbox("item_id");
109 $this->addMultiCommand(
110 "hideSelected",
111 $this->lng->txt("trac_hide_selected")
112 );
113
114 $this->setShowTemplates(true);
115 } else {
116 $olp = ilObjectLP::getInstance($this->parent_obj_id);
117 $collection = $olp->getCollectionInstance();
118 $this->has_object_subitems = ($collection instanceof ilLPCollectionOfRepositoryObjects);
119
120 $this->setTitle($this->lng->txt("details")); // #15247
121
122 $this->addColumn($this->lng->txt("trac_title"), "title", "31%");
123 $this->addColumn($this->lng->txt("status"), "status", "7%");
124
125 if ($this->mode == ilLPObjSettings::LP_MODE_SCORM) {
126 $this->lng->loadLanguageModule('content');
127 $this->addColumn($this->lng->txt('cont_score'), 'score', '10%');
128 } elseif ($this->has_object_subitems) {
129 $this->addColumn(
130 $this->lng->txt('trac_status_changed'),
131 'status_changed',
132 '10%'
133 );
134 $this->addColumn(
135 $this->lng->txt("trac_percentage"),
136 "percentage",
137 "7%"
138 );
139 $this->addColumn($this->lng->txt("trac_mark"), "", "5%");
140 $this->addColumn($this->lng->txt("comment"), "", "10%");
141 $this->addColumn($this->lng->txt("trac_mode"), "", "20%");
142 $this->addColumn($this->lng->txt("path"), "", "20%");
143 }
144 }
145
146 $this->setEnableHeader(true);
147 $this->setFormAction(
148 $this->ctrl->getFormActionByClass(get_class($this))
149 );
150 $this->setRowTemplate(
151 "tpl.lp_progress_list_row.html",
152 "Services/Tracking"
153 );
154 $this->setEnableHeader(true);
155 $this->setEnableNumInfo(false);
156 $this->setEnableTitle(true);
157 $this->setDefaultOrderField("title");
158 $this->setDefaultOrderDirection("asc");
159
160 if ($this->has_object_subitems) {
161 $this->setExportFormats(
162 array(self::EXPORT_CSV, self::EXPORT_EXCEL)
163 );
164 }
165
166 // area selector gets in the way
167 if ($this->tracked_user) {
168 $this->getItems();
169 }
170 }
171
172 public function numericOrdering(string $a_field): bool
173 {
174 return $a_field == "percentage";
175 }
176
177 public function getItems(): void
178 {
179 $data = [];
181 if (!$obj_ids && !$this->details) {
182 switch ($this->lp_context) {
184 $obj_ids = $this->searchObjects(
185 $this->getCurrentFilter(true),
186 ''
187 );
188 break;
189
190 default:
191 $obj_ids = $this->searchObjects(
192 $this->getCurrentFilter(true),
193 "read"
194 );
195
196 // check for LP relevance
198 $this->tracked_user->getId(),
199 $obj_ids,
200 null,
201 true
202 ) as $obj_id => $status) {
203 if (!$status) {
204 unset($obj_ids[$obj_id]);
205 }
206 }
207 break;
208 }
209 }
210 if ($obj_ids) {
211 switch ($this->mode) {
214 $this->tracked_user->getId(),
215 $this->parent_obj_id,
217 );
218 break;
219
222 $this->tracked_user->getId(),
223 $this->parent_obj_id,
225 );
226 break;
227
231 if ($this->tracked_user) {
233 $this->tracked_user->getId(),
234 $this->parent_obj_id,
236 );
237 }
238 break;
239
240 default:
242 $this->tracked_user->getId(),
244 );
245 foreach ($data as $idx => $item) {
246 if (!($item["status"] ?? false) && !($this->filter["status"] ?? false) && !$this->details) {
247 unset($data[$idx]);
248 } else {
250 $item["obj_id"],
251 $item["type"]
252 );
253 }
254 }
255 break;
256 }
257
258 // #15334
259 foreach ($data as $idx => $row) {
260 if (!$this->isPercentageAvailable($row["obj_id"] ?? 0)) {
261 // #17000 - enable proper (numeric) sorting
262 $data[$idx]["percentage"] = -1;
263 }
264 }
265 $this->setData($data);
266 }
267 }
268
269 protected function fillRow(array $a_set): void
270 {
271 if (!$this->details) {
272 $this->tpl->setCurrentBlock("column_checkbox");
273 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
274 $this->tpl->parseCurrentBlock();
275 }
276
277 $this->tpl->setVariable(
278 "ICON_SRC",
279 ilObject::_getIcon(0, "tiny", $a_set["type"])
280 );
281 $this->tpl->setVariable("ICON_ALT", $this->lng->txt("obj_" . $a_set["type"]));
282 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
283
284 if ($a_set["offline"] ?? false) {
285 $this->tpl->setCurrentBlock("offline");
286 $this->tpl->setVariable("TEXT_STATUS", $this->lng->txt("status"));
287 $this->tpl->setVariable("TEXT_OFFLINE", $this->lng->txt("offline"));
288 $this->tpl->parseCurrentBlock();
289 }
290
292 $this->tpl->setVariable(
293 "STATUS_ICON",
294 $icons->renderIconForStatus((int) $a_set["status"])
295 );
296
297 if ($this->mode == ilLPObjSettings::LP_MODE_SCORM) {
298 $this->tpl->setVariable('SCORE_VAL', $a_set["score"]);
299 } elseif ($this->has_object_subitems) {
300 $this->tpl->setCurrentBlock("status_details");
301
302 $this->tpl->setVariable(
303 'STATUS_CHANGED_VAL',
305 new ilDateTime(
306 $a_set['status_changed'],
308 )
309 )
310 );
311
312 $olp = ilObjectLP::getInstance($a_set["obj_id"]);
313 $this->tpl->setVariable(
314 "MODE_TEXT",
315 $olp->getModeText($a_set["u_mode"])
316 );
317 $this->tpl->setVariable("MARK_VALUE", $a_set["mark"]);
318 $this->tpl->setVariable("COMMENT_TEXT", $a_set["comment"]);
319
320 if ($a_set["percentage"] < 0) {
321 $this->tpl->setVariable("PERCENTAGE_VALUE", "");
322 } else {
323 $this->tpl->setVariable(
324 "PERCENTAGE_VALUE",
325 sprintf("%d%%", $a_set["percentage"])
326 );
327 }
328
329 // path
330 $path = $this->buildPath($a_set["ref_ids"]);
331 if ($path) {
332 $this->tpl->setCurrentBlock("item_path");
333 foreach ($path as $path_item) {
334 $this->tpl->setVariable("PATH_ITEM", $path_item);
335 $this->tpl->parseCurrentBlock();
336 }
337 }
338
339 $this->tpl->parseCurrentBlock();
340 }
341
342 // not for objectives/scos
343 if (!$this->mode) {
344 // tlt warning
345 if ($a_set["status"] != ilLPStatus::LP_STATUS_COMPLETED_NUM && $a_set["ref_ids"]) {
346 $ref_id = $a_set["ref_ids"];
347 $ref_id = array_shift($ref_id);
348 $timing = $this->showTimingsWarning(
349 $ref_id,
350 $this->tracked_user->getId()
351 );
352 if ($timing) {
353 if ($timing !== true) {
354 $timing = ": " . ilDatePresentation::formatDate(
355 new ilDate($timing, IL_CAL_UNIX)
356 );
357 } else {
358 $timing = "";
359 }
360 $this->tpl->setCurrentBlock('warning_img');
361 $this->tpl->setVariable(
362 'WARNING_IMG',
364 'time_warn.svg'
365 )
366 );
367 $this->tpl->setVariable(
368 'WARNING_ALT',
369 $this->lng->txt(
370 'trac_time_passed'
371 ) . $timing
372 );
373 $this->tpl->parseCurrentBlock();
374 }
375 }
376
377 // hide / unhide?!
378 if (!$this->details) {
379 $this->tpl->setCurrentBlock("item_command");
380 $this->ctrl->setParameterByClass(
381 get_class($this),
382 'hide',
383 $a_set["obj_id"]
384 );
385 $this->tpl->setVariable(
386 "HREF_COMMAND",
387 $this->ctrl->getLinkTargetByClass(
388 get_class($this),
389 'hide'
390 )
391 );
392 $this->tpl->setVariable(
393 "TXT_COMMAND",
394 $this->lng->txt('trac_hide')
395 );
396 $this->tpl->parseCurrentBlock();
397
398 $olp = ilObjectLP::getInstance($a_set["obj_id"]);
399 if ($olp->getCollectionInstance() && $a_set["ref_ids"]) {
400 $ref_id = $a_set["ref_ids"];
401 $ref_id = array_shift($ref_id);
402 $this->ctrl->setParameterByClass(
403 $this->ctrl->getCmdClass(),
404 'details_id',
405 $ref_id
406 );
407 $this->tpl->setVariable(
408 "HREF_COMMAND",
409 $this->ctrl->getLinkTargetByClass(
410 $this->ctrl->getCmdClass(),
411 'details'
412 )
413 );
414 $this->ctrl->setParameterByClass(
415 $this->ctrl->getCmdClass(),
416 'details_id',
417 ''
418 );
419 $this->tpl->setVariable(
420 "TXT_COMMAND",
421 $this->lng->txt('trac_subitems')
422 );
423 $this->tpl->parseCurrentBlock();
424 }
425
426 $this->tpl->setCurrentBlock("column_action");
427 $this->tpl->parseCurrentBlock();
428 }
429 }
430 }
431
432 protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
433 {
434 $a_excel->setCell($a_row, 0, $this->lng->txt("type"));
435 $a_excel->setCell($a_row, 1, $this->lng->txt("trac_title"));
436 $a_excel->setCell($a_row, 2, $this->lng->txt("status"));
437 $a_excel->setCell($a_row, 3, $this->lng->txt("trac_status_changed"));
438 $a_excel->setCell($a_row, 4, $this->lng->txt("trac_percentage"));
439 $a_excel->setCell($a_row, 5, $this->lng->txt("trac_mark"));
440 $a_excel->setCell($a_row, 6, $this->lng->txt("comment"));
441 $a_excel->setCell($a_row, 7, $this->lng->txt("trac_mode"));
442 // $a_excel->setCell($a_row, 7, $this->lng->txt("path"));
443
444 $a_excel->setBold("A" . $a_row . ":H" . $a_row);
445 }
446
447 protected function fillRowExcel(
448 ilExcel $a_excel,
449 int &$a_row,
450 array $a_set
451 ): void {
452 $a_excel->setCell($a_row, 0, $this->lng->txt("obj_" . $a_set["type"]));
453 $a_excel->setCell($a_row, 1, $a_set["title"]);
454 $a_excel->setCell(
455 $a_row,
456 2,
458 $a_set["status"]
459 )
460 );
461
462 $a_excel->setCell(
463 $a_row,
464 3,
465 new ilDateTime(
466 $a_set['status_changed'],
468 )
469 );
470
471 if (!$this->isPercentageAvailable($a_set['obj_id'])) {
472 $a_excel->setCell($a_row, 4, '-');
473 } else {
474 $a_excel->setCell($a_row, 4, $a_set["percentage"] . "%");
475 }
476 $a_excel->setCell($a_row, 5, (string) $a_set["mark"]);
477 $a_excel->setCell($a_row, 6, (string) $a_set["comment"]);
478 $a_excel->setCell(
479 $a_row,
480 7,
481 ilLPObjSettings::_mode2Text($a_set["u_mode"])
482 );
483 }
484
485 protected function fillHeaderCSV(ilCSVWriter $a_csv): void
486 {
487 $a_csv->addColumn($this->lng->txt("type"));
488 $a_csv->addColumn($this->lng->txt("trac_title"));
489 $a_csv->addColumn($this->lng->txt("status"));
490 $a_csv->addColumn($this->lng->txt("trac_status_changed"));
491 $a_csv->addColumn($this->lng->txt("trac_percentage"));
492 $a_csv->addColumn($this->lng->txt("trac_mark"));
493 $a_csv->addColumn($this->lng->txt("comment"));
494 $a_csv->addColumn($this->lng->txt("trac_mode"));
495 // $a_csv->addColumn($this->lng->txt("path"));
496 $a_csv->addRow();
497 }
498
499 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
500 {
501 $a_csv->addColumn($this->lng->txt("obj_" . $a_set["type"]));
502 $a_csv->addColumn($a_set["title"]);
503 $a_csv->addColumn(
505 );
506
508 $a_csv->addColumn(
510 new ilDateTime(
511 $a_set['status_changed'],
513 )
514 )
515 );
517
518 if (!$this->isPercentageAvailable($a_set['obj_id'])) {
519 $a_csv->addColumn('-');
520 } else {
521 $a_csv->addColumn(sprintf("%d%%", $a_set["percentage"]));
522 }
523 $a_csv->addColumn((string) $a_set["mark"]);
524 $a_csv->addColumn((string) $a_set["comment"]);
525 $a_csv->addColumn(ilLPObjSettings::_mode2Text($a_set["u_mode"]));
526
527 $a_csv->addRow();
528 }
529}
const IL_CAL_UNIX
const IL_CAL_DATETIME
addColumn(string $a_col)
static resetToDefaults()
reset to defaults
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class for single dates.
setBold(string $a_coords)
Set cell(s) to bold.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
static _mode2Text(int $a_mode)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fillRow(array $a_set)
Standard Version of Fill Row.
fillHeaderExcel(ilExcel $a_excel, int &$a_row)
Excel Version of Fill Header.
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
__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.
fillHeaderCSV(ilCSVWriter $a_csv)
CSV Version of Fill Header.
numericOrdering(string $a_field)
Should this field be sorted numeric?
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
const LP_STATUS_COMPLETED_NUM
TableGUI class for learning progress.
showTimingsWarning(int $a_ref_id, int $a_user_id)
getCurrentFilter(bool $as_query=false)
initBaseFilter(bool $a_split_learning_resources=false, bool $a_include_no_status_filter=true)
Init filter.
isPercentageAvailable(int $a_obj_id)
searchObjects(array $filter, string $permission, ?array $preset_obj_ids=null, bool $a_check_lp_activation=true)
Search objects that match current filters.
static isObjectOffline(int $a_obj_id, string $a_type='')
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
User class.
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)
static getInstance(int $obj_id)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
setExportFormats(array $formats)
Set available export formats.
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
setShowTemplates(bool $a_value)
setFormAction(string $a_form_action, bool $a_multipart=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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
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.
ilLanguage $lng
static getSCOsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_sco_ids)
static getObjectivesStatusForUser(int $a_user_id, int $a_obj_id, array $a_objective_ids)
static getSubItemsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_item_ids)
Get subitems status.
static getObjectsStatusForUser(int $a_user_id, array $obj_refs)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc