ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestPassesSelector.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 {
13  protected $db;
14 
15  protected $testOBJ;
16 
17  private $activeId;
18 
20 
22  {
23  $this->db = $db;
24  $this->testOBJ = $testOBJ;
25  }
26 
27  public function getActiveId()
28  {
29  return $this->activeId;
30  }
31 
32  public function setActiveId($activeId)
33  {
34  $this->activeId = $activeId;
35  }
36 
37  public function getLastFinishedPass()
38  {
40  }
41 
43  {
44  $this->lastFinishedPass = $lastFinishedPass;
45  }
46 
47  public function getExistingPasses()
48  {
49  return $this->loadExistingPasses();
50  }
51 
52  public function getNumExistingPasses()
53  {
54  return count($this->loadExistingPasses());
55  }
56 
57  public function getClosedPasses()
58  {
59  $existingPasses = $this->loadExistingPasses();
60  $closedPasses = $this->fetchClosedPasses($existingPasses);
61 
62  return $closedPasses;
63  }
64 
65  public function getReportablePasses()
66  {
67  $existingPasses = $this->loadExistingPasses();
68  $reportablePasses = $this->fetchReportablePasses($existingPasses);
69 
70  return $reportablePasses;
71  }
72 
73  private function loadExistingPasses()
74  {
75  $query = "
76  SELECT DISTINCT tst_pass_result.pass FROM tst_pass_result
77  INNER JOIN tst_test_result
78  ON tst_pass_result.pass = tst_test_result.pass
79  AND tst_pass_result.active_fi = tst_test_result.active_fi
80  WHERE tst_pass_result.active_fi = %s
81  ";
82 
83  $res = $this->db->queryF(
84  $query, array('integer'), array($this->getActiveId())
85  );
86 
87  $existingPasses = array();
88 
89  while( $row = $this->db->fetchAssoc($res) )
90  {
91  $existingPasses[] = $row['pass'];
92  }
93 
94  return $existingPasses;
95  }
96 
97  private function fetchReportablePasses($existingPasses)
98  {
99  $lastPass = $this->fetchLastPass($existingPasses);
100 
101  $reportablePasses = array();
102 
103  foreach($existingPasses as $pass)
104  {
105  if( $this->isReportablePass($lastPass, $pass) )
106  {
107  $reportablePasses[] = $pass;
108  }
109  }
110 
111  return $reportablePasses;
112  }
113 
114  private function fetchClosedPasses($existingPasses)
115  {
116  $closedPasses = array();
117 
118  foreach($existingPasses as $pass)
119  {
120  if( $this->isClosedPass($pass) )
121  {
122  $closedPasses[] = $pass;
123  }
124  }
125 
126  return $closedPasses;
127  }
128 
129  private function fetchLastPass($existingPasses)
130  {
131  $lastPass = null;
132 
133  foreach($existingPasses as $pass)
134  {
135  if( $lastPass === null || $pass > $lastPass )
136  {
137  $lastPass = $pass;
138  }
139  }
140 
141  return $lastPass;
142  }
143 
144  private function isReportablePass($lastPass, $pass)
145  {
146  if($pass < $lastPass)
147  {
148  return true;
149  }
150 
151  if( $this->isClosedPass($pass) )
152  {
153  return true;
154  }
155 
156  return false;
157  }
158 
159  private function isClosedPass($pass)
160  {
161  if( $pass <= $this->getLastFinishedPass() )
162  {
163  return true;
164  }
165 
166  if( $this->isProcessingTimeReached($pass) )
167  {
168  return true;
169  }
170 
171  return false;
172  }
173 
174  private function isProcessingTimeReached($pass)
175  {
176  if( !$this->testOBJ->getEnableProcessingTime() )
177  {
178  return false;
179  }
180 
181  $startingTime = $this->testOBJ->getStartingTimeOfUser($this->getActiveId(), $pass);
182 
183  if($startingTime === FALSE)
184  {
185  return false;
186  }
187 
188  return $this->testOBJ->isMaxProcessingTimeReached($startingTime, $this->getActiveId());
189  }
190 }
__construct(ilDB $db, ilObjTest $testOBJ)
setLastFinishedPass($lastFinishedPass)
fetchReportablePasses($existingPasses)
Database Wrapper.
Definition: class.ilDB.php:28