ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilTrSummaryTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 protected ?ilObjectLP $olp = null;
29 protected bool $is_root;
30 protected bool $is_in_course = false;
31 protected bool $is_in_group = false;
32 protected int $ref_id;
33 protected ?string $type = null;
34 protected int $obj_id;
35
38
42 public function __construct(
43 ?object $a_parent_obj,
44 string $a_parent_cmd,
45 int $a_ref_id,
46 bool $a_print_mode = false
47 ) {
48 global $DIC;
49 $this->objDefinition = $DIC['objDefinition'];
50 $this->rbacsystem = $DIC->rbac()->system();
51 $this->access = $DIC->access();
52 $this->ref_id = $a_ref_id;
53 $this->obj_id = ilObject::_lookupObjId($a_ref_id);
54 $this->is_root = ($a_ref_id == ROOT_FOLDER_ID);
55
56 $this->setId("trsmy");
57
58 if (!$this->is_root) {
59 // #17084 - are we multi-object or not?
60 // we cannot parse type filter (too complicated)
61 $type = ilObject::_lookupType($this->obj_id);
62 if (!$this->objDefinition->isContainer($type)) {
63 $this->type = $type;
64 $this->olp = ilObjectLP::getInstance($this->obj_id);
65 }
66 }
67
68 if (
69 !$this->is_root &&
70 $DIC->repositoryTree()->checkForParentType($this->ref_id, 'grp')
71 ) {
72 $this->is_in_group = true;
73 } elseif (
74 !$this->is_root &&
75 $DIC->repositoryTree()->checkForParentType($this->ref_id, 'crs')
76 ) {
77 $this->is_in_course = true;
78 }
79
80 parent::__construct($a_parent_obj, $a_parent_cmd);
81
82 if ($a_print_mode) {
83 $this->setPrintMode(true);
84 }
85
86 $this->parseTitle($this->obj_id, "trac_summary");
87 $this->setLimit(9999);
88 $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
89
90 $this->addColumn($this->lng->txt("title"), "title");
91 $this->setDefaultOrderField("title");
92
93 $labels = $this->getSelectableColumns();
94 foreach ($this->getSelectedColumns() as $c) {
95 // see bug #35119; these column list percentage lists and are not sortable
96 if (in_array($c, ["status", "mark", "language", "gender", "city", "country"])) {
97 $this->addColumn($labels[$c]["txt"]);
98 } else {
99 $this->addColumn($labels[$c]["txt"], $c);
100 }
101 }
102
103 if ($this->is_root) {
104 $this->addColumn($this->lng->txt("path"));
105 $this->addColumn($this->lng->txt("action"));
106 }
107
108 // $this->setExternalSorting(true);
109 $this->setEnableHeader(true);
110 $this->setFormAction(
111 $this->ctrl->getFormActionByClass(get_class($this))
112 );
113 $this->setRowTemplate("tpl.trac_summary_row.html", "components/ILIAS/Tracking");
114 $this->initFilter();
115
116 $this->getItems($a_parent_obj->getObjId(), $a_ref_id);
117 }
118
119 public function getSelectableColumns(): array
120 {
121 $lng_map = array("user_total" => "users",
122 "first_access_min" => "trac_first_access",
123 "last_access_max" => "trac_last_access",
124 "mark" => "trac_mark",
125 "status" => "trac_status",
126 'status_changed_max' => 'trac_status_changed',
127 "spent_seconds_avg" => "trac_spent_seconds",
128 "percentage_avg" => "trac_percentage",
129 "read_count_sum" => "trac_read_count",
130 "read_count_avg" => "trac_read_count",
131 "read_count_spent_seconds_avg" => "trac_read_count_spent_seconds"
132 );
133
134 $all = array("user_total");
135 $default = array();
136
137 // show only if extended data was activated in lp settings
138 $tracking = new ilObjUserTracking();
139 if ($tracking->hasExtendedData(
141 )) {
142 $all[] = "read_count_sum";
143 $all[] = "read_count_avg";
144 $default[] = "read_count_sum";
145 }
146 if ($tracking->hasExtendedData(
148 )) {
149 if ($this->is_root || !$this->type || ilObjectLP::supportsSpentSeconds(
150 $this->type
151 )) {
152 $all[] = "spent_seconds_avg";
153 $default[] = "spent_seconds_avg";
154 }
155 }
156 if ($tracking->hasExtendedData(
158 ) &&
159 $tracking->hasExtendedData(
161 )) {
162 if ($this->is_root || !$this->type || ilObjectLP::supportsSpentSeconds(
163 $this->type
164 )) {
165 $all[] = "read_count_spent_seconds_avg";
166 // $default[] = "read_count_spent_seconds_avg";
167 }
168 }
169
170 if ($this->is_root || !$this->type || $this->isPercentageAvailable(
171 $this->obj_id
172 )) {
173 $all[] = "percentage_avg";
174 }
175
176 if ($this->is_root || !$this->olp || $this->olp->isActive()) {
177 $all[] = "status";
178 $all[] = 'status_changed_max';
179 }
180
181 if ($this->is_root || !$this->type || ilObjectLP::supportsMark(
182 $this->type
183 )) {
184 $all[] = "mark";
185 }
186
187 $privacy = array("gender", "city", "country");
188 foreach ($privacy as $field) {
189 if (
190 ($this->is_in_course && $this->setting->get("usr_settings_course_export_" . $field)) ||
191 ($this->is_in_group && $this->setting->get("usr_settings_group_export_" . $field))
192 ) {
193 $all[] = $field;
194 }
195 }
196
197 $all[] = "language";
198
199 $default[] = "percentage_avg";
200 $default[] = "status";
201 $default[] = "mark";
202
203 if ($tracking->hasExtendedData(
205 )) {
206 $all[] = "first_access_min";
207 $all[] = "last_access_max";
208 }
209
210 $all[] = "create_date_min";
211 $all[] = "create_date_max";
212
213 $columns = array();
214 foreach ($all as $column) {
215 $l = $column;
216
217 $prefix = false;
218 if (substr($l, -3) == "avg") {
219 $prefix = "&#216; ";
220 } elseif (substr($l, -3) == "sum" || $l == "user_total") {
221 $prefix = "&#8721; ";
222 }
223
224 if (isset($lng_map[$l])) {
225 $l = $lng_map[$l];
226 }
227
228 $txt = $prefix . $this->lng->txt($l);
229
230 if (in_array(
231 $column,
232 array("read_count_avg",
233 "spent_seconds_avg",
234 "percentage_avg"
235 )
236 )) {
237 $txt .= " / " . $this->lng->txt("user");
238 }
239
240 $columns[$column] = array(
241 "txt" => $txt,
242 "default" => (in_array($column, $default) ? true : false)
243 );
244 }
245 return $columns;
246 }
247
248 public function initFilter(): void
249 {
250 if ($this->is_root) {
251 parent::initBaseFilter(true, false);
252 return;
253 }
254
255 // show only if extended data was activated in lp settings
256 $tracking = new ilObjUserTracking();
257
258 $item = $this->addFilterItemByMetaType(
259 "user_total",
261 true,
262 "&#8721; " . $this->lng->txt("users")
263 );
264 $this->filter["user_total"] = $item->getValue();
265
266 if ($tracking->hasExtendedData(
268 )) {
269 $item = $this->addFilterItemByMetaType(
270 "read_count_sum",
272 true,
273 "&#8721; " . $this->lng->txt("trac_read_count")
274 );
275 $this->filter["read_count"] = $item->getValue();
276 }
277
278 if ($tracking->hasExtendedData(
280 )) {
281 if ($this->is_root || !$this->type || ilObjectLP::supportsSpentSeconds(
282 $this->type
283 )) {
284 $item = $this->addFilterItemByMetaType(
285 "spent_seconds",
287 true,
288 "&#216; " . $this->lng->txt(
289 "trac_spent_seconds"
290 ) . " / " . $this->lng->txt("user")
291 );
292 $this->filter["spent_seconds"]["from"] = $item->getCombinationItem(
293 "from"
294 )->getValueInSeconds();
295 $this->filter["spent_seconds"]["to"] = $item->getCombinationItem(
296 "to"
297 )->getValueInSeconds();
298 }
299 }
300
301 if ($this->is_root || !$this->type || $this->isPercentageAvailable(
302 $this->obj_id
303 )) {
304 $item = $this->addFilterItemByMetaType(
305 "percentage",
307 true,
308 "&#216; " . $this->lng->txt(
309 "trac_percentage"
310 ) . " / " . $this->lng->txt("user")
311 );
312 $this->filter["percentage"] = $item->getValue();
313 }
314
315 if ($this->is_root || !$this->olp || $this->olp->isActive()) {
316 $item = $this->addFilterItemByMetaType(
317 "status",
319 true
320 );
321 $item->setOptions(
322 array("" => $this->lng->txt("trac_all"),
323 ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM + 1 => $this->lng->txt(
325 ),
326 ilLPStatus::LP_STATUS_IN_PROGRESS_NUM + 1 => $this->lng->txt(
328 ),
329 ilLPStatus::LP_STATUS_COMPLETED_NUM + 1 => $this->lng->txt(
331 ),
332 ilLPStatus::LP_STATUS_FAILED_NUM + 1 => $this->lng->txt(
334 )
335 )
336 );
337 $this->filter["status"] = $item->getValue();
338 if ($this->filter["status"]) {
339 $this->filter["status"]--;
340 }
341
342 $item = $this->addFilterItemByMetaType(
343 "status_changed_max",
345 true,
346 $this->lng->txt("trac_status_changed")
347 );
348 $this->filter["status_changed"] = $item->getDate();
349 }
350
351 if ($this->is_root || !$this->type || ilObjectLP::supportsMark(
352 $this->type
353 )) {
354 $item = $this->addFilterItemByMetaType(
355 "mark",
357 true,
358 $this->lng->txt("trac_mark")
359 );
360 $this->filter["mark"] = $item->getValue();
361 }
362
363 if ($this->setting->get("usr_settings_course_export_gender")) {
364 $item = $this->addFilterItemByMetaType(
365 "gender",
367 true
368 );
369 $item->setOptions(
370 array(
371 "" => $this->lng->txt("trac_all"),
372 "n" => $this->lng->txt("gender_n"),
373 "m" => $this->lng->txt("gender_m"),
374 "f" => $this->lng->txt("gender_f"),
375 )
376 );
377 $this->filter["gender"] = $item->getValue();
378 }
379
380 if ($this->setting->get("usr_settings_course_export_city")) {
381 $item = $this->addFilterItemByMetaType(
382 "city",
384 true
385 );
386 $this->filter["city"] = $item->getValue();
387 }
388
389
390 if ($this->setting->get("usr_settings_course_export_country")) {
391 $item = $this->addFilterItemByMetaType(
392 "country",
394 true
395 );
396 $item->setOptions(
397 array("" => $this->lng->txt(
398 "trac_all"
399 )
400 ) + $this->getSelCountryCodes()
401 );
402 $this->filter["country"] = $item->getValue();
403 }
404
405 $item = $this->addFilterItemByMetaType(
406 "language",
408 true
409 );
410 $this->filter["language"] = $item->getValue();
411
412 if ($tracking->hasExtendedData(
414 )) {
415 $item = $this->addFilterItemByMetaType(
416 "first_access_min",
418 true,
419 $this->lng->txt("trac_first_access")
420 );
421 $this->filter["first_access"] = $item->getDate();
422
423 $item = $this->addFilterItemByMetaType(
424 "last_access_max",
426 true,
427 $this->lng->txt("trac_last_access")
428 );
429 $this->filter["last_access"] = $item->getDate();
430 }
431
432 $item = $this->addFilterItemByMetaType(
433 "registration_filter",
435 true
436 );
437 $this->filter["registration"] = $item->getDate();
438 }
439
440 public function getSelCountryCodes(): array
441 {
442 $options = array();
443 foreach (ilCountry::getCountryCodes() as $c) {
444 $options[$c] = $this->lng->txt("meta_c_" . $c);
445 }
446 asort($options);
447 return $options;
448 }
449
453 public function getItems(int $a_object_id, int $a_ref_id): void
454 {
455 // show only selected subobjects for lp mode
456 $preselected_obj_ids = $filter = null;
457
459 if (
464 ) {
465 $collection = $olp->getCollectionInstance();
466 $preselected_obj_ids[$a_object_id][] = $a_ref_id;
467 foreach ($collection->getItems() as $item => $item_info) {
468 $tmp_lp = ilObjectLP::getInstance(
469 ilObject::_lookupObjId($item_info)
470 );
471 if ($tmp_lp->isActive()) {
472 $preselected_obj_ids[ilObject::_lookupObjId(
473 $item_info
474 )][] = $item_info;
475 }
476 }
477 $filter = $this->getCurrentFilter();
478 } elseif ($this->is_root) {
479 // using search to get all relevant objects
480 // #8498/#8499: restrict to objects with at least "read_learning_progress" access
481 $preselected_obj_ids = $this->searchObjects(
482 $this->getCurrentFilter(true),
483 "read_learning_progress"
484 );
485 } else {
486 // using summary filters
487 $filter = $this->getCurrentFilter();
488 }
489
491 $a_object_id,
492 $a_ref_id,
497 $filter,
498 $this->getSelectedColumns(),
499 $preselected_obj_ids
500 );
501
502 // build status to image map
503 $valid_status = array(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM,
507 );
508 $status_map = array();
510 foreach ($valid_status as $status) {
511 $status_map[$status] = $status_icons->renderIconForStatus($status);
512 }
513
514 // language map
515 $this->lng->loadLanguageModule("meta");
516 $languages = array();
517 foreach ($this->lng->getInstalledLanguages() as $lang_key) {
518 $languages[$lang_key] = $this->lng->txt("meta_l_" . $lang_key);
519 }
520
521 $rows = array();
522 foreach ($data["set"] as $idx => $result) {
523 // sessions have no title
524 if ($result["title"] == "" && $result["type"] == "sess") {
525 $sess = new ilObjSession($result["obj_id"], false);
526 $data["set"][$idx]["title"] = $sess->getFirstAppointment(
527 )->appointmentToString();
528 }
529
530 $data["set"][$idx]["offline"] = ilLearningProgressBaseGUI::isObjectOffline(
531 $result["obj_id"],
532 $result["type"]
533 );
534
535 // #13807
536 if ($result["ref_ids"]) {
537 $valid = false;
538 foreach ($result["ref_ids"] as $check_ref_id) {
540 'read_learning_progress',
541 $check_ref_id
542 )) {
543 $valid = true;
544 break;
545 }
546 }
547 if (!$valid) {
548 foreach (array_keys($data["set"][$idx]) as $col_id) {
549 if (!in_array(
550 $col_id,
551 array("type",
552 "title",
553 "obj_id",
554 "ref_id",
555 "offline"
556 )
557 )) {
558 $data["set"][$idx][$col_id] = null;
559 }
560 }
561 $data["set"][$idx]["privacy_conflict"] = true;
562 continue;
563 }
564 }
565
566 // percentages
567 $users_no = $result["user_total"];
568 $data["set"][$idx]["gender"] = $this->getItemsPercentages(
569 $result["gender"],
570 $users_no,
571 array(
572 "n" => $this->lng->txt("gender_n"),
573 "m" => $this->lng->txt("gender_m"),
574 "f" => $this->lng->txt("gender_f"),
575 )
576 );
577 $data["set"][$idx]["city"] = $this->getItemsPercentages(
578 $result["city"],
579 $users_no
580 );
581 $data["set"][$idx]["country"] = $this->getItemsPercentages(
582 $result["country"],
583 $users_no,
584 $this->getSelCountryCodes()
585 );
586 $data["set"][$idx]["mark"] = $this->getItemsPercentages(
587 $result["mark"],
588 $users_no
589 );
590 $data["set"][$idx]["language"] = $this->getItemsPercentages(
591 $result["language"],
592 $users_no,
593 $languages
594 );
595
596 // if we encounter any invalid status codes, e.g. null, map them to not attempted instead
597 foreach ($result["status"] as $status_code => $status_counter) {
598 // null is cast to ""
599 if ($status_code === "" || !in_array(
600 $status_code,
601 $valid_status
602 )) {
603 $result['status'][ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM] =
604 $result['status'][ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM] ?? 0 + $status_counter;
605 unset($result["status"][$status_code]);
606 }
607 }
608 $data["set"][$idx]["status"] = $this->getItemsPercentagesStatus(
609 $result["status"],
610 $users_no,
611 $status_map
612 );
613
614 if (!$this->isPercentageAvailable($result["obj_id"])) {
615 $data["set"][$idx]["percentage_avg"] = null;
616 }
617 }
618
619 $this->setMaxCount($data["cnt"]);
620 $this->setData($data["set"]);
621 }
622
626 protected function getItemsPercentages(
627 $data = null,
628 int $overall = 0,
629 ?array $value_map = null,
630 $limit = 3
631 ): array {
632 if (!$overall) {
633 return [];
634 }
635
636 $result = [];
637
638 if ($data) {
639 if (is_array($data) && count($data) < $limit) {
640 $limit = count($data);
641 }
642 if (is_array($data) && (count($data) == $limit + 1)) {
643 ++$limit;
644 }
645 $counter = $others_counter = 0;
646 $others_sum = $overall;
647 $all_sum = 0;
648 foreach ($data as $id => $count) {
649 $counter++;
650 $all_sum += $count;
651 if ($counter <= $limit) {
652 $caption = $id;
653
654 if ($value_map && isset($value_map[$id])) {
655 $caption = $value_map[$id];
656 }
657 if ($caption == "") {
658 $caption = $this->lng->txt("none");
659 }
660 if (
661 $counter == $limit &&
662 $all_sum < $overall
663 ) {
664 ++$others_counter;
665 continue;
666 }
667 $perc = round($count / $overall * 100);
668 $result[] = array(
669 "caption" => $caption,
670 "absolute" => $count,
671 // ." ".($count > 1 ? $lng->txt("users") : $lng->txt("user")),
672 "percentage" => $perc
673 );
674 $others_sum -= $count;
675 } else {
676 $others_counter++;
677 }
678 }
679
680 if ($others_counter) {
681 $perc = round($others_sum / $overall * 100);
682 $result[] = array(
683 "caption" => $others_counter . " " . $this->lng->txt(
684 "trac_others"
685 ),
686 "absolute" => $others_sum,
687 // ." ".($others_sum > 1 ? $lng->txt("users") : $lng->txt("user")),
688 "percentage" => $perc
689 );
690 }
691 }
692
693 return $result;
694 }
695
699 protected function getItemsPercentagesStatus(
700 $data = null,
701 int $overall = 0,
702 ?array $value_map = null
703 ): array {
704 $result = array();
705 foreach ($value_map as $id => $caption) {
706 $count = 0;
707 if (isset($data[$id])) {
708 $count = $data[$id];
709 }
710 $perc = round($count / $overall * 100);
711
712 $result[] = array(
713 "caption" => $caption,
714 "absolute" => $count,
715 "percentage" => $perc
716 );
717 }
718
719 return $result;
720 }
721
722 protected function parseValue(
723 string $id,
724 ?string $value,
725 string $type
726 ): string {
727 // get rid of aggregation
728 $pos = strrpos($id, "_");
729 if ($pos !== false) {
730 $function = strtoupper(substr($id, $pos + 1));
731 if (in_array(
732 $function,
733 array("MIN", "MAX", "SUM", "AVG", "COUNT")
734 )) {
735 $id = substr($id, 0, $pos);
736 }
737 }
738
739 if (trim((string) $value) == "") {
740 if ($id == "title") {
741 return "--" . $this->lng->txt("none") . "--";
742 }
743 return "";
744 }
745 switch ($id) {
746 case 'status_changed':
747 case "first_access":
748 case "create_date":
750 new ilDateTime($value, IL_CAL_DATETIME)
751 );
752 break;
753
754 case "last_access":
756 new ilDateTime($value, IL_CAL_UNIX)
757 );
758 break;
759
760 case "spent_seconds":
761 case "read_count_spent_seconds":
763 $value = "-";
764 } else {
766 (int) $value,
767 $value < 3600
768 ); // #14858
769 }
770 break;
771
772 case "percentage":
773 if (false /* $this->isPercentageAvailable() */) {
774 $value = "-";
775 } else {
776 $value = $value . "%";
777 }
778 break;
779
780 case "mark":
781 if (!ilObjectLP::supportsMark($type)) {
782 $value = "-";
783 }
784 break;
785 }
786
787 return $value;
788 }
789
793 protected function fillRow(array $a_set): void
794 {
795 $this->tpl->setVariable(
796 "ICON",
798 (int) $a_set["obj_id"],
799 "tiny",
800 $a_set["type"]
801 )
802 );
803 $this->tpl->setVariable("ICON_ALT", $this->lng->txt($a_set["type"]));
804 $this->tpl->setVariable("TITLE", $a_set["title"]);
805
806 if ($a_set["offline"] || ($a_set["privacy_conflict"] ?? null)) {
807 $mess = array();
808 if ($a_set["offline"]) {
809 $mess[] = $this->lng->txt("offline");
810 }
811 if ($a_set["privacy_conflict"] ?? null) {
812 $mess[] = $this->lng->txt("status_no_permission");
813 }
814 $this->tpl->setCurrentBlock("status_bl");
815 $this->tpl->setVariable("TEXT_STATUS", implode(", ", $mess));
816 $this->tpl->parseCurrentBlock();
817 }
818
819 foreach ($this->getSelectedColumns() as $c) {
820 switch ($c) {
821 case "gender":
822 case "city":
823 case "language":
824 case "status":
825 case "mark":
826 case "country":
827 $this->renderPercentages($c, $a_set[$c]);
828 break;
829
830 case "percentage_avg":
831 if ((int) $a_set[$c] === 0 || !$this->isPercentageAvailable(
832 $a_set["obj_id"]
833 )) {
834 $this->tpl->setVariable(strtoupper($c), "");
835 break;
836 }
837
838 // no break
839 default:
840 $value = $this->parseValue($c, $a_set[$c], $a_set["type"]);
841 $this->tpl->setVariable(strtoupper($c), $value);
842 break;
843 }
844 }
845
846 if ($this->is_root) {
847 $path = $this->buildPath($a_set["ref_ids"]);
848 if ($path) {
849 $this->tpl->setCurrentBlock("item_path");
850 foreach ($path as $ref_id => $path_item) {
851 $this->tpl->setVariable("PATH_ITEM", $path_item);
852
853 if (!$this->anonymized) {
854 $this->ctrl->setParameterByClass(
855 $this->ctrl->getCmdClass(),
856 'details_id',
857 $ref_id
858 );
859 $this->tpl->setVariable(
860 "URL_DETAILS",
861 $this->ctrl->getLinkTargetByClass(
862 $this->ctrl->getCmdClass(),
863 'details'
864 )
865 );
866 $this->ctrl->setParameterByClass(
867 $this->ctrl->getCmdClass(),
868 'details_id',
869 ''
870 );
871 $this->tpl->setVariable(
872 "TXT_DETAILS",
873 $this->lng->txt(
874 'trac_participants'
875 )
876 );
877 } else {
878 $this->tpl->setVariable(
879 "URL_DETAILS",
880 ilLink::_getLink(
881 $ref_id,
882 $a_set["type"]
883 )
884 );
885 $this->tpl->setVariable(
886 "TXT_DETAILS",
887 $this->lng->txt('view')
888 );
889 }
890
891 $this->tpl->parseCurrentBlock();
892 }
893 }
894
895 $this->tpl->setCurrentBlock("item_command");
896 $this->ctrl->setParameterByClass(
897 get_class($this),
898 'hide',
899 $a_set["obj_id"]
900 );
901 $this->tpl->setVariable(
902 "HREF_COMMAND",
903 $this->ctrl->getLinkTargetByClass(
904 get_class($this),
905 'hide'
906 )
907 );
908 $this->tpl->setVariable(
909 "TXT_COMMAND",
910 $this->lng->txt('trac_hide')
911 );
912 $this->tpl->parseCurrentBlock();
913
914 $this->tpl->touchBlock("path_action");
915 } elseif ($a_set["ref_ids"]) { // #18446
916 // #16453
917 $path = new ilPathGUI();
918 $path = $path->getPath(
919 $this->ref_id,
920 (int) array_pop($a_set["ref_ids"])
921 );
922 if ($path) {
923 $this->tpl->setVariable(
924 'COLL_PATH',
925 $this->lng->txt('path') . ': ' . $path
926 );
927 }
928 }
929 }
930
931 protected function renderPercentages(string $id, array $data): void
932 {
933 if ($data) {
934 foreach ($data as $item) {
935 $this->tpl->setCurrentBlock($id . "_row");
936 $this->tpl->setVariable("CAPTION", $item["caption"]);
937 $this->tpl->setVariable("ABSOLUTE", $item["absolute"]);
938 $this->tpl->setVariable("PERCENTAGE", $item["percentage"]);
939 $this->tpl->parseCurrentBlock();
940 }
941 } else {
942 $this->tpl->touchBlock($id);
943 }
944 }
945
946 protected function isArrayColumn(string $a_name): bool
947 {
948 if (in_array(
949 $a_name,
950 array(
951 "gender",
952 "city",
953 "language",
954 "status",
955 "mark",
956 'country'
957 )
958 )) {
959 return true;
960 }
961 return false;
962 }
963
964 public function numericOrdering(string $a_field): bool
965 {
966 $pos = strrpos($a_field, "_");
967 if ($pos !== false) {
968 $function = strtoupper(substr($a_field, $pos + 1));
969 if (in_array(
970 $function,
971 array("MIN", "MAX", "SUM", "AVG", "COUNT", "TOTAL")
972 )) {
973 return true;
974 }
975 }
976 return false;
977 }
978
979 public function isStatusShown(): bool
980 {
981 return in_array('status', $this->getSelectedColumns());
982 }
983
984 protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
985 {
986 $a_excel->setCell($a_row, 0, $this->lng->txt("title"));
987
988 $labels = $this->getSelectableColumns();
989 $cnt = 1;
990 foreach ($this->getSelectedColumns() as $c) {
991 $label = $labels[$c]["txt"];
992 $label = str_replace(
993 "&#216;",
994 $this->lng->txt("trac_average"),
995 $label
996 );
997 $label = str_replace(
998 "&#8721;",
999 $this->lng->txt("trac_sum"),
1000 $label
1001 );
1002
1003 if (!$this->isArrayColumn($c)) {
1004 $a_excel->setCell($a_row, $cnt, $label);
1005 $cnt++;
1006 } else {
1007 if ($c != "status") {
1008 $a_excel->setCell($a_row, $cnt, $label . " #1");
1009 $a_excel->setCell($a_row, ++$cnt, $label . " #1");
1010 $a_excel->setCell($a_row, ++$cnt, $label . " #1 %");
1011 $a_excel->setCell($a_row, ++$cnt, $label . " #2");
1012 $a_excel->setCell($a_row, ++$cnt, $label . " #2");
1013 $a_excel->setCell($a_row, ++$cnt, $label . " #2 %");
1014 $a_excel->setCell($a_row, ++$cnt, $label . " #3");
1015 $a_excel->setCell($a_row, ++$cnt, $label . " #3");
1016 $a_excel->setCell($a_row, ++$cnt, $label . " #3 %");
1017 $a_excel->setCell(
1018 $a_row,
1019 ++$cnt,
1020 $label . " " . $this->lng->txt(
1021 "trac_others"
1022 )
1023 );
1024 $a_excel->setCell(
1025 $a_row,
1026 ++$cnt,
1027 $label . " " . $this->lng->txt(
1028 "trac_others"
1029 )
1030 );
1031 $a_excel->setCell(
1032 $a_row,
1033 ++$cnt,
1034 $label . " " . $this->lng->txt(
1035 "trac_others"
1036 ) . " %"
1037 );
1038 } else {
1039 // build status to image map
1040 $valid_status = array(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM,
1044 );
1045 $cnt--;
1046 foreach ($valid_status as $status) {
1048 $status
1049 );
1050 $a_excel->setCell($a_row, ++$cnt, $text);
1051 $a_excel->setCell($a_row, ++$cnt, $text . " %");
1052 }
1053 }
1054 $cnt++;
1055 }
1056 }
1057
1058 $a_excel->setBold(
1059 "A" . $a_row . ":" . $a_excel->getColumnCoord($cnt) . $a_row
1060 );
1061 }
1062
1063 protected function fillRowExcel(
1064 ilExcel $a_excel,
1065 int &$a_row,
1066 array $a_set
1067 ): void {
1068 $a_excel->setCell($a_row, 0, $a_set["title"]);
1069
1070 $cnt = 1;
1071 foreach ($this->getSelectedColumns() as $c) {
1072 if (!$this->isArrayColumn($c)) {
1073 $val = $this->parseValue($c, $a_set[$c], $a_set["type"]);
1074 $a_excel->setCell($a_row, $cnt, $val);
1075 $cnt++;
1076 } else {
1077 foreach ((array) $a_set[$c] as $idx => $value) {
1078 if ($c == "status") {
1079 $a_excel->setCell(
1080 $a_row,
1081 $cnt,
1082 (int) $value["absolute"]
1083 );
1084 $a_excel->setCell(
1085 $a_row,
1086 ++$cnt,
1087 $value["percentage"] . "%"
1088 );
1089 } else {
1090 $a_excel->setCell($a_row, $cnt, $value["caption"]);
1091 $a_excel->setCell(
1092 $a_row,
1093 ++$cnt,
1094 (int) $value["absolute"]
1095 );
1096 $a_excel->setCell(
1097 $a_row,
1098 ++$cnt,
1099 $value["percentage"] . "%"
1100 );
1101 }
1102 $cnt++;
1103 }
1104 if (sizeof($a_set[$c]) < 4 && $c != "status") {
1105 for ($loop = 4; $loop > sizeof($a_set[$c]); $loop--) {
1106 $a_excel->setCell($a_row, $cnt, "");
1107 $a_excel->setCell($a_row, ++$cnt, "");
1108 $a_excel->setCell($a_row, ++$cnt, "");
1109 $cnt++;
1110 }
1111 }
1112 }
1113 }
1114 }
1115
1116 protected function fillHeaderCSV(ilCSVWriter $a_csv): void
1117 {
1118 $a_csv->addColumn($this->lng->txt("title"));
1119
1120 $labels = $this->getSelectableColumns();
1121 foreach ($this->getSelectedColumns() as $c) {
1122 $label = $labels[$c]["txt"];
1123 $label = str_replace(
1124 "&#216;",
1125 $this->lng->txt("trac_average"),
1126 $label
1127 );
1128 $label = str_replace(
1129 "&#8721;",
1130 $this->lng->txt("trac_sum"),
1131 $label
1132 );
1133
1134 if (!$this->isArrayColumn($c)) {
1135 $a_csv->addColumn($label);
1136 } else {
1137 if ($c != "status") {
1138 $a_csv->addColumn($label . " #1");
1139 $a_csv->addColumn($label . " #1");
1140 $a_csv->addColumn($label . " #1 %");
1141 $a_csv->addColumn($label . " #2");
1142 $a_csv->addColumn($label . " #2");
1143 $a_csv->addColumn($label . " #2 %");
1144 $a_csv->addColumn($label . " #3");
1145 $a_csv->addColumn($label . " #3");
1146 $a_csv->addColumn($label . " #3 %");
1147 $a_csv->addColumn(
1148 $label . " " . $this->lng->txt("trac_others")
1149 );
1150 $a_csv->addColumn(
1151 $label . " " . $this->lng->txt("trac_others")
1152 );
1153 $a_csv->addColumn(
1154 $label . " " . $this->lng->txt("trac_others") . " %"
1155 );
1156 } else {
1157 // build status to image map
1158 $valid_status = array(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM,
1162 );
1163 foreach ($valid_status as $status) {
1165 $status
1166 );
1167 $a_csv->addColumn($text);
1168 $a_csv->addColumn($text . " %");
1169 }
1170 }
1171 }
1172 }
1173
1174 $a_csv->addRow();
1175 }
1176
1177 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
1178 {
1179 $a_csv->addColumn($a_set["title"]);
1180
1181 foreach ($this->getSelectedColumns() as $c) {
1182 if (!$this->isArrayColumn($c)) {
1183 $val = $this->parseValue($c, $a_set[$c], $a_set["type"]);
1184 $a_csv->addColumn($val);
1185 } else {
1186 foreach ((array) $a_set[$c] as $idx => $value) {
1187 if ($c != "status") {
1188 $a_csv->addColumn($value["caption"]);
1189 }
1190 $a_csv->addColumn((string) $value["absolute"]);
1191 $a_csv->addColumn($value["percentage"]);
1192 }
1193 if (sizeof($a_set[$c]) < 4 && $c != "status") {
1194 for ($loop = 4; $loop > sizeof($a_set[$c]); $loop--) {
1195 $a_csv->addColumn("");
1196 $a_csv->addColumn("");
1197 $a_csv->addColumn("");
1198 }
1199 }
1200 }
1201 }
1202
1203 $a_csv->addRow();
1204 }
1205}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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 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, ?ilObjUser $user=null,)
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
@classDescription Date and time handling
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.
getColumnCoord(int $a_col)
Get column "name" from number.
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
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.
getCurrentFilter(bool $as_query=false)
isPercentageAvailable(int $a_obj_id)
parseTitle(int $a_obj_id, string $action, int $a_user_id=0)
searchObjects(array $filter, string $permission, ?array $preset_obj_ids=null, bool $a_check_lp_activation=true)
Search objects that match current filters.
static checkPermission(string $a_permission, int $a_ref_id, ?int $a_user_id=null)
wrapper for rbac access checks
static isObjectOffline(int $a_obj_id, string $a_type='')
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
Base class for object lp connectors.
static supportsSpentSeconds(string $obj_type)
static supportsMark(string $obj_type)
static getInstance(int $obj_id)
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setExportFormats(array $formats)
Set available export formats.
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)
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)
const FILTER_DURATION_RANGE
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
const FILTER_NUMBER_RANGE
const FILTER_DATETIME_RANGE
setMaxCount(int $a_max_count)
set max.
static getObjectsSummaryForObject(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, ?array $a_preselected_obj_ids=null)
Get all aggregated tracking data for parent object :TODO: sorting, offset, limit, objectives,...
getItemsPercentages( $data=null, int $overall=0, ?array $value_map=null, $limit=3)
Render data as needed for summary list (based on grouped values)
renderPercentages(string $id, array $data)
getItems(int $a_object_id, int $a_ref_id)
Build summary item rows for given object and filter(s.
getSelectableColumns()
Get selectable columns.
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
__construct(?object $a_parent_obj, string $a_parent_cmd, int $a_ref_id, bool $a_print_mode=false)
Constructor.
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.
fillHeaderExcel(ilExcel $a_excel, int &$a_row)
Excel Version of Fill Header.
fillHeaderCSV(ilCSVWriter $a_csv)
CSV Version of Fill Header.
getItemsPercentagesStatus( $data=null, int $overall=0, ?array $value_map=null)
Render status data as needed for summary list (based on grouped values)
parseValue(string $id, ?string $value, string $type)
fillRow(array $a_set)
Fill table row.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
const ROOT_FOLDER_ID
Definition: constants.php:32
$c
Definition: deliver.php:25
$valid
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$counter
$text
Definition: xapiexit.php:21