ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  );
111 
112  // #21330
113  $mappedTaxFilter = $definition->getMappedTaxonomyFilter();
114  if (is_array($mappedTaxFilter) && count($mappedTaxFilter) > 0) {
115  $attributes['taxFilter'] = serialize($mappedTaxFilter);
116  }
117 
118  $xmlWriter->xmlStartTag('RandomQuestionSelectionDefinition', $attributes);
119  $xmlWriter->xmlElement('RandomQuestionSourcePoolTitle', null, $definition->getPoolTitle());
120  $xmlWriter->xmlElement('RandomQuestionSourcePoolPath', null, $definition->getPoolPath());
121  $xmlWriter->xmlEndTag('RandomQuestionSelectionDefinition');
122  }
123 
124  $xmlWriter->xmlEndTag('RandomQuestionSelectionDefinitions');
125  }
126 
127  protected function getQuestionsQtiXml()
128  {
129  $questionQtiXml = '';
130 
131  foreach ($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId) {
132  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
133 
134  foreach ($questionList as $questionId) {
135  $questionQtiXml .= $this->getQuestionQtiXml($questionId);
136  }
137  }
138 
139  return $questionQtiXml;
140  }
141 
145  protected function getQuestionIds()
146  {
147  $questionIds = array();
148 
149  foreach ($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId) {
150  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
151 
152  foreach ($questionList as $questionId) {
153  $questionIds[] = $questionId;
154  }
155  }
156 
157  return $questionIds;
158  }
159 
164  protected function getLoadedStagingPoolQuestionList($poolId)
165  {
166  if (!isset($this->stagingPoolQuestionListByPoolId[$poolId])) {
167  global $DIC;
168  $ilDB = $DIC['ilDB'];
169  $ilPluginAdmin = $DIC['ilPluginAdmin'];
170 
171  $questionList = new ilTestRandomQuestionSetStagingPoolQuestionList($ilDB, $ilPluginAdmin);
172  $questionList->setTestId($this->test_obj->getTestId());
173  $questionList->setPoolId($poolId);
174  $questionList->loadQuestions();
175 
176  $this->stagingPoolQuestionListByPoolId[$poolId] = $questionList;
177  }
178 
179  return $this->stagingPoolQuestionListByPoolId[$poolId];
180  }
181 }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
global $DIC
Definition: saml.php:7
getQuestionQtiXml($questionId)
XML writer class.
Export class for tests.
xmlData($data, $encode=true, $escape=true)
Writes data.
xmlEndTag($tag)
Writes an endtag.
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $ilDB