ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
47
53 public function getSourceQuestionPoolId()
54 {
56 }
57
64 {
65 $this->sourceQuestionPoolId = (int)$sourceQuestionPoolId;
66 }
67
74 {
75 return $this->sourceQuestionPoolTitle;
76 }
77
83 public function setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
84 {
85 $this->sourceQuestionPoolTitle = $sourceQuestionPoolTitle;
86 }
87
92 {
94 }
95
100 {
101 $this->answerStatusFilterEnabled = $answerStatusFilterEnabled;
102 }
103
109 public function isTaxonomyFilterEnabled()
110 {
112 }
113
120 {
121 $this->taxonomyFilterEnabled = (bool)$taxonomyFilterEnabled;
122 }
123
129 public function getOrderingTaxonomyId()
130 {
132 }
133
140 {
141 $this->orderingTaxonomyId = $orderingTaxonomyId;
142 }
143
148 {
150 }
151
156 {
157 $this->previousQuestionsListEnabled = $previousQuestionsListEnabled;
158 }
159
166 public function initFromArray($dataArray)
167 {
168 foreach($dataArray as $field => $value)
169 {
170 switch($field)
171 {
172 case 'source_qpl_fi': $this->setSourceQuestionPoolId($value); break;
173 case 'source_qpl_title': $this->setSourceQuestionPoolTitle($value); break;
174 case 'answer_filter_enabled': $this->setAnswerStatusFilterEnabled($value); break;
175 case 'tax_filter_enabled': $this->setTaxonomyFilterEnabled($value); break;
176 case 'order_tax': $this->setOrderingTaxonomyId($value); break;
177 case 'prev_quest_list_enabled': $this->setPreviousQuestionsListEnabled($value); break;
178 }
179 }
180 }
181
187 public function loadFromDb()
188 {
189 $res = $this->db->queryF(
190 "SELECT * FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
191 array('integer'), array($this->testOBJ->getTestId())
192 );
193
194 while( $row = $this->db->fetchAssoc($res) )
195 {
196 $this->initFromArray($row);
197
198 return true;
199 }
200
201 return false;
202 }
203
207 public function saveToDb()
208 {
209 if( $this->dbRecordExists($this->testOBJ->getTestId()) )
210 {
211 $this->updateDbRecord($this->testOBJ->getTestId());
212 }
213 else
214 {
215 $this->insertDbRecord($this->testOBJ->getTestId());
216 }
217 }
218
224 public function cloneToDbForTestId($testId)
225 {
226 $this->insertDbRecord($testId);
227 }
228
234 public function deleteFromDb()
235 {
236 $aff = $this->db->manipulateF(
237 "DELETE FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
238 array('integer'), array($this->testOBJ->getTestId())
239 );
240
241 return (bool)$aff;
242 }
243
250 private function dbRecordExists($testId)
251 {
252 $res = $this->db->queryF(
253 "SELECT COUNT(*) cnt FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
254 array('integer'), array($testId)
255 );
256
257 $row = $this->db->fetchAssoc($res);
258
259 return (bool)$row['cnt'];
260 }
261
268 private function updateDbRecord($testId)
269 {
270 $this->db->update('tst_dyn_quest_set_cfg',
271 array(
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 'prev_quest_list_enabled' => array('integer', $this->isPreviousQuestionsListEnabled())
278 ),
279 array(
280 'test_fi' => array('integer', $testId)
281 )
282 );
283 }
284
291 private function insertDbRecord($testId)
292 {
293 $this->db->insert('tst_dyn_quest_set_cfg', array(
294 'test_fi' => array('integer', $testId),
295 'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
296 'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
297 'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
298 'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
299 'order_tax' => array('integer', $this->getOrderingTaxonomyId()),
300 'prev_quest_list_enabled' => array('integer', $this->isPreviousQuestionsListEnabled())
301 ));
302 }
303
309 public function isQuestionSetConfigured()
310 {
311 return $this->getSourceQuestionPoolId() > 0;
312 }
313
320 {
321 return $this->isQuestionSetConfigured();
322 }
323
329 {
330 $this->deleteFromDb();
331 }
332
334 {
335 // nothing to do
336 }
337
343 public function cloneQuestionSetRelatedData($cloneTestOBJ)
344 {
345 $this->loadFromDb();
346 $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
347 }
348
355 {
356 $poolRefs = $this->getSourceQuestionPoolRefIds();
357
358 if( !count($poolRefs) )
359 {
360 $sourceQuestionPoolSummaryString = sprintf(
361 $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_deleted'),
362 $this->getSourceQuestionPoolTitle()
363 );
364
365 return $sourceQuestionPoolSummaryString;
366 }
367
368 foreach($poolRefs as $refId)
369 {
370 if( !$this->tree->isDeleted($refId) )
371 {
372 $sourceQuestionPoolSummaryString = sprintf(
373 $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
374 $this->getSourceQuestionPoolTitle(),
375 $this->getQuestionPoolPathString($this->getSourceQuestionPoolId()),
376 $this->getSourceQuestionPoolNumQuestions()
377 );
378
379 return $sourceQuestionPoolSummaryString;
380 }
381 }
382
383 $sourceQuestionPoolSummaryString = sprintf(
384 $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_trashed'),
385 $this->getSourceQuestionPoolTitle(),
386 $this->getSourceQuestionPoolNumQuestions()
387 );
388
389 return $sourceQuestionPoolSummaryString;
390 }
391
396 {
397 $query = "
398 SELECT COUNT(*) num from qpl_questions
399 WHERE obj_fi = %s AND original_id IS NULL
400 ";
401
402 $res = $this->db->queryF(
403 $query, array('integer'), array($this->getSourceQuestionPoolId())
404 );
405
406 $row = $this->db->fetchAssoc($res);
407
408 return $row['num'];
409 }
410
412 {
413 if( !$this->getSourceQuestionPoolId() )
414 {
415 return false;
416 }
417
418 $poolRefs = $this->getSourceQuestionPoolRefIds();
419
420 foreach( $poolRefs as $refId )
421 {
422 if( !$this->tree->isDeleted($refId) )
423 {
424 return false;
425 }
426 }
427
428 return true;
429 }
430
432 {
433 $msg = sprintf(
434 $lng->txt('tst_dyn_quest_set_pool_trashed'), $this->getSourceQuestionPoolTitle()
435 );
436
437 return $msg;
438 }
439
440 public function areDepenciesBroken()
441 {
442 if( !$this->getSourceQuestionPoolId() )
443 {
444 return false;
445 }
446
447 $poolRefs = $this->getSourceQuestionPoolRefIds();
448
449 if( count($poolRefs) )
450 {
451 return false;
452 }
453
454 return true;
455 }
456
458 {
459 $msg = sprintf(
460 $lng->txt('tst_dyn_quest_set_pool_deleted'), $this->getSourceQuestionPoolTitle()
461 );
462
463 return $msg;
464 }
465
467 {
468 //vd($nextClass, $cmd);
469
470 if( !$this->testOBJ->participantDataExist() )
471 {
472 return true;
473 }
474
475 switch( $nextClass )
476 {
477 case 'ilobjtestdynamicquestionsetconfiggui':
478
479 case 'ilmdeditorgui':
480 case 'ilpermissiongui':
481
482 return true;
483
484 case 'ilobjtestgui':
485 case '':
486
487 $cmds = array(
488 'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
489 'deleteAllUserResults', 'confirmDeleteAllUserResults',
490 'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
491 );
492
493 if( in_array($cmd, $cmds) )
494 {
495 return true;
496 }
497
498 break;
499 }
500
501 return false;
502 }
503
505 {
506 return array(
507 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
508 );
509 }
510
512
514 {
515 if( $this->sourceQuestionPoolRefIds === null )
516 {
517 $this->sourceQuestionPoolRefIds = ilObject::_getAllReferences($this->getSourceQuestionPoolId());
518 }
519
521 }
522
527 public static function getPoolQuestionChangeListener(ilDB $db, $poolObjId)
528 {
529 $query = "
530 SELECT obj_fi
531 FROM tst_dyn_quest_set_cfg
532 INNER JOIN tst_tests
533 ON tst_tests.test_id = tst_dyn_quest_set_cfg.test_fi
534 WHERE source_qpl_fi = %s
535 ";
536
537 $res = $db->queryF($query, array('integer'), array($poolObjId));
538
539 require_once 'Modules/Test/classes/class.ilDynamicTestQuestionChangeListener.php';
540 $questionChangeListener = new ilDynamicTestQuestionChangeListener($db);
541
542 while( $row = $db->fetchAssoc($res) )
543 {
544 $questionChangeListener->addTestObjId( $row['obj_fi'] );
545 }
546
547 return $questionChangeListener;
548 }
549
551 {
552 return false;
553 }
554
556 {
557 if( $this->isTaxonomyFilterEnabled() )
558 {
559 return true;
560 }
561
562 if( $this->isAnswerStatusFilterEnabled() )
563 {
564 return true;
565 }
566
567 return false;
568 }
569}
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
cloneQuestionSetRelatedData($cloneTestOBJ)
removes all question set config related data for cloned/copied test
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
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)
static _getAllReferences($a_id)
get all reference ids of object
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35