ILIAS  release_8 Revision v8.24
class.ilTestService.php
Go to the documentation of this file.
1<?php
2
28{
33 protected $object = null;
34
39 public function __construct(ilObjTest $a_object)
40 {
41 $this->object = $a_object;
42 }
43
51 public function getPassOverviewData($active_id, $short = false): array
52 {
53 $passOverwiewData = array();
54
55 global $DIC;
56 $ilUser = $DIC['ilUser'];
57
58 $scoredPass = $this->object->_getResultPass($active_id);
59 $lastPass = ilObjTest::_getPass($active_id);
60
61 $testPercentage = 0;
62 $testReachedPoints = 0;
63 $testMaxPoints = 0;
64
65 for ($pass = 0; $pass <= $lastPass; $pass++) {
66 $passFinishDate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
67
68 if ($passFinishDate <= 0) {
69 continue;
70 }
71
72 if (!$short) {
73 $resultData = &$this->object->getTestResult($active_id, $pass);
74
75 if (!$resultData["pass"]["total_max_points"]) {
76 $passPercentage = 0;
77 } else {
78 $passPercentage = ($resultData["pass"]["total_reached_points"] / $resultData["pass"]["total_max_points"]) * 100;
79 }
80
81 $passMaxPoints = $resultData["pass"]["total_max_points"];
82 $passReachedPoints = $resultData["pass"]["total_reached_points"];
83
84 $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass);
85 $passTotalQuestions = count($resultData) - 2;
86
87 if ($pass == $scoredPass) {
88 $isScoredPass = true;
89
90 if (!$resultData["test"]["total_max_points"]) {
91 $testPercentage = 0;
92 } else {
93 $testPercentage = ($resultData["test"]["total_reached_points"] / $resultData["test"]["total_max_points"]) * 100;
94 }
95
96 $testMaxPoints = $resultData["test"]["total_max_points"];
97 $testReachedPoints = $resultData["test"]["total_reached_points"];
98
99 $passOverwiewData['test'] = array(
100 'active_id' => $active_id,
101 'scored_pass' => $scoredPass,
102 'max_points' => $testMaxPoints,
103 'reached_points' => $testReachedPoints,
104 'percentage' => $testPercentage
105 );
106 } else {
107 $isScoredPass = false;
108 }
109
110 $passOverwiewData['passes'][] = array(
111 'active_id' => $active_id,
112 'pass' => $pass,
113 'finishdate' => $passFinishDate,
114 'max_points' => $passMaxPoints,
115 'reached_points' => $passReachedPoints,
116 'percentage' => $passPercentage,
117 'answered_questions' => $passAnsweredQuestions,
118 'total_questions' => $passTotalQuestions,
119 'is_scored_pass' => $isScoredPass
120 );
121 }
122 }
123
124 return $passOverwiewData;
125 }
126
134 public function getManScoringQuestionGuiList($activeId, $pass): array
135 {
136 include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
137 $manScoringQuestionTypes = ilObjAssessmentFolder::_getManualScoring();
138
139 $testResultData = $this->object->getTestResult($activeId, $pass);
140
141 $manScoringQuestionGuiList = array();
142
143 foreach ($testResultData as $questionData) {
144 if (!isset($questionData['qid'])) {
145 continue;
146 }
147
148 if (!isset($questionData['type'])) {
149 throw new ilTestException('no question type given!');
150 }
151
152 $questionGUI = $this->object->createQuestionGUI("", $questionData['qid']);
153
154 if (!in_array($questionGUI->object->getQuestionTypeID(), $manScoringQuestionTypes)) {
155 continue;
156 }
157
158 $manScoringQuestionGuiList[ $questionData['qid'] ] = $questionGUI;
159 }
160
161 return $manScoringQuestionGuiList;
162 }
163
173 public static function isManScoringDone($activeId): bool
174 {
175 $assessmentSetting = new ilSetting("assessment");
176 return $assessmentSetting->get("manscoring_done_" . $activeId, false);
177 }
178
188 public static function setManScoringDone($activeId, $manScoringDone)
189 {
190 $assessmentSetting = new ilSetting("assessment");
191 $assessmentSetting->set("manscoring_done_" . $activeId, (bool) $manScoringDone);
192 }
193
194 public function buildVirtualSequence(ilTestSession $testSession)
195 {
196 global $DIC;
197 $ilDB = $DIC['ilDB'];
198 $lng = $DIC['lng'];
199 $refinery = $DIC['refinery'];
200 $component_repository = $DIC['component.repository'];
201
202 $testSequenceFactory = new ilTestSequenceFactory($ilDB, $lng, $refinery, $component_repository, $this->object);
203
204 if ($this->object->isRandomTest()) {
205 $virtualSequence = new ilTestVirtualSequenceRandomQuestionSet($ilDB, $this->object, $testSequenceFactory);
206 } else {
207 $virtualSequence = new ilTestVirtualSequence($ilDB, $this->object, $testSequenceFactory);
208 }
209
210 $virtualSequence->setActiveId($testSession->getActiveId());
211
212 $virtualSequence->init();
213
214 return $virtualSequence;
215 }
216
217 public function getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence): array
218 {
219 $resultsByPass = array();
220
221 foreach ($virtualSequence->getUniquePasses() as $pass) {
222 $results = $this->object->getTestResult(
223 $virtualSequence->getActiveId(),
224 $pass,
225 false,
226 true,
227 true
228 );
229
230 $resultsByPass[$pass] = $results;
231 }
232
233 $virtualPassResults = array();
234
235 foreach ($virtualSequence->getQuestionsPassMap() as $questionId => $pass) {
236 foreach ($resultsByPass[$pass] as $key => $questionResult) {
237 if ($key === 'test' || $key === 'pass') {
238 continue;
239 }
240
241 if ($questionResult['qid'] == $questionId) {
242 $questionResult['pass'] = $pass;
243 $virtualPassResults[$questionId] = $questionResult;
244 break;
245 }
246 }
247 }
248
249 return $virtualPassResults;
250 }
251
257 public function getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, $obligationsFilterEnabled): array
258 {
259 $result_array = $testSequence->getSequenceSummary($obligationsFilterEnabled);
260
261 $marked_questions = array();
262
263 if ($this->object->getShowMarker()) {
264 include_once "./Modules/Test/classes/class.ilObjTest.php";
265 $marked_questions = ilObjTest::_getSolvedQuestions($testSequence->getActiveId());
266 }
267
268 $data = array();
269 $firstQuestion = true;
270
271 foreach ($result_array as $key => $value) {
272 $disableLink = (
273 $this->object->isFollowupQuestionAnswerFixationEnabled()
274 && !$value['presented'] && !$firstQuestion
275 );
276
277 $description = "";
278 if ($this->object->getListOfQuestionsDescription()) {
279 $description = $value["description"];
280 }
281
282 $points = "";
283 if (!$this->object->getTitleOutput()) {
284 $points = $value["points"];
285 }
286
287 $marked = false;
288 if (count($marked_questions)) {
289 if (array_key_exists($value["qid"], $marked_questions)) {
290 $obj = $marked_questions[$value["qid"]];
291 if ($obj["solved"] == 1) {
292 $marked = true;
293 }
294 }
295 }
296
297 // fau: testNav - add number parameter for getQuestionTitle()
298 $data[] = array(
299 'order' => $value["nr"],
300 'title' => $this->object->getQuestionTitle($value["title"], $value["nr"]),
301 'description' => $description,
302 'disabled' => $disableLink,
303 'worked_through' => $value["worked_through"],
304 'postponed' => $value["postponed"],
305 'points' => $points,
306 'marked' => $marked,
307 'sequence' => $value["sequence"],
308 'obligatory' => $value['obligatory'],
309 'isAnswered' => $value['isAnswered']
310 );
311
312 $firstQuestion = false;
313 // fau.
314 }
315
316 return $data;
317 }
318}
static _getManualScoring()
Retrieve the manual scoring settings.
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
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getManScoringQuestionGuiList($activeId, $pass)
Returns the list of answers of a users test pass and offers a scoring option.
static setManScoringDone($activeId, $manScoringDone)
stores the flag wether manscoring is done for the given test active or not within the global settings...
__construct(ilObjTest $a_object)
@access public
getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence)
getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, $obligationsFilterEnabled)
getPassOverviewData($active_id, $short=false)
@access public @global ilObjUser $ilUser
static isManScoringDone($activeId)
reads the flag wether manscoring is done for the given test active or not from the global settings (s...
buildVirtualSequence(ilTestSession $testSession)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSequenceSummary($obligationsFilterEnabled=false)
string $key
Consumer key/client ID value.
Definition: System.php:193
Refinery Factory $refinery
$results
$lng