ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestVirtualSequence.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  protected ?int $active_id;
30 
31  protected array $questions_pass_map;
32 
33  public function __construct(
34  protected ilDBInterface $db,
35  protected ilObjTest $test_obj,
36  protected ilTestSequenceFactory $test_sequence_factory
37  ) {
38  $this->active_id = null;
39 
40  $this->questions_pass_map = [];
41  }
42 
43  public function getActiveId(): ?int
44  {
45  return $this->active_id;
46  }
47 
48  public function setActiveId(int $active_id): void
49  {
50  $this->active_id = $active_id;
51  }
52 
53  public function getQuestionIds(): array
54  {
55  return array_keys($this->questions_pass_map);
56  }
57 
58  public function getQuestionsPassMap(): array
59  {
61  }
62 
63  public function getUniquePasses(): array
64  {
65  return array_unique(array_values($this->questions_pass_map));
66  }
67 
68  public function init(): void
69  {
70  $passes = $this->getExistingPassesDescendent($this->getActiveId());
71  $this->fetchQuestionsFromPasses($this->getActiveId(), $passes);
72  }
73 
74  private function getExistingPassesDescendent(int $active_id): array
75  {
76  $passes_selector = new ilTestPassesSelector($this->db, $this->test_obj);
77  $passes_selector->setActiveId($active_id);
78 
79  $passes = $passes_selector->getExistingPasses();
80 
81  rsort($passes, SORT_NUMERIC);
82 
83  return $passes;
84  }
85 
86  protected function getTestSequence(int $active_id, int $pass): ilTestSequence
87  {
88  $test_sequence = $this->test_sequence_factory->getSequenceByActiveIdAndPass($active_id, $pass);
89 
90  $test_sequence->loadFromDb();
91  $test_sequence->loadQuestions();
92 
93  $test_sequence->setConsiderHiddenQuestionsEnabled(true);
94  $test_sequence->setConsiderOptionalQuestionsEnabled(true);
95  return $test_sequence;
96  }
97 
98  protected function wasAnsweredInThisPass(ilTestSequence $test_sequence, int $question_id): bool
99  {
100  if ($test_sequence->isHiddenQuestion($question_id)) {
101  return false;
102  }
103 
104  if (!$test_sequence->isQuestionOptional($question_id)) {
105  return true;
106  }
107 
108  if ($test_sequence->isAnsweringOptionalQuestionsConfirmed()) {
109  return true;
110  }
111 
112  return false;
113  }
114 
118  protected function fetchQuestionsFromPasses(int $active_id, array $passes): void
119  {
120  $this->questions_pass_map = [];
121 
122  foreach ($passes as $pass) {
123  $test_sequence = $this->getTestSequence($active_id, $pass);
124 
125  foreach ($test_sequence->getOrderedSequenceQuestions() as $question_id) {
126  if (isset($this->questions_pass_map[$question_id])) {
127  continue;
128  }
129 
130  if ($this->wasAnsweredInThisPass($test_sequence, $question_id)) {
131  $this->questions_pass_map[$question_id] = $pass;
132  }
133  }
134  }
135  }
136 }
loadFromDb()
Loads the sequence data for a given active id.
getTestSequence(int $active_id, int $pass)
__construct(protected ilDBInterface $db, protected ilObjTest $test_obj, protected ilTestSequenceFactory $test_sequence_factory)
isHiddenQuestion(int $question_id)
Test sequence handler.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
fetchQuestionsFromPasses(int $active_id, array $passes)
wasAnsweredInThisPass(ilTestSequence $test_sequence, int $question_id)
isQuestionOptional(int $question_id)