ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestRandomQuestionSetSourcePoolDefinitionList.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
17  protected $db = null;
18 
24  protected $testOBJ = null;
25 
29  private $sourcePoolDefinitions = array();
30 
35 
43  {
44  $this->db = $db;
45  $this->testOBJ = $testOBJ;
46  $this->sourcePoolDefinitionFactory = $sourcePoolDefinitionFactory;
47  }
48 
49  public function addDefinition(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition)
50  {
51  $this->sourcePoolDefinitions[ $sourcePoolDefinition->getId() ] = $sourcePoolDefinition;
52  }
53 
54  public function loadDefinitions()
55  {
56  $query = "SELECT * FROM tst_rnd_quest_set_qpls WHERE test_fi = %s ORDER BY sequence_pos ASC";
57  $res = $this->db->queryF($query, array('integer'), array($this->testOBJ->getTestId()));
58 
59  while( $row = $this->db->fetchAssoc($res) )
60  {
61  $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getEmptySourcePoolDefinition();
62 
63  $sourcePoolDefinition->initFromArray($row);
64 
65  $this->addDefinition($sourcePoolDefinition);
66  }
67  }
68 
69  public function saveDefinitions()
70  {
71  foreach($this as $sourcePoolDefinition)
72  {
74  $sourcePoolDefinition->saveToDb();
75  }
76  }
77 
78  public function cloneDefinitionsForTestId($testId)
79  {
80  foreach($this as $definition)
81  {
83  $definition->cloneToDbForTestId($testId);
84  }
85 
86  }
87 
88  public function deleteDefinitions()
89  {
90  $query = "DELETE FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
91  $this->db->manipulateF($query, array('integer'), array($this->testOBJ->getTestId()));
92  }
93 
94  public function reindexPositions()
95  {
96  $positionIndex = array();
97 
98  foreach($this as $definition)
99  {
101  $positionIndex[ $definition->getId() ] = $definition->getSequencePosition();
102  }
103 
104  asort($positionIndex);
105 
106  $i = 1;
107 
108  foreach($positionIndex as $definitionId => $definitionPosition)
109  {
110  $positionIndex[$definitionId] = $i++;
111  }
112 
113  foreach($this as $definition)
114  {
115  $definition->setSequencePosition( $positionIndex[$definition->getId()] );
116  }
117  }
118 
119  public function getNextPosition()
120  {
121  return ( count($this->sourcePoolDefinitions) + 1 );
122  }
123 
124  public function getInvolvedSourcePoolIds()
125  {
126  $involvedSourcePoolIds = array();
127 
128  foreach($this as $definition)
129  {
131  $involvedSourcePoolIds[ $definition->getPoolId() ] = $definition->getPoolId();
132  }
133 
134  return array_values($involvedSourcePoolIds);
135  }
136 
137  public function getQuestionAmount()
138  {
139  $questionAmount = 0;
140 
141  foreach($this as $definition)
142  {
144  $questionAmount += $definition->getQuestionAmount();
145  }
146 
147  return $questionAmount;
148  }
149 
153  public function savedDefinitionsExist()
154  {
155  $query = "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
156  $res = $this->db->queryF($query, array('integer'), array($this->testOBJ->getTestId()));
157 
158  $row = $this->db->fetchAssoc($res);
159 
160  return $row['cnt'] > 0;
161  }
162 
163  public function hasTaxonomyFilters()
164  {
165  foreach($this as $definition)
166  {
168  if( $definition->getMappedFilterTaxId() && $definition->getMappedFilterTaxNodeId() )
169  {
170  return true;
171  }
172  }
173 
174  return false;
175  }
176 
180  public function rewind()
181  {
182  return reset($this->sourcePoolDefinitions);
183  }
184 
188  public function current()
189  {
190  return current($this->sourcePoolDefinitions);
191  }
192 
196  public function key()
197  {
198  return key($this->sourcePoolDefinitions);
199  }
200 
204  public function next()
205  {
206  return next($this->sourcePoolDefinitions);
207  }
208 
212  public function valid()
213  {
214  return key($this->sourcePoolDefinitions) !== null;
215  }
216 }
__construct(ilDB $db, ilObjTest $testOBJ, ilTestRandomQuestionSetSourcePoolDefinitionFactory $sourcePoolDefinitionFactory)
Constructor.
addDefinition(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition)
Database Wrapper.
Definition: class.ilDB.php:28