• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Test/classes/class.ilTestSession.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00033 class ilTestSession
00034 {
00042         var $active_id;
00043 
00051         var $user_id;
00052 
00060         var $anonymous_id;
00061 
00069         var $test_id;
00070 
00078         var $lastsequence;
00079 
00087         var $submitted;
00088 
00096         var $submittedTimestamp;
00097 
00106         function ilTestSession($active_id = "")
00107         {
00108                 $this->active_id = 0;
00109                 $this->user_id = 0;
00110                 $this->anonymous_id = 0;
00111                 $this->test_id = 0;
00112                 $this->lastsequence = 0;
00113                 $this->submitted = FALSE;
00114                 $this->submittedTimestamp = "";
00115                 $this->pass = 0;
00116                 if ($active_id > 0)
00117                 {
00118                         $this->loadFromDb($active_id);
00119                 }
00120         }
00121         
00122         function saveToDb()
00123         {
00124                 global $ilDB, $ilLog;
00125                 
00126                 $submitted = ($this->isSubmitted()) ? "1" : "0";
00127                 $submittedTimestamp = (strlen($this->getSubmittedTimestamp())) ? $ilDB->quote($this->getSubmittedTimestamp()) : "NULL";
00128                 if ($this->active_id > 0)
00129                 {
00130                         $query = sprintf("UPDATE tst_active SET lastindex = %s, tries = %s, submitted = %s, submittimestamp = %s WHERE active_id = %s",
00131                                 $ilDB->quote($this->getLastSequence() . ""),
00132                                 $ilDB->quote($this->getPass() . ""),
00133                                 $ilDB->quote($submitted . ""),
00134                                 $submittedTimestamp,
00135                                 $ilDB->quote($this->getActiveId() . "")
00136                         );
00137                         $result = $ilDB->query($query);
00138                 }
00139                 else
00140                 {
00141                         $anonymous_id = ($this->getAnonymousId()) ? $ilDB->quote($this->getAnonymousId() . "") : "NULL";
00142                         $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)",
00143                                 $ilDB->quote($this->getUserId() . ""),
00144                                 $anonymous_id,
00145                                 $ilDB->quote($this->getTestId() . ""),
00146                                 $ilDB->quote($this->getLastSequence() . ""),
00147                                 $ilDB->quote($this->getPass() . ""),
00148                                 $ilDB->quote($submitted . ""),
00149                                 $submittedTimestamp
00150                         );
00151                         $result = $ilDB->query($query);
00152                         $this->active_id = $ilDB->getLastInsertId();
00153                 }
00154         }
00155         
00156         function loadTestSession($test_id, $user_id = "", $anonymous_id = "")
00157         {
00158                 global $ilDB;
00159                 global $ilUser;
00160 
00161                 if (!$user_id)
00162                 {
00163                         $user_id = $ilUser->getId();
00164                 }
00165                 if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && (strlen($_SESSION["tst_access_code"][$test_id])))
00166                 {
00167                         $query = sprintf("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
00168                                 $ilDB->quote($user_id),
00169                                 $ilDB->quote($test_id),
00170                                 $ilDB->quote($_SESSION["tst_access_code"][$test_id])
00171                         );
00172                 }
00173                 else if (strlen($anonymous_id))
00174                 {
00175                         $query = sprintf("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
00176                                 $ilDB->quote($user_id),
00177                                 $ilDB->quote($test_id),
00178                                 $ilDB->quote($anonymous_id)
00179                         );
00180                 }
00181                 else
00182                 {
00183                         if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
00184                         {
00185                                 return NULL;
00186                         }
00187                         $query = sprintf("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
00188                                 $ilDB->quote($user_id),
00189                                 $ilDB->quote($test_id)
00190                         );
00191                 }
00192                 $result = $ilDB->query($query);
00193                 if ($result->numRows())
00194                 {
00195                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00196                         $this->active_id = $row["active_id"];
00197                         $this->user_id = $row["user_fi"];
00198                         $this->anonymous_id = $row["anonymous_id"];
00199                         $this->test_id = $row["test_fi"];
00200                         $this->lastsequence = $row["lastindex"];
00201                         $this->pass = $row["tries"];
00202                         $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
00203                         $this->submittedTimestamp = $row["submittimestamp"];
00204                 }
00205         }
00206         
00215         private function loadFromDb($active_id)
00216         {
00217                 global $ilDB;
00218                 $query = sprintf("SELECT * FROM tst_active WHERE active_id = %s", 
00219                         $ilDB->quote($active_id . "")
00220                 );
00221                 $result = $ilDB->query($query);
00222                 if ($result->numRows())
00223                 {
00224                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00225                         $this->active_id = $row["active_id"];
00226                         $this->user_id = $row["user_fi"];
00227                         $this->anonymous_id = $row["anonymous_id"];
00228                         $this->test_id = $row["test_fi"];
00229                         $this->lastsequence = $row["lastindex"];
00230                         $this->pass = $row["tries"];
00231                         $this->submitted = ($row["submitted"]) ? TRUE : FALSE;
00232                         $this->submittedTimestamp = $row["submittimestamp"];
00233                 }
00234         }
00235         
00236         function getActiveId()
00237         {
00238                 return $this->active_id;
00239         }
00240         
00241         function setUserId($user_id)
00242         {
00243                 $this->user_id = $user_id;
00244         }
00245         
00246         function getUserId()
00247         {
00248                 return $this->user_id;
00249         }
00250         
00251         function setTestId($test_id)
00252         {
00253                 $this->test_id = $test_id;
00254         }
00255         
00256         function getTestId()
00257         {
00258                 return $this->test_id;
00259         }
00260         
00261         function setAnonymousId($anonymous_id)
00262         {
00263                 $this->anonymous_id = $anonymous_id;
00264         }
00265         
00266         function getAnonymousId()
00267         {
00268                 return $this->anonymous_id;
00269         }
00270         
00271         function setLastSequence($lastsequence)
00272         {
00273                 $this->lastsequence = $lastsequence;
00274         }
00275         
00276         function getLastSequence()
00277         {
00278                 return $this->lastsequence;
00279         }
00280         
00281         function setPass($pass)
00282         {
00283                 $this->pass = $pass;
00284         }
00285         
00286         function getPass()
00287         {
00288                 return $this->pass;
00289         }
00290         
00291         function increasePass()
00292         {
00293                 $this->pass += 1;
00294         }
00295         
00296         function isSubmitted()
00297         {
00298                 return $this->submitted;
00299         }
00300         
00301         function setSubmitted()
00302         {
00303                 $this->submitted = TRUE;
00304         }
00305         
00306         function getSubmittedTimestamp()
00307         {
00308                 return $this->submittedTimestamp;
00309         }
00310         
00311         function setSubmittedTimestamp()
00312         {
00313                 $this->submittedTimestamp = strftime("%Y-%m-%d %H:%M:%S");
00314         }
00315 }
00316 
00317 ?>

Generated on Fri Dec 13 2013 17:56:53 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1