ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestSession.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
34 {
43 
51  var $user_id;
52 
61 
69  var $test_id;
70 
79 
88 
97 
106  function ilTestSession($active_id = "")
107  {
108  $this->active_id = 0;
109  $this->user_id = 0;
110  $this->anonymous_id = 0;
111  $this->test_id = 0;
112  $this->lastsequence = 0;
113  $this->submitted = FALSE;
114  $this->submittedTimestamp = "";
115  $this->pass = 0;
116  if ($active_id > 0)
117  {
118  $this->loadFromDb($active_id);
119  }
120  }
121 
122  function saveToDb()
123  {
124  global $ilDB, $ilLog;
125 
126  $submitted = ($this->isSubmitted()) ? "1" : "0";
127  $submittedTimestamp = (strlen($this->getSubmittedTimestamp())) ? $ilDB->quote($this->getSubmittedTimestamp()) : "NULL";
128  if ($this->active_id > 0)
129  {
130  $query = sprintf("UPDATE tst_active SET lastindex = %s, tries = %s, submitted = %s, submittimestamp = %s WHERE active_id = %s",
131  $ilDB->quote($this->getLastSequence() . ""),
132  $ilDB->quote($this->getPass() . ""),
133  $ilDB->quote($submitted . ""),
135  $ilDB->quote($this->getActiveId() . "")
136  );
137  $result = $ilDB->query($query);
138  }
139  else
140  {
141  $anonymous_id = ($this->getAnonymousId()) ? $ilDB->quote($this->getAnonymousId() . "") : "NULL";
142  $query = sprintf("INSERT INTO tst_active (active_id, user_fi, anonymous_id, test_fi, lastindex, tries, submitted, submittimestamp) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s)",
143  $ilDB->quote($this->getUserId() . ""),
145  $ilDB->quote($this->getTestId() . ""),
146  $ilDB->quote($this->getLastSequence() . ""),
147  $ilDB->quote($this->getPass() . ""),
148  $ilDB->quote($submitted . ""),
150  );
151  $result = $ilDB->query($query);
152  $this->active_id = $ilDB->getLastInsertId();
153  }
154  }
155 
157  {
158  global $ilDB;
159  global $ilUser;
160 
161  if (!$user_id)
162  {
163  $user_id = $ilUser->getId();
164  }
165  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && (strlen($_SESSION["tst_access_code"][$test_id])))
166  {
167  $query = sprintf("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
168  $ilDB->quote($user_id),
169  $ilDB->quote($test_id),
170  $ilDB->quote($_SESSION["tst_access_code"][$test_id])
171  );
172  }
173  else if (strlen($anonymous_id))
174  {
175  $query = sprintf("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
176  $ilDB->quote($user_id),
177  $ilDB->quote($test_id),
178  $ilDB->quote($anonymous_id)
179  );
180  }
181  else
182  {
183  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
184  {
185  return NULL;
186  }
187  $query = sprintf("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
188  $ilDB->quote($user_id),
189  $ilDB->quote($test_id)
190  );
191  }
192  $result = $ilDB->query($query);
193  if ($result->numRows())
194  {
195  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
196  $this->active_id = $row["active_id"];
197  $this->user_id = $row["user_fi"];
198  $this->anonymous_id = $row["anonymous_id"];
199  $this->test_id = $row["test_fi"];
200  $this->lastsequence = $row["lastindex"];
201  $this->pass = $row["tries"];
202  $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
203  $this->submittedTimestamp = $row["submittimestamp"];
204  }
205  }
206 
215  private function loadFromDb($active_id)
216  {
217  global $ilDB;
218  $query = sprintf("SELECT * FROM tst_active WHERE active_id = %s",
219  $ilDB->quote($active_id . "")
220  );
221  $result = $ilDB->query($query);
222  if ($result->numRows())
223  {
224  $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
225  $this->active_id = $row["active_id"];
226  $this->user_id = $row["user_fi"];
227  $this->anonymous_id = $row["anonymous_id"];
228  $this->test_id = $row["test_fi"];
229  $this->lastsequence = $row["lastindex"];
230  $this->pass = $row["tries"];
231  $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
232  $this->submittedTimestamp = $row["submittimestamp"];
233  }
234  }
235 
236  function getActiveId()
237  {
238  return $this->active_id;
239  }
240 
241  function setUserId($user_id)
242  {
243  $this->user_id = $user_id;
244  }
245 
246  function getUserId()
247  {
248  return $this->user_id;
249  }
250 
251  function setTestId($test_id)
252  {
253  $this->test_id = $test_id;
254  }
255 
256  function getTestId()
257  {
258  return $this->test_id;
259  }
260 
262  {
263  $this->anonymous_id = $anonymous_id;
264  }
265 
266  function getAnonymousId()
267  {
268  return $this->anonymous_id;
269  }
270 
272  {
273  $this->lastsequence = $lastsequence;
274  }
275 
276  function getLastSequence()
277  {
278  return $this->lastsequence;
279  }
280 
281  function setPass($pass)
282  {
283  $this->pass = $pass;
284  }
285 
286  function getPass()
287  {
288  return $this->pass;
289  }
290 
291  function increasePass()
292  {
293  $this->pass += 1;
294  }
295 
296  function isSubmitted()
297  {
298  return $this->submitted;
299  }
300 
301  function setSubmitted()
302  {
303  $this->submitted = TRUE;
304  }
305 
307  {
309  }
310 
312  {
313  $this->submittedTimestamp = strftime("%Y-%m-%d %H:%M:%S");
314  }
315 }
316 
317 ?>