ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestLearningObjectivesStatusGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Factory as UIFactory;
22use ILIAS\UI\Renderer as UIRenderer;
24
32{
33 private ?int $crs_obj_id = null;
34 private ?int $usr_id = null;
35
36 public function __construct(
37 private ilLanguage $lng,
38 private ilCtrlInterface $ctrl,
39 private UIFactory $ui_factory,
40 private UIRenderer $ui_renderer,
41 private RequestDataCollector $testrequest
42 ) {
43 }
44
48 public function getCrsObjId(): ?int
49 {
50 return $this->crs_obj_id;
51 }
52
56 public function setCrsObjId($crs_obj_id)
57 {
58 $this->crs_obj_id = $crs_obj_id;
59 }
60
64 public function getUsrId(): ?int
65 {
66 return $this->usr_id;
67 }
68
72 public function setUsrId($usr_id)
73 {
74 $this->usr_id = $usr_id;
75 }
76
77 public function getHTML(?int $objective_id = null): string
78 {
79 $this->lng->loadLanguageModule('crs');
80
81 $items = $this->buildStatusItems(
82 $objective_id,
84 $this->getCrsObjId(),
85 $this->getUsrId()
86 )
87 );
88
89 $panel = $this->ui_factory->panel()->standard(
90 $this->lng->txt($this->getHeaderLangVar($objective_id)),
91 $items
92 );
93
94 return $this->ui_renderer->render($panel);
95 }
96
97 private function getHeaderLangVar(?int $objective_id): string
98 {
99 if ($objective_id !== null) {
100 return 'tst_objective_progress_header';
101 }
102
103 return 'tst_objectives_progress_header';
104 }
105
110 private function buildStatusItems(?int $objective_id, array $lo_status_data): array
111 {
112 $items = [];
113
114 foreach ($lo_status_data as $objtv) {
115 if ($objective_id !== null && $objtv['id'] !== $objective_id) {
116 continue;
117 }
118
119 $loc_settings = ilLOSettings::getInstanceByObjId($this->getCrsObjId());
120 $compare_value = null;
121 if ($objtv["type"] === ilLOUserResults::TYPE_QUALIFIED
122 && $loc_settings->getInitialTest() === 1
123 && isset($objtv['initial']['result_perc'])) {
124 $compare_value = $objtv['initial']['result_perc'];
125 }
126
127 $items[] = $this->ui_factory->item()->standard($objtv["title"])
128 ->withLeadIcon(
129 $this->ui_factory->symbol()->icon()->custom(
130 ilObject::_getIcon($objtv["id"], "small", "lobj"),
131 $this->lng->txt("crs_objectives")
132 )
133 )->withProgress(
134 $this->ui_factory->chart()->progressMeter()->standard(
135 100,
136 $objtv['result_perc'],
137 $objtv['limit_perc'],
138 $compare_value
139 )
140 );
141
142 // since ilContainerObjectiveGUI::buildObjectiveProgressBar() "sets an empty ref_id" for ilObjTestGUI,
143 // after creating links for different test refs, the "saved ref_id param" for ilObjTestGUI gets overwritten.
144 // (!) we need to set an explicit ref_id param for ilObjTestGUI again to keep the things running (!)
145 $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $this->testrequest->getRefId());
146 }
147
148 return $items;
149 }
150
152 {
154 $objective_items = $collection_of_objectives->getItems();
155
156 if ($objective_items === []) {
157 return [];
158 }
159
160 $lo_results = $this->getUsersObjectivesResults($crs_obj_id, $usr_id);
162
163 $res = [];
164 $tmp = [];
165 foreach ($objective_items as $objective_id) {
166 $title = ilCourseObjective::lookupObjectiveTitle($objective_id, true);
167
168 $tmp[$objective_id] = [
169 "id" => $objective_id,
170 "title" => $title["title"],
171 "desc" => $title["description"],
172 "itest" => $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL),
173 "qtest" => $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED)
174 ];
175
176 // patch optes end
177
178 if (array_key_exists($objective_id, $lo_results)) {
179 $lo_result = $lo_results[$objective_id];
180 $tmp[$objective_id]["user_id"] = $lo_result["user_id"];
181 $tmp[$objective_id]["result_perc"] = $lo_result["result_perc"];
182 $tmp[$objective_id]["limit_perc"] = $lo_result["limit_perc"];
183 $tmp[$objective_id]["status"] = $lo_result["status"];
184 $tmp[$objective_id]["type"] = $lo_result["type"];
185 $tmp[$objective_id]["initial"] = $lo_result["initial"] ?? null;
186 }
187 }
188
189 // order
190 foreach ($objective_items as $objtv_id) {
191 $res[] = $tmp[$objtv_id];
192 }
193
194 return $res;
195 }
196
197 private function getUsersObjectivesResults(int $crs_obj_id, int $usr_id): array
198 {
199 $res = [];
200 $initial_status = null;
202
203 foreach ($lur->getCourseResultsForUserPresentation() as $objective_id => $types) {
204 // show either initial or qualified for objective
205 if (isset($types[ilLOUserResults::TYPE_INITIAL])) {
206 $initial_status = $types[ilLOUserResults::TYPE_INITIAL]["status"];
207 }
208
209 // qualified test has priority
210 if (isset($types[ilLOUserResults::TYPE_QUALIFIED])) {
211 $result = $types[ilLOUserResults::TYPE_QUALIFIED];
212 $result["type"] = ilLOUserResults::TYPE_QUALIFIED;
213 $result["initial"] = $types[ilLOUserResults::TYPE_INITIAL] ?? null;
214 } else {
215 $result = $types[ilLOUserResults::TYPE_INITIAL];
216 $result["type"] = ilLOUserResults::TYPE_INITIAL;
217 }
218
219 $result["initial_status"] = $initial_status;
220
221 $res[$objective_id] = $result;
222 }
223
224 return $res;
225 }
226}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static getInstanceByObjId(int $a_obj_id)
static getInstance(int $a_container_id)
language handling
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
buildStatusItems(?int $objective_id, array $lo_status_data)
__construct(private ilLanguage $lng, private ilCtrlInterface $ctrl, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private RequestDataCollector $testrequest)
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
global $lng
Definition: privfeed.php:31