ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPProgressTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(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
108 $this->setSelectAllCheckbox("item_id");
109 $this->addMultiCommand(
110 "hideSelected",
111 $this->lng->txt("trac_hide_selected")
112 );
113 } else {
114 $olp = ilObjectLP::getInstance($this->parent_obj_id);
115 $collection = $olp->getCollectionInstance();
116 $this->has_object_subitems = ($collection instanceof ilLPCollectionOfRepositoryObjects);
117
118 $this->setTitle($this->lng->txt("details")); // #15247
119
120 $this->addColumn($this->lng->txt("trac_title"), "title", "31%");
121 $this->addColumn($this->lng->txt("status"), "status", "7%");
122
123 if ($this->mode == ilLPObjSettings::LP_MODE_SCORM) {
124 $this->lng->loadLanguageModule('content');
125 $this->addColumn($this->lng->txt('cont_score'), 'score', '10%');
126 } elseif ($this->has_object_subitems) {
127 $this->addColumn(
128 $this->lng->txt('trac_status_changed'),
129 'status_changed',
130 '10%'
131 );
132 $this->addColumn(
133 $this->lng->txt("trac_percentage"),
134 "percentage",
135 "7%"
136 );
137 $this->addColumn($this->lng->txt("trac_mark"), "", "5%");
138 $this->addColumn($this->lng->txt("comment"), "", "10%");
139 $this->addColumn($this->lng->txt("trac_mode"), "", "20%");
140 $this->addColumn($this->lng->txt("path"), "", "20%");
141 }
142 }
143
144 $this->setEnableHeader(true);
145 $this->setFormAction(
146 $this->ctrl->getFormActionByClass(get_class($this))
147 );
148 $this->setRowTemplate(
149 "tpl.lp_progress_list_row.html",
150 "components/ILIAS/Tracking"
151 );
152 $this->setEnableHeader(true);
153 $this->setEnableNumInfo(false);
154 $this->setEnableTitle(true);
155 $this->setDefaultOrderField("title");
156 $this->setDefaultOrderDirection("asc");
157
158 if ($this->has_object_subitems) {
159 $this->setExportFormats(
160 array(self::EXPORT_CSV, self::EXPORT_EXCEL)
161 );
162 }
163
164 // area selector gets in the way
165 if ($this->tracked_user) {
166 $this->getItems();
167 }
168 }
169
170 public function numericOrdering(string $a_field): bool
171 {
172 return $a_field == "percentage";
173 }
174
175 public function getItems(): void
176 {
177 $data = [];
179 if (!$obj_ids && !$this->details) {
180 switch ($this->lp_context) {
182 $obj_ids = $this->searchObjects(
183 $this->getCurrentFilter(true),
184 ''
185 );
186 break;
187
188 default:
189 $obj_ids = $this->searchObjects(
190 $this->getCurrentFilter(true),
191 "read"
192 );
193
194 // check for LP relevance
196 $this->tracked_user->getId(),
197 $obj_ids,
198 null,
199 true
200 ) as $obj_id => $status) {
201 if (!$status) {
202 unset($obj_ids[$obj_id]);
203 }
204 }
205 break;
206 }
207 }
208 if ($obj_ids) {
209 switch ($this->mode) {
212 $this->tracked_user->getId(),
213 $this->parent_obj_id,
215 );
216 break;
217
220 $this->tracked_user->getId(),
221 $this->parent_obj_id,
223 );
224 break;
225
229 if ($this->tracked_user) {
231 $this->tracked_user->getId(),
232 $this->parent_obj_id,
234 );
235 }
236 break;
237
238 default:
240 $this->tracked_user->getId(),
242 );
243 foreach ($data as $idx => $item) {
244 if (!($item["status"] ?? false) && !($this->filter["status"] ?? false) && !$this->details) {
245 unset($data[$idx]);
246 } else {
248 $item["obj_id"],
249 $item["type"]
250 );
251 }
252 }
253 break;
254 }
255
256 // #15334
257 foreach ($data as $idx => $row) {
258 if (!$this->isPercentageAvailable($row["obj_id"] ?? 0)) {
259 // #17000 - enable proper (numeric) sorting
260 $data[$idx]["percentage"] = -1;
261 }
262 }
263 $this->setData($data);
264 }
265 }
266
267 protected function fillRow(array $a_set): void
268 {
269 if (!$this->details) {
270 $this->tpl->setCurrentBlock("column_checkbox");
271 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
272 $this->tpl->parseCurrentBlock();
273 }
274
275 $this->tpl->setVariable(
276 "ICON_SRC",
277 ilObject::_getIcon(0, "tiny", $a_set["type"])
278 );
279 $this->tpl->setVariable("ICON_ALT", $this->lng->txt('obj_' . $a_set["type"]));
280 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
281
282 if ($a_set["offline"] ?? false) {
283 $this->tpl->setCurrentBlock("offline");
284 $this->tpl->setVariable("TEXT_STATUS", $this->lng->txt("status"));
285 $this->tpl->setVariable("TEXT_OFFLINE", $this->lng->txt("offline"));
286 $this->tpl->parseCurrentBlock();
287 }
288
290 $this->tpl->setVariable(
291 "STATUS_ICON",
292 $icons->renderIconForStatus((int) $a_set["status"])
293 );
294
295 if ($this->mode == ilLPObjSettings::LP_MODE_SCORM) {
296 $this->tpl->setVariable('SCORE_VAL', $a_set["score"]);
297 } elseif ($this->has_object_subitems) {
298 $this->tpl->setCurrentBlock("status_details");
299
300 $this->tpl->setVariable(
301 'STATUS_CHANGED_VAL',
303 new ilDateTime(
304 $a_set['status_changed'],
306 )
307 )
308 );
309
310 $olp = ilObjectLP::getInstance($a_set["obj_id"]);
311 $this->tpl->setVariable(
312 "MODE_TEXT",
313 $olp->getModeText($a_set["u_mode"])
314 );
315 $this->tpl->setVariable("MARK_VALUE", $a_set["mark"]);
316 $this->tpl->setVariable("COMMENT_TEXT", $a_set["comment"]);
317
318 if ($a_set["percentage"] < 0) {
319 $this->tpl->setVariable("PERCENTAGE_VALUE", "");
320 } else {
321 $this->tpl->setVariable(
322 "PERCENTAGE_VALUE",
323 sprintf("%d%%", $a_set["percentage"])
324 );
325 }
326
327 // path
328 $path = $this->buildPath($a_set["ref_ids"]);
329 if ($path) {
330 $this->tpl->setCurrentBlock("item_path");
331 foreach ($path as $path_item) {
332 $this->tpl->setVariable("PATH_ITEM", $path_item);
333 $this->tpl->parseCurrentBlock();
334 }
335 }
336
337 $this->tpl->parseCurrentBlock();
338 }
339
340 // not for objectives/scos
341 if (!$this->mode) {
342 // tlt warning
343 if ($a_set["status"] != ilLPStatus::LP_STATUS_COMPLETED_NUM && $a_set["ref_ids"]) {
344 $ref_id = $a_set["ref_ids"];
345 $ref_id = array_shift($ref_id);
346 $timing = $this->showTimingsWarning(
347 $ref_id,
348 $this->tracked_user->getId()
349 );
350 if ($timing) {
351 if ($timing !== true) {
352 $timing = ": " . ilDatePresentation::formatDate(
353 new ilDate($timing, IL_CAL_UNIX)
354 );
355 } else {
356 $timing = "";
357 }
358 $this->tpl->setCurrentBlock('warning_img');
359 $this->tpl->setVariable(
360 'WARNING_IMG',
362 'media/time_warn.svg'
363 )
364 );
365 $this->tpl->setVariable(
366 'WARNING_ALT',
367 $this->lng->txt(
368 'trac_time_passed'
369 ) . $timing
370 );
371 $this->tpl->parseCurrentBlock();
372 }
373 }
374
375 // hide / unhide?!
376 if (!$this->details) {
377 $this->tpl->setCurrentBlock("item_command");
378 $this->ctrl->setParameterByClass(
379 get_class($this),
380 'hide',
381 $a_set["obj_id"]
382 );
383 $this->tpl->setVariable(
384 "HREF_COMMAND",
385 $this->ctrl->getLinkTargetByClass(
386 get_class($this),
387 'hide'
388 )
389 );
390 $this->tpl->setVariable(
391 "TXT_COMMAND",
392 $this->lng->txt('trac_hide')
393 );
394 $this->tpl->parseCurrentBlock();
395
396 $olp = ilObjectLP::getInstance($a_set["obj_id"]);
397 if ($olp->getCollectionInstance() && $a_set["ref_ids"]) {
398 $ref_id = $a_set["ref_ids"];
399 $ref_id = array_shift($ref_id);
400 $this->ctrl->setParameterByClass(
401 $this->ctrl->getCmdClass(),
402 'details_id',
403 $ref_id
404 );
405 $this->tpl->setVariable(
406 "HREF_COMMAND",
407 $this->ctrl->getLinkTargetByClass(
408 $this->ctrl->getCmdClass(),
409 'details'
410 )
411 );
412 $this->ctrl->setParameterByClass(
413 $this->ctrl->getCmdClass(),
414 'details_id',
415 ''
416 );
417 $this->tpl->setVariable(
418 "TXT_COMMAND",
419 $this->lng->txt('trac_subitems')
420 );
421 $this->tpl->parseCurrentBlock();
422 }
423
424 $this->tpl->setCurrentBlock("column_action");
425 $this->tpl->parseCurrentBlock();
426 }
427 }
428 }
429
430 protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
431 {
432 $a_excel->setCell($a_row, 0, $this->lng->txt("type"));
433 $a_excel->setCell($a_row, 1, $this->lng->txt("trac_title"));
434 $a_excel->setCell($a_row, 2, $this->lng->txt("status"));
435 $a_excel->setCell($a_row, 3, $this->lng->txt("trac_status_changed"));
436 $a_excel->setCell($a_row, 4, $this->lng->txt("trac_percentage"));
437 $a_excel->setCell($a_row, 5, $this->lng->txt("trac_mark"));
438 $a_excel->setCell($a_row, 6, $this->lng->txt("comment"));
439 $a_excel->setCell($a_row, 7, $this->lng->txt("trac_mode"));
440 // $a_excel->setCell($a_row, 7, $this->lng->txt("path"));
441
442 $a_excel->setBold("A" . $a_row . ":H" . $a_row);
443 }
444
445 protected function fillRowExcel(
446 ilExcel $a_excel,
447 int &$a_row,
448 array $a_set
449 ): void {
450 $a_excel->setCell($a_row, 0, $this->lng->txt('obj_' . $a_set["type"]));
451 $a_excel->setCell($a_row, 1, $a_set["title"]);
452 $a_excel->setCell(
453 $a_row,
454 2,
456 $a_set["status"]
457 )
458 );
459
460 $a_excel->setCell(
461 $a_row,
462 3,
463 new ilDateTime(
464 $a_set['status_changed'],
466 )
467 );
468
469 if (!$this->isPercentageAvailable($a_set['obj_id'])) {
470 $a_excel->setCell($a_row, 4, '-');
471 } else {
472 $a_excel->setCell($a_row, 4, $a_set["percentage"] . "%");
473 }
474 $a_excel->setCell($a_row, 5, (string) $a_set["mark"]);
475 $a_excel->setCell($a_row, 6, (string) $a_set["comment"]);
476 $a_excel->setCell(
477 $a_row,
478 7,
479 ilLPObjSettings::_mode2Text($a_set["u_mode"])
480 );
481 }
482
483 protected function fillHeaderCSV(ilCSVWriter $a_csv): void
484 {
485 $a_csv->addColumn($this->lng->txt("type"));
486 $a_csv->addColumn($this->lng->txt("trac_title"));
487 $a_csv->addColumn($this->lng->txt("status"));
488 $a_csv->addColumn($this->lng->txt("trac_status_changed"));
489 $a_csv->addColumn($this->lng->txt("trac_percentage"));
490 $a_csv->addColumn($this->lng->txt("trac_mark"));
491 $a_csv->addColumn($this->lng->txt("comment"));
492 $a_csv->addColumn($this->lng->txt("trac_mode"));
493 // $a_csv->addColumn($this->lng->txt("path"));
494 $a_csv->addRow();
495 }
496
497 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
498 {
499 $a_csv->addColumn($this->lng->txt('obj_' . $a_set["type"]));
500 $a_csv->addColumn($a_set["title"]);
501 $a_csv->addColumn(
503 );
504
506 $a_csv->addColumn(
508 new ilDateTime(
509 $a_set['status_changed'],
511 )
512 )
513 );
515
516 if (!$this->isPercentageAvailable($a_set['obj_id'])) {
517 $a_csv->addColumn('-');
518 } else {
519 $a_csv->addColumn(sprintf("%d%%", $a_set["percentage"]));
520 }
521 $a_csv->addColumn((string) $a_set["mark"]);
522 $a_csv->addColumn((string) $a_set["comment"]);
523 $a_csv->addColumn(ilLPObjSettings::_mode2Text($a_set["u_mode"]));
524
525 $a_csv->addRow();
526 }
527}
const IL_CAL_UNIX
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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, ?ilObjUser $user=null,)
@classDescription Date and time handling
Class for single dates.
setBold(string $a_coords)
Set cell(s) to bold.
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
static _mode2Text(int $a_mode)
TableGUI class for learning progress.
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)
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 $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26