ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 {
37  public function __construct(
38  protected ilObjTest $object,
39  protected ilDBInterface $db,
40  protected \ILIAS\TestQuestionPool\QuestionInfoService $questioninfo
41  ) {
42  }
43 
44  public function getPassOverviewData(int $active_id, bool $short = false): array
45  {
46  $passOverwiewData = [];
47 
48  $scoredPass = $this->object->_getResultPass($active_id);
49  $lastPass = ilObjTest::_getPass($active_id);
50 
51  $testPercentage = 0;
52  $testReachedPoints = 0;
53  $testMaxPoints = 0;
54 
55  for ($pass = 0; $pass <= $lastPass; $pass++) {
56  $passFinishDate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
57 
58  if ($passFinishDate <= 0) {
59  continue;
60  }
61 
62  if (!$short) {
63  $resultData = &$this->object->getTestResult($active_id, $pass);
64 
65  if (!$resultData["pass"]["total_max_points"]) {
66  $passPercentage = 0;
67  } else {
68  $passPercentage = ($resultData["pass"]["total_reached_points"] / $resultData["pass"]["total_max_points"]) * 100;
69  }
70 
71  $passMaxPoints = $resultData["pass"]["total_max_points"];
72  $passReachedPoints = $resultData["pass"]["total_reached_points"];
73 
74  $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass);
75  $passTotalQuestions = count($resultData) - 2;
76 
77  if ($pass == $scoredPass) {
78  $isScoredPass = true;
79 
80  if (!$resultData["test"]["total_max_points"]) {
81  $testPercentage = 0;
82  } else {
83  $testPercentage = ($resultData["test"]["total_reached_points"] / $resultData["test"]["total_max_points"]) * 100;
84  }
85 
86  $testMaxPoints = $resultData["test"]["total_max_points"];
87  $testReachedPoints = $resultData["test"]["total_reached_points"];
88 
89  $passOverwiewData['test'] = array(
90  'active_id' => $active_id,
91  'scored_pass' => $scoredPass,
92  'max_points' => $testMaxPoints,
93  'reached_points' => $testReachedPoints,
94  'percentage' => $testPercentage
95  );
96  } else {
97  $isScoredPass = false;
98  }
99 
100  $passOverwiewData['passes'][] = array(
101  'active_id' => $active_id,
102  'pass' => $pass,
103  'finishdate' => $passFinishDate,
104  'max_points' => $passMaxPoints,
105  'reached_points' => $passReachedPoints,
106  'percentage' => $passPercentage,
107  'answered_questions' => $passAnsweredQuestions,
108  'total_questions' => $passTotalQuestions,
109  'is_scored_pass' => $isScoredPass
110  );
111  }
112  }
113 
114  return $passOverwiewData;
115  }
116 
120  public function getManScoringQuestionGuiList(int $active_id, int $pass): array
121  {
122  $manScoringQuestionTypes = ilObjAssessmentFolder::_getManualScoring();
123 
124  $testResultData = $this->object->getTestResult($active_id, $pass);
125 
126  $manScoringQuestionGuiList = [];
127 
128  foreach ($testResultData as $questionData) {
129  if (!isset($questionData['qid'])) {
130  continue;
131  }
132 
133  if (!isset($questionData['type'])) {
134  throw new ilTestException('no question type given!');
135  }
136 
137  $questionGUI = $this->object->createQuestionGUI("", $questionData['qid']);
138 
139  if (!in_array($questionGUI->object->getQuestionTypeID(), $manScoringQuestionTypes)) {
140  continue;
141  }
142 
143  $manScoringQuestionGuiList[ $questionData['qid'] ] = $questionGUI;
144  }
145 
146  return $manScoringQuestionGuiList;
147  }
148 
149  public static function isManScoringDone(int $active_id): bool
150  {
151  return (new TestManScoringDoneHelper())->isDone($active_id);
152  }
153 
154  public static function setManScoringDone(int $activeId, bool $manScoringDone): void
155  {
156  (new TestManScoringDoneHelper())->setDone($activeId, $manScoringDone);
157  }
158 
160  {
161  $test_sequence_factory = new ilTestSequenceFactory($this->object, $this->db, $this->questioninfo);
162 
163  if ($this->object->isRandomTest()) {
164  $virtual_sequence = new ilTestVirtualSequenceRandomQuestionSet($this->db, $this->object, $test_sequence_factory);
165  } else {
166  $virtual_sequence = new ilTestVirtualSequence($this->db, $this->object, $test_sequence_factory);
167  }
168 
169  $virtual_sequence->setActiveId($testSession->getActiveId());
170 
171  $virtual_sequence->init();
172 
173  return $virtual_sequence;
174  }
175 
176  public function getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence): array
177  {
178  $resultsByPass = [];
179 
180  foreach ($virtualSequence->getUniquePasses() as $pass) {
181  $results = $this->object->getTestResult(
182  $virtualSequence->getActiveId(),
183  $pass,
184  false,
185  true,
186  true
187  );
188 
189  $resultsByPass[$pass] = $results;
190  }
191 
192  $virtualPassResults = [];
193 
194  foreach ($virtualSequence->getQuestionsPassMap() as $questionId => $pass) {
195  foreach ($resultsByPass[$pass] as $key => $questionResult) {
196  if ($key === 'test' || $key === 'pass') {
197  continue;
198  }
199 
200  if ($questionResult['qid'] == $questionId) {
201  $questionResult['pass'] = $pass;
202  $virtualPassResults[$questionId] = $questionResult;
203  break;
204  }
205  }
206  }
207 
208  return $virtualPassResults;
209  }
210 
211  public function getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, bool $obligationsFilterEnabled): array
212  {
213  $result_array = $testSequence->getSequenceSummary($obligationsFilterEnabled);
214 
215  $marked_questions = [];
216 
217  if ($this->object->getShowMarker()) {
218  $marked_questions = ilObjTest::_getSolvedQuestions($testSequence->getActiveId());
219  }
220 
221  $data = [];
222  $firstQuestion = true;
223 
224  foreach ($result_array as $key => $value) {
225  $disableLink = (
226  $this->object->isFollowupQuestionAnswerFixationEnabled()
227  && !$value['presented'] && !$firstQuestion
228  );
229 
230  $description = "";
231  if ($this->object->getListOfQuestionsDescription()) {
232  $description = $value["description"];
233  }
234 
235  $points = "";
236  if (!$this->object->getTitleOutput()) {
237  $points = $value["points"];
238  }
239 
240  $marked = false;
241  if (count($marked_questions)) {
242  if (array_key_exists($value["qid"], $marked_questions)) {
243  $obj = $marked_questions[$value["qid"]];
244  if ($obj["solved"] == 1) {
245  $marked = true;
246  }
247  }
248  }
249 
250 
251 
252  // fau: testNav - add number parameter for getQuestionTitle()
253  $data[] = array(
254  'order' => $value["nr"],
255  'title' => $this->object->getQuestionTitle($value["title"], $value["nr"], $value["points"]),
256  'description' => $description,
257  'disabled' => $disableLink,
258  'worked_through' => $value["worked_through"],
259  'postponed' => $value["postponed"],
260  'points' => $points,
261  'marked' => $marked,
262  'sequence' => $value["sequence"],
263  'obligatory' => $value['obligatory'],
264  'isAnswered' => $value['isAnswered'],
265  'has_authorized_answer' => $value['has_authorized_answer'],
266  );
267 
268  $firstQuestion = false;
269  // fau.
270  }
271 
272  return $data;
273  }
274 }
getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
Class ChatMainBarProvider .
static lookupPassResultsUpdateTimestamp($active_id, $pass)
getSequenceSummary(bool $obligationsFilterEnabled=false)
static isManScoringDone(int $active_id)
Base Exception for all Exceptions relating to Modules/Test.
getPassOverviewData(int $active_id, bool $short=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setManScoringDone(int $activeId, bool $manScoringDone)
getManScoringQuestionGuiList(int $active_id, int $pass)
Returns the list of answers of a users test pass and offers a scoring option.
buildVirtualSequence(ilTestSession $testSession)
static _getSolvedQuestions($active_id, $question_fi=null)
get solved questions
string $key
Consumer key/client ID value.
Definition: System.php:193
$results
Service class for tests.
getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, bool $obligationsFilterEnabled)
static _getManualScoring()
Retrieve the manual scoring settings.
__construct(protected ilObjTest $object, protected ilDBInterface $db, protected \ILIAS\TestQuestionPool\QuestionInfoService $questioninfo)
public