ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
19 private $lastFinishedPass = null;
20
21 private $passes = null;
22
24 {
25 $this->db = $db;
26 $this->testOBJ = $testOBJ;
27 }
28
29 public function getActiveId()
30 {
31 return $this->activeId;
32 }
33
34 public function setActiveId($activeId)
35 {
36 $this->activeId = $activeId;
37 }
38
39 public function getLastFinishedPass()
40 {
42 }
43
45 {
47 $this->lastFinishedPass = $lastFinishedPass;
48 }
49
50 private function passesLoaded()
51 {
52 return is_array($this->passes);
53 }
54
55 private function ensureLoadedPasses()
56 {
57 if( !$this->passesLoaded() )
58 {
59 $this->loadPasses();
60 }
61 }
62 private function loadPasses()
63 {
64 $query = "
65 SELECT DISTINCT tst_pass_result.* FROM tst_pass_result
66 LEFT JOIN tst_test_result
67 ON tst_pass_result.pass = tst_test_result.pass
68 AND tst_pass_result.active_fi = tst_test_result.active_fi
69 WHERE tst_pass_result.active_fi = %s
70 ORDER BY tst_pass_result.pass
71 ";
72
73 $res = $this->db->queryF(
74 $query, array('integer'), array($this->getActiveId())
75 );
76
77 $this->passes = array();
78
79 while( $row = $this->db->fetchAssoc($res) )
80 {
81 $this->passes[$row['pass']] = $row;
82 }
83 }
84
85 private function getLazyLoadedPasses()
86 {
87 $this->ensureLoadedPasses();
88 return $this->passes;
89 }
90
91 public function loadLastFinishedPass()
92 {
93 $query = "
94 SELECT last_finished_pass FROM tst_active WHERE active_id = %s
95 ";
96
97 $res = $this->db->queryF(
98 $query, array('integer'), array($this->getActiveId())
99 );
100
101 while( $row = $this->db->fetchAssoc($res) )
102 {
103 $this->setLastFinishedPass($row['last_finished_pass']);
104 }
105 }
106
107 public function getExistingPasses()
108 {
109 return array_keys($this->getLazyLoadedPasses());
110 }
111
112 public function getNumExistingPasses()
113 {
114 return count($this->getExistingPasses());
115 }
116
117 public function getClosedPasses()
118 {
119 $existingPasses = $this->getExistingPasses();
120 $closedPasses = $this->fetchClosedPasses($existingPasses);
121
122 return $closedPasses;
123 }
124
125 public function getReportablePasses()
126 {
127 $existingPasses = $this->getExistingPasses();
128
129 $reportablePasses = $this->fetchReportablePasses($existingPasses);
130
131 return $reportablePasses;
132 }
133
134 private function fetchReportablePasses($existingPasses)
135 {
136 $lastPass = $this->fetchLastPass($existingPasses);
137
138 $reportablePasses = array();
139
140 foreach($existingPasses as $pass)
141 {
142 if( $this->isReportablePass($lastPass, $pass) )
143 {
144 $reportablePasses[] = $pass;
145 }
146 }
147
148 return $reportablePasses;
149 }
150
151 private function fetchClosedPasses($existingPasses)
152 {
153 $closedPasses = array();
154
155 foreach($existingPasses as $pass)
156 {
157 if( $this->isClosedPass($pass) )
158 {
159 $closedPasses[] = $pass;
160 }
161 }
162
163 return $closedPasses;
164 }
165
166 private function fetchLastPass($existingPasses)
167 {
168 $lastPass = null;
169
170 foreach($existingPasses as $pass)
171 {
172 if( $lastPass === null || $pass > $lastPass )
173 {
174 $lastPass = $pass;
175 }
176 }
177
178 return $lastPass;
179 }
180
181 private function isReportablePass($lastPass, $pass)
182 {
183 switch( $this->testOBJ->getScoreReporting() )
184 {
186
187 return true;
188
190
191 return $this->isReportingDateReached();
192
194
195 if($pass < $lastPass)
196 {
197 return true;
198 }
199
200 return $this->isClosedPass($pass);
201 }
202
203 return false;
204 }
205
207 {
208 if( $this->getLastFinishedPass() === null )
209 {
210 throw new ilTestException('invalid object state: last finished pass was not set!');
211 }
212 }
213
214 private function isClosedPass($pass)
215 {
217
218 if( $pass <= $this->getLastFinishedPass() )
219 {
220 return true;
221 }
222
223 if( $this->isProcessingTimeReached($pass) )
224 {
225 return true;
226 }
227
228 return false;
229 }
230
231 private function isReportingDateReached()
232 {
233 $reg = '/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/';
234 $date = $this->testOBJ->getReportingDate();
235 $matches = null;
236
237 if( !preg_match($reg, $date, $matches) )
238 {
239 return false;
240 }
241
242 $repTS = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
243
244 return time() >= $repTS;
245 }
246
248 {
249 if( !$this->testOBJ->getEnableProcessingTime() )
250 {
251 return false;
252 }
253
254 $startingTime = $this->testOBJ->getStartingTimeOfUser($this->getActiveId(), $pass);
255
256 if($startingTime === FALSE)
257 {
258 return false;
259 }
260
261 return $this->testOBJ->isMaxProcessingTimeReached($startingTime, $this->getActiveId());
262 }
263
268 {
269 if( $this->getLastFinishedPass() === null )
270 {
271 return null;
272 }
273
274 $passes = $this->getLazyLoadedPasses();
275 return $passes[$this->getLastFinishedPass()]['tstamp'];
276 }
277}
An exception for terminatinating execution or to throw for unit testing.
const SCORE_REPORTING_IMMIDIATLY
const SCORE_REPORTING_FINISHED
const SCORE_REPORTING_DATE
Base Exception for all Exceptions relating to Modules/Test.
__construct(ilDBInterface $db, ilObjTest $testOBJ)
setLastFinishedPass($lastFinishedPass)
Interface ilDBInterface.