ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
class.ilTestRandomQuestionSetStagingPoolQuestionList.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
18  private $db = null;
19 
23  private $pluginAdmin = null;
24 
28  private $testObjId = -1;
29 
33  private $testId = -1;
34 
38  private $poolId = -1;
39 
43  private $taxFilters = array();
44 
48  private $questions = array();
49 
55  {
56  $this->db = $db;
57  $this->pluginAdmin = $pluginAdmin;
58  }
59 
60  public function setTestObjId($testObjId)
61  {
62  $this->testObjId = $testObjId;
63  }
64 
65  public function getTestObjId()
66  {
67  return $this->testObjId;
68  }
69 
70  public function setTestId($testId)
71  {
72  $this->testId = $testId;
73  }
74 
75  public function getTestId()
76  {
77  return $this->testId;
78  }
79 
80  public function setPoolId($poolId)
81  {
82  $this->poolId = $poolId;
83  }
84 
85  public function getPoolId()
86  {
87  return $this->poolId;
88  }
89 
90  public function addTaxonomyFilter($taxId, $taxNodes)
91  {
92  $this->taxFilters[$taxId] = $taxNodes;
93  }
94 
95  public function getTaxonomyFilters()
96  {
97  return $this->taxFilters;
98  }
99 
100  public function loadQuestions()
101  {
102  $query = "
103  SELECT qpl_questions.question_id,
104  qpl_qst_type.type_tag,
105  qpl_qst_type.plugin
106 
107  FROM tst_rnd_cpy
108 
109  INNER JOIN qpl_questions
110  ON qpl_questions.question_id = tst_rnd_cpy.qst_fi
111 
112  INNER JOIN qpl_qst_type
113  ON qpl_qst_type.question_type_id = qpl_questions.question_type_fi
114 
115  WHERE tst_rnd_cpy.tst_fi = %s
116  AND tst_rnd_cpy.qpl_fi = %s
117 
118  {$this->getConditionalExpression()}
119  ";
120 
121  $res = $this->db->queryF(
122  $query, array('integer', 'integer'), array($this->getTestId(), $this->getPoolId())
123  );
124 
125  //vd($this->db->db->last_query);
126 
127  while( $row = $this->db->fetchAssoc($res) )
128  {
129  if( !$this->isActiveQuestionType($row) )
130  {
131  continue;
132  }
133 
134  $this->questions[] = $row['question_id'];
135  }
136  }
137 
138  private function getConditionalExpression()
139  {
140  $CONDITIONS = $this->getTaxonomyFilterExpressions();
141 
142  $CONDITIONS = implode(' AND ', $CONDITIONS);
143 
144  return strlen($CONDITIONS) ? 'AND '.$CONDITIONS : '';
145  }
146 
147  private function getTaxonomyFilterExpressions()
148  {
149  $expressions = array();
150 
151  require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php';
152  require_once 'Services/Taxonomy/classes/class.ilTaxNodeAssignment.php';
153 
154  foreach($this->getTaxonomyFilters() as $taxId => $taxNodes)
155  {
156  $questionIds = array();
157 
158  $forceBypass = true;
159 
160  foreach($taxNodes as $taxNode)
161  {
162  $forceBypass = false;
163 
164  $taxTree = new ilTaxonomyTree($taxId);
165 
166  $taxNodeAssignment = new ilTaxNodeAssignment('tst', $this->getTestObjId(), 'quest', $taxId);
167 
168  $subNodes = $taxTree->getSubTreeIds($taxNode);
169  $subNodes[] = $taxNode;
170 
171  $taxItems = $taxNodeAssignment->getAssignmentsOfNode($subNodes);
172 
173  foreach($taxItems as $taxItem)
174  {
175  $questionIds[$taxItem['item_id']] = $taxItem['item_id'];
176  }
177  }
178 
179  if( !$forceBypass )
180  {
181  $expressions[] = $this->db->in('question_id', $questionIds, false, 'integer');
182  }
183  }
184 
185  return $expressions;
186  }
187 
188  private function isActiveQuestionType($questionData)
189  {
190  if( !isset($questionData['plugin']) )
191  {
192  return false;
193  }
194 
195  if( !$questionData['plugin'] )
196  {
197  return true;
198  }
199 
200  return $this->pluginAdmin->isActive(IL_COMP_MODULE, 'TestQuestionPool', 'qst', $questionData['type_tag']);
201  }
202 
203  public function resetQuestionList()
204  {
205  $this->questions = array();
206  $this->taxFilters = array();
207 
208  $this->testObjId = -1;
209  $this->testId = -1;
210  $this->poolId = -1;
211 
212  }
213 
214  public function getQuestions()
215  {
216  return array_values($this->questions);
217  }
218 
219  // =================================================================================================================
220 
224  public function rewind()
225  {
226  return reset($this->questions);
227  }
228 
232  public function current()
233  {
234  return current($this->questions);
235  }
236 
240  public function key()
241  {
242  return key($this->questions);
243  }
244 
248  public function next()
249  {
250  return next($this->questions);
251  }
252 
256  public function valid()
257  {
258  return key($this->questions) !== null;
259  }
260 }
Taxonomy node <-> item assignment.
Administration class for plugins.
const IL_COMP_MODULE
Database Wrapper.
Definition: class.ilDB.php:28