ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilLOSettings.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
14
15 const QT_VISIBLE_ALL = 0;
17
18
19 const LOC_INITIAL_ALL = 1;
20 const LOC_INITIAL_SEL = 2;
21 const LOC_QUALIFIED = 3;
22 const LOC_PRACTISE = 4;
23
24
25 private static $instances = array();
26
27 private $container_id = 0;
28 private $type = 0;
29 private $initial_test = 0;
30 private $qualified_test = 0;
31 private $qt_visible_all = true;
32 private $qt_visible_lo = false;
33 private $reset_results = true;
34
35
36 private $entry_exists = false;
37
38
43 protected function __construct($a_cont_id)
44 {
45 $this->container_id = $a_cont_id;
46 $this->read();
47 }
48
54 public static function getInstanceByObjId($a_obj_id)
55 {
56 if(self::$instances[$a_obj_id])
57 {
58 return self::$instances[$a_obj_id];
59 }
60 return self::$instances[$a_obj_id] = new ilLOSettings($a_obj_id);
61 }
62
67 public static function isObjectiveTest($a_trst_ref_id)
68 {
69 global $ilDB;
70
71 $query = 'SELECT obj_id FROM loc_settings '.
72 'WHERE itest = '.$ilDB->quote($a_trst_ref_id,'integer').' '.
73 'OR qtest = '.$ilDB->quote($a_trst_ref_id,'integer');
74 $res = $ilDB->query($query);
75 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
76 {
77 return $row->obj_id;
78 }
79 return 0;
80 }
81
88 public static function cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
89 {
90 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
92 $mappings = $options->getMappings();
93
94 $settings = self::getInstanceByObjId($a_container_id);
95 $new_settings = self::getInstanceByObjId($a_new_container_id);
96
97 $new_settings->setType($settings->getType());
98 $new_settings->setGeneralQualifiedTestVisibility($settings->isGeneralQualifiedTestVisible());
99 $new_settings->setQualifiedTestPerObjectiveVisibility($settings->isQualifiedTestPerObjectiveVisible());
100 $new_settings->resetResults($settings->isResetResultsEnabled());
101
102 if($settings->getInitialTest() and array_key_exists($settings->getInitialTest(), $mappings))
103 {
104 $new_settings->setInitialTest($mappings[$settings->getInitialTest()]);
105 }
106
107 if($settings->getQualifiedTest() and array_key_exists($settings->getQualifiedTest(), $mappings))
108 {
109 $new_settings->setQualifiedTest($mappings[$settings->getQualifiedTest()]);
110 }
111
112 $new_settings->create();
113 }
114
115
119 public function worksWithInitialTest()
120 {
121 return
122 ($this->getType() == self::LOC_INITIAL_ALL) or
123 ($this->getType() == self::LOC_INITIAL_SEL)
124 ;
125 }
126
132 {
134 }
135
140 public function setGeneralQualifiedTestVisibility($a_stat)
141 {
142 $this->qt_visible_all = $a_stat;
143 return true;
144 }
145
147 {
149 }
150
152 {
153 $this->qt_visible_lo = $a_stat;
154 }
155
160 public function settingsExist()
161 {
162 return $this->entry_exists;
163 }
164
165 public function getObjId()
166 {
167 return $this->container_id;
168 }
169
170 public function setType($a_type)
171 {
172 $this->type = $a_type;
173 }
174
175 public function getType()
176 {
177 return $this->type;
178 }
179
180
181 public function getTestByType($a_type)
182 {
183 switch($a_type)
184 {
186 return $this->getInitialTest();
187
189 return $this->getQualifiedTest();
190 }
191 }
192
197 public function getTests()
198 {
199 $tests = array();
200 if($this->getInitialTest())
201 {
202 $tests[] = $this->getInitialTest();
203 }
204 if($this->getQualifiedTest())
205 {
206 $tests[] = $this->getQualifiedTest();
207 }
208 return $tests;
209 }
210
216 public function isRandomTestType($a_type)
217 {
218 $tst = $this->getTestByType($a_type);
219 include_once './Modules/Test/classes/class.ilObjTest.php';
221 }
222
227 public function setInitialTest($a_id)
228 {
229 $this->initial_test = $a_id;
230 }
231
232 public function getInitialTest()
233 {
234 return $this->initial_test;
235 }
236
237 public function setQualifiedTest($a_id)
238 {
239 $this->qualified_test = $a_id;
240 }
241
242 public function getQualifiedTest()
243 {
245 }
246
247 public function resetResults($a_status)
248 {
249 $this->reset_results = $a_status;
250 }
251
252 public function isResetResultsEnabled()
253 {
254 return (bool) $this->reset_results;
255 }
256
260 public function create()
261 {
262 global $ilDB;
263
264 $query = 'INSERT INTO loc_settings '.
265 '(obj_id, type,itest,qtest,qt_vis_all,qt_vis_obj,reset_results) VALUES ( '.
266 $ilDB->quote($this->getObjId(),'integer').', '.
267 $ilDB->quote($this->getType(),'integer').', '.
268 $ilDB->quote($this->getInitialTest(),'integer').', '.
269 $ilDB->quote($this->getQualifiedTest(),'integer').', '.
270 $ilDB->quote($this->isGeneralQualifiedTestVisible(),'integer').', '.
271 $ilDB->quote($this->isQualifiedTestPerObjectiveVisible(),'integer').', '.
272 $ilDB->quote($this->isResetResultsEnabled(),'integer').' '.
273 ') ';
274 $ilDB->manipulate($query);
275 }
276
277
282 public function update()
283 {
284 global $ilDB;
285
286 if(!$this->entry_exists)
287 {
288 return $this->create();
289 }
290
291 $query = 'UPDATE loc_settings '.' '.
292 'SET type = '.$ilDB->quote($this->getType(),'integer').', '.
293 'itest = '.$ilDB->quote($this->getInitialTest(),'integer').', '.
294 'qtest = '.$ilDB->quote($this->getQualifiedTest(),'integer').', '.
295 'qt_vis_all = '.$ilDB->quote($this->isGeneralQualifiedTestVisible(),'integer').', '.
296 'qt_vis_obj = '.$ilDB->quote($this->isQualifiedTestPerObjectiveVisible(),'integer').', '.
297 'reset_results = '.$ilDB->quote($this->isResetResultsEnabled(),'integer').' '.
298 'WHERE obj_id = '.$ilDB->quote($this->getObjId(),'integer');
299
300 $ilDB->manipulate($query);
301 }
302
310 {
311 switch($this->getType())
312 {
314 if($start->exists($this->getQualifiedTest()))
315 {
316 $start->deleteItem($this->getQualifiedTest());
317 }
318 if(!$start->exists($this->getInitialTest()))
319 {
320 $start->add($this->getInitialTest());
321 }
322 break;
323
326 if($start->exists($this->getQualifiedTest()))
327 {
328 $start->deleteItem($this->getQualifiedTest());
329 }
330 if($start->exists($this->getInitialTest()))
331 {
332 $start->deleteItem($this->getInitialTest());
333 }
334 break;
335
337 if(!$start->exists($this->getQualifiedTest()))
338 {
339 $start->add($this->getQualifiedTest());
340 }
341 if($start->exists($this->getInitialTest()))
342 {
343 $start->deleteItem($this->getInitialTest());
344 }
345 break;
346 }
347 return true;
348 }
349
350
354 protected function read()
355 {
356 global $ilDB;
357
358 $query = 'SELECT * FROM loc_settings '.
359 'WHERE obj_id = '.$ilDB->quote($this->getObjId(),'integer');
360 $res = $ilDB->query($query);
361 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
362 {
363 $this->entry_exists = true;
364 $this->setType($row->type);
365 $this->setInitialTest($row->itest);
366 $this->setQualifiedTest($row->qtest);
367 #$this->setGeneralQualifiedTestVisibility($row->qt_vis_all);
369 $this->resetResults($row->reset_results);
370 }
371
372
373 if($GLOBALS['tree']->isDeleted($this->getInitialTest()))
374 {
375 $this->setInitialTest(0);
376 }
377 if($GLOBALS['tree']->isDeleted($this->getQualifiedTest()))
378 {
379 $this->setQualifiedTest(0);
380 }
381 }
382}
383?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
deleteItem($a_item_ref_id)
Delete item by ref_id.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Settings for LO courses.
getTests()
Get assigned tests.
setQualifiedTestPerObjectiveVisibility($a_stat)
update()
update settings @global type $ilDB
setGeneralQualifiedTestVisibility($a_stat)
Check if qualified test for all objectives is visible.
isRandomTestType($a_type)
Check if test is of type random test.
setInitialTest($a_id)
set initial test id
updateStartObjects(ilContainerStartObjects $start)
Update start objects Depends on course objective settings.
resetResults($a_status)
worksWithInitialTest()
Check if the loc is configured for initial tests.
__construct($a_cont_id)
Constructor.
static cloneSettings($a_copy_id, $a_container_id, $a_new_container_id)
Clone settings.
static isObjectiveTest($a_trst_ref_id)
Check if test ref_id is used in an objective course.
static getInstanceByObjId($a_obj_id)
get singleton instance
create()
Create new entry.
isGeneralQualifiedTestVisible()
Check if qualified test for all objectives is visible.
static _lookupRandomTest($a_obj_id)
Returns the fact wether the test with passed obj id is a random questions test or not.
static _lookupObjId($a_id)
$GLOBALS['ct_recipient']
global $ilDB
if(!is_array($argv)) $options