24 include_once
"./classes/class.ilObjectAccess.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
56 function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id =
"")
58 global $ilUser,
$lng, $rbacsystem, $ilAccess;
61 $a_user_id = $ilUser->getId();
64 switch ($a_permission)
69 (!$rbacsystem->checkAccess(
'write', $a_ref_id)))
106 $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",
107 array(
'integer',
'integer',
'integer'),
108 array($test_id,
$pass, $user_id)
113 $max =
$row[
"maxpoints"];
118 $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",
125 $max =
$row[
"maxpoints"];
142 $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",
143 array(
'integer',
'integer'),
144 array($user_id, $a_obj_id)
148 $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",
149 array(
'integer',
'integer'),
150 array($user_id, $a_obj_id)
153 if (
$row[
'active_id'] > 0)
155 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
163 $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",
164 array(
'integer',
'integer'),
165 array($user_id, $a_obj_id)
169 $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",
170 array(
'integer',
'integer'),
171 array($user_id, $a_obj_id)
180 if (
$points[0][
"pass_scoring"] == 0)
188 if (strlen($active_id) && strlen(
$pass))
190 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
192 $max =
$res[
'maxpoints'];
193 $reached =
$res[
'points'];
201 if ($row[
"points"] > $reached)
203 $reached = $row[
"points"];
204 $max = $row[
"maxpoints"];
207 $active_id = $row[
"active_fi"];
208 $pass = $row[
"pass"];
209 if (strlen($active_id) && strlen(
$pass))
211 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
213 $max =
$res[
'maxpoints'];
214 $reached =
$res[
'points'];
220 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
221 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
223 return ($mark[
"passed"]) ? TRUE : FALSE;
228 return (
$row[
'passed']) ?
true :
false;
241 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
277 array(
"permission" =>
"read",
"cmd" =>
"infoScreen",
"lang_var" =>
"tst_run",
279 array(
"permission" =>
"write",
"cmd" =>
"",
"lang_var" =>
"edit"),
280 array(
"permission" =>
"tst_statistics",
"cmd" =>
"outEvaluation",
"lang_var" =>
"tst_statistical_evaluation")
297 $result = $ilDB->queryF(
"SELECT complete FROM tst_tests WHERE obj_fi=%s",
306 return (
$row[
'complete']) ?
true :
false;
322 $res = $ilDB->queryF(
"SELECT active_id FROM tst_active WHERE user_fi = %s AND test_fi = %s AND tries > '0'",
323 array(
'integer',
'integer'),
326 return $res->numRows() ?
true :
false;
340 $result = $ilDB->queryF(
"SELECT test_id FROM tst_tests WHERE obj_fi = %s",
347 $test_id =
$row[
"test_id"];
358 $questions = array();
361 $result = $ilDB->queryF(
"SELECT test_fi FROM tst_active WHERE active_id = %s",
369 $test_id =
$row[
"test_fi"];
375 $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",
384 array_push($questions,
$row);
390 $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",
391 array(
'integer',
'integer'),
392 array($active_id,
$pass)
398 array_push($questions,
$row);
416 $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",
425 if ((strlen(
$row[
"title"])) &&
426 (strlen(
$row[
"author"])) &&
450 if ((
$test->getTitle()) and (
$test->author) and (count(
$test->mark_schema->mark_steps)) and (count(
$test->questions)))
470 $result = $ilDB->queryF(
"SELECT * FROM tst_tests WHERE test_id = %s",
478 return $ilDB->fetchAssoc(
$result);
495 if (
$test[
"random_test"] == 1)
497 if (
$test[
"random_question_count"] > 0)
499 $num =
$test[
"random_question_count"];
503 $result = $ilDB->queryF(
"SELECT SUM(num_of_q) questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id",
510 $num =
$row[
"questioncount"];
516 $result = $ilDB->queryF(
"SELECT test_question_id FROM tst_test_question WHERE test_fi = %s",
535 $result = $ilDB->queryF(
"SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
542 if (
$row[
"fixed_participants"])
544 $result = $ilDB->queryF(
"SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
545 array(
'integer',
'integer'),
546 array(
$row[
"test_id"], $a_user_id)
551 if (trim(
$row[
'clientip']) !=
"")
553 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"",
$row[
'clientip']);
554 $row[
'clientip'] = str_replace(
".",
"\\.",
$row[
'clientip']);
555 $row[
'clientip'] = str_replace(Array(
"?",
"*",
","), Array(
"[0-9]",
"[0-9]*",
"|"),
$row[
'clientip']);
556 if (!preg_match(
"/^".
$row[
'clientip'].
"$/", $_SERVER[
"REMOTE_ADDR"]))
558 return $lng->txt(
"tst_user_wrong_clientip");
572 return $lng->txt(
"tst_user_not_invited");
597 $result = $ilDB->queryF(
"SELECT user_fi, test_fi FROM tst_active WHERE active_id = %s",
602 $user_id =
$row[
"user_fi"];
603 $test_id =
$row[
"test_fi"];
605 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
610 $obj_id =
$row[
"obj_fi"];
612 include_once
"./Modules/Test/classes/class.ilObjTest.php";
615 include_once
'./Services/User/classes/class.ilObjUser.php';
619 if (strlen($uname[
"firstname"].$uname[
"lastname"]) == 0)
621 $name = $lng->txt(
"deleted_user");
625 if ($user_id == ANONYMOUS_USER_ID)
631 $name = trim($uname[
"lastname"] .
", " . $uname[
"firstname"] .
" " . $uname[
"title"]);
635 $name = $lng->txt(
"anonymous");
659 $passed_users = array();
661 $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",
665 $all_participants = array();
666 while (
$row = $ilDB->fetchAssoc($userresult))
668 array_push($all_participants,
$row[
'active_id']);
671 $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'));
672 $found_all = (
$result->numRows() == count($all_participants)) ?
true :
false;
676 $found_participants = array();
679 array_push($found_participants,
$data[
'active_fi']);
681 foreach ($all_participants as $active_id)
683 if (!in_array($active_id, $found_participants))
685 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
689 $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'));
694 array_push($passed_users,
$data);
696 return $passed_users;
706 $t_arr = explode(
"_", $a_target);
708 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0)
713 if ($ilAccess->checkAccess(
"visible",
"", $t_arr[1]))