ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ExportRandomQuestionSet.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test\ExportImport;
22 
30 {
31  protected \ilTestRandomQuestionSetSourcePoolDefinitionList $src_pool_def_list;
32 
37 
38  protected function initXmlExport(): void
39  {
40  $src_pool_def_factory = new \ilTestRandomQuestionSetSourcePoolDefinitionFactory(
41  $this->db,
42  $this->test_obj
43  );
44 
45  $this->src_pool_def_list = new \ilTestRandomQuestionSetSourcePoolDefinitionList(
46  $this->db,
47  $this->test_obj,
48  $src_pool_def_factory
49  );
50 
51  $this->src_pool_def_list->loadDefinitions();
52 
53  $this->test_obj->questions = $this->getQuestionIds();
54  $this->staging_pool_question_list_by_pool_id = [];
55  }
56 
57  protected function populateQuestionSetConfigXml(\ilXmlWriter $xml_writer): void
58  {
59  $xml_writer->xmlStartTag('RandomQuestionSetConfig');
60  $this->populateCommonSettings($xml_writer);
61  $this->populateQuestionStages($xml_writer);
62  $this->populateSelectionDefinitions($xml_writer);
63  $xml_writer->xmlEndTag('RandomQuestionSetConfig');
64  }
65 
66  protected function populateCommonSettings(\ilXmlWriter $xml_writer)
67  {
68  $question_set_config = new \ilTestRandomQuestionSetConfig(
69  $this->tree,
70  $this->db,
71  $this->lng,
72  $this->logger,
73  $this->component_repository,
74  $this->test_obj,
75  $this->questionrepository
76  );
77  $question_set_config->loadFromDb();
78 
79  $xml_writer->xmlElement('RandomQuestionSetSettings', [
80  'amountMode' => $question_set_config->getQuestionAmountConfigurationMode(),
81  'questAmount' => $question_set_config->getQuestionAmountPerTest(),
82  'homogeneous' => $question_set_config->arePoolsWithHomogeneousScoredQuestionsRequired(),
83  'synctimestamp' => $question_set_config->getLastQuestionSyncTimestamp()
84  ]);
85  }
86 
87  protected function populateQuestionStages(\ilXmlWriter $xml_writer)
88  {
89  $xml_writer->xmlStartTag('RandomQuestionStage');
90 
91  foreach ($this->src_pool_def_list->getInvolvedSourcePoolIds() as $pool_id) {
92  $question_list = $this->getLoadedStagingPoolQuestionList($pool_id);
93 
94  $xml_writer->xmlStartTag('RandomQuestionStagingPool', ['poolId' => $pool_id]);
95  $xml_writer->xmlData(implode(',', $question_list->getQuestions()));
96  $xml_writer->xmlEndTag('RandomQuestionStagingPool');
97  }
98 
99  $xml_writer->xmlEndTag('RandomQuestionStage');
100  }
101 
102  protected function populateSelectionDefinitions(\ilXmlWriter $xml_writer)
103  {
104  $xml_writer->xmlStartTag('RandomQuestionSelectionDefinitions');
105 
106  foreach ($this->src_pool_def_list as $definition) {
107  $attributes = [
108  'id' => $definition->getId(),
109  'ref_id' => $definition->getPoolRefId(),
110  'poolId' => $definition->getPoolId(),
111  'questAmount' => $definition->getQuestionAmount() ?? '',
112  'poolQuestCount' => $definition->getPoolQuestionCount(),
113  'position' => $definition->getSequencePosition(),
114  'typeFilter' => implode(',', $definition->getTypeFilterAsTypeTags()),
115  ];
116 
117 
118  // #21330
119  $mappedTaxFilter = $definition->getMappedTaxonomyFilter();
120  if (is_array($mappedTaxFilter) && count($mappedTaxFilter) > 0) {
121  $attributes['taxFilter'] = serialize($mappedTaxFilter);
122  }
123 
124  $xml_writer->xmlStartTag('RandomQuestionSelectionDefinition', $attributes);
125  $xml_writer->xmlElement('RandomQuestionSourcePoolTitle', null, $definition->getPoolTitle());
126  $xml_writer->xmlElement('RandomQuestionSourcePoolPath', null, $definition->getPoolPath());
127  $xml_writer->xmlEndTag('RandomQuestionSelectionDefinition');
128  }
129 
130  $xml_writer->xmlEndTag('RandomQuestionSelectionDefinitions');
131  }
132 
133  protected function getQuestionsQtiXml(): string
134  {
135  $question_qti_xml = '';
136 
137  foreach ($this->src_pool_def_list->getInvolvedSourcePoolIds() as $pool_id) {
138  $question_list = $this->getLoadedStagingPoolQuestionList($pool_id);
139 
140  foreach ($question_list as $question_id) {
141  $question_qti_xml .= $this->getQuestionQtiXml($question_id);
142  }
143  }
144 
145  return $question_qti_xml;
146  }
147 
151  protected function getQuestionIds(): array
152  {
153  $question_ids = [];
154 
155  foreach ($this->src_pool_def_list->getInvolvedSourcePoolIds() as $pool_id) {
156  $question_list = $this->getLoadedStagingPoolQuestionList($pool_id);
157 
158  foreach ($question_list as $question_id) {
159  $question_ids[] = $question_id;
160  }
161  }
162 
163  return $question_ids;
164  }
165 
167  {
168  if (!isset($this->staging_pool_question_list_by_pool_id[$pool_id])) {
169  $question_list = new \ilTestRandomQuestionSetStagingPoolQuestionList($this->db, $this->component_repository);
170  $question_list->setTestId($this->test_obj->getTestId());
171  $question_list->setPoolId($pool_id);
172  $question_list->loadQuestions();
173 
174  $this->staging_pool_question_list_by_pool_id[$pool_id] = $question_list;
175  }
176 
177  return $this->staging_pool_question_list_by_pool_id[$pool_id];
178  }
179 }
getQuestionQtiXml(int $question_id)
Definition: Export.php:224
ilTestRandomQuestionSetSourcePoolDefinitionList $src_pool_def_list
xmlData(string $data, bool $encode=true, bool $escape=true)
Writes data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Export class for tests.
Definition: Export.php:39
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)