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)
110 if ($result->numRows())
112 $row = $ilDB->fetchAssoc($result);
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",
122 if ($result->numRows())
124 $row = $ilDB->fetchAssoc($result);
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)
146 if (!$result->numRows())
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)
152 $row = $ilDB->fetchAssoc($result);
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)
167 if (!$result->numRows())
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)
174 while (
$row = $ilDB->fetchAssoc($result))
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;
227 $row = $ilDB->fetchAssoc($result);
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",
301 if ($result->numRows() == 1)
303 $row = $ilDB->fetchAssoc($result);
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",
344 if ($result->numRows())
346 $row = $ilDB->fetchAssoc($result);
347 $test_id =
$row[
"test_id"];
358 $questions = array();
361 $result = $ilDB->queryF(
"SELECT test_fi FROM tst_active WHERE active_id = %s",
366 if ($result->numRows())
368 $row = $ilDB->fetchAssoc($result);
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",
379 if ($result->numRows())
382 while (
$row = $ilDB->fetchAssoc($result))
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)
394 if ($result->numRows())
396 while (
$row = $ilDB->fetchAssoc($result))
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",
420 $found = $result->numRows();
423 $row = $ilDB->fetchAssoc($result);
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",
474 if (!$result->numRows())
478 return $ilDB->fetchAssoc($result);
491 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
496 $row = $ilDB->fetchAssoc($result);
497 return $row[
"obj_fi"];
514 if (
$test[
"random_test"] == 1)
516 if (
$test[
"random_question_count"] > 0)
518 $num =
$test[
"random_question_count"];
522 $result = $ilDB->queryF(
"SELECT SUM(num_of_q) questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id",
526 if ($result->numRows())
528 $row = $ilDB->fetchAssoc($result);
529 $num =
$row[
"questioncount"];
535 $result = $ilDB->queryF(
"SELECT test_question_id FROM tst_test_question WHERE test_fi = %s",
539 $num = $result->numRows();
555 $query =
'SELECT DISTINCT t.obj_fi '
557 .
'INNER JOIN tst_test_random r '
558 .
'ON t.test_id = r.test_fi '
559 .
'WHERE r.questionpool_fi = '
560 . $ilDB->quote($qpl_id,
'integer');
562 $result = $ilDB->query(
$query);
565 while (
$row = $ilDB->fetchAssoc($result))
584 $result = $ilDB->queryF(
"SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
588 if ($result->numRows())
590 $row = $ilDB->fetchAssoc($result);
591 if (
$row[
"fixed_participants"])
593 $result = $ilDB->queryF(
"SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
594 array(
'integer',
'integer'),
595 array(
$row[
"test_id"], $a_user_id)
597 if ($result->numRows())
599 $row = $ilDB->fetchAssoc($result);
600 if (trim(
$row[
'clientip']) !=
"")
602 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"",
$row[
'clientip']);
603 $row[
'clientip'] = str_replace(
".",
"\\.",
$row[
'clientip']);
604 $row[
'clientip'] = str_replace(Array(
"?",
"*",
","), Array(
"[0-9]",
"[0-9]*",
"|"),
$row[
'clientip']);
605 if (!preg_match(
"/^".
$row[
'clientip'].
"$/", $_SERVER[
"REMOTE_ADDR"]))
607 return $lng->txt(
"tst_user_wrong_clientip");
621 return $lng->txt(
"tst_user_not_invited");
646 $result = $ilDB->queryF(
"SELECT * FROM tst_active WHERE active_id = %s",
650 $row = $ilDB->fetchAssoc($result);
651 $user_id =
$row[
"user_fi"];
652 $test_id =
$row[
"test_fi"];
653 $importname =
$row[
'importname'];
655 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
659 $row = $ilDB->fetchAssoc($result);
660 $obj_id =
$row[
"obj_fi"];
662 include_once
"./Modules/Test/classes/class.ilObjTest.php";
665 include_once
'./Services/User/classes/class.ilObjUser.php';
669 if (strlen($importname))
671 $name = $importname .
' (' . $lng->txt(
'imported') .
')';
673 else if (strlen($uname[
"firstname"].$uname[
"lastname"]) == 0)
675 $name = $lng->txt(
"deleted_user");
679 if ($user_id == ANONYMOUS_USER_ID)
685 $name = trim($uname[
"lastname"] .
", " . $uname[
"firstname"] .
" " . $uname[
"title"]);
689 $name = $lng->txt(
"anonymous");
705 $result = $ilDB->queryF(
"SELECT user_fi FROM tst_active WHERE active_id = %s",
709 $row = $ilDB->fetchAssoc($result);
710 return $row[
"user_fi"];
732 $passed_users = array();
734 $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",
738 $all_participants = array();
739 while (
$row = $ilDB->fetchAssoc($userresult))
741 array_push($all_participants,
$row[
'active_id']);
744 $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'));
745 $found_all = ($result->numRows() == count($all_participants)) ?
true :
false;
749 $found_participants = array();
750 while (
$data = $ilDB->fetchAssoc($result))
752 array_push($found_participants,
$data[
'active_fi']);
754 foreach ($all_participants as $active_id)
756 if (!in_array($active_id, $found_participants))
758 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
762 $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'));
764 while (
$data = $ilDB->fetchAssoc($result))
767 array_push($passed_users,
$data);
769 return $passed_users;
779 $t_arr = explode(
"_", $a_target);
781 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0)
786 if ($ilAccess->checkAccess(
"visible",
"", $t_arr[1]))