ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilTestSession Class Reference

Test session handler. More...

+ Inheritance diagram for ilTestSession:
+ Collaboration diagram for ilTestSession:

Public Member Functions

 __construct ()
 ilTestSession constructor
 setRefId ($a_val)
 Set Ref id.
 getRefId ()
 Get Ref id.
 increaseTestPass ()
 saveToDb ()
 loadTestSession ($test_id, $user_id="", $anonymous_id="")
 loadFromDb ($active_id)
 Loads the session data for a given active id.
 getActiveId ()
 setUserId ($user_id)
 getUserId ()
 setTestId ($test_id)
 getTestId ()
 setAnonymousId ($anonymous_id)
 getAnonymousId ()
 setLastSequence ($lastsequence)
 getLastSequence ()
 setPass ($pass)
 getPass ()
 increasePass ()
 isSubmitted ()
 setSubmitted ()
 getSubmittedTimestamp ()
 setSubmittedTimestamp ()
 setLastFinishedPass ($lastFinishedPass)
 getLastFinishedPass ()
 setObjectiveOrientedContainerId ($objectiveOriented)
 getObjectiveOrientedContainerId ()
 isObjectiveOriented ()
 persistTestStartLock ($testStartLock)
 lookupTestStartLock ()
 setAccessCodeToSession ($access_code)
 unsetAccessCodeInSession ()
 getAccessCodeFromSession ()
 doesAccessCodeInSessionExists ()
 createNewAccessCode ()
 isAccessCodeUsed ($code)
 isAnonymousUser ()

Data Fields

const ACCESS_CODE_SESSION_INDEX = "tst_access_code"
const ACCESS_CODE_CHAR_DOMAIN = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const ACCESS_CODE_LENGTH = 5
 $active_id
 $user_id
 $anonymous_id
 $test_id
 $lastsequence
 $submitted
 $tstamp
 $submittedTimestamp

Protected Member Functions

 activeIDExists ($user_id, $test_id)

Private Member Functions

 buildAccessCode ()

Private Attributes

 $lastFinishedPass
 $objectiveOrientedContainerId

Detailed Description

Test session handler.

This class manages the test session for a participant

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
Id:
class.ilTestSession.php 59532 2015-06-18 10:41:15Z gitmgr

Definition at line 13 of file class.ilTestSession.php.

Constructor & Destructor Documentation

ilTestSession::__construct ( )

ilTestSession constructor

The constructor takes possible arguments an creates an instance of the ilTestSession object.

public

Reimplemented in ilTestSessionDynamicQuestionSet.

Definition at line 89 of file class.ilTestSession.php.

{
$this->active_id = 0;
$this->user_id = 0;
$this->anonymous_id = 0;
$this->test_id = 0;
$this->lastsequence = 0;
$this->submitted = FALSE;
$this->submittedTimestamp = "";
$this->pass = 0;
$this->ref_id = 0;
$this->tstamp = 0;
$this->lastFinishedPass = null;
$this->objectiveOrientedContainerId = 0;
}

Member Function Documentation

ilTestSession::activeIDExists (   $user_id,
  $test_id 
)
protected

Definition at line 126 of file class.ilTestSession.php.

References $_SESSION, $ilDB, $result, $row, $test_id, $user_id, setLastFinishedPass(), and setObjectiveOrientedContainerId().

Referenced by increaseTestPass(), ilTestSessionDynamicQuestionSet\saveToDb(), and saveToDb().

{
global $ilDB;
if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
{
$result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
array('integer','integer'),
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$this->active_id = $row["active_id"];
$this->user_id = $row["user_fi"];
$this->anonymous_id = $row["anonymous_id"];
$this->test_id = $row["test_fi"];
$this->lastsequence = $row["lastindex"];
$this->pass = $row["tries"];
$this->submitted = ($row["submitted"]) ? TRUE : FALSE;
$this->submittedTimestamp = $row["submittimestamp"];
$this->tstamp = $row["tstamp"];
$this->setLastFinishedPass($row['last_finished_pass']);
$this->setObjectiveOrientedContainerId((int)$row['objective_container']);
return true;
}
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSession::buildAccessCode ( )
private

Definition at line 576 of file class.ilTestSession.php.

References ACCESS_CODE_CHAR_DOMAIN, and ACCESS_CODE_LENGTH.

Referenced by createNewAccessCode().

{
// create a 5 character code
mt_srand();
$code = "";
for($i = 1; $i <= self::ACCESS_CODE_LENGTH; $i++)
{
$index = mt_rand(0, strlen($codestring)-1);
$code .= substr($codestring, $index, 1);
}
return $code;
}

+ Here is the caller graph for this function:

ilTestSession::createNewAccessCode ( )

Definition at line 552 of file class.ilTestSession.php.

References buildAccessCode(), and isAccessCodeUsed().

{
do
{
$code = $this->buildAccessCode();
}
while( $this->isAccessCodeUsed($code) );
return $code;
}

+ Here is the call graph for this function:

ilTestSession::doesAccessCodeInSessionExists ( )

Definition at line 542 of file class.ilTestSession.php.

References $_SESSION, and getTestId().

Referenced by ilTestPlayerAbstractGUI\ensureExistingTestSession(), ilTestSessionDynamicQuestionSet\loadTestSession(), and loadTestSession().

{
if( !is_array($_SESSION[self::ACCESS_CODE_SESSION_INDEX]) )
{
return false;
}
return isset($_SESSION[self::ACCESS_CODE_SESSION_INDEX][$this->getTestId()]);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSession::getAccessCodeFromSession ( )

Definition at line 527 of file class.ilTestSession.php.

References $_SESSION, ACCESS_CODE_SESSION_INDEX, and getTestId().

Referenced by ilTestPlayerAbstractGUI\ensureExistingTestSession(), ilTestSessionDynamicQuestionSet\loadTestSession(), and loadTestSession().

{
if( !is_array($_SESSION[self::ACCESS_CODE_SESSION_INDEX]) )
{
return null;
}
if( !isset($_SESSION[self::ACCESS_CODE_SESSION_INDEX][$this->getTestId()]) )
{
return null;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSession::getAnonymousId ( )

Definition at line 409 of file class.ilTestSession.php.

References $anonymous_id.

Referenced by increaseTestPass(), ilTestSessionDynamicQuestionSet\saveToDb(), and saveToDb().

{
}

+ Here is the caller graph for this function:

ilTestSession::getLastFinishedPass ( )

Definition at line 464 of file class.ilTestSession.php.

References $lastFinishedPass.

Referenced by increaseTestPass(), and saveToDb().

+ Here is the caller graph for this function:

ilTestSession::getLastSequence ( )
ilTestSession::getObjectiveOrientedContainerId ( )
ilTestSession::getPass ( )
ilTestSession::getSubmittedTimestamp ( )

Definition at line 449 of file class.ilTestSession.php.

References $submittedTimestamp.

Referenced by increaseTestPass(), ilTestSessionDynamicQuestionSet\saveToDb(), and saveToDb().

+ Here is the caller graph for this function:

ilTestSession::getTestId ( )
ilTestSession::getUserId ( )
ilTestSession::increasePass ( )

Definition at line 434 of file class.ilTestSession.php.

Referenced by increaseTestPass().

{
$this->pass += 1;
}

+ Here is the caller graph for this function:

ilTestSession::increaseTestPass ( )

Definition at line 158 of file class.ilTestSession.php.

References $_SESSION, $anonymous_id, $ilDB, $ilLog, $submitted, ilObjTestAccess\_getParticipantId(), ilObjTestAccess\_lookupObjIdForTestId(), ilLPStatusWrapper\_updateStatus(), activeIDExists(), getActiveId(), getAnonymousId(), getLastFinishedPass(), getLastSequence(), getObjectiveOrientedContainerId(), getPass(), getSubmittedTimestamp(), getTestId(), getUserId(), increasePass(), isSubmitted(), and setLastSequence().

{
global $ilDB, $ilLog;
$this->increasePass();
$this->setLastSequence(0);
$submitted = ($this->isSubmitted()) ? 1 : 0;
// there has to be at least 10 seconds between new test passes (to ensure that noone double clicks the finish button and increases the test pass by more than 1)
if (time() - $_SESSION['tst_last_increase_pass'] > 10)
{
$_SESSION['tst_last_increase_pass'] = time();
$this->tstamp = time();
if ($this->active_id > 0)
{
$ilDB->update('tst_active',
array(
'lastindex' => array('integer', $this->getLastSequence()),
'tries' => array('integer', $this->getPass()),
'submitted' => array('integer', $submitted),
'submittimestamp' => array('timestamp', strlen($this->getSubmittedTimestamp()) ? $this->getSubmittedTimestamp() : NULL),
'tstamp' => array('integer', time()),
'last_finished_pass' => array('integer', $this->getLastFinishedPass()),
'objective_container' => array('integer', (int)$this->getObjectiveOrientedContainerId())
),
array(
'active_id' => array('integer', $this->getActiveId())
)
);
// update learning progress
include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
}
else
{
if (!$this->activeIDExists($this->getUserId(), $this->getTestId()))
{
$anonymous_id = ($this->getAnonymousId()) ? $this->getAnonymousId() : NULL;
$next_id = $ilDB->nextId('tst_active');
$affectedRows = $ilDB->manipulateF("INSERT INTO tst_active (active_id, user_fi, anonymous_id, test_fi, lastindex, tries, submitted, submittimestamp, tstamp, objective_container) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
array('integer', 'integer', 'text', 'integer', 'integer', 'integer', 'integer', 'timestamp', 'integer', 'integer'),
array(
$next_id,
$this->getUserId(),
$this->getTestId(),
$this->getLastSequence(),
$this->getPass(),
(strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL,
time(),
)
);
$this->active_id = $next_id;
// update learning progress
include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
$this->getUserId());
}
}
}
}

+ Here is the call graph for this function:

ilTestSession::isAccessCodeUsed (   $code)

Definition at line 563 of file class.ilTestSession.php.

References $ilDB, $query, $result, and getTestId().

Referenced by createNewAccessCode().

{
global $ilDB;
$query = "SELECT anonymous_id FROM tst_active WHERE test_fi = %s AND anonymous_id = %s";
$result = $ilDB->queryF(
$query, array('integer', 'text'), array($this->getTestId(), $code)
);
return ($result->numRows() > 0);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSession::isAnonymousUser ( )

Definition at line 594 of file class.ilTestSession.php.

References getUserId().

Referenced by ilTestPlayerAbstractGUI\ensureExistingTestSession().

{
return $this->getUserId() == ANONYMOUS_USER_ID;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSession::isObjectiveOriented ( )

Definition at line 479 of file class.ilTestSession.php.

References getObjectiveOrientedContainerId().

{
return (bool)$this->getObjectiveOrientedContainerId();
}

+ Here is the call graph for this function:

ilTestSession::isSubmitted ( )

Definition at line 439 of file class.ilTestSession.php.

References $submitted.

Referenced by increaseTestPass(), ilTestSessionDynamicQuestionSet\saveToDb(), and saveToDb().

{
}

+ Here is the caller graph for this function:

ilTestSession::loadFromDb (   $active_id)

Loads the session data for a given active id.

Parameters
integer$active_idThe database id of the test session

Reimplemented in ilTestSessionDynamicQuestionSet.

Definition at line 354 of file class.ilTestSession.php.

References $active_id, $ilDB, $result, $row, setLastFinishedPass(), and setObjectiveOrientedContainerId().

{
global $ilDB;
$result = $ilDB->queryF("SELECT * FROM tst_active WHERE active_id = %s",
array('integer'),
array($active_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$this->active_id = $row["active_id"];
$this->user_id = $row["user_fi"];
$this->anonymous_id = $row["anonymous_id"];
$this->test_id = $row["test_fi"];
$this->lastsequence = $row["lastindex"];
$this->pass = $row["tries"];
$this->submitted = ($row["submitted"]) ? TRUE : FALSE;
$this->submittedTimestamp = $row["submittimestamp"];
$this->tstamp = $row["tstamp"];
$this->setLastFinishedPass($row['last_finished_pass']);
$this->setObjectiveOrientedContainerId((int)$row['objective_container']);
}
}

+ Here is the call graph for this function:

ilTestSession::loadTestSession (   $test_id,
  $user_id = "",
  $anonymous_id = "" 
)

Reimplemented in ilTestSessionDynamicQuestionSet.

Definition at line 293 of file class.ilTestSession.php.

References $_SESSION, $anonymous_id, $ilDB, $ilUser, $result, $row, $test_id, $user_id, doesAccessCodeInSessionExists(), getAccessCodeFromSession(), setLastFinishedPass(), setObjectiveOrientedContainerId(), and unsetAccessCodeInSession().

{
global $ilDB;
global $ilUser;
if (!$user_id)
{
$user_id = $ilUser->getId();
}
if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && $this->doesAccessCodeInSessionExists())
{
$result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
array('integer','integer','text'),
);
}
else if (strlen($anonymous_id))
{
$result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s AND anonymous_id = %s",
array('integer','integer','text'),
);
}
else
{
if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
{
return NULL;
}
$result = $ilDB->queryF("SELECT * FROM tst_active WHERE user_fi = %s AND test_fi = %s",
array('integer','integer'),
);
}
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$this->active_id = $row["active_id"];
$this->user_id = $row["user_fi"];
$this->anonymous_id = $row["anonymous_id"];
$this->test_id = $row["test_fi"];
$this->lastsequence = $row["lastindex"];
$this->pass = $row["tries"];
$this->submitted = ($row["submitted"]) ? TRUE : FALSE;
$this->submittedTimestamp = $row["submittimestamp"];
$this->tstamp = $row["tstamp"];
$this->setLastFinishedPass($row['last_finished_pass']);
$this->setObjectiveOrientedContainerId((int)$row['objective_container']);
}
elseif( $this->doesAccessCodeInSessionExists() )
{
}
}

+ Here is the call graph for this function:

ilTestSession::lookupTestStartLock ( )

Definition at line 495 of file class.ilTestSession.php.

References $ilDB, $res, $row, and getActiveId().

{
global $ilDB;
$res = $ilDB->queryF(
"SELECT start_lock FROM tst_active WHERE active_id = %s",
array('integer'), array($this->getActiveId())
);
while($row = $ilDB->fetchAssoc($res))
{
return $row['start_lock'];
}
return null;
}

+ Here is the call graph for this function:

ilTestSession::persistTestStartLock (   $testStartLock)

Definition at line 484 of file class.ilTestSession.php.

References $ilDB, and getActiveId().

{
global $ilDB;
$ilDB->update(
'tst_active',
array('start_lock' => array('text', $testStartLock)),
array('active_id' => array('integer', $this->getActiveId()))
);
}

+ Here is the call graph for this function:

ilTestSession::saveToDb ( )

Reimplemented in ilTestSessionDynamicQuestionSet.

Definition at line 226 of file class.ilTestSession.php.

References $anonymous_id, $ilDB, $ilLog, $submitted, ilObjTestAccess\_getParticipantId(), ilObjTestAccess\_lookupObjIdForTestId(), ilLearningProgress\_tracProgress(), ilLPStatusWrapper\_updateStatus(), activeIDExists(), getActiveId(), getAnonymousId(), getLastFinishedPass(), getLastSequence(), getObjectiveOrientedContainerId(), getPass(), getRefId(), getSubmittedTimestamp(), getTestId(), getUserId(), and isSubmitted().

Referenced by ilTestPlayerAbstractGUI\ensureExistingTestSession().

{
global $ilDB, $ilLog;
$submitted = ($this->isSubmitted()) ? 1 : 0;
if ($this->active_id > 0)
{
$ilDB->update('tst_active',
array(
'lastindex' => array('integer', $this->getLastSequence()),
'tries' => array('integer', $this->getPass()),
'submitted' => array('integer', $submitted),
'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL),
'tstamp' => array('integer', time()-10),
'last_finished_pass' => array('integer', $this->getLastFinishedPass()),
'objective_container' => array('integer', (int)$this->getObjectiveOrientedContainerId())
),
array(
'active_id' => array('integer', $this->getActiveId())
)
);
// update learning progress
include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
}
else
{
if (!$this->activeIDExists($this->getUserId(), $this->getTestId()))
{
$anonymous_id = ($this->getAnonymousId()) ? $this->getAnonymousId() : NULL;
$next_id = $ilDB->nextId('tst_active');
$ilDB->insert('tst_active',
array(
'active_id' => array('integer', $next_id),
'user_fi' => array('integer', $this->getUserId()),
'anonymous_id' => array('text', $anonymous_id),
'test_fi' => array('integer', $this->getTestId()),
'lastindex' => array('integer', $this->getLastSequence()),
'tries' => array('integer', $this->getPass()),
'submitted' => array('integer', $submitted),
'submittimestamp' => array('timestamp', (strlen($this->getSubmittedTimestamp())) ? $this->getSubmittedTimestamp() : NULL),
'tstamp' => array('integer', time()-10),
'last_finished_pass' => array('integer', $this->getLastFinishedPass()),
'objective_container' => array('integer', (int)$this->getObjectiveOrientedContainerId())
)
);
$this->active_id = $next_id;
// update learning progress
include_once("./Modules/Test/classes/class.ilObjTestAccess.php");
include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
$this->getUserId());
}
}
include_once './Modules/Test/classes/class.ilObjTestAccess.php';
include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
$this->getRefId(),
'tst');
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTestSession::setAccessCodeToSession (   $access_code)

Definition at line 512 of file class.ilTestSession.php.

References $_SESSION, ACCESS_CODE_SESSION_INDEX, and getTestId().

{
if (!is_array($_SESSION[self::ACCESS_CODE_SESSION_INDEX]))
{
}
}

+ Here is the call graph for this function:

ilTestSession::setAnonymousId (   $anonymous_id)

Definition at line 404 of file class.ilTestSession.php.

References $anonymous_id.

Referenced by ilTestPlayerAbstractGUI\ensureExistingTestSession().

{
$this->anonymous_id = $anonymous_id;
}

+ Here is the caller graph for this function:

ilTestSession::setLastFinishedPass (   $lastFinishedPass)

Definition at line 459 of file class.ilTestSession.php.

References $lastFinishedPass.

Referenced by activeIDExists(), loadFromDb(), and loadTestSession().

{
$this->lastFinishedPass = $lastFinishedPass;
}

+ Here is the caller graph for this function:

ilTestSession::setLastSequence (   $lastsequence)

Definition at line 414 of file class.ilTestSession.php.

References $lastsequence.

Referenced by increaseTestPass(), and ilTestSessionDynamicQuestionSet\setCurrentQuestionId().

{
$this->lastsequence = $lastsequence;
}

+ Here is the caller graph for this function:

ilTestSession::setObjectiveOrientedContainerId (   $objectiveOriented)

Definition at line 469 of file class.ilTestSession.php.

Referenced by activeIDExists(), loadFromDb(), and loadTestSession().

{
$this->objectiveOrientedContainerId = $objectiveOriented;
}

+ Here is the caller graph for this function:

ilTestSession::setPass (   $pass)

Definition at line 424 of file class.ilTestSession.php.

References $pass.

{
$this->pass = $pass;
}
ilTestSession::setRefId (   $a_val)

Set Ref id.

Parameters
integerRef id

Definition at line 111 of file class.ilTestSession.php.

{
$this->ref_id = $a_val;
}
ilTestSession::setSubmitted ( )

Definition at line 444 of file class.ilTestSession.php.

{
$this->submitted = TRUE;
}
ilTestSession::setSubmittedTimestamp ( )

Definition at line 454 of file class.ilTestSession.php.

{
$this->submittedTimestamp = strftime("%Y-%m-%d %H:%M:%S");
}
ilTestSession::setTestId (   $test_id)

Definition at line 394 of file class.ilTestSession.php.

References $test_id.

{
$this->test_id = $test_id;
}
ilTestSession::setUserId (   $user_id)

Definition at line 384 of file class.ilTestSession.php.

References $user_id.

Referenced by ilTestPlayerAbstractGUI\ensureExistingTestSession().

{
$this->user_id = $user_id;
}

+ Here is the caller graph for this function:

ilTestSession::unsetAccessCodeInSession ( )

Definition at line 522 of file class.ilTestSession.php.

References $_SESSION, and getTestId().

Referenced by ilTestSessionDynamicQuestionSet\loadTestSession(), and loadTestSession().

{
unset($_SESSION[self::ACCESS_CODE_SESSION_INDEX][$this->getTestId()]);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilTestSession::$active_id
ilTestSession::$lastFinishedPass
private

Definition at line 77 of file class.ilTestSession.php.

Referenced by getLastFinishedPass(), and setLastFinishedPass().

ilTestSession::$lastsequence

Definition at line 54 of file class.ilTestSession.php.

Referenced by getLastSequence(), and setLastSequence().

ilTestSession::$objectiveOrientedContainerId
private

Definition at line 79 of file class.ilTestSession.php.

Referenced by getObjectiveOrientedContainerId().

ilTestSession::$submitted
ilTestSession::$submittedTimestamp

Definition at line 75 of file class.ilTestSession.php.

Referenced by getSubmittedTimestamp().

ilTestSession::$tstamp

Definition at line 68 of file class.ilTestSession.php.

const ilTestSession::ACCESS_CODE_CHAR_DOMAIN = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Definition at line 17 of file class.ilTestSession.php.

Referenced by buildAccessCode().

const ilTestSession::ACCESS_CODE_LENGTH = 5

Definition at line 19 of file class.ilTestSession.php.

Referenced by buildAccessCode().

const ilTestSession::ACCESS_CODE_SESSION_INDEX = "tst_access_code"

Definition at line 15 of file class.ilTestSession.php.

Referenced by getAccessCodeFromSession(), and setAccessCodeToSession().


The documentation for this class was generated from the following file: