ILIAS  release_8 Revision v8.24
class.ilAssIncompleteQuestionPurger.php
Go to the documentation of this file.
1<?php
2
26{
30 protected $db;
31
32 protected $ownerId;
33
35
36 public function __construct(ilDBInterface $db)
37 {
38 $this->db = $db;
39
40 $this->ignoredContainerObjectTypes = array('lm');
41 }
42
43 public function getOwnerId()
44 {
45 return $this->ownerId;
46 }
47
48 public function setOwnerId($ownerId): void
49 {
50 $this->ownerId = $ownerId;
51 }
52
53 public function purge(): void
54 {
55 $questionIds = $this->getPurgableQuestionIds();
56 $this->purgeQuestionIds($questionIds);
57 }
58
59 private function getPurgableQuestionIds(): array
60 {
61 $INtypes = $this->db->in('object_data.type', $this->getIgnoredContainerObjectTypes(), true, 'text');
62
63 $query = "
64 SELECT qpl_questions.question_id
65 FROM qpl_questions
66 INNER JOIN object_data
67 ON object_data.obj_id = qpl_questions.obj_fi
68 AND $INtypes
69 WHERE qpl_questions.owner = %s
70 AND qpl_questions.tstamp = %s
71 ";
72
73 $res = $this->db->queryF($query, array('integer', 'integer'), array($this->getOwnerId(), 0));
74
75 $questionIds = array();
76
77 while ($row = $this->db->fetchAssoc($res)) {
78 $questionIds[] = $row['question_id'];
79 }
80
81 return $questionIds;
82 }
83
84 private function purgeQuestionIds($questionIds): void
85 {
86 require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
87
88 foreach ($questionIds as $questionId) {
89 $question = assQuestion::_instantiateQuestion($questionId);
90 $question->delete($questionId);
91 }
92 }
93
95 {
96 $this->ignoredContainerObjectTypes = $ignoredContainerObjectTypes;
97 }
98
99 protected function getIgnoredContainerObjectTypes(): array
100 {
102 }
103}
static _instantiateQuestion(int $question_id)
setIgnoredContainerObjectTypes($ignoredContainerObjectTypes)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query