ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $definitionIdMap = array();
81
82 foreach($this as $definition)
83 {
86 $originalId = $definition->getId();
87 $definition->cloneToDbForTestId($testId);
88 $cloneId = $definition->getId();
89
90 $definitionIdMap[$originalId] = $cloneId;
91 }
92
93 return $definitionIdMap;
94 }
95
96 public function deleteDefinitions()
97 {
98 $query = "DELETE FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
99 $this->db->manipulateF($query, array('integer'), array($this->testOBJ->getTestId()));
100 }
101
102 public function reindexPositions()
103 {
104 $positionIndex = array();
105
106 foreach($this as $definition)
107 {
109 $positionIndex[ $definition->getId() ] = $definition->getSequencePosition();
110 }
111
112 asort($positionIndex);
113
114 $i = 1;
115
116 foreach($positionIndex as $definitionId => $definitionPosition)
117 {
118 $positionIndex[$definitionId] = $i++;
119 }
120
121 foreach($this as $definition)
122 {
123 $definition->setSequencePosition( $positionIndex[$definition->getId()] );
124 }
125 }
126
127 public function getNextPosition()
128 {
129 return ( count($this->sourcePoolDefinitions) + 1 );
130 }
131
132 public function getInvolvedSourcePoolIds()
133 {
134 $involvedSourcePoolIds = array();
135
136 foreach($this as $definition)
137 {
139 $involvedSourcePoolIds[ $definition->getPoolId() ] = $definition->getPoolId();
140 }
141
142 return array_values($involvedSourcePoolIds);
143 }
144
145 public function getQuestionAmount()
146 {
147 $questionAmount = 0;
148
149 foreach($this as $definition)
150 {
152 $questionAmount += $definition->getQuestionAmount();
153 }
154
155 return $questionAmount;
156 }
157
161 public function savedDefinitionsExist()
162 {
163 $query = "SELECT COUNT(*) cnt FROM tst_rnd_quest_set_qpls WHERE test_fi = %s";
164 $res = $this->db->queryF($query, array('integer'), array($this->testOBJ->getTestId()));
165
166 $row = $this->db->fetchAssoc($res);
167
168 return $row['cnt'] > 0;
169 }
170
171 public function hasTaxonomyFilters()
172 {
173 foreach($this as $definition)
174 {
176 if( $definition->getMappedFilterTaxId() && $definition->getMappedFilterTaxNodeId() )
177 {
178 return true;
179 }
180 }
181
182 return false;
183 }
184
188 public function rewind()
189 {
190 return reset($this->sourcePoolDefinitions);
191 }
192
196 public function current()
197 {
198 return current($this->sourcePoolDefinitions);
199 }
200
204 public function key()
205 {
206 return key($this->sourcePoolDefinitions);
207 }
208
212 public function next()
213 {
214 return next($this->sourcePoolDefinitions);
215 }
216
220 public function valid()
221 {
222 return key($this->sourcePoolDefinitions) !== null;
223 }
224}
Database Wrapper.
Definition: class.ilDB.php:29
__construct(ilDB $db, ilObjTest $testOBJ, ilTestRandomQuestionSetSourcePoolDefinitionFactory $sourcePoolDefinitionFactory)
Constructor.
addDefinition(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition)