ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilObjTestAccess Class Reference

Class ilObjTestAccess. More...

+ Inheritance diagram for ilObjTestAccess:
+ Collaboration diagram for ilObjTestAccess:

Public Member Functions

 _checkAccess ($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
 Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess)
 _getMaxPointsForTestPass ($random, $user_id, $test_id, $pass)
 Returns the maximum number of points available for a test pass.
 _checkCondition ($a_obj_id, $a_operator, $a_value, $a_usr_id=0)
 check condition
 _getCommands ()
 get commands
 _lookupCreationComplete ($a_obj_id)
 checks wether all necessary parts of the test are given
 _getTestIDFromObjectID ($object_id)
 Returns the ILIAS test id for a given object id.
_getTestQuestions ($active_id, $pass=NULL)
 _isComplete ($a_obj_id)
 Returns true, if a test is complete for use.
_getTestData ($test_id)
 Returns the database content of a test with a given id.
 _getQuestionCount ($test_id)
 Calculates the number of questions in a test.
 _lookupOnlineTestAccess ($a_test_id, $a_user_id)
 Checks if a user is allowd to run an online exam.
 _getParticipantData ($active_id)
 Retrieves a participant name from active id.
_getPassedUsers ($a_obj_id)
 Returns an array containing the users who passed the test.
 _checkGoto ($a_target)
 check whether goto script will succeed

Static Public Member Functions

static _isPassed ($user_id, $a_obj_id)
 Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id.
 _hasFinished ($a_user_id, $a_obj_id)
 Returns information if a specific user has finished a test.

Detailed Description

Class ilObjTestAccess.

This class contains methods that check object specific conditions for accessing test objects.

Author
Helmut Schottmueller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilObjTestAccess.php 23462 2010-04-01 09:13:09Z hschottm

Definition at line 39 of file class.ilObjTestAccess.php.

Member Function Documentation

ilObjTestAccess::_checkAccess (   $a_cmd,
  $a_permission,
  $a_ref_id,
  $a_obj_id,
  $a_user_id = "" 
)

Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess)

Please do not check any preconditions handled by ilConditionHandler here.

Parameters
string$a_cmdcommand (not permission!)
string$a_permissionpermission
int$a_ref_idreference id
int$a_obj_idobject id
int$a_user_iduser id (if not provided, current user is taken)
Returns
boolean true, if everything is ok

Reimplemented from ilObjectAccess.

Definition at line 56 of file class.ilObjTestAccess.php.

References $lng, _lookupCreationComplete(), and IL_NO_OBJECT_ACCESS.

{
global $ilUser, $lng, $rbacsystem, $ilAccess;
if ($a_user_id == "")
{
$a_user_id = $ilUser->getId();
}
switch ($a_permission)
{
case "read":
case "visible":
(!$rbacsystem->checkAccess('write', $a_ref_id)))
{
$ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("tst_warning_test_not_complete"));
return false;
}
break;
}
switch ($a_cmd)
{
case "eval_a":
case "eval_stat":
{
$ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("tst_warning_test_not_complete"));
return false;
}
break;
}
return true;
}

+ Here is the call graph for this function:

ilObjTestAccess::_checkCondition (   $a_obj_id,
  $a_operator,
  $a_value,
  $a_usr_id = 0 
)

check condition

this method is called by ilConditionHandler

Reimplemented from ilObjectAccess.

Definition at line 237 of file class.ilObjTestAccess.php.

References _hasFinished(), and _isPassed().

Referenced by ilCourseStart\isFullfilled().

{
global $ilUser;
$a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
switch($a_operator)
{
case 'passed':
return ilObjTestAccess::_isPassed($a_usr_id, $a_obj_id);
break;
case 'finished':
return ilObjTestAccess::_hasFinished($a_usr_id,$a_obj_id);
case 'not_finished':
return !ilObjTestAccess::_hasFinished($a_usr_id,$a_obj_id);
default:
return true;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjTestAccess::_checkGoto (   $a_target)

check whether goto script will succeed

Reimplemented from ilObjectAccess.

Definition at line 702 of file class.ilObjTestAccess.php.

{
global $ilAccess;
$t_arr = explode("_", $a_target);
if ($t_arr[0] != "tst" || ((int) $t_arr[1]) <= 0)
{
return false;
}
if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
{
return true;
}
return false;
}
ilObjTestAccess::_getCommands ( )

get commands

this method returns an array of all possible commands/permission combinations

example: $commands = array ( array("permission" => "read", "cmd" => "view", "lang_var" => "show"), array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"), );

Reimplemented from ilObjectAccess.

Definition at line 273 of file class.ilObjTestAccess.php.

Referenced by ilObjTestListGUI\init().

{
$commands = array
(
array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "tst_run",
"default" => true),
array("permission" => "write", "cmd" => "", "lang_var" => "edit"),
array("permission" => "tst_statistics", "cmd" => "outEvaluation", "lang_var" => "tst_statistical_evaluation")
);
return $commands;
}

+ Here is the caller graph for this function:

ilObjTestAccess::_getMaxPointsForTestPass (   $random,
  $user_id,
  $test_id,
  $pass 
)

Returns the maximum number of points available for a test pass.

Parameters
boolean$randomTRUE if the test is a random test, otherwise FALSE
int$test_idThe test id
int$passThe test pass
Returns
int The available points for the test pass

Definition at line 100 of file class.ilObjTestAccess.php.

References $ilDB, $pass, $result, and $row.

{
global $ilDB;
$max = 0;
if ($random)
{
$result = $ilDB->queryF("SELECT SUM(qpl_questions.points) maxpoints FROM tst_test_rnd_qst, qpl_questions, tst_active WHERE tst_active.active_id = tst_test_rnd_qst.active_fi AND tst_test_rnd_qst.question_fi = qpl_questions.question_id AND tst_active.test_fi = %s AND tst_test_rnd_qst.pass = %s AND tst_active.user_fi = %s",
array('integer','integer','integer'),
array($test_id, $pass, $user_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$max = $row["maxpoints"];
}
}
else
{
$result = $ilDB->queryF("SELECT SUM(qpl_questions.points) maxpoints FROM tst_test_question, qpl_questions WHERE tst_test_question.question_fi = qpl_questions.question_id AND tst_test_question.test_fi = %s",
array('integer'),
array($test_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$max = $row["maxpoints"];
}
}
return $max;
}
ilObjTestAccess::_getParticipantData (   $active_id)

Retrieves a participant name from active id.

Parameters
integer$active_idActive ID of the participant
Returns
string The output name of the user public

Definition at line 593 of file class.ilObjTestAccess.php.

References $ilDB, $lng, $name, $result, $row, ilObjTest\_lookupAnonymity(), and ilObjUser\_lookupName().

Referenced by assQuestion\_setReachedPoints(), assFileUpload\getFileUploadZIPFile(), and ilObjTest\saveManualFeedback().

{
global $lng, $ilDB;
$result = $ilDB->queryF("SELECT user_fi, test_fi FROM tst_active WHERE active_id = %s",
array("integer"),
array($active_id)
);
$row = $ilDB->fetchAssoc($result);
$user_id = $row["user_fi"];
$test_id = $row["test_fi"];
$result = $ilDB->queryF("SELECT obj_fi FROM tst_tests WHERE test_id = %s",
array("integer"),
array($test_id)
);
$row = $ilDB->fetchAssoc($result);
$obj_id = $row["obj_fi"];
include_once "./Modules/Test/classes/class.ilObjTest.php";
$is_anonymous = ilObjTest::_lookupAnonymity($obj_id);
include_once './Services/User/classes/class.ilObjUser.php';
$uname = ilObjUser::_lookupName($user_id);
$name = "";
if (strlen($uname["firstname"].$uname["lastname"]) == 0)
{
$name = $lng->txt("deleted_user");
}
else
{
if ($user_id == ANONYMOUS_USER_ID)
{
$name = $lastname;
}
else
{
$name = trim($uname["lastname"] . ", " . $uname["firstname"] . " " . $uname["title"]);
}
if ($is_anonymous)
{
$name = $lng->txt("anonymous");
}
}
return $name;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

& ilObjTestAccess::_getPassedUsers (   $a_obj_id)

Returns an array containing the users who passed the test.

Returns
array An array containing the users who passed the test. Format of the values of the resulting array: array( "user_id" => user ID, "max_points" => maximum available points in the test "reached_points" => maximum reached points of the user "mark_short" => short text of the passed mark "mark_official" => official text of the passed mark ) public

Definition at line 655 of file class.ilObjTestAccess.php.

References $data, $ilDB, $result, $row, and assQuestion\_updateTestResultCache().

Referenced by ilLPStatusTestPassed\_getStatusInfo().

{
global $ilDB;
$passed_users = array();
// Maybe SELECT DISTINCT(tst_active.user_fi)... ?
$userresult = $ilDB->queryF("SELECT DISTINCT(tst_active.active_id) FROM tst_active, tst_tests WHERE tst_tests.test_id = tst_active.test_fi AND tst_tests.obj_fi = %s",
array('integer'),
array($a_obj_id)
);
$all_participants = array();
while ($row = $ilDB->fetchAssoc($userresult))
{
array_push($all_participants, $row['active_id']);
}
$result = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM tst_result_cache, tst_active WHERE tst_active.active_id = tst_result_cache.active_fi AND " . $ilDB->in('active_fi', $all_participants, false, 'integer'));
$found_all = ($result->numRows() == count($all_participants)) ? true : false;
if (!$found_all)
{
// if the result cache entries do not exist, create them
$found_participants = array();
while ($data = $ilDB->fetchAssoc($result))
{
array_push($found_participants, $data['active_fi']);
}
foreach ($all_participants as $active_id)
{
if (!in_array($active_id, $found_participants))
{
include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
}
}
$result = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM tst_result_cache, tst_active WHERE tst_active.active_id = tst_result_cache.active_fi AND " . $ilDB->in('active_fi', $all_participants, false, 'integer'));
}
while ($data = $ilDB->fetchAssoc($result))
{
$data['user_id'] = $data['user_fi'];
array_push($passed_users, $data);
}
return $passed_users;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjTestAccess::_getQuestionCount (   $test_id)

Calculates the number of questions in a test.

Returns
int The number of questions in the test public

Definition at line 487 of file class.ilObjTestAccess.php.

References $ilDB, $result, $row, $test, and _getTestData().

Referenced by _isComplete().

{
global $ilDB;
$num = 0;
if ($test["random_test"] == 1)
{
if ($test["random_question_count"] > 0)
{
$num = $test["random_question_count"];
}
else
{
$result = $ilDB->queryF("SELECT SUM(num_of_q) questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id",
array('integer'),
array($test_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$num = $row["questioncount"];
}
}
}
else
{
$result = $ilDB->queryF("SELECT test_question_id FROM tst_test_question WHERE test_fi = %s",
array('integer'),
array($test_id)
);
$num = $result->numRows();
}
return $num;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

& ilObjTestAccess::_getTestData (   $test_id)

Returns the database content of a test with a given id.

Parameters
int$test_idDatabase id of the test
Returns
array An associative array with the contents of the tst_tests database row public

Definition at line 467 of file class.ilObjTestAccess.php.

References $ilDB, and $result.

Referenced by _getQuestionCount().

{
global $ilDB;
$result = $ilDB->queryF("SELECT * FROM tst_tests WHERE test_id = %s",
array('integer'),
array($test_id)
);
if (!$result->numRows())
{
return 0;
}
return $ilDB->fetchAssoc($result);
}

+ Here is the caller graph for this function:

ilObjTestAccess::_getTestIDFromObjectID (   $object_id)

Returns the ILIAS test id for a given object id.

Parameters
integer$object_idThe object id
Returns
mixed The ILIAS test id or FALSE if the query was not successful public

Definition at line 336 of file class.ilObjTestAccess.php.

References $ilDB, $result, and $row.

Referenced by _hasFinished(), and _isComplete().

{
global $ilDB;
$test_id = FALSE;
$result = $ilDB->queryF("SELECT test_id FROM tst_tests WHERE obj_fi = %s",
array('integer'),
array($object_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$test_id = $row["test_id"];
}
return $test_id;
}

+ Here is the caller graph for this function:

& ilObjTestAccess::_getTestQuestions (   $active_id,
  $pass = NULL 
)

Definition at line 352 of file class.ilObjTestAccess.php.

References $ilDB, $pass, $result, and $row.

{
if (is_null($pass))
{
$pass = 0;
}
$questions = array();
global $ilDB;
$result = $ilDB->queryF("SELECT test_fi FROM tst_active WHERE active_id = %s",
array('integer'),
array($active_id)
);
$test_id = "";
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
$test_id = $row["test_fi"];
}
else
{
return $questions;
}
$result = $ilDB->queryF("SELECT qpl_questions.question_id, qpl_questions.points FROM qpl_questions, tst_test_question WHERE tst_test_question.question_fi = qpl_questions.question_id AND tst_test_question.test_fi = %s ORDER BY tst_test_question.sequence",
array('integer'),
array($test_id)
);
if ($result->numRows())
{
// standard test
while ($row = $ilDB->fetchAssoc($result))
{
array_push($questions, $row);
}
}
else
{
// random test
$result = $ilDB->queryF("SELECT qpl_questions.question_id, qpl_questions.points FROM qpl_questions, tst_test_rnd_qst WHERE tst_test_rnd_qst.question_fi = qpl_questions.question_id AND tst_test_rnd_qst.active_fi = %s AND tst_test_rnd_qst.pass = %s ORDER BY tst_test_rnd_qst.sequence",
array('integer','integer'),
array($active_id, $pass)
);
if ($result->numRows())
{
while ($row = $ilDB->fetchAssoc($result))
{
array_push($questions, $row);
}
}
}
return $questions;
}
ilObjTestAccess::_hasFinished (   $a_user_id,
  $a_obj_id 
)
static

Returns information if a specific user has finished a test.

Parameters
integer$user_idDatabase id of the user
integertest obj_id
Returns
bool public

Definition at line 318 of file class.ilObjTestAccess.php.

References $ilDB, $res, and _getTestIDFromObjectID().

Referenced by _checkCondition().

{
global $ilDB;
$res = $ilDB->queryF("SELECT active_id FROM tst_active WHERE user_fi = %s AND test_fi = %s AND tries > '0'",
array('integer','integer'),
array($a_user_id, ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))
);
return $res->numRows() ? true : false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjTestAccess::_isComplete (   $a_obj_id)

Returns true, if a test is complete for use.

Returns
boolean True, if the test is complete for use, otherwise false public

Definition at line 411 of file class.ilObjTestAccess.php.

References $ilDB, $result, $row, $test, _getQuestionCount(), and _getTestIDFromObjectID().

{
global $ilDB;
$result = $ilDB->queryF("SELECT tst_mark.*, tst_tests.* FROM tst_tests, tst_mark WHERE tst_mark.test_fi = tst_tests.test_id AND tst_tests.test_id = %s",
array('integer'),
array($test_id)
);
$found = $result->numRows();
if ($found)
{
$row = $ilDB->fetchAssoc($result);
// check for at least: title, author and minimum of 1 mark step
if ((strlen($row["title"])) &&
(strlen($row["author"])) &&
($found))
{
// check also for minmum of 1 question
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
$test = new ilObjTest($obj_id, false);
$test->loadFromDb();
if (($test->getTitle()) and ($test->author) and (count($test->mark_schema->mark_steps)) and (count($test->questions)))
{
return true;
}
else
{
return false;
}
}

+ Here is the call graph for this function:

static ilObjTestAccess::_isPassed (   $user_id,
  $a_obj_id 
)
static

Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id.

Parameters
int$user_idThe user id
int$a_obj_idThe object id
Returns
boolean TRUE if the user passed the test, FALSE otherwise

Definition at line 138 of file class.ilObjTestAccess.php.

References $ilDB, $pass, $points, $res, $result, $row, ASS_MarkSchema\_getMatchingMarkFromObjId(), assQuestion\_updateTestPassResults(), and assQuestion\_updateTestResultCache().

Referenced by _checkCondition().

{
global $ilDB;
$result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
array('integer','integer'),
array($user_id, $a_obj_id)
);
if (!$result->numRows())
{
$result = $ilDB->queryF("SELECT tst_active.active_id FROM tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s",
array('integer','integer'),
array($user_id, $a_obj_id)
);
$row = $ilDB->fetchAssoc($result);
if ($row['active_id'] > 0)
{
include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
}
else
{
return false;
}
}
$result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
array('integer','integer'),
array($user_id, $a_obj_id)
);
if (!$result->numRows())
{
$result = $ilDB->queryF("SELECT tst_pass_result.*, tst_tests.pass_scoring, tst_tests.random_test, tst_tests.test_id FROM tst_pass_result, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_pass_result.active_fi = tst_active.active_id ORDER BY tst_pass_result.pass",
array('integer','integer'),
array($user_id, $a_obj_id)
);
$points = array();
while ($row = $ilDB->fetchAssoc($result))
{
array_push($points, $row);
}
$reached = 0;
$max = 0;
if ($points[0]["pass_scoring"] == 0)
{
$reached = $points[count($points)-1]["points"];
$max = $points[count($points)-1]["maxpoints"];
if (!$max)
{
$active_id = $points[count($points)-1]["active_fi"];
$pass = $points[count($points)-1]["pass"];
if (strlen($active_id) && strlen($pass))
{
include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
$max = $res['maxpoints'];
$reached = $res['points'];
}
}
}
else
{
foreach ($points as $row)
{
if ($row["points"] > $reached)
{
$reached = $row["points"];
$max = $row["maxpoints"];
if (!$max)
{
$active_id = $row["active_fi"];
$pass = $row["pass"];
if (strlen($active_id) && strlen($pass))
{
include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
$max = $res['maxpoints'];
$reached = $res['points'];
}
}
}
}
}
include_once "./Modules/Test/classes/class.assMarkSchema.php";
$percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
$mark = ASS_MarkSchema::_getMatchingMarkFromObjId($a_obj_id, $percentage);
return ($mark["passed"]) ? TRUE : FALSE;
}
else
{
$row = $ilDB->fetchAssoc($result);
return ($row['passed']) ? true : false;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjTestAccess::_lookupCreationComplete (   $a_obj_id)

checks wether all necessary parts of the test are given

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

References $ilDB, $result, and $row.

Referenced by _checkAccess(), and ilObjTestListGUI\getProperties().

{
global $ilDB;
$result = $ilDB->queryF("SELECT complete FROM tst_tests WHERE obj_fi=%s",
array('integer'),
array($a_obj_id)
);
if ($result->numRows() == 1)
{
$row = $ilDB->fetchAssoc($result);
}
return ($row['complete']) ? true : false;
}

+ Here is the caller graph for this function:

ilObjTestAccess::_lookupOnlineTestAccess (   $a_test_id,
  $a_user_id 
)

Checks if a user is allowd to run an online exam.

Returns
mixed true if the user is allowed to run the online exam or if the test isn't an online exam, an alert message if the test is an online exam and the user is not allowed to run it public

Definition at line 531 of file class.ilObjTestAccess.php.

References $ilDB, $lng, $result, and $row.

Referenced by ilObjTestListGUI\getProperties(), and ilObjTestGUI\infoScreen().

{
global $ilDB, $lng;
$result = $ilDB->queryF("SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
array('integer'),
array($a_test_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
if ($row["fixed_participants"])
{
$result = $ilDB->queryF("SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
array('integer','integer'),
array($row["test_id"], $a_user_id)
);
if ($result->numRows())
{
$row = $ilDB->fetchAssoc($result);
if (trim($row['clientip']) != "")
{
$row['clientip'] = preg_replace("/[^0-9.?*,:]+/","",$row['clientip']);
$row['clientip'] = str_replace(".","\\.",$row['clientip']);
$row['clientip'] = str_replace(Array("?","*",","), Array("[0-9]","[0-9]*","|"), $row['clientip']);
if (!preg_match("/^".$row['clientip']."$/", $_SERVER["REMOTE_ADDR"]))
{
return $lng->txt("tst_user_wrong_clientip");
}
else
{
return true;
}
}
else
{
return true;
}
}
else
{
return $lng->txt("tst_user_not_invited");
}
}
else
{
return true;
}
}
else
{
return true;
}
}

+ Here is the caller graph for this function:


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