ILIAS  release_8 Revision v8.24
class.ilLPTableBaseGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
21use ILIAS\Refinery\Factory as RefineryFactory;
22use ILIAS\HTTP\Services as HttpService;
23
31{
32 public const HIT_LIMIT = 5000;
33 protected RefineryFactory $refinery;
34 protected HttpService $http;
35
36 protected array $filter = [];
37 protected bool $anonymized = true;
43 protected ilTree $tree;
44 protected \ilGlobalTemplateInterface $main_tpl;
45
46 public function __construct(
47 ?object $a_parent_obj,
48 string $a_parent_cmd = "",
49 string $a_template_context = ""
50 ) {
51 global $DIC;
52 $this->main_tpl = $DIC->ui()->mainTemplate();
53
54 $this->objDefinition = $DIC['objDefinition'];
55 $this->ilObjDataCache = $DIC['ilObjDataCache'];
56 $this->tree = $DIC->repositoryTree();
57 $this->user = $DIC->user();
58 $this->setting = $DIC->settings();
59 $this->http = $DIC->http();
60 $this->refinery = $DIC->refinery();
61
62 $this->anonymized = !ilObjUserTracking::_enabledUserRelatedData();
63 if (!$this->anonymized && isset($this->obj_id) && $this->obj_id > 0) {
64 $olp = ilObjectLP::getInstance($this->obj_id);
65 $this->anonymized = $olp->isAnonymized();
66 }
67
68 /*
69 * BT 35453: parent constructor needs to be called after $this->anonymized
70 * is set, in order for getSelectableUserColumns to also properly return
71 * user defined fields (e.g. firstname, lastname, and other user data).
72 */
73 parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context);
74
75 // country names
76 $this->lng->loadLanguageModule("meta");
77 }
78
79 protected function initItemIdFromPost(): array
80 {
81 if ($this->http->wrapper()->post()->has('item_id')) {
82 return $this->http->wrapper()->post()->retrieve(
83 'item_id',
84 $this->refinery->kindlyTo()->listOf(
85 $this->refinery->kindlyTo()->int()
86 )
87 );
88 }
89 return [];
90 }
91
92 protected function initUidFromPost(): array
93 {
94 if ($this->http->wrapper()->post()->has('uid')) {
95 return $this->http->wrapper()->post()->retrieve(
96 'uid',
97 $this->refinery->kindlyTo()->listOf(
98 $this->refinery->kindlyTo()->int()
99 )
100 );
101 }
102 return [];
103 }
104
105 public function executeCommand(): bool
106 {
108 if (!$this->ctrl->getNextClass($this)) {
109 $to_hide = false;
110
111 switch ($this->ctrl->getCmd()) {
112 case "applyFilter":
113 $this->resetOffset();
114 $this->writeFilterToSession();
115 $this->storeProperty("offset", "0");
116 break;
117
118 case "resetFilter":
119 $this->resetOffset();
120 $this->resetFilter();
121 $this->storeProperty("offset", "0");
122 break;
123
124 case "hideSelected":
125 $to_hide = $this->initItemIdFromPost();
126 break;
127
128 case "hide":
129 $hide = 0;
130 if ($this->http->wrapper()->query()->has('hide')) {
131 $hide = $this->http->wrapper()->query()->retrieve(
132 'hide',
133 $this->refinery->kindlyTo()->int()
134 );
135 }
136 $to_hide = [$hide];
137 break;
138
139 case "mailselectedusers":
140 if (!$this->initUidFromPost()) {
141 $this->main_tpl->setOnScreenMessage(
142 'failure',
143 $this->lng->txt(
144 "no_checkbox"
145 ),
146 true
147 );
148 } else {
149 $this->sendMail(
150 $this->initUidFromPost(),
151 $this->parent_obj,
152 $this->parent_cmd
153 );
154 }
155 break;
156
157 case 'addToClipboard':
158 if (!$this->initUidFromPost()) {
159 $this->main_tpl->setOnScreenMessage(
160 'failure',
161 $this->lng->txt(
162 'no_checkbox'
163 ),
164 true
165 );
166 } else {
167 $this->addToClipboard();
168 }
169 break;
170
171 // page selector
172 default:
174 $this->storeNavParameter();
175 $this->storeProperty("offset", (string) $this->getOffset());
176 break;
177 }
178
179 if ($to_hide) {
180 $obj = $this->getFilterItemByPostVar("hide");
181 $value = array_unique(
182 array_merge((array) $obj->getValue(), $to_hide)
183 );
184 $obj->setValue($value);
185 $obj->writeToSession();
186 }
187
188 if ($this->requested_tmpl_create !== "") {
189 $this->ctrl->setParameter(
190 $this->parent_obj,
191 "tbltplcrt",
192 $this->requested_tmpl_create
193 );
194 }
195 if ($this->requested_tmpl_delete !== "") {
196 $this->ctrl->setParameter(
197 $this->parent_obj,
198 "tbltpldel",
199 $this->requested_tmpl_delete
200 );
201 }
202 $this->ctrl->redirect($this->parent_obj, $this->parent_cmd);
203 } else {
204 // e.g. repository selector
205 return parent::executeCommand();
206 }
207 return true;
208 }
209
213 protected function findReferencesForObjId(int $a_obj_id): array
214 {
215 $ref_ids = array_keys(ilObject::_getAllReferences($a_obj_id));
216 sort($ref_ids, SORT_NUMERIC);
217 return $ref_ids;
218 }
219
220
221
222 protected function sendMail(
223 array $a_user_ids,
224 $a_parent_obj,
225 string $a_parent_cmd
226 ): void {
227 // see ilObjCourseGUI::sendMailToSelectedUsersObject()
228
229 $rcps = array();
230 foreach ($a_user_ids as $usr_id) {
231 $rcps[] = ilObjUser::_lookupLogin($usr_id);
232 }
233
234 $template = array();
235 $sig = null;
236
237 $ref_id = 0;
238 if ($this->http->wrapper()->query()->has('ref_id')) {
239 $ref_id = $this->http->wrapper()->query()->retrieve(
240 'ref_id',
241 $this->refinery->kindlyTo()->int()
242 );
243 }
244 // repository-object-specific
245 if ($ref_id) {
246 $obj_lp = ilObjectLP::getInstance(
248 );
249 $tmpl_id = $obj_lp->getMailTemplateId();
250
251 if ($tmpl_id) {
252 $template = array(
253 ilMailFormCall::CONTEXT_KEY => $tmpl_id,
254 'ref_id' => $ref_id,
255 'ts' => time()
256 );
257 } else {
259 $sig = rawurlencode(base64_encode($sig));
260 }
261 }
262
265 $a_parent_obj,
266 $a_parent_cmd,
267 array(),
268 array(
269 'type' => 'new',
270 'rcp_to' => implode(',', $rcps),
271 'sig' => $sig
272 ),
273 $template
274 )
275 );
276 }
277
281 protected function searchObjects(
282 array $filter,
283 string $permission,
284 ?array $preset_obj_ids = null,
285 bool $a_check_lp_activation = true
286 ): array {
287 $query_parser = new ilQueryParser($filter["query"] ?? '');
288 $query_parser->setMinWordLength(0);
289 $query_parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
290 $query_parser->parse();
291 if (!$query_parser->validate()) {
292 ilLoggerFactory::getLogger('trac')->notice(
293 $query_parser->getMessage()
294 );
295 // echo $query_parser->getMessage();
296 return [];
297 }
298
299 if ($filter["type"] == "lres") {
300 $filter["type"] = array('lm', 'sahs', 'htlm');
301 } else {
302 $filter["type"] = array($filter["type"]);
303 }
304
305 $object_search = new ilLikeObjectSearch($query_parser);
306 $object_search->setFilter($filter["type"]);
307 if ($preset_obj_ids) {
308 $object_search->setIdFilter($preset_obj_ids);
309 }
310 $res = $object_search->performSearch();
311
312 if ($permission) {
313 $res->setRequiredPermission($permission);
314 }
315
316 $res->setMaxHits(self::HIT_LIMIT);
317
318 if ($a_check_lp_activation) {
319 $res->addObserver($this, "searchFilterListener");
320 }
321
322 if (!$this->filter["area"]) {
323 $res->filter(ROOT_FOLDER_ID, true);
324 } else {
325 $res->filter($this->filter["area"], true);
326 }
327
328 $objects = array();
329 foreach ($res->getResults() as $obj_data) {
330 $objects[$obj_data['obj_id']][] = $obj_data['ref_id'];
331 }
332 return $objects ?: array();
333 }
334
340 public function searchFilterListener(int $a_ref_id, array $a_data): bool
341 {
342 if (is_array($this->filter["hide"]) && in_array(
343 $a_data["obj_id"],
344 $this->filter["hide"]
345 )) {
346 return false;
347 }
348 $olp = ilObjectLP::getInstance($a_data["obj_id"]);
349 if (get_class(
350 $olp
351 ) != "ilObjectLP" && // #13654 - LP could be unsupported
352 !$olp->isActive()) {
353 return false;
354 }
355 return true;
356 }
357
358 protected function isForwardingToFormDispatcher(): bool
359 {
360 return false;
361 }
362
363 protected function initRepositoryFilter(array $filter): array
364 {
366 $this->lng->txt('trac_filter_area'),
367 'effective_from',
368 false,
369 ($this->isForwardingToFormDispatcher()) ? $this : null
370 );
371 $white_list = [];
372 foreach ($this->objDefinition->getAllRepositoryTypes() as $type) {
373 if ($this->objDefinition->isContainer($type)) {
374 $white_list[] = $type;
375 }
376 }
377 $repo->getExplorerGUI()->setTypeWhiteList($white_list);
378 $this->addFilterItem($repo);
379 $repo->readFromSession();
380 $filter['area'] = (int) $repo->getValue();
381 return $filter;
382 }
383
387 public function initBaseFilter(
388 bool $a_split_learning_resources = false,
389 bool $a_include_no_status_filter = true
390 ) {
391 $this->setDisableFilterHiding(true);
392
393 // object type selection
394 $si = new ilSelectInputGUI($this->lng->txt("obj_type"), "type");
395 $si->setOptions($this->getPossibleTypes($a_split_learning_resources));
396 $this->addFilterItem($si);
397 $si->readFromSession();
398 if (!$si->getValue()) {
399 $si->setValue("crs");
400 }
401 $this->filter["type"] = $si->getValue();
402
403 // hidden items
404 $msi = new ilMultiSelectInputGUI(
405 $this->lng->txt("trac_filter_hidden"),
406 "hide"
407 );
408 $this->addFilterItem($msi);
409 $msi->readFromSession();
410 $this->filter["hide"] = $msi->getValue();
411 if ($this->filter["hide"]) {
412 // create options from current value
413 $types = $this->getCurrentFilter(true);
414 $type = $types["type"];
415 $options = array();
416 if ($type == 'lres') {
417 $type = array('lm', 'sahs', 'htlm');
418 } else {
419 $type = array($type);
420 }
421 foreach ($this->filter["hide"] as $obj_id) {
422 if (in_array(
423 $this->ilObjDataCache->lookupType((int) $obj_id),
424 $type
425 )) {
426 $options[$obj_id] = $this->ilObjDataCache->lookupTitle(
427 (int) $obj_id
428 );
429 }
430 }
431 $msi->setOptions($options);
432 }
433
434 // title/description
435 $ti = new ilTextInputGUI(
436 $this->lng->txt("trac_title_description"),
437 "query"
438 );
439 $ti->setMaxLength(64);
440 $ti->setSize(20);
441 $this->addFilterItem($ti);
442 $ti->readFromSession();
443 $this->filter["query"] = $ti->getValue();
444
445 // repository area selection
447 $this->lng->txt("trac_filter_area"),
448 "area"
449 );
450 $rs->setSelectText($this->lng->txt("trac_select_area"));
451 $this->addFilterItem($rs);
452 $rs->readFromSession();
453 $this->filter["area"] = $rs->getValue();
454
455 // hide "not started yet"
456 if ($a_include_no_status_filter) {
457 $cb = new ilCheckboxInputGUI(
458 $this->lng->txt("trac_filter_has_status"),
459 "status"
460 );
461 $this->addFilterItem($cb);
462 $cb->readFromSession();
463 $this->filter["status"] = $cb->getChecked();
464 }
465 }
466
469 protected function buildPath(array $ref_ids): array
470 {
471 if (!count($ref_ids)) {
472 return [];
473 }
474 $result = [];
475 foreach ($ref_ids as $ref_id) {
476 $path = "...";
477 $counter = 0;
478 $path_full = $this->tree->getPathFull($ref_id);
479 foreach ($path_full as $data) {
480 if (++$counter < (count($path_full) - 1)) {
481 continue;
482 }
483 $path .= " &raquo; ";
484 if ($ref_id != $data['ref_id']) {
485 $path .= $data['title'];
486 } else {
487 $path .= ('<a target="_top" href="' .
489 $data['ref_id'],
490 $data['type']
491 ) . '">' .
492 $data['title'] . '</a>');
493 }
494 }
495
496 $result[$ref_id] = $path;
497 }
498 return $result;
499 }
500
501 protected function getPossibleTypes(
502 bool $a_split_learning_resources = false,
503 bool $a_include_digilib = false,
504 bool $a_allow_undefined_lp = false
505 ): array {
506 global $DIC;
507
508 $component_repository = $DIC['component.repository'];
509
510 $options = array();
511
512 if ($a_split_learning_resources) {
513 $options['lm'] = $this->lng->txt('objs_lm');
514 $options['sahs'] = $this->lng->txt('objs_sahs');
515 $options['htlm'] = $this->lng->txt('objs_htlm');
516 } else {
517 $options['lres'] = $this->lng->txt('obj_lrss');
518 }
519
520 $options['crs'] = $this->lng->txt('objs_crs');
521 $options['grp'] = $this->lng->txt('objs_grp');
522 $options['exc'] = $this->lng->txt('objs_exc');
523 $options['file'] = $this->lng->txt('objs_file');
524 $options['mcst'] = $this->lng->txt('objs_mcst');
525 $options['svy'] = $this->lng->txt('objs_svy');
526 $options['tst'] = $this->lng->txt('objs_tst');
527 $options['prg'] = $this->lng->txt('objs_prg');
528 $options['iass'] = $this->lng->txt('objs_iass');
529 $options['copa'] = $this->lng->txt('objs_copa');
530 $options['frm'] = $this->lng->txt('objs_frm');
531 $options['cmix'] = $this->lng->txt('objs_cmix');
532 $options['lti'] = $this->lng->txt('objs_lti');
533 $options['lso'] = $this->lng->txt('objs_lso');
534
535 if ($a_allow_undefined_lp) {
536 $options['root'] = $this->lng->txt('obj_reps');
537 $options['cat'] = $this->lng->txt('objs_cat');
538 $options["webr"] = $this->lng->txt("objs_webr");
539 $options["wiki"] = $this->lng->txt("objs_wiki");
540 $options["blog"] = $this->lng->txt("objs_blog");
541 $options["prtf"] = $this->lng->txt("objs_prtf");
542 $options["prtt"] = $this->lng->txt("objs_prtt");
543 }
544
545 // repository plugins (currently only active)
546 $plugins = $component_repository->getPluginSlotById(
547 "robj"
548 )->getActivePlugins();
549 foreach ($plugins as $pl) {
550 $pl_id = $pl->getId();
552 $options[$pl_id] = ilObjectPlugin::lookupTxtById(
553 $pl_id,
554 "objs_" . $pl_id
555 );
556 }
557 }
558
559 asort($options);
560 return $options;
561 }
562
563 protected function parseValue(
564 string $id,
565 ?string $value,
566 string $type
567 ): string {
568 // get rid of aggregation
569 $pos = strrpos($id, "_");
570 if ($pos !== false) {
571 $function = strtoupper(substr($id, $pos + 1));
572 if (in_array(
573 $function,
574 array("MIN", "MAX", "SUM", "AVG", "COUNT")
575 )) {
576 $id = substr($id, 0, $pos);
577 }
578 }
579
580 if (trim($value) == "" && $id != "status") {
581 if ($id == "title" &&
582 get_class($this) != "ilTrObjectUsersPropsTableGUI" &&
583 get_class($this) != "ilTrMatrixTableGUI") {
584 return "--" . $this->lng->txt("none") . "--";
585 }
586 return " ";
587 }
588
589 switch ($id) {
590 case "first_access":
591 case "create_date":
592 case 'status_changed':
594 new ilDateTime($value, IL_CAL_DATETIME)
595 );
596 break;
597
598 case "last_access":
600 new ilDateTime($value, IL_CAL_UNIX)
601 );
602 break;
603
604 case "birthday":
606 new ilDate($value, IL_CAL_DATE)
607 );
608 break;
609
610 case "spent_seconds":
612 $value = "-";
613 } else {
615 $value,
616 ($value < 3600 ? true : false)
617 ); // #14858
618 }
619 break;
620
621 case "percentage":
622 if (false /* $this->isPercentageAvailable() */) {
623 $value = "-";
624 } else {
625 $value = $value . "%";
626 }
627 break;
628
629 case "mark":
631 $value = "-";
632 }
633 break;
634
635 case "gender":
636 $value = $this->lng->txt("gender_" . $value);
637 break;
638
639 case "status":
640 $icons = ilLPStatusIcons::getInstance($this->getIconVariant());
641 $value = $icons->renderIconForStatus((int) $value);
642 break;
643
644 case "language":
645 $this->lng->loadLanguageModule("meta");
646 $value = $this->lng->txt("meta_l_" . $value);
647 break;
648
649 case "sel_country":
650 $value = $this->lng->txt("meta_c_" . $value);
651 break;
652 }
653
654 return $value;
655 }
656
657 public function getCurrentFilter(bool $as_query = false): array
658 {
659 $result = array();
660 foreach ($this->filter as $id => $value) {
661 $item = $this->getFilterItemByPostVar($id);
662 switch ($id) {
663 case "title":
664 case "country":
665 case "gender":
666 case "city":
667 case "language":
668 case "login":
669 case "firstname":
670 case "lastname":
671 case "mark":
672 case "u_comment":
673 case "institution":
674 case "department":
675 case "street":
676 case "zipcode":
677 case "email":
678 case "matriculation":
679 case "sel_country":
680 case "query":
681 case "type":
682 case "area":
683 if ($value) {
684 $result[$id] = $value;
685 }
686 break;
687
688 case "status":
689 if (!is_null($value) && $value !== "") {
690 $result[$id] = $value;
691 }
692 break;
693
694 case "user_total":
695 case "read_count":
696 case "percentage":
697 case "hide":
698 case "spent_seconds":
699 if (is_array($value) && implode("", $value)) {
700 $result[$id] = $value;
701 }
702 break;
703
704 case "registration":
705 case "create_date":
706 case "first_access":
707 case "last_access":
708 case 'status_changed':
709 if ($value) {
710 if ($value["from"]) {
711 $result[$id]["from"] = $value["from"]->get(
713 );
714 }
715 if ($value["to"]) {
716 $result[$id]["to"] = $value["to"]->get(
718 );
719 }
720 }
721 break;
722
723 case "birthday":
724 if ($value) {
725 if ($value["from"]) {
726 $result[$id]["from"] = $value["from"]->get(
728 );
729 $result[$id]["from"] = substr(
730 $result[$id]["from"],
731 0,
732 -8
733 ) . "00:00:00";
734 }
735 if ($value["to"]) {
736 $result[$id]["to"] = $value["to"]->get(
738 );
739 $result[$id]["to"] = substr(
740 $result[$id]["to"],
741 0,
742 -8
743 ) . "23:59:59";
744 }
745 }
746 break;
747 }
748 }
749 return $result;
750 }
751
752 protected function isPercentageAvailable(int $a_obj_id): bool
753 {
754 if ($a_obj_id === 0) {
755 return false;
756 }
757 $olp = ilObjectLP::getInstance($a_obj_id);
758 $mode = $olp->getCurrentMode();
759 if (in_array(
760 $mode,
773 )
774 )) {
775 return true;
776 }
777 return false;
778 }
779
780 protected function parseTitle(
781 int $a_obj_id,
782 string $action,
783 int $a_user_id = 0
784 ) {
785 global $DIC;
786
787 $user = "";
788 if ($a_user_id) {
789 if ($a_user_id != $this->user->getId()) {
790 $a_user = ilObjectFactory::getInstanceByObjId($a_user_id);
791 } else {
792 $a_user = $this->user;
793 }
794 $user .= ", " . $a_user->getFullName(
795 ); // " [".$a_user->getLogin()."]";
796 }
797
798 if ($a_obj_id != ROOT_FOLDER_ID) {
799 $this->setTitle(
800 $this->lng->txt(
801 $action
802 ) . ": " . $this->ilObjDataCache->lookupTitle($a_obj_id) . $user
803 );
804
805 $olp = ilObjectLP::getInstance($a_obj_id);
806 $this->setDescription(
807 $this->lng->txt('trac_mode') . ": " . $olp->getModeText(
808 $olp->getCurrentMode()
809 )
810 );
811 } else {
812 $this->setTitle($this->lng->txt($action));
813 }
814 }
815
819 protected function getExportMeta(): array
820 {
821 global $DIC;
822
823 $ilClientIniFile = $DIC['ilClientIniFile'];
824
825 /* see spec
826 Name of installation
827 Name of the course
828 Permalink to course
829 Owner of course object
830 Date of report generation
831 Reporting period
832 Name of person who generated the report.
833 */
834
836
837 $data = array();
838 $data[$this->lng->txt(
839 "trac_name_of_installation"
840 )] = $ilClientIniFile->readVariable('client', 'name');
841
842 if ($this->obj_id) {
843 $data[$this->lng->txt(
844 "trac_object_name"
845 )] = $this->ilObjDataCache->lookupTitle((int) $this->obj_id);
846 if ($this->ref_id) {
847 $data[$this->lng->txt("trac_object_link")] = ilLink::_getLink(
848 $this->ref_id,
849 ilObject::_lookupType($this->obj_id)
850 );
851 }
852 $data[$this->lng->txt(
853 "trac_object_owner"
855 ilObject::_lookupOwner($this->obj_id)
856 );
857 }
858
859 $data[$this->lng->txt(
860 "trac_report_date"
862 new ilDateTime(
863 time(),
865 )
866 );
867 $data[$this->lng->txt("trac_report_owner")] = $this->user->getFullName(
868 );
869
870 return $data;
871 }
872
873 protected function fillMetaExcel(ilExcel $a_excel, int &$a_row): void
874 {
875 foreach ($this->getExportMeta() as $caption => $value) {
876 $a_excel->setCell($a_row, 0, $caption);
877 $a_excel->setCell($a_row, 1, $value);
878 $a_row++;
879 }
880 $a_row++;
881 }
882
883 protected function fillMetaCSV(ilCSVWriter $a_csv): void
884 {
885 foreach ($this->getExportMeta() as $caption => $value) {
886 $a_csv->addColumn(strip_tags($caption));
887 $a_csv->addColumn(strip_tags($value));
888 $a_csv->addRow();
889 }
890 $a_csv->addRow();
891 }
892
898 protected function showTimingsWarning(int $a_ref_id, int $a_user_id)
899 {
900 $timing_cache = ilTimingCache::getInstanceByRefId($a_ref_id);
901 if ($timing_cache->isWarningRequired($a_user_id)) {
902 $timings = ilTimingCache::_getTimings($a_ref_id);
903 if (
904 $timings['item']['changeable'] &&
905 ($timings['user'][$a_user_id] ?? false) &&
906 $timings['user'][$a_user_id]['end']
907 ) {
908 $end = $timings['user'][$a_user_id]['end'];
909 } elseif ($timings['item']['suggestion_end']) {
910 $end = $timings['item']['suggestion_end'];
911 } else {
912 $end = true;
913 }
914 return $end;
915 }
916 return false;
917 }
918
919 protected function formatSeconds(
920 int $seconds,
921 bool $a_shorten_zero = false
922 ): string {
923 $seconds = ($seconds > 0) ? $seconds : 0;
924 if ($a_shorten_zero && !$seconds) {
925 return "-";
926 }
927
928 $hours = floor($seconds / 3600);
929 $rest = $seconds % 3600;
930
931 $minutes = floor($rest / 60);
932 $rest = $rest % 60;
933
934 if ($rest) {
935 $minutes++;
936 }
937
938 return sprintf("%dh%02dm", $hours, $minutes);
939 }
940
946 protected function anonymizeValue($a_value, bool $a_force_number = false)
947 {
948 // currently inactive
949 return $a_value;
950 }
951
952 protected function buildValueScale(
953 int $a_max_value,
954 bool $a_anonymize = false,
955 bool $a_format_seconds = false
956 ): array {
957 $step = 0;
958 if ($a_max_value) {
959 $step = $a_max_value / 10;
960 $base = ceil(log($step, 10));
961 $fac = ceil($step / pow(10, ($base - 1)));
962 $step = pow(10, $base - 1) * $fac;
963 }
964 if ($step <= 1) {
965 $step = 1;
966 }
967 $ticks = range(0, $a_max_value + $step, $step);
968
969 $value_ticks = array(0 => 0);
970 foreach ($ticks as $tick) {
971 $value = $tvalue = $tick;
972 if ($a_anonymize) {
973 $value = $this->anonymizeValue($value, true);
974 $tvalue = $this->anonymizeValue($tvalue);
975 }
976 if ($a_format_seconds) {
977 $tvalue = $this->formatSeconds($value);
978 }
979 $value_ticks[$value] = $tvalue;
980 }
981
982 return $value_ticks;
983 }
984
985 protected function getMonthsFilter($a_short = false): array
986 {
987 $options = array();
988 for ($loop = 0; $loop < 10; $loop++) {
989 $year = date("Y") - $loop;
990 $options[$year] = $year;
991 for ($loop2 = 12; $loop2 > 0; $loop2--) {
992 $month = str_pad($loop2, 2, "0", STR_PAD_LEFT);
993 if ($year . $month <= date("Ym")) {
994 if (!$a_short) {
995 $caption = $year . " / " . $this->lng->txt(
996 "month_" . $month . "_long"
997 );
998 } else {
999 $caption = $year . "/" . $month;
1000 }
1001 $options[$year . "-" . $month] = $caption;
1002 }
1003 }
1004 }
1005 return $options;
1006 }
1007
1008 protected function getMonthsYear($a_year = null, $a_short = false): array
1009 {
1010 if (!$a_year) {
1011 $a_year = date("Y");
1012 }
1013
1014 $all = array();
1015 for ($loop = 1; $loop < 13; $loop++) {
1016 $month = str_pad($loop, 2, "0", STR_PAD_LEFT);
1017 if ($a_year . "-" . $month <= date("Y-m")) {
1018 if (!$a_short) {
1019 $caption = $this->lng->txt("month_" . $month . "_long");
1020 } else {
1021 $caption = $this->lng->txt("month_" . $month . "_short");
1022 }
1023 $all[$a_year . "-" . $month] = $caption;
1024 }
1025 }
1026 return $all;
1027 }
1028
1029 protected function getSelectableUserColumns(
1030 int $a_in_course = 0,
1031 int $a_in_group = 0
1032 ): array {
1033 $cols = $privacy_fields = array();
1034
1035 $up = new ilUserProfile();
1036 $up->skipGroup("preferences");
1037 $up->skipGroup("settings");
1038 $up->skipGroup("interests");
1039 $ufs = $up->getStandardFields();
1040
1041 // default fields
1042 $cols["login"] = array(
1043 "txt" => $this->lng->txt("login"),
1044 "default" => true
1045 );
1046
1047 if (!$this->anonymized) {
1048 $cols["firstname"] = array(
1049 "txt" => $this->lng->txt("firstname"),
1050 "default" => true
1051 );
1052 $cols["lastname"] = array(
1053 "txt" => $this->lng->txt("lastname"),
1054 "default" => true
1055 );
1056 }
1057
1058 // show only if extended data was activated in lp settings
1059 $tracking = new ilObjUserTracking();
1060 if ($tracking->hasExtendedData(
1062 )) {
1063 $cols["first_access"] = array(
1064 "txt" => $this->lng->txt("trac_first_access"),
1065 "default" => true
1066 );
1067 $cols["last_access"] = array(
1068 "txt" => $this->lng->txt("trac_last_access"),
1069 "default" => true
1070 );
1071 }
1072 if ($tracking->hasExtendedData(
1074 )) {
1075 $cols["read_count"] = array(
1076 "txt" => $this->lng->txt("trac_read_count"),
1077 "default" => true
1078 );
1079 }
1080 if ($tracking->hasExtendedData(
1082 ) &&
1083 ilObjectLP::supportsSpentSeconds($this->type)) {
1084 $cols["spent_seconds"] = array(
1085 "txt" => $this->lng->txt("trac_spent_seconds"),
1086 "default" => true
1087 );
1088 }
1089
1090 if ($this->isPercentageAvailable($this->obj_id)) {
1091 $cols["percentage"] = array(
1092 "txt" => $this->lng->txt("trac_percentage"),
1093 "default" => true
1094 );
1095 }
1096
1097 // do not show status if learning progress is deactivated
1098 $olp = ilObjectLP::getInstance($this->obj_id);
1099 if ($olp->isActive()) {
1100 $cols["status"] = array(
1101 "txt" => $this->lng->txt("trac_status"),
1102 "default" => true
1103 );
1104
1105 $cols['status_changed'] = array(
1106 'txt' => $this->lng->txt('trac_status_changed'),
1107 'default' => false
1108 );
1109 }
1110
1111 if (ilObjectLP::supportsMark($this->type)) {
1112 $cols["mark"] = array(
1113 "txt" => $this->lng->txt("trac_mark"),
1114 "default" => true
1115 );
1116 }
1117
1118 $cols["u_comment"] = array(
1119 "txt" => $this->lng->txt("trac_comment"),
1120 "default" => false
1121 );
1122
1123 $cols["create_date"] = array(
1124 "txt" => $this->lng->txt("create_date"),
1125 "default" => false
1126 );
1127 $cols["language"] = array(
1128 "txt" => $this->lng->txt("language"),
1129 "default" => false
1130 );
1131
1132 // add user data only if object is [part of] course
1133 if (!$this->anonymized &&
1134 ($a_in_course || $a_in_group)) {
1135 // only show if export permission is granted
1136 if (ilPrivacySettings::getInstance()->checkExportAccess(
1137 $a_in_group === 0 ? $a_in_course : $a_in_group
1138 )) {
1139 // other user profile fields
1140 foreach ($ufs as $f => $fd) {
1141 if (!isset($cols[$f]) && $f != "username" && !($fd["lists_hide"] ?? false)) {
1142 if ($a_in_course &&
1143 !(($fd["course_export_fix_value"] ?? false) || $this->setting->get(
1144 "usr_settings_course_export_" . $f
1145 ))) {
1146 continue;
1147 }
1148 if ($a_in_group &&
1149 !(($fd["group_export_fix_value"] ?? false) || $this->setting->get(
1150 "usr_settings_group_export_" . $f
1151 ))) {
1152 continue;
1153 }
1154
1155 $cols[$f] = array(
1156 "txt" => $this->lng->txt($f),
1157 "default" => false
1158 );
1159 $privacy_fields[] = $f;
1160 }
1161 }
1162
1163 // additional defined user data fields
1164 $user_defined_fields = ilUserDefinedFields::_getInstance();
1165 if ($a_in_course) {
1166 $user_defined_fields = $user_defined_fields->getCourseExportableFields(
1167 );
1168 } else {
1169 $user_defined_fields = $user_defined_fields->getGroupExportableFields(
1170 );
1171 }
1172 foreach ($user_defined_fields as $definition) {
1173 if ($definition["field_type"] != UDF_TYPE_WYSIWYG) {
1174 $f = "udf_" . $definition["field_id"];
1175 $cols[$f] = array(
1176 "txt" => $definition["field_name"],
1177 "default" => false
1178 );
1179
1180 $privacy_fields[] = $f;
1181 }
1182 }
1183 }
1184 }
1185 return array($cols, $privacy_fields);
1186 }
1187
1191 protected function addToClipboard(): void
1192 {
1193 $users = $this->initUidFromPost();
1194 $clip = ilUserClipboard::getInstance($this->user->getId());
1195 $clip->add($users);
1196 $clip->save();
1197 $this->lng->loadLanguageModule('user');
1198 $this->main_tpl->setOnScreenMessage(
1199 'success',
1200 $this->lng->txt(
1201 'clipboard_user_added'
1202 ),
1203 true
1204 );
1205 }
1206
1210 public function getIconVariant(): int
1211 {
1212 return $this->icon_variant;
1213 }
1214
1218 public function setIconVariant(int $variant): void
1219 {
1220 $this->icon_variant = $variant;
1221 }
1222}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const UDF_TYPE_WYSIWYG
addColumn(string $a_col)
This class represents a checkbox property in a property form.
static setUseRelativeDates(bool $a_status)
set use relative dates
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
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.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
const LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
TableGUI class for learning progress.
ilObjectDefinition $objDefinition
fillMetaExcel(ilExcel $a_excel, int &$a_row)
Add meta information to excel export.
sendMail(array $a_user_ids, $a_parent_obj, string $a_parent_cmd)
setIconVariant(int $variant)
Sets the variant of LP icons that is shown in the table.
addToClipboard()
Add selected users to clipboard.
fillMetaCSV(ilCSVWriter $a_csv)
Add meta information to csv export.
showTimingsWarning(int $a_ref_id, int $a_user_id)
ilObjectDataCache $ilObjDataCache
RefineryFactory $refinery
formatSeconds(int $seconds, bool $a_shorten_zero=false)
getMonthsYear($a_year=null, $a_short=false)
anonymizeValue($a_value, bool $a_force_number=false)
searchFilterListener(int $a_ref_id, array $a_data)
Listener for SearchResultFilter Checks wheather the object is hidden and mode is not LP_MODE_DEACTIVA...
initRepositoryFilter(array $filter)
getPossibleTypes(bool $a_split_learning_resources=false, bool $a_include_digilib=false, bool $a_allow_undefined_lp=false)
getIconVariant()
Gets the variant of LP icons that is shown in the table.
findReferencesForObjId(int $a_obj_id)
getCurrentFilter(bool $as_query=false)
getMonthsFilter($a_short=false)
getExportMeta()
Build export meta data.
parseValue(string $id, ?string $value, string $type)
buildValueScale(int $a_max_value, bool $a_anonymize=false, bool $a_format_seconds=false)
initBaseFilter(bool $a_split_learning_resources=false, bool $a_include_no_status_filter=true)
Init filter.
__construct(?object $a_parent_obj, string $a_parent_cmd="", string $a_template_context="")
isPercentageAvailable(int $a_obj_id)
parseTitle(int $a_obj_id, string $action, int $a_user_id=0)
ilGlobalTemplateInterface $main_tpl
getSelectableUserColumns(int $a_in_course=0, int $a_in_group=0)
searchObjects(array $filter, string $permission, ?array $preset_obj_ids=null, bool $a_check_lp_activation=true)
Search objects that match current filters.
static getLogger(string $a_component_id)
Get component logger.
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupFullname(int $a_user_id)
static _lookupLogin(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parses the objects.xml it handles the xml-description of all ilias objects
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static supportsSpentSeconds(string $obj_type)
static supportsMark(string $obj_type)
static getInstance(int $obj_id)
static lookupTxtById(string $plugin_id, string $lang_var)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _lookupOwner(int $obj_id)
Lookup owner user ID for object ID.
static _getAllReferences(int $id)
get all reference ids for object ID
setMinWordLength(int $a_length)
static isTypePluginWithLP(string $a_type, bool $a_active_status=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFilterItemByPostVar(string $a_post_var)
determineOffsetAndOrder(bool $a_omit_offset=false)
resetOffset(bool $a_in_determination=false)
storeProperty(string $type, string $value)
This class represents a text property in a property form.
static getInstanceByRefId(int $ref_id)
static _getTimings(int $a_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $a_usr_id)
Class ilUserProfile.
static redirect(string $a_script)
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
$rest
Definition: goto.php:49
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$base
Definition: index.php:4
$type
$cols
Definition: xhr_table.php:11