ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestService.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
33{
38 public function __construct(
39 protected ilObjTest $object,
40 protected ilDBInterface $db,
41 protected GeneralQuestionPropertiesRepository $questionrepository
42 ) {
43 }
44
45 public function getPassOverviewData(int $active_id, bool $short = false): array
46 {
47 $passOverwiewData = [];
48
49 $scoredPass = $this->object->_getResultPass($active_id);
50 $lastPass = ilObjTest::_getPass($active_id);
51
52 $testPercentage = 0;
53 $testReachedPoints = 0;
54 $testMaxPoints = 0;
55
56 for ($pass = 0; $pass <= $lastPass; $pass++) {
57 $passFinishDate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
58
59 if ($passFinishDate <= 0) {
60 continue;
61 }
62
63 if (!$short) {
64 $result_data = $this->object->getTestResult($active_id, $pass);
65
66 if (!$result_data["pass"]["total_max_points"]) {
67 $passPercentage = 0;
68 } else {
69 $passPercentage = ($result_data["pass"]["total_reached_points"] / $result_data["pass"]["total_max_points"]) * 100;
70 }
71
72 $passMaxPoints = $result_data["pass"]["total_max_points"];
73 $passReachedPoints = $result_data["pass"]["total_reached_points"];
74
75 $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass);
76 $passTotalQuestions = count($result_data) - 2;
77
78 if ($pass == $scoredPass) {
79 $isScoredPass = true;
80
81 if (!$result_data["test"]["total_max_points"]) {
82 $testPercentage = 0;
83 } else {
84 $testPercentage = ($result_data["test"]["total_reached_points"] / $result_data["test"]["total_max_points"]) * 100;
85 }
86
87 $testMaxPoints = $result_data["test"]["total_max_points"];
88 $testReachedPoints = $result_data["test"]["total_reached_points"];
89
90 $passOverwiewData['test'] = [
91 'active_id' => $active_id,
92 'scored_pass' => $scoredPass,
93 'max_points' => $testMaxPoints,
94 'reached_points' => $testReachedPoints,
95 'percentage' => $testPercentage
96 ];
97 } else {
98 $isScoredPass = false;
99 }
100
101 $passOverwiewData['passes'][] = [
102 'active_id' => $active_id,
103 'pass' => $pass,
104 'finishdate' => $passFinishDate,
105 'max_points' => $passMaxPoints,
106 'reached_points' => $passReachedPoints,
107 'percentage' => $passPercentage,
108 'answered_questions' => $passAnsweredQuestions,
109 'total_questions' => $passTotalQuestions,
110 'is_scored_pass' => $isScoredPass
111 ];
112 }
113 }
114
115 return $passOverwiewData;
116 }
117
118 public static function isManScoringDone(int $active_id): bool
119 {
120 return (new TestManScoringDoneHelper())->isDone($active_id);
121 }
122
123 public static function setManScoringDone(int $activeId, bool $manScoringDone): void
124 {
125 (new TestManScoringDoneHelper())->setDone($activeId, $manScoringDone);
126 }
127
129 {
130 $test_sequence_factory = new ilTestSequenceFactory($this->object, $this->db, $this->questionrepository);
131
132 if ($this->object->isRandomTest()) {
133 $virtual_sequence = new ilTestVirtualSequenceRandomQuestionSet($this->db, $this->object, $test_sequence_factory);
134 } else {
135 $virtual_sequence = new ilTestVirtualSequence($this->db, $this->object, $test_sequence_factory);
136 }
137
138 $virtual_sequence->setActiveId($testSession->getActiveId());
139
140 $virtual_sequence->init();
141
142 return $virtual_sequence;
143 }
144
145 public function getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence): array
146 {
147 $resultsByPass = [];
148
149 foreach ($virtualSequence->getUniquePasses() as $pass) {
150 $results = $this->object->getTestResult(
151 $virtualSequence->getActiveId(),
152 $pass,
153 false,
154 true,
155 true
156 );
157
158 $resultsByPass[$pass] = $results;
159 }
160
161 $virtualPassResults = [];
162
163 foreach ($virtualSequence->getQuestionsPassMap() as $questionId => $pass) {
164 foreach ($resultsByPass[$pass] as $key => $questionResult) {
165 if ($key === 'test' || $key === 'pass') {
166 continue;
167 }
168
169 if ($questionResult['qid'] == $questionId) {
170 $questionResult['pass'] = $pass;
171 $virtualPassResults[$questionId] = $questionResult;
172 break;
173 }
174 }
175 }
176
177 return $virtualPassResults;
178 }
179
180 public function getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence): array
181 {
182 $result_array = $testSequence->getSequenceSummary();
183
184 $marked_questions = [];
185
186 if ($this->object->getShowMarker()) {
187 $marked_questions = ilObjTest::_getSolvedQuestions($testSequence->getActiveId());
188 }
189
190 $data = [];
191 $firstQuestion = true;
192
193 foreach ($result_array as $key => $value) {
194 $disableLink = (
195 $this->object->isFollowupQuestionAnswerFixationEnabled()
196 && !$value['presented'] && !$firstQuestion
197 );
198
199 $description = "";
200 if ($this->object->getListOfQuestionsDescription()) {
201 $description = $value["description"];
202 }
203
204 $points = "";
205 if (!$this->object->getTitleOutput()) {
206 $points = $value["points"];
207 }
208
209 $marked = false;
210 if (count($marked_questions)) {
211 if (array_key_exists($value["qid"], $marked_questions)) {
212 $obj = $marked_questions[$value["qid"]];
213 if ($obj["solved"] == 1) {
214 $marked = true;
215 }
216 }
217 }
218
219 $data[] = [
220 'order' => $value['nr'],
221 'title' => $this->object->getQuestionTitle($value['title'], $value['nr'], $value['points']),
222 'description' => $description,
223 'disabled' => $disableLink,
224 'worked_through' => $value['worked_through'],
225 'postponed' => $value['postponed'],
226 'points' => $points,
227 'marked' => $marked,
228 'sequence' => $value['sequence'],
229 'isAnswered' => $value['isAnswered'],
230 'has_authorized_answer' => $value['has_authorized_answer']
231 ];
232 $firstQuestion = false;
233 // fau.
234 }
235
236 return $data;
237 }
238}
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static lookupPassResultsUpdateTimestamp($active_id, $pass)
static _getSolvedQuestions($active_id, $question_fi=null)
get solved questions
Service class for tests.
getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence)
__construct(protected ilObjTest $object, protected ilDBInterface $db, protected GeneralQuestionPropertiesRepository $questionrepository)
@access public
static setManScoringDone(int $activeId, bool $manScoringDone)
static isManScoringDone(int $active_id)
getPassOverviewData(int $active_id, bool $short=false)
buildVirtualSequence(ilTestSession $testSession)
getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence)
Test session handler.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$results