ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilObjTestDynamicQuestionSetConfig.php
Go to the documentation of this file.
1<?php
2
28{
34 private $sourceQuestionPoolId = null;
35
40
47 private $taxonomyFilterEnabled = null;
48
54 private $orderingTaxonomyId = null;
55
61 public function getSourceQuestionPoolId(): ?int
62 {
64 }
65
72 {
73 $this->sourceQuestionPoolId = (int) $sourceQuestionPoolId;
74 }
75
81 public function getSourceQuestionPoolTitle(): string
82 {
83 return $this->sourceQuestionPoolTitle;
84 }
85
91 public function setSourceQuestionPoolTitle($sourceQuestionPoolTitle)
92 {
93 $this->sourceQuestionPoolTitle = $sourceQuestionPoolTitle;
94 }
95
99 public function isAnswerStatusFilterEnabled(): ?bool
100 {
102 }
103
108 {
109 $this->answerStatusFilterEnabled = $answerStatusFilterEnabled;
110 }
111
117 public function isTaxonomyFilterEnabled(): ?bool
118 {
120 }
121
128 {
129 $this->taxonomyFilterEnabled = (bool) $taxonomyFilterEnabled;
130 }
131
137 public function getOrderingTaxonomyId(): ?int
138 {
140 }
141
148 {
149 $this->orderingTaxonomyId = $orderingTaxonomyId;
150 }
151
158 public function initFromArray($dataArray)
159 {
160 foreach ($dataArray as $field => $value) {
161 switch ($field) {
162 case 'source_qpl_fi': $this->setSourceQuestionPoolId($value); break;
163 case 'source_qpl_title': $this->setSourceQuestionPoolTitle($value); break;
164 case 'answer_filter_enabled': $this->setAnswerStatusFilterEnabled($value); break;
165 case 'tax_filter_enabled': $this->setTaxonomyFilterEnabled($value); break;
166 case 'order_tax': $this->setOrderingTaxonomyId($value); break;
167 }
168 }
169 }
170
176 public function loadFromDb(): bool
177 {
178 $res = $this->db->queryF(
179 "SELECT * FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
180 array('integer'),
181 array($this->testOBJ->getTestId())
182 );
183
184 while ($row = $this->db->fetchAssoc($res)) {
185 $this->initFromArray($row);
186
187 return true;
188 }
189
190 return false;
191 }
192
196 public function saveToDb()
197 {
198 if ($this->dbRecordExists($this->testOBJ->getTestId())) {
199 $this->updateDbRecord($this->testOBJ->getTestId());
200 } else {
201 $this->insertDbRecord($this->testOBJ->getTestId());
202 }
203 }
204
210 public function cloneToDbForTestId($testId)
211 {
212 $this->insertDbRecord($testId);
213 }
214
220 public function deleteFromDb(): bool
221 {
222 $aff = $this->db->manipulateF(
223 "DELETE FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
224 array('integer'),
225 array($this->testOBJ->getTestId())
226 );
227
228 return (bool) $aff;
229 }
230
237 private function dbRecordExists($testId): bool
238 {
239 $res = $this->db->queryF(
240 "SELECT COUNT(*) cnt FROM tst_dyn_quest_set_cfg WHERE test_fi = %s",
241 array('integer'),
242 array($testId)
243 );
244
245 $row = $this->db->fetchAssoc($res);
246
247 return (bool) $row['cnt'];
248 }
249
256 private function updateDbRecord($testId)
257 {
258 $this->db->update(
259 'tst_dyn_quest_set_cfg',
260 array(
261 'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
262 'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
263 'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
264 'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
265 'order_tax' => array('integer', $this->getOrderingTaxonomyId())
266 ),
267 array(
268 'test_fi' => array('integer', $testId)
269 )
270 );
271 }
272
279 private function insertDbRecord($testId)
280 {
281 $this->db->insert('tst_dyn_quest_set_cfg', array(
282 'test_fi' => array('integer', $testId),
283 'source_qpl_fi' => array('integer', $this->getSourceQuestionPoolId()),
284 'source_qpl_title' => array('text', $this->getSourceQuestionPoolTitle()),
285 'answer_filter_enabled' => array('integer', $this->isAnswerStatusFilterEnabled()),
286 'tax_filter_enabled' => array('integer', $this->isTaxonomyFilterEnabled()),
287 'order_tax' => array('integer', $this->getOrderingTaxonomyId())
288 ));
289 }
290
296 public function isQuestionSetConfigured(): bool
297 {
298 return $this->getSourceQuestionPoolId() > 0;
299 }
300
306 public function doesQuestionSetRelatedDataExist(): bool
307 {
308 return $this->isQuestionSetConfigured();
309 }
310
315 public function removeQuestionSetRelatedData(): void
316 {
317 $this->deleteFromDb();
318 }
319
321 {
322 // nothing to do
323 }
324
330 public function cloneQuestionSetRelatedData(ilObjTest $cloneTestOBJ)
331 {
332 $this->loadFromDb();
333 $this->cloneToDbForTestId($cloneTestOBJ->getTestId());
334 }
335
342 {
343 $poolRefs = $this->getSourceQuestionPoolRefIds();
344
345 if (!count($poolRefs)) {
346 $sourceQuestionPoolSummaryString = sprintf(
347 $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_deleted'),
348 $this->getSourceQuestionPoolTitle()
349 );
350
351 return $sourceQuestionPoolSummaryString;
352 }
353
354 foreach ($poolRefs as $refId) {
355 if (!$this->tree->isDeleted($refId)) {
356 $sourceQuestionPoolSummaryString = sprintf(
357 $lng->txt('tst_dynamic_question_set_source_questionpool_summary_string'),
358 $this->getSourceQuestionPoolTitle(),
359 $this->getQuestionPoolPathString($this->getSourceQuestionPoolId()),
360 $this->getSourceQuestionPoolNumQuestions()
361 );
362
363 return $sourceQuestionPoolSummaryString;
364 }
365 }
366
367 $sourceQuestionPoolSummaryString = sprintf(
368 $lng->txt('tst_dyn_quest_set_src_qpl_summary_string_trashed'),
369 $this->getSourceQuestionPoolTitle(),
370 $this->getSourceQuestionPoolNumQuestions()
371 );
372
373 return $sourceQuestionPoolSummaryString;
374 }
375
380 {
381 $query = "
382 SELECT COUNT(*) num from qpl_questions
383 WHERE obj_fi = %s AND original_id IS NULL
384 ";
385
386 $res = $this->db->queryF(
387 $query,
388 array('integer'),
389 array($this->getSourceQuestionPoolId())
390 );
391
392 $row = $this->db->fetchAssoc($res);
393
394 return $row['num'];
395 }
396
397 public function areDepenciesInVulnerableState(): bool
398 {
399 if (!$this->getSourceQuestionPoolId()) {
400 return false;
401 }
402
403 $poolRefs = $this->getSourceQuestionPoolRefIds();
404
405 foreach ($poolRefs as $refId) {
406 if (!$this->tree->isDeleted($refId)) {
407 return false;
408 }
409 }
410
411 return true;
412 }
413
415 {
416 $msg = sprintf(
417 $lng->txt('tst_dyn_quest_set_pool_trashed'),
418 $this->getSourceQuestionPoolTitle()
419 );
420
421 return $msg;
422 }
423
424 public function areDepenciesBroken(): bool
425 {
426 if (!$this->getSourceQuestionPoolId()) {
427 return false;
428 }
429
430 $poolRefs = $this->getSourceQuestionPoolRefIds();
431
432 if (count($poolRefs)) {
433 return false;
434 }
435
436 return true;
437 }
438
440 {
441 $msg = sprintf(
442 $lng->txt('tst_dyn_quest_set_pool_deleted'),
443 $this->getSourceQuestionPoolTitle()
444 );
445
446 return $msg;
447 }
448
449 public function isValidRequestOnBrokenQuestionSetDepencies($nextClass, $cmd): bool
450 {
451 //vd($nextClass, $cmd);
452
453 if (!$this->testOBJ->participantDataExist()) {
454 return true;
455 }
456
457 switch ($nextClass) {
458 case 'ilobjtestdynamicquestionsetconfiggui':
459
460 case 'ilobjectmetadatagui':
461 case 'ilpermissiongui':
462
463 return true;
464
465 case 'ilobjtestgui':
466 case '':
467
468 $cmds = array(
469 'infoScreen', 'participants', 'npSetFilter', 'npResetFilter',
470 'deleteAllUserResults', 'confirmDeleteAllUserResults',
471 'deleteSingleUserResults', 'confirmDeleteSelectedUserData', 'cancelDeleteSelectedUserData'
472 );
473
474 if (in_array($cmd, $cmds)) {
475 return true;
476 }
477
478 break;
479 }
480
481 return false;
482 }
483
484 public function getHiddenTabsOnBrokenDepencies(): array
485 {
486 return array(
487 'settings', 'manscoring', 'scoringadjust', 'statistics', 'history', 'export'
488 );
489 }
490
492
493 public function getSourceQuestionPoolRefIds(): array
494 {
495 if ($this->sourceQuestionPoolRefIds === null) {
496 $this->sourceQuestionPoolRefIds = ilObject::_getAllReferences($this->getSourceQuestionPoolId());
497 }
498
500 }
501
502 public function isResultTaxonomyFilterSupported(): bool
503 {
504 return false;
505 }
506
507 public function isAnyQuestionFilterEnabled(): bool
508 {
509 if ($this->isTaxonomyFilterEnabled()) {
510 return true;
511 }
512
513 if ($this->isAnswerStatusFilterEnabled()) {
514 return true;
515 }
516
517 return false;
518 }
519
520 public function getSourceQuestionPoolLink(): string
521 {
523 $href = ilLink::_getLink($refId, 'qpl');
524 $title = $this->getSourceQuestionPoolTitle();
525
526 return "<a href=\"$href\" alt=\"$title\">$title</a>";
527 }
528}
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(int $id)
get all reference ids for object ID
$res
Definition: ltiservices.php:69
$query
$lng
$refId
Definition: xapitoken.php:58