ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 = ['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, ['integer', 'integer'], [$this->getOwnerId(), 0]);
74
75 $questionIds = [];
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 foreach ($questionIds as $questionId) {
87 $question = assQuestion::instantiateQuestion($questionId);
88 $question->delete($questionId);
89 }
90 }
91
93 {
94 $this->ignoredContainerObjectTypes = $ignoredContainerObjectTypes;
95 }
96
97 protected function getIgnoredContainerObjectTypes(): array
98 {
100 }
101}
static instantiateQuestion(int $question_id)
setIgnoredContainerObjectTypes($ignoredContainerObjectTypes)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69