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