ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestVirtualSequence.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
29  protected ilDBInterface $db;
30 
31  protected ilObjTest $testOBJ;
32 
34 
35  protected ?int $activeId;
36 
37  protected array $questionsPassMap;
38 
39  public function __construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestSequenceFactory $testSequenceFactory)
40  {
41  $this->db = $db;
42  $this->testOBJ = $testOBJ;
43  $this->testSequenceFactory = $testSequenceFactory;
44 
45  $this->activeId = null;
46 
47  $this->questionsPassMap = array();
48  }
49 
50  public function getActiveId(): ?int
51  {
52  return $this->activeId;
53  }
54 
55  public function setActiveId(int $activeId): void
56  {
57  $this->activeId = $activeId;
58  }
59 
60  public function getQuestionIds(): array
61  {
62  return array_keys($this->questionsPassMap);
63  }
64 
65  public function getQuestionsPassMap(): array
66  {
68  }
69 
70  public function getUniquePasses(): array
71  {
72  return array_unique(array_values($this->questionsPassMap));
73  }
74 
75  public function init(): void
76  {
77  $passes = $this->getExistingPassesDescendent($this->getActiveId());
78  $this->fetchQuestionsFromPasses($this->getActiveId(), $passes);
79  }
80 
81  private function getExistingPassesDescendent($activeId): array
82  {
83  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
84  $passesSelector = new ilTestPassesSelector($this->db, $this->testOBJ);
85  $passesSelector->setActiveId($activeId);
86 
87  $passes = $passesSelector->getExistingPasses();
88 
89  rsort($passes, SORT_NUMERIC);
90 
91  return $passes;
92  }
93 
97  protected function getTestSequence(int $activeId, int $pass)
98  {
99  $testSequence = $this->testSequenceFactory->getSequenceByActiveIdAndPass($activeId, $pass);
100 
101  $testSequence->loadFromDb();
102  $testSequence->loadQuestions();
103 
104  $testSequence->setConsiderHiddenQuestionsEnabled(true);
105  $testSequence->setConsiderOptionalQuestionsEnabled(true);
106  return $testSequence;
107  }
108 
109  protected function wasAnsweredInThisPass(ilTestSequence $testSequence, $questionId): bool
110  {
111  if ($testSequence->isHiddenQuestion($questionId)) {
112  return false;
113  }
114 
115  if (!$testSequence->isQuestionOptional($questionId)) {
116  return true;
117  }
118 
119  if ($testSequence->isAnsweringOptionalQuestionsConfirmed()) {
120  return true;
121  }
122 
123  return false;
124  }
125 
129  protected function fetchQuestionsFromPasses(int $activeId, array $passes): void
130  {
131  $this->questionsPassMap = array();
132 
133  foreach ($passes as $pass) {
134  $testSequence = $this->getTestSequence($activeId, $pass);
135 
136  foreach ($testSequence->getOrderedSequenceQuestions() as $questionId) {
137  if (isset($this->questionsPassMap[$questionId])) {
138  continue;
139  }
140 
141  if ($this->wasAnsweredInThisPass($testSequence, $questionId)) {
142  $this->questionsPassMap[$questionId] = $pass;
143  }
144  }
145  }
146  }
147 }
fetchQuestionsFromPasses(int $activeId, array $passes)
isQuestionOptional($questionId)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilTestSequenceFactory $testSequenceFactory
getTestSequence(int $activeId, int $pass)
isHiddenQuestion($question_id)
wasAnsweredInThisPass(ilTestSequence $testSequence, $questionId)
__construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestSequenceFactory $testSequenceFactory)