ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilDB, $ilPluginAdmin;
27 
28  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
30  $ilDB, $this->test_obj
31  );
32 
33  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
34  $this->srcPoolDefList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
35  $ilDB, $this->test_obj, $srcPoolDefFactory
36  );
37 
38  $this->srcPoolDefList->loadDefinitions();
39 
40 // fau: fixRandomTestExportPages - use the complete random question list
41 // ilObjTest::exportPagesXML() uses $this->questions
42 // ilObjTest::loadQuestions() loads only those of the current active_id of ilUser
43  $this->test_obj->questions = $this->getQuestionIds();
44 // fau.
45  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolQuestionList.php';
46 
47  $this->stagingPoolQuestionListByPoolId = array();
48  }
49 
50  protected function populateQuestionSetConfigXml(ilXmlWriter $xmlWriter)
51  {
52  $xmlWriter->xmlStartTag('RandomQuestionSetConfig');
53  $this->populateCommonSettings($xmlWriter);
54  $this->populateQuestionStages($xmlWriter);
55  $this->populateSelectionDefinitions($xmlWriter);
56  $xmlWriter->xmlEndTag('RandomQuestionSetConfig');
57  }
58 
59  protected function populateCommonSettings(ilXmlWriter $xmlWriter)
60  {
61  global $tree, $ilDB, $ilPluginAdmin;
62 
63  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfig.php';
64  $questionSetConfig = new ilTestRandomQuestionSetConfig($tree, $ilDB, $ilPluginAdmin, $this->test_obj);
65  $questionSetConfig->loadFromDb();
66 
67  $xmlWriter->xmlElement('RandomQuestionSetSettings', array(
68  'amountMode' => $questionSetConfig->getQuestionAmountConfigurationMode(),
69  'questAmount' => $questionSetConfig->getQuestionAmountPerTest(),
70  'homogeneous' => $questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired()
71  ));
72  }
73 
74  protected function populateQuestionStages(ilXmlWriter $xmlWriter)
75  {
76  $xmlWriter->xmlStartTag('RandomQuestionStage');
77 
78  foreach($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId)
79  {
80  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
81 
82  $xmlWriter->xmlStartTag('RandomQuestionStagingPool', array('poolId' => $poolId));
83  $xmlWriter->xmlData(implode(',', $questionList->getQuestions()));
84  $xmlWriter->xmlEndTag('RandomQuestionStagingPool');
85  }
86 
87  $xmlWriter->xmlEndTag('RandomQuestionStage');
88  }
89 
90  protected function populateSelectionDefinitions(ilXmlWriter $xmlWriter)
91  {
92  $xmlWriter->xmlStartTag('RandomQuestionSelectionDefinitions');
93 
94  foreach($this->srcPoolDefList as $definition)
95  {
96  $attributes = array(
97  'id' => $definition->getId(),
98  'poolId' => $definition->getPoolId(),
99  'poolQuestCount' => $definition->getPoolQuestionCount(),
100  'questAmount' => $definition->getQuestionAmount(),
101  'position' => $definition->getSequencePosition()
102  );
103 
104  if( $definition->getMappedFilterTaxId() && $definition->getMappedFilterTaxNodeId() )
105  {
106  $attributes['tax'] = $definition->getMappedFilterTaxId();
107  $attributes['taxNode'] = $definition->getMappedFilterTaxNodeId();
108  }
109 
110  $xmlWriter->xmlStartTag('RandomQuestionSelectionDefinition', $attributes);
111  $xmlWriter->xmlElement('RandomQuestionSourcePoolTitle', null, $definition->getPoolTitle());
112  $xmlWriter->xmlElement('RandomQuestionSourcePoolPath', null, $definition->getPoolPath());
113  $xmlWriter->xmlEndTag('RandomQuestionSelectionDefinition', $attributes);
114  }
115 
116  $xmlWriter->xmlEndTag('RandomQuestionSelectionDefinitions');
117  }
118 
119  protected function getQuestionsQtiXml()
120  {
121  $questionQtiXml = '';
122 
123  foreach($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId)
124  {
125  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
126 
127  foreach ($questionList as $questionId)
128  {
129  $questionQtiXml .= $this->getQuestionQtiXml($questionId);
130  }
131  }
132 
133  return $questionQtiXml;
134  }
135 
139  protected function getQuestionIds()
140  {
141  $questionIds = array();
142 
143  foreach($this->srcPoolDefList->getInvolvedSourcePoolIds() as $poolId)
144  {
145  $questionList = $this->getLoadedStagingPoolQuestionList($poolId);
146 
147  foreach ($questionList as $questionId)
148  {
149  $questionIds[] = $questionId;
150  }
151  }
152 
153  return $questionIds;
154  }
155 
160  protected function getLoadedStagingPoolQuestionList($poolId)
161  {
162  if( !isset($this->stagingPoolQuestionListByPoolId[$poolId]) )
163  {
164  global $ilDB, $ilPluginAdmin;
165 
166  $questionList = new ilTestRandomQuestionSetStagingPoolQuestionList($ilDB, $ilPluginAdmin);
167  $questionList->setTestId($this->test_obj->getTestId());
168  $questionList->setPoolId($poolId);
169  $questionList->loadQuestions();
170 
171  $this->stagingPoolQuestionListByPoolId[$poolId] = $questionList;
172  }
173 
174  return $this->stagingPoolQuestionListByPoolId[$poolId];
175  }
176 }
xmlData($data, $encode=TRUE, $escape=TRUE)
Writes data.
getQuestionQtiXml($questionId)
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
Export class for tests.
xmlEndTag($tag)
Writes an endtag.
Create styles array
The data for the language used.
global $ilDB