ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilObjTestDynamicQuestionSetConfig.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilTestQuestionSetConfig.php';
5
15{
21 private $sourceQuestionPoolId = null;
22
27
34 private $taxonomyFilterEnabled = null;
35
41 private $orderingTaxonomyId = null;
42
48 public function getSourceQuestionPoolId()
49 {
51 }
52
59 {
60 $this->sourceQuestionPoolId = (int)$sourceQuestionPoolId;
61 }
62
69 {
70 return $this->sourceQuestionPoolTitle;
71 }
72
78 public function setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
79 {
80 $this->sourceQuestionPoolTitle = $sourceQuestionPoolTitle;
81 }
82
87 {
89 }
90
95 {
96 $this->answerStatusFilterEnabled = $answerStatusFilterEnabled;
97 }
98
104 public function isTaxonomyFilterEnabled()
105 {
107 }
108
115 {
116 $this->taxonomyFilterEnabled = (bool)$taxonomyFilterEnabled;
117 }
118
124 public function getOrderingTaxonomyId()
125 {
127 }
128
135 {
136 $this->orderingTaxonomyId = $orderingTaxonomyId;
137 }
138
145 public function initFromArray($dataArray)
146 {
147 foreach($dataArray as $field => $value)
148 {
149 switch($field)
150 {
151 case 'source_qpl_fi': $this->setSourceQuestionPoolId($value); break;
152 case 'source_qpl_title': $this->setSourceQuestionPoolTitle($value); break;
153 case 'answer_filter_enabled': $this->setAnswerStatusFilterEnabled($value); break;
154 case 'tax_filter_enabled': $this->setTaxonomyFilterEnabled($value); break;
155 case 'order_tax': $this->setOrderingTaxonomyId($value); break;
156 }
157 }
158 }
159
165 public function loadFromDb()
166 {
167 $res = $this->db->queryF(
168 "SELECT * FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
169 array('integer'), array($this->testOBJ->getTestId())
170 );
171
172 while( $row = $this->db->fetchAssoc($res) )
173 {
174 $this->initFromArray($row);
175
176 return true;
177 }
178
179 return false;
180 }
181
185 public function saveToDb()
186 {
187 if( $this->dbRecordExists($this->testOBJ->getTestId()) )
188 {
189 $this->updateDbRecord($this->testOBJ->getTestId());
190 }
191 else
192 {
193 $this->insertDbRecord($this->testOBJ->getTestId());
194 }
195 }
196
202 public function cloneToDbForTestId($testId)
203 {
204 $this->insertDbRecord($testId);
205 }
206
212 public function deleteFromDb()
213 {
214 $aff = $this->db->manipulateF(
215 "DELETE FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
216 array('integer'), array($this->testOBJ->getTestId())
217 );
218
219 return (bool)$aff;
220 }
221
228 private function dbRecordExists($testId)
229 {
230 $res = $this->db->queryF(
231 "SELECT COUNT(*) cnt FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
232 array('integer'), array($testId)
233 );
234
235 $row = $this->db->fetchAssoc($res);
236
237 return (bool)$row['cnt'];
238 }
239
246 private function updateDbRecord($testId)
247 {
248 $this->db->update('tst_dyn_quest_set_cfg',
249 array(
250 'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
251 'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
252 'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
253 'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
254 'order_tax' => array('integer', $this->getOrderingTaxonomyId())
255 ),
256 array(
257 'test_fi' => array('integer', $testId)
258 )
259 );
260 }
261
268 private function insertDbRecord($testId)
269 {
270 $this->db->insert('tst_dyn_quest_set_cfg', array(
271 'test_fi' => array('integer', $testId),
272 'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
273 'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
274 'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
275 'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
276 'order_tax' => array('integer', $this->getOrderingTaxonomyId())
277 ));
278 }
279
285 public function isQuestionSetConfigured()
286 {
287 return $this->getSourceQuestionPoolId() > 0;
288 }
289
296 {
297 return $this->isQuestionSetConfigured();
298 }
299
305 {
306 $this->deleteFromDb();
307 }
308
310 {
311 // nothing to do
312 }
313
319 public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
320 {
321 $this->loadFromDb();
322 $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
323 }
324
331 {
332 $poolRefs = $this->getSourceQuestionPoolRefIds();
333
334 if( !count($poolRefs) )
335 {
336 $sourceQuestionPoolSummaryString = sprintf(
337 $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_deleted'),
338 $this->getSourceQuestionPoolTitle()
339 );
340
341 return $sourceQuestionPoolSummaryString;
342 }
343
344 foreach($poolRefs as $refId)
345 {
346 if( !$this->tree->isDeleted($refId) )
347 {
348 $sourceQuestionPoolSummaryString = sprintf(
349 $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
350 $this->getSourceQuestionPoolTitle(),
351 $this->getQuestionPoolPathString($this->getSourceQuestionPoolId()),
352 $this->getSourceQuestionPoolNumQuestions()
353 );
354
355 return $sourceQuestionPoolSummaryString;
356 }
357 }
358
359 $sourceQuestionPoolSummaryString = sprintf(
360 $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_trashed'),
361 $this->getSourceQuestionPoolTitle(),
362 $this->getSourceQuestionPoolNumQuestions()
363 );
364
365 return $sourceQuestionPoolSummaryString;
366 }
367
372 {
373 $query = "
374 SELECT COUNT(*) num from qpl_questions
375 WHERE obj_fi = %s AND original_id IS NULL
376 ";
377
378 $res = $this->db->queryF(
379 $query, array('integer'), array($this->getSourceQuestionPoolId())
380 );
381
382 $row = $this->db->fetchAssoc($res);
383
384 return $row['num'];
385 }
386
388 {
389 if( !$this->getSourceQuestionPoolId() )
390 {
391 return false;
392 }
393
394 $poolRefs = $this->getSourceQuestionPoolRefIds();
395
396 foreach( $poolRefs as $refId )
397 {
398 if( !$this->tree->isDeleted($refId) )
399 {
400 return false;
401 }
402 }
403
404 return true;
405 }
406
408 {
409 $msg = sprintf(
410 $lng->txt('tst_dyn_quest_set_pool_trashed'), $this->getSourceQuestionPoolTitle()
411 );
412
413 return $msg;
414 }
415
416 public function areDepenciesBroken()
417 {
418 if( !$this->getSourceQuestionPoolId() )
419 {
420 return false;
421 }
422
423 $poolRefs = $this->getSourceQuestionPoolRefIds();
424
425 if( count($poolRefs) )
426 {
427 return false;
428 }
429
430 return true;
431 }
432
434 {
435 $msg = sprintf(
436 $lng->txt('tst_dyn_quest_set_pool_deleted'), $this->getSourceQuestionPoolTitle()
437 );
438
439 return $msg;
440 }
441
443 {
444 //vd($nextClass, $cmd);
445
446 if( !$this->testOBJ->participantDataExist() )
447 {
448 return true;
449 }
450
451 switch( $nextClass )
452 {
453 case 'ilobjtestdynamicquestionsetconfiggui':
454
455 case 'ilobjectmetadatagui':
456 case 'ilpermissiongui':
457
458 return true;
459
460 case 'ilobjtestgui':
461 case '':
462
463 $cmds = array(
464 'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
465 'deleteAllUserResults', 'confirmDeleteAllUserResults',
466 'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
467 );
468
469 if( in_array($cmd, $cmds) )
470 {
471 return true;
472 }
473
474 break;
475 }
476
477 return false;
478 }
479
481 {
482 return array(
483 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
484 );
485 }
486
488
490 {
491 if( $this->sourceQuestionPoolRefIds === null )
492 {
493 $this->sourceQuestionPoolRefIds = ilObject::_getAllReferences($this->getSourceQuestionPoolId());
494 }
495
497 }
498
503 public static function getPoolQuestionChangeListener(ilDB $db, $poolObjId)
504 {
505 $query = "
506 SELECT obj_fi
507 FROM tst_dyn_quest_set_cfg
508 INNER JOIN tst_tests
509 ON tst_tests.test_id = tst_dyn_quest_set_cfg.test_fi
510 WHERE source_qpl_fi = %s
511 ";
512
513 $res = $db->queryF($query, array('integer'), array($poolObjId));
514
515 require_once 'Modules/Test/classes/class.ilDynamicTestQuestionChangeListener.php';
516 $questionChangeListener = new ilDynamicTestQuestionChangeListener($db);
517
518 while( $row = $db->fetchAssoc($res) )
519 {
520 $questionChangeListener->addTestObjId( $row['obj_fi'] );
521 }
522
523 return $questionChangeListener;
524 }
525
527 {
528 return false;
529 }
530
532 {
533 if( $this->isTaxonomyFilterEnabled() )
534 {
535 return true;
536 }
537
538 if( $this->isAnswerStatusFilterEnabled() )
539 {
540 return true;
541 }
542
543 return false;
544 }
545
547 {
548 $refId = current(ilObject::_getAllReferences($this->getSourceQuestionPoolId()));
549 $href = ilLink::_getLink($refId, 'qpl');
550 $title = $this->getSourceQuestionPoolTitle();
551
552 return "<a href=\"$href\" alt=\"$title\">$title</a>";
553 }
554}
Database Wrapper.
Definition: class.ilDB.php:29
language handling
saveToDb()
saves the question set config for current test to the database
getSourceQuestionPoolId()
getter for source question pool id
insertDbRecord($testId)
inserts a new record for the question set config for the current test into the database
cloneToDbForTestId($testId)
saves the question set config for test with given id to the database
setTaxonomyFilterEnabled($taxonomyFilterEnabled)
setter for taxonomie filter enabled
updateDbRecord($testId)
updates the record in the database that corresponds to the question set config for the current test
setSourceQuestionPoolId($sourceQuestionPoolId)
getter for source question pool id
setOrderingTaxonomyId($orderingTaxonomyId)
getter for ordering taxonomy id
resetQuestionSetRelatedTestSettings()
resets all test settings that depends on a non changed question set config
doesQuestionSetRelatedDataExist()
returns the fact wether a useable question set config exists or not
getSourceQuestionPoolTitle()
getter for source question pool title
setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
getter for source question pool title
isTaxonomyFilterEnabled()
isser for taxonomie filter enabled
isQuestionSetConfigured()
returns the fact wether a useable question set config exists or not
cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
removes all question set config related data for cloned/copied test
loadFromDb()
loads the question set config for current test from the database
initFromArray($dataArray)
initialises the current object instance with values from matching properties within the passed array
dbRecordExists($testId)
checks wether a question set config for current test exists in the database
deleteFromDb()
deletes the question set config for current test from the database
removeQuestionSetRelatedData()
removes all question set config related data (in this case it's only the config itself)
getTestId()
Gets the database id of the additional test data.
static _getAllReferences($a_id)
get all reference ids of object
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35