ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 loadLastFinishedPass()
48 {
49 $query = "
50 SELECT last_finished_pass FROM tst_active WHERE active_id = %s
51 ";
52
53 $res = $this->db->queryF(
54 $query, array('integer'), array($this->getActiveId())
55 );
56
57 while( $row = $this->db->fetchAssoc($res) )
58 {
59 $this->setLastFinishedPass($row['last_finished_pass']);
60 }
61 }
62
63 public function getExistingPasses()
64 {
65 return $this->loadExistingPasses();
66 }
67
68 public function getNumExistingPasses()
69 {
70 return count($this->loadExistingPasses());
71 }
72
73 public function getClosedPasses()
74 {
75 $existingPasses = $this->loadExistingPasses();
76 $closedPasses = $this->fetchClosedPasses($existingPasses);
77
78 return $closedPasses;
79 }
80
81 public function getReportablePasses()
82 {
83 $existingPasses = $this->loadExistingPasses();
84
85 $reportablePasses = $this->fetchReportablePasses($existingPasses);
86
87 return $reportablePasses;
88 }
89
90 private function loadExistingPasses()
91 {
92 $query = "
93 SELECT DISTINCT tst_pass_result.pass FROM tst_pass_result
94 LEFT JOIN tst_test_result
95 ON tst_pass_result.pass = tst_test_result.pass
96 AND tst_pass_result.active_fi = tst_test_result.active_fi
97 WHERE tst_pass_result.active_fi = %s
98 ORDER BY tst_pass_result.pass
99 ";
100
101 $res = $this->db->queryF(
102 $query, array('integer'), array($this->getActiveId())
103 );
104
105 $existingPasses = array();
106
107 while( $row = $this->db->fetchAssoc($res) )
108 {
109 $existingPasses[] = $row['pass'];
110 }
111
112 return $existingPasses;
113 }
114
115 private function fetchReportablePasses($existingPasses)
116 {
117 $lastPass = $this->fetchLastPass($existingPasses);
118
119 $reportablePasses = array();
120
121 foreach($existingPasses as $pass)
122 {
123 if( $this->isReportablePass($lastPass, $pass) )
124 {
125 $reportablePasses[] = $pass;
126 }
127 }
128
129 return $reportablePasses;
130 }
131
132 private function fetchClosedPasses($existingPasses)
133 {
134 $closedPasses = array();
135
136 foreach($existingPasses as $pass)
137 {
138 if( $this->isClosedPass($pass) )
139 {
140 $closedPasses[] = $pass;
141 }
142 }
143
144 return $closedPasses;
145 }
146
147 private function fetchLastPass($existingPasses)
148 {
149 $lastPass = null;
150
151 foreach($existingPasses as $pass)
152 {
153 if( $lastPass === null || $pass > $lastPass )
154 {
155 $lastPass = $pass;
156 }
157 }
158
159 return $lastPass;
160 }
161
162 private function isReportablePass($lastPass, $pass)
163 {
164 switch( $this->testOBJ->getScoreReporting() )
165 {
167
168 return true;
169
171
172 return $this->isReportingDateReached();
173
175
176 if($pass < $lastPass)
177 {
178 return true;
179 }
180
181 return $this->isClosedPass($pass);
182 }
183
184 return false;
185 }
186
187 private function isClosedPass($pass)
188 {
189 if( $pass <= $this->getLastFinishedPass() )
190 {
191 return true;
192 }
193
194 if( $this->isProcessingTimeReached($pass) )
195 {
196 return true;
197 }
198
199 return false;
200 }
201
202 private function isReportingDateReached()
203 {
204 $reg = '/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/';
205 $date = $this->testOBJ->getReportingDate();
206 $matches = null;
207
208 if( !preg_match($reg, $date, $matches) )
209 {
210 return false;
211 }
212
213 $repTS = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
214
215 return time() >= $repTS;
216 }
217
219 {
220 if( !$this->testOBJ->getEnableProcessingTime() )
221 {
222 return false;
223 }
224
225 $startingTime = $this->testOBJ->getStartingTimeOfUser($this->getActiveId(), $pass);
226
227 if($startingTime === FALSE)
228 {
229 return false;
230 }
231
232 return $this->testOBJ->isMaxProcessingTimeReached($startingTime, $this->getActiveId());
233 }
234}
Database Wrapper.
Definition: class.ilDB.php:29
const SCORE_REPORTING_IMMIDIATLY
const SCORE_REPORTING_FINISHED
const SCORE_REPORTING_DATE
__construct(ilDB $db, ilObjTest $testOBJ)
setLastFinishedPass($lastFinishedPass)