ILIAS  release_8 Revision v8.24
class.ilCourseLPBadgeGUI.php
Go to the documentation of this file.
1<?php
25{
26 protected int $parent_ref_id = 0;
27
28 protected ilTree $tree;
30 protected ilLanguage $lng;
31
32 public function __construct()
33 {
34 global $DIC;
35
36 $this->tree = $DIC->repositoryTree();
37 $this->ctrl = $DIC->ctrl();
38 $this->lng = $DIC->language();
39 $this->lng->loadLanguageModule('trac');
40 }
41
42 public function initConfigForm(ilPropertyFormGUI $a_form, int $a_parent_ref_id): void
43 {
44 $this->parent_ref_id = $a_parent_ref_id;
45
46 $subitems = new ilRepositorySelector2InputGUI($this->lng->txt("objects"), "subitems", true);
47
48 $exp = $subitems->getExplorerGUI();
49 $exp->setSkipRootNode(true);
50 $exp->setRootId($this->parent_ref_id);
51 $white = $this->getLPTypes($this->parent_ref_id);
52 $exp->setSelectableTypes($white);
53 if (!in_array("fold", $white)) {
54 $white[] = "fold";
55 }
56 $exp->setTypeWhiteList($white);
57 $subitems->setTitleModifier(function ($a_id): string {
58 $a_id = (int) $a_id;
59
60 $obj_id = ilObject::_lookupObjId($a_id);
61 $olp = ilObjectLP::getInstance($obj_id);
63 $mode = $olp->getModeText($olp->getCurrentMode());
64 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
65 $mode = "<strong>$mode</strong>";
66 }
67 return ilObject::_lookupTitle(ilObject::_lookupObjId($a_id)) . " (" . $mode . ")";
68 });
69
70 $subitems->setRequired(true);
71 $a_form->addItem($subitems);
72 }
73
74 protected function getLPTypes(int $a_parent_ref_id): array
75 {
76 $res = [];
77 $root = $this->tree->getNodeData($a_parent_ref_id);
78 $sub_items = $this->tree->getSubTree($root);
79 array_shift($sub_items); // remove root
80
81 foreach ($sub_items as $node) {
82 if (ilObjectLP::isSupportedObjectType($node["type"])) {
83 $class = ilObjectLP::getTypeClass($node["type"]);
85 $modes = $class::getDefaultModes(ilObjUserTracking::_enabledLearningProgress());
86 if (count($modes) > 1) {
87 $res[] = $node["type"];
88 }
89 }
90 }
91 return $res;
92 }
93
94 public function importConfigToForm(ilPropertyFormGUI $a_form, array $a_config): void
95 {
96 if (is_array($a_config["subitems"])) {
97 $items = $a_form->getItemByPostVar("subitems");
98 $items->setValue($a_config["subitems"]);
99 }
100 }
101
102 public function getConfigFromForm(ilPropertyFormGUI $a_form): array
103 {
104 return ["subitems" => $a_form->getInput("subitems")];
105 }
106
107 public static function getInvalidLPModes(): array
108 {
109
110 /* supported modes
111 LP_MODE_TLT
112 LP_MODE_OBJECTIVES
113 LP_MODE_TEST_FINISHED
114 LP_MODE_TEST_PASSED
115 LP_MODE_EXERCISE_RETURNED
116 LP_MODE_EVENT
117 LP_MODE_SCORM_PACKAGE
118 LP_MODE_PLUGIN
119 LP_MODE_QUESTIONS
120 LP_MODE_SURVEY_FINISHED
121 LP_MODE_VISITED_PAGES
122 LP_MODE_DOWNLOADED
123 LP_MODE_STUDY_PROGRAMME ?!
124 */
125
126 $invalid_modes = array(ilLPObjSettings::LP_MODE_DEACTIVATED,
128 );
129
130 // without active LP the following modes cannot be supported
132 // status cannot be set without active LP
133 $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
136
137 // mode cannot be configured without active LP
138 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
141 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
142 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
143 }
144 return $invalid_modes;
145 }
146
147 public function validateForm(ilPropertyFormGUI $a_form): bool
148 {
149 $invalid = array();
150 $invalid_modes = self::getInvalidLPModes();
151 foreach ($a_form->getInput("subitems") as $ref_id) {
152 $obj_id = ilObject::_lookupObjId((int) $ref_id);
153 $olp = ilObjectLP::getInstance($obj_id);
154 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
155 $invalid[] = ilObject::_lookupTitle($obj_id);
156 }
157 }
158 if ($invalid !== []) {
159 $mess = sprintf($this->lng->txt("badge_course_lp_invalid"), implode(", ", $invalid));
160 $a_form->getItemByPostVar("subitems")->setAlert($mess);
161 return false;
162 }
163 return true;
164 }
165}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getConfigFromForm(ilPropertyFormGUI $a_form)
Export values to DB.
importConfigToForm(ilPropertyFormGUI $a_form, array $a_config)
Set form values.
getLPTypes(int $a_parent_ref_id)
validateForm(ilPropertyFormGUI $a_form)
Custom form validation.
initConfigForm(ilPropertyFormGUI $a_form, int $a_parent_ref_id)
Add custom fields to form.
language handling
static isSupportedObjectType(string $type)
static getTypeClass(string $type)
static getInstance(int $obj_id)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
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...
global $DIC
Definition: feed.php:28
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...
$ref_id
Definition: ltiauth.php:67
$res
Definition: ltiservices.php:69