ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLORandomTestQuestionPools.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
5 include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
6 
16 {
17  protected $container_id = 0;
18  protected $objective_id = 0;
19  protected $test_type = 0;
20  protected $test_id = 0;
21  protected $qpl_seq = 0;
22  protected $limit = 50;
23 
24 
30  public function __construct($a_container_id, $a_objective_id, $a_test_type)
31  {
32  $this->container_id = $a_container_id;
33  $this->objective_id = $a_objective_id;
34  $this->test_type = $a_test_type;
35 
36  $this->read();
37  }
38 
39  public static function lookupLimit($a_container_id, $a_objective_id, $a_test_type)
40  {
41  global $ilDB;
42 
43  $query = 'SELECT * FROM loc_rnd_qpl '.
44  'WHERE container_id = '.$ilDB->quote($a_container_id,'integer').' '.
45  'AND objective_id = '.$ilDB->quote($a_objective_id,'integer').' '.
46  'AND tst_type = '.$ilDB->quote($a_test_type,'integer');
47  $res = $ilDB->query($query);
48  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
49  {
50  return $row->percentage;
51  }
52  return 0;
53  }
54 
55  public static function lookupSequence($a_container_id, $a_objective_id, $a_test_id)
56  {
57  global $ilDB;
58 
59  $query = 'SELECT * FROM loc_rnd_qpl '.
60  'WHERE container_id = '.$ilDB->quote($a_container_id,'integer').' '.
61  'AND objective_id = '.$ilDB->quote($a_objective_id,'integer').' '.
62  'AND tst_id = '.$ilDB->quote($a_test_id,'integer');
63  $res = $ilDB->query($query);
64  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
65  {
66  return $row->qp_seq;
67  }
68  return 0;
69 
70  }
71 
75  public static function lookupObjectiveIdsBySequence($a_container_id, $a_seq_id)
76  {
77  global $ilDB;
78 
79  $query = 'SELECT objective_id FROM loc_rnd_qpl '.
80  'WHERE container_id = '.$ilDB->quote($a_container_id,'integer').' '.
81  'AND qp_seq = '.$ilDB->quote($a_seq_id,'integer');
82  $res = $ilDB->query($query);
83  $objectiveIds = array();
84  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
85  {
86  $objectiveIds[] = $row->objective_id;
87  }
88  return $objectiveIds;
89  }
90 
91 
92  public function setContainerId($a_id)
93  {
94  $this->container_id = $a_id;
95  }
96 
97  public function getContainerId()
98  {
99  return $this->container_id;
100  }
101 
102  public function setObjectiveId($a_id)
103  {
104  $this->objective_id = $a_id;
105  }
106 
107  public function getObjectiveId()
108  {
109  return $this->objective_id;
110  }
111 
112  public function setTestType($a_type)
113  {
114  $this->test_type = $a_type;
115  }
116 
117  public function getTestType()
118  {
119  return $this->test_type;
120  }
121 
122  public function setTestId($a_id)
123  {
124  $this->test_id = $a_id;
125  }
126 
127  public function getTestId()
128  {
129  return $this->test_id;
130  }
131 
132  public function setQplSequence($a_id)
133  {
134  $this->qpl_seq = $a_id;
135  }
136 
137  public function getQplSequence()
138  {
139  return $this->qpl_seq;
140  }
141 
142  public function setLimit($a_id)
143  {
144  $this->limit = $a_id;
145  }
146 
147  public function getLimit()
148  {
149  return $this->limit;
150  }
151 
157  public function copy($a_copy_id, $a_new_course_id, $a_new_objective_id)
158  {
159  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
161  $mappings = $options->getMappings();
162 
163  $new_ass = new self(
164  $a_new_course_id,
165  $a_new_objective_id,
166  $this->getTestType()
167  );
168  $new_ass->setLimit($this->getLimit());
169 
170  $mapped_id = 0;
171  $test_ref_id = 0;
172  foreach((array) ilObject::_getAllReferences($this->getTestId()) as $tmp => $ref_id)
173  {
174  ilLoggerFactory::getLogger('crs')->debug($tmp .' ' . $ref_id);
175  $test_ref_id = $ref_id;
176  $mapped_id = $mappings[$ref_id];
177  if($mapped_id)
178  {
179  continue;
180  }
181  }
182 
183  if(!$mapped_id)
184  {
185  ilLoggerFactory::getLogger('crs')->debug('No test mapping found for random question pool assignment: ' . $this->getTestId());
186  return FALSE;
187  }
188  $new_ass->setTestId($mapped_id);
189 
190  // Mapping for sequence
191  $new_question_info = $mappings[$test_ref_id.'_rndSelDef_'.$this->getQplSequence()];
192  $new_question_arr = explode('_',$new_question_info);
193  if(!isset($new_question_arr[2]) or !$new_question_arr[2])
194  {
195  ilLoggerFactory::getLogger('crs')->debug(print_r($mappings,TRUE));
196  ilLoggerFactory::getLogger('crs')->debug('Found invalid or no mapping format of random question id mapping: ' . print_r($new_question_arr,TRUE));
197  return FALSE;
198  }
199 
200  $new_ass->setQplSequence($new_question_arr[2]);
201  $new_ass->create();
202  }
203 
204 
205  public function read()
206  {
207  global $ilDB;
208 
209  $query = 'SELECT * FROM loc_rnd_qpl '.
210  'WHERE container_id = '.$ilDB->quote($this->getContainerId(),'integer').' '.
211  'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' '.
212  'AND tst_type = '.$ilDB->quote($this->getTestType(),'integer');
213 
214  $res = $ilDB->query($query);
215  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
216  {
217  $this->setLimit($row->percentage);
218  $this->setTestId($row->tst_id);
219  $this->setQplSequence($row->qp_seq);
220  }
221  return true;
222  }
223 
224  public function delete()
225  {
226  global $ilDB;
227 
228  $query = 'DELETE FROM loc_rnd_qpl '.
229  'WHERE container_id = '.$ilDB->quote($this->getContainerId(),'integer').' '.
230  'AND objective_id = '.$ilDB->quote($this->getObjectiveId(),'integer').' '.
231  'AND tst_type = '.$ilDB->quote($this->getTestType(),'integer');
232  $ilDB->manipulate($query);
233  }
234 
235  public function create()
236  {
237  global $ilDB;
238 
239  $query = 'INSERT INTO loc_rnd_qpl ' .
240  '(container_id, objective_id, tst_type, tst_id, qp_seq, percentage) '.
241  'VALUES ( '.
242  $ilDB->quote($this->getContainerId(),'integer').', '.
243  $ilDB->quote($this->getObjectiveId(),'integer').', '.
244  $ilDB->quote($this->getTestType(),'integer').', '.
245  $ilDB->quote($this->getTestId(),'integer').', '.
246  $ilDB->quote($this->getQplSequence(),'integer').', '.
247  $ilDB->quote($this->getLimit()).' '.
248  ')';
249  $ilDB->manipulate($query);
250  }
251 
252  // begin-patch optes_lok_export
253  public static function toXml(ilXmlWriter $writer, $a_objective_id)
254  {
255  global $ilDB;
256 
257  $query = 'SELECT * FROM loc_rnd_qpl '.
258  'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer');
259  $res = $ilDB->query($query);
260  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
261  {
262  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
263  $writer->xmlElement(
264  'Test',
265  array(
266  'type' => ilLOXmlWriter::TYPE_TST_RND,
267  'objId' => $row->tst_id,
268  'testType' => $row->tst_type,
269  'limit' => $row->percentage,
270  'poolId' => $row->qp_seq
271  )
272  );
273  }
274  }
275  // end-patch optes_lok_export
276 }
277 ?>
static toXml(ilXmlWriter $writer, $a_objective_id)
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
__construct($a_container_id, $a_objective_id, $a_test_type)
Constructor.
static _getAllReferences($a_id)
get all reference ids of object
$a_type
Definition: workflow.php:93
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static lookupSequence($a_container_id, $a_objective_id, $a_test_id)
if(!is_array($argv)) $options
Create styles array
The data for the language used.
static lookupObjectiveIdsBySequence($a_container_id, $a_seq_id)
Lookup objective id by sequence.
$ref_id
Definition: sahs_server.php:39
global $ilDB
copy($a_copy_id, $a_new_course_id, $a_new_objective_id)
Copy assignment.
static getLogger($a_component_id)
Get component logger.
static lookupLimit($a_container_id, $a_objective_id, $a_test_type)