ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssIncompleteQuestionPurger.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 {
16  protected $db;
17 
18  protected $ownerId;
19 
21 
22  public function __construct(ilDB $db)
23  {
24  $this->db = $db;
25 
26  $this->ignoredContainerObjectTypes = array('lm');
27  }
28 
29  public function getOwnerId()
30  {
31  return $this->ownerId;
32  }
33 
34  public function setOwnerId($ownerId)
35  {
36  $this->ownerId = $ownerId;
37  }
38 
39  public function purge()
40  {
41  $questionIds = $this->getPurgableQuestionIds();
42  $this->purgeQuestionIds($questionIds);
43  }
44 
45  private function getPurgableQuestionIds()
46  {
47  $INtypes = $this->db->in('object_data.type', $this->getIgnoredContainerObjectTypes(), true, 'text');
48 
49  $query = "
50  SELECT qpl_questions.question_id
51  FROM qpl_questions
52  INNER JOIN object_data
53  ON object_data.obj_id = qpl_questions.obj_fi
54  AND $INtypes
55  WHERE qpl_questions.owner = %s
56  AND qpl_questions.tstamp = %s
57  ";
58 
59  $res = $this->db->queryF($query, array('integer', 'integer'), array($this->getOwnerId(), 0));
60 
61  $questionIds = array();
62 
63  while( $row = $this->db->fetchAssoc($res) )
64  {
65  $questionIds[] = $row['question_id'];
66  }
67 
68  return $questionIds;
69  }
70 
71  private function purgeQuestionIds($questionIds)
72  {
73  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
74 
75  foreach($questionIds as $questionId)
76  {
77  $question = assQuestion::_instantiateQuestion($questionId);
78  $question->delete($questionId);
79  }
80  }
81 
83  {
84  $this->ignoredContainerObjectTypes = $ignoredContainerObjectTypes;
85  }
86 
87  protected function getIgnoredContainerObjectTypes()
88  {
90  }
91 }