ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Factory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Test\Results\Presentation\Settings as ResultPresentationSettings;
25use ILIAS\UI\Factory as UIFactory;
26use ILIAS\UI\Renderer as UIRenderer;
27
29{
30 /*
31 * @var array<int test_obj_id, \ilTestEvaluationData> $test_data
32 */
33 private array $test_data = [];
34 public function __construct(
35 protected \ilTestShuffler $shuffler,
36 protected UIFactory $ui_factory,
37 protected UIRenderer $ui_renderer
38 ) {
39 }
40
44 public function getAttemptIdsArrayFor(
45 \ilObjTest $test_obj,
46 int $active_id
47 ): array {
48 $eval = $this->retrieveResultData($test_obj);
49 return array_keys($eval->getParticipant($active_id)->getPasses());
50 }
51
52 public function getOverviewDataForTest(
53 \ilObjTest $test_obj
54 ): ?TestOverview {
55 $eval = $this->retrieveResultData($test_obj);
56 $found_participants = $eval->getParticipants();
57 if ($found_participants === []) {
58 return null;
59 }
60
61 $total_passed = 0;
62 $total_passed_reached = 0.0;
63 $total_passed_max = 0.0;
64 $total_passed_time = 0;
65 foreach ($found_participants as $userdata) {
66 if ($userdata->getMark()?->getPassed()) {
67 $total_passed++;
68 $total_passed_reached += $userdata->getReached();
69 $total_passed_max += $userdata->getMaxpoints();
70 $total_passed_time += $userdata->getTimeOnTask();
71 }
72 }
73
74 return new TestOverview(
75 $test_obj->getId(),
76 count($found_participants),
77 $eval->getTotalFinishedParticipants(),
78 $total_passed,
79 $test_obj->evalTotalStartedAverageTime($eval->getParticipantIds()),
80 $total_passed_time,
81 $eval->getStatistics()->rankMedian(),
82 $eval->getStatistics()->getEvaluationDataOfMedianUser()?->getMark()?->getShortName() ?? '',
83 $eval->getStatistics()->median(),
84 $total_passed === 0 ? 0 : $total_passed_reached / $total_passed
85 );
86 }
87
88 public function getAttemptOverviewFor(
89 ResultPresentationSettings $settings,
90 \ilObjTest $test_obj,
91 int $active_id,
92 ?int $attempt_id
93 ): ?AttemptOverview {
94 $eval = $this->retrieveResultData($test_obj);
95 $found_participants = $eval->getParticipants();
96 $participant_data = $eval->getParticipant($active_id);
97 if ($attempt_id === null) {
98 $attempt_id = $participant_data?->getScoredPass();
99 }
100 if ($found_participants === []
101 || $attempt_id === null) {
102 return null;
103 }
104
105 $attempt_data = $participant_data?->getPass($attempt_id);
106 if ($attempt_data === null) {
107 return null;
108 }
109
110 return new AttemptOverview(
111 $active_id,
112 $attempt_id,
113 $settings,
114 $attempt_data->getExamId(),
115 $attempt_data->getReachedPoints(),
116 $attempt_data->getMaxPoints(),
117 $attempt_data->getMark(),
118 $attempt_data->getAnsweredQuestionCount(),
119 $attempt_data->getQuestionCount(),
120 $attempt_data->getWorkingTime(),
121 $participant_data->getTimeOnTask(),
122 $attempt_data->getStartTime(),
123 $attempt_data->getLastAccessTime(),
124 $participant_data->getPassCount(),
125 $participant_data->getScoredPass(),
126 $eval->getStatistics()->rank($participant_data->getReached()),
127 $attempt_data->getStatusOfAttempt()
128 );
129 }
130
137 ResultPresentationSettings $settings,
138 \ilObjTest $test_obj,
139 array $participants
140 ): array {
141 return array_map(
142 function (Participant $v) use ($settings, $test_obj, $participants): Participant {
143 if ($v->getActiveId() === null) {
144 return $v;
145 }
146
147 $scored_attempt = $this->getAttemptOverviewFor(
148 $settings,
149 $test_obj,
150 $v->getActiveId(),
151 null
152 );
153
154 if ($scored_attempt !== null
155 && $scored_attempt->getStatusOfAttempt() === StatusOfAttempt::RUNNING
156 && $scored_attempt->getStartedDate() !== null) {
157 $v = $v->withRunningAttemptStart($scored_attempt->getStartedDate());
158 }
159
160 return $v->withAttemptOverviewInformation(
161 $scored_attempt
162 );
163 },
164 $participants
165 );
166 }
167
168 public function getAttemptResultsFor(
169 ResultPresentationSettings $settings,
170 \ilObjTest $test_obj,
171 int $active_id,
172 int $attempt_id,
173 bool $is_user_output
175 return $this->buildAttemptResults(
176 $settings,
177 $test_obj,
178 $active_id,
179 $attempt_id,
180 $is_user_output
181 );
182 }
183
184 private function buildAttemptResults(
185 ResultPresentationSettings $settings,
186 \ilObjTest $test_obj,
187 int $active_id,
188 int $attempt_id,
189 bool $is_user_output
191 $question_results = [];
192
193 $results = $test_obj->getTestResult(
194 $active_id,
195 $attempt_id,
196 false, //$ordered_sequence
197 $settings->getShowHiddenQuestions(),
198 $settings->getShowOptionalQuestions()
199 );
200
201 // params of getSolutionOutput
202 $graphical_output = false;
203 $result_output = false;
204 $show_question_only = $settings->getQuestionTextOnly();
205 $show_feedback = false; //general
206 $show_correct_solution = false;
207 $show_manual_scoring = false;
208 $show_question_text = true;
209 $show_inline_feedback = true;
210
211 foreach ($results as $idx => $qresult) {
212 if (!is_numeric($idx)) {
213 continue;
214 }
215
216 $qid = $qresult['qid'];
217 $type = $qresult['type'];
218 $title = $qresult['title'];
219 $question_score = $qresult['max'];
220 $usr_score = $qresult['reached'];
221 $workedthrough = (bool) $qresult['workedthrough'];
222 $answered = (bool) $qresult['answered'];
223
224 $question_gui = $test_obj->createQuestionGUI('', $qid);
225 $shuffle_trafo = $this->shuffler->getAnswerShuffleFor($qid, $active_id, $attempt_id);
226 $question = $question_gui->getObject();
227 $question->setShuffler($shuffle_trafo);
228 $question_gui->setObject($question);
229
230 $graphical_output = true;
231 $show_correct_solution = false;
232 $show_feedback = $settings->getShowFeedback();
233 $usr_solution = $question_gui->getSolutionOutput(
234 $active_id,
235 $attempt_id,
236 $graphical_output,
237 $result_output,
238 $show_question_only,
239 $show_feedback,
240 $show_correct_solution,
241 $show_manual_scoring,
242 $show_question_text,
243 $show_inline_feedback
244 );
245
246 if ($test_obj->getAutosave() &&
247 $type === 'assTextQuestion'
248 ) {
249 $usr_solution .= $question_gui->getAutoSavedSolutionOutput(
250 $active_id,
251 $attempt_id,
252 false,
253 false,
254 false,
255 false,
256 false,
257 false,
258 false,
259 true
260 );
261 }
262
263 $graphical_output = false;
264 $show_correct_solution = true;
265 $show_feedback = false;
266 $show_inline_feedback = false;
267 $best_solution = $question_gui->getSolutionOutput(
268 $active_id,
269 $attempt_id,
270 $graphical_output,
271 $result_output,
272 $show_question_only,
273 $show_feedback,
274 $show_correct_solution,
275 $show_manual_scoring,
276 $show_question_text,
277 $show_inline_feedback
278 );
279
280 if ($show_question_only) {
281 $usr_solution = $this->ui_renderer->render($this->ui_factory->legacy()->content('<div class="ilc_question_Standard">' . $usr_solution . '</div>'));
282 $best_solution = $this->ui_renderer->render($this->ui_factory->legacy()->content('<div class="ilc_question_Standard">' . $best_solution . '</div>'));
283 }
284
285 $feedback = $question_gui->getGenericFeedbackOutput($active_id, $attempt_id);
286
287 $recapitulation = null;
288 if ($is_user_output && $settings->getShowRecapitulation()) {
289 $recapitulation = $question_gui->getObject()->getSuggestedSolutionOutput();
290 }
291
292 $question_results[] = new QuestionResult(
293 $qid,
294 $type,
295 $title,
296 $question_score,
297 $usr_score,
298 $usr_solution,
299 $best_solution,
300 $feedback,
301 $workedthrough,
302 $answered,
303 $recapitulation,
304 $idx
305 );
306 }
307
308 return new AttemptSolutions(
309 $active_id,
310 $attempt_id,
311 $question_results
312 );
313 }
314
315 private function retrieveResultData(\ilObjTest $test_obj): \ilTestEvaluationData
316 {
317 if (!isset($this->test_data[$test_obj->getId()])) {
318 $this->test_data[$test_obj->getId()] = $test_obj->getCompleteEvaluationData();
319 }
320
321 return $this->test_data[$test_obj->getId()];
322 }
323}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(protected \ilTestShuffler $shuffler, protected UIFactory $ui_factory, protected UIRenderer $ui_renderer)
Definition: Factory.php:34
buildAttemptResults(ResultPresentationSettings $settings, \ilObjTest $test_obj, int $active_id, int $attempt_id, bool $is_user_output)
Definition: Factory.php:184
getAttemptIdsArrayFor(\ilObjTest $test_obj, int $active_id)
Definition: Factory.php:44
getAttemptOverviewFor(ResultPresentationSettings $settings, \ilObjTest $test_obj, int $active_id, ?int $attempt_id)
Definition: Factory.php:88
addAttemptOverviewInformationToParticipants(ResultPresentationSettings $settings, \ilObjTest $test_obj, array $participants)
Definition: Factory.php:136
retrieveResultData(\ilObjTest $test_obj)
Definition: Factory.php:315
getOverviewDataForTest(\ilObjTest $test_obj)
Definition: Factory.php:52
getAttemptResultsFor(ResultPresentationSettings $settings, \ilObjTest $test_obj, int $active_id, int $attempt_id, bool $is_user_output)
Definition: Factory.php:168
createQuestionGUI($question_type, $question_id=-1)
Creates a question GUI instance of a given question type.
getTestResult(int $active_id, ?int $attempt=null, bool $ordered_sequence=false, bool $consider_hidden_questions=true, bool $consider_optional_questions=true)
Calculates the results of a test for a given user and returns an array with all test results.
evalTotalStartedAverageTime(?array $active_ids_to_filter=null)
getCompleteEvaluationData($filterby='', $filtertext='')
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
Definition: Renderer.php:31
$results
if(!file_exists('../ilias.ini.php'))