ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestExportRandomQuestionSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Test/classes/class.ilTestExport.php';
5 
13 {
17  protected $srcPoolDefList;
18 
23 
24  protected function initXmlExport()
25  {
26  global $DIC;
27  $ilDB = $DIC['ilDB'];
28  $ilPluginAdmin = $DIC['ilPluginAdmin'];
29 
30  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
32  $ilDB,
33  $this->test_obj
34  );
35 
36  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
37  $this->srcPoolDefList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
38  $ilDB,
39  $this->test_obj,
40  $srcPoolDefFactory
41  );
42 
43  $this->srcPoolDefList->loadDefinitions();
44 
45  // fau: fixRandomTestExportPages - use the complete random question list
46  // ilObjTest::exportPagesXML() uses $this->questions
47  // ilObjTest::loadQuestions() loads only those of the current active_id of ilUser
48  $this->test_obj->questions = $this->getQuestionIds();
49  // fau.
50  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php';
51 
52  $this->stagingPoolQuestionListByPoolId = array();
53  }
54 
55  protected function populateQuestionSetConfigXml(ilXmlWriter $xmlWriter)
56  {
57  $xmlWriter->xmlStartTag('RandomQuestionSetConfig');
58  $this->populateCommonSettings($xmlWriter);
59  $this->populateQuestionStages($xmlWriter);
60  $this->populateSelectionDefinitions($xmlWriter);
61  $xmlWriter->xmlEndTag('RandomQuestionSetConfig');
62  }
63 
64  protected function populateCommonSettings(ilXmlWriter $xmlWriter)
65  {
66  global $DIC;
67  $tree = $DIC['tree'];
68  $ilDB = $DIC['ilDB'];
69  $ilPluginAdmin = $DIC['ilPluginAdmin'];
70 
71  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfig.php';
72  $questionSetConfig = new ilTestRandomQuestionSetConfig($tree, $ilDB, $ilPluginAdmin, $this->test_obj);
73  $questionSetConfig->loadFromDb();
74 
75  $xmlWriter->xmlElement('RandomQuestionSetSettings', array(
76  'amountMode' => $questionSetConfig->getQuestionAmountConfigurationMode(),
77  'questAmount' => $questionSetConfig->getQuestionAmountPerTest(),
78  'homogeneous' => $questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired(),
79  'synctimestamp' => $questionSetConfig->getLastQuestionSyncTimestamp()
80  ));
81  }
82 
83  protected function populateQuestionStages(ilXmlWriter $xmlWriter)
84  {
85  $xmlWriter->xmlStartTag('RandomQuestionStage');
86 
87  foreach ($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId) {
88  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
89 
90  $xmlWriter->xmlStartTag('RandomQuestionStagingPool', array('poolId' => $poolId));
91  $xmlWriter->xmlData(implode(',', $questionList->getQuestions()));
92  $xmlWriter->xmlEndTag('RandomQuestionStagingPool');
93  }
94 
95  $xmlWriter->xmlEndTag('RandomQuestionStage');
96  }
97 
98  protected function populateSelectionDefinitions(ilXmlWriter $xmlWriter)
99  {
100  $xmlWriter->xmlStartTag('RandomQuestionSelectionDefinitions');
101 
102  foreach ($this->srcPoolDefList as $definition) {
103  $attributes = array(
104  'id' => $definition->getId(),
105  'ref_id' => $definition->getPoolRefId(),
106  'poolId' => $definition->getPoolId(),
107  'poolQuestCount' => $definition->getPoolQuestionCount(),
108  'questAmount' => $definition->getQuestionAmount(),
109  'position' => $definition->getSequencePosition(),
110  'typeFilter' => implode(',', $definition->getTypeFilterAsTypeTags()),
111  );
112 
113  // #21330
114  $mappedTaxFilter = $definition->getMappedTaxonomyFilter();
115  if (is_array($mappedTaxFilter) && count($mappedTaxFilter) > 0) {
116  $attributes['taxFilter'] = serialize($mappedTaxFilter);
117  }
118 
119  $xmlWriter->xmlStartTag('RandomQuestionSelectionDefinition', $attributes);
120  $xmlWriter->xmlElement('RandomQuestionSourcePoolTitle', null, $definition->getPoolTitle());
121  $xmlWriter->xmlElement('RandomQuestionSourcePoolPath', null, $definition->getPoolPath());
122  $xmlWriter->xmlEndTag('RandomQuestionSelectionDefinition');
123  }
124 
125  $xmlWriter->xmlEndTag('RandomQuestionSelectionDefinitions');
126  }
127 
128  protected function getQuestionsQtiXml()
129  {
130  $questionQtiXml = '';
131 
132  foreach ($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId) {
133  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
134 
135  foreach ($questionList as $questionId) {
136  $questionQtiXml .= $this->getQuestionQtiXml($questionId);
137  }
138  }
139 
140  return $questionQtiXml;
141  }
142 
146  protected function getQuestionIds()
147  {
148  $questionIds = array();
149 
150  foreach ($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId) {
151  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
152 
153  foreach ($questionList as $questionId) {
154  $questionIds[] = $questionId;
155  }
156  }
157 
158  return $questionIds;
159  }
160 
165  protected function getLoadedStagingPoolQuestionList($poolId)
166  {
167  if (!isset($this->stagingPoolQuestionListByPoolId[$poolId])) {
168  global $DIC;
169  $ilDB = $DIC['ilDB'];
170  $ilPluginAdmin = $DIC['ilPluginAdmin'];
171 
172  $questionList = new ilTestRandomQuestionSetStagingPoolQuestionList($ilDB, $ilPluginAdmin);
173  $questionList->setTestId($this->test_obj->getTestId());
174  $questionList->setPoolId($poolId);
175  $questionList->loadQuestions();
176 
177  $this->stagingPoolQuestionListByPoolId[$poolId] = $questionList;
178  }
179 
180  return $this->stagingPoolQuestionListByPoolId[$poolId];
181  }
182 }
$attributes
Definition: metadata.php:231
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
getQuestionQtiXml($questionId)
XML writer class.
Export class for tests.
xmlData($data, $encode=true, $escape=true)
Writes data.
xmlEndTag($tag)
Writes an endtag.
global $DIC
Definition: goto.php:24
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $ilDB