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)
176 array_push($points,
$row);
180 if ($points[0][
"pass_scoring"] == 0)
182 $reached = $points[count($points)-1][
"points"];
183 $max = $points[count($points)-1][
"maxpoints"];
186 $active_id = $points[count($points)-1][
"active_fi"];
187 $pass = $points[count($points)-1][
"pass"];
188 if (strlen($active_id) && strlen(
$pass))
190 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
192 $max =
$res[
'maxpoints'];
193 $reached =
$res[
'points'];
199 foreach ($points as
$row)
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" =>
"write",
"cmd" =>
"showPage",
"lang_var" =>
"tst_edit_questions"),
278 array(
"permission" =>
"write",
"cmd" =>
"properties",
"lang_var" =>
"settings"),
279 array(
"permission" =>
"read",
"cmd" =>
"infoScreen",
"lang_var" =>
"tst_run",
282 array(
"permission" =>
"tst_statistics",
"cmd" =>
"outEvaluation",
"lang_var" =>
"tst_statistical_evaluation"),
299 $result = $ilDB->queryF(
"SELECT complete FROM tst_tests WHERE obj_fi=%s",
308 return (
$row[
'complete']) ?
true :
false;
324 $res = $ilDB->queryF(
"SELECT active_id FROM tst_active WHERE user_fi = %s AND test_fi = %s AND tries > '0'",
325 array(
'integer',
'integer'),
328 return $res->numRows() ?
true :
false;
342 $result = $ilDB->queryF(
"SELECT test_id FROM tst_tests WHERE obj_fi = %s",
349 $test_id =
$row[
"test_id"];
360 $questions = array();
363 $result = $ilDB->queryF(
"SELECT test_fi FROM tst_active WHERE active_id = %s",
371 $test_id =
$row[
"test_fi"];
377 $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",
386 array_push($questions,
$row);
392 $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",
393 array(
'integer',
'integer'),
394 array($active_id,
$pass)
400 array_push($questions,
$row);
418 $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",
427 if ((strlen(
$row[
"title"])) &&
428 (strlen(
$row[
"author"])) &&
452 if ((
$test->getTitle()) and (
$test->author) and (count(
$test->mark_schema->mark_steps)) and (count(
$test->questions)))
472 $result = $ilDB->queryF(
"SELECT * FROM tst_tests WHERE test_id = %s",
480 return $ilDB->fetchAssoc(
$result);
493 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
499 return $row[
"obj_fi"];
516 if (
$test[
"random_test"] == 1)
518 if (
$test[
"random_question_count"] > 0)
520 $num =
$test[
"random_question_count"];
524 $result = $ilDB->queryF(
"SELECT SUM(num_of_q) questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id",
531 $num =
$row[
"questioncount"];
537 $result = $ilDB->queryF(
"SELECT test_question_id FROM tst_test_question WHERE test_fi = %s",
557 $query =
'SELECT DISTINCT t.obj_fi '
559 .
'INNER JOIN tst_test_random r '
560 .
'ON t.test_id = r.test_fi '
561 .
'WHERE r.questionpool_fi = '
562 . $ilDB->quote($qpl_id,
'integer');
586 $result = $ilDB->queryF(
"SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
593 if (
$row[
"fixed_participants"])
595 $result = $ilDB->queryF(
"SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
596 array(
'integer',
'integer'),
597 array(
$row[
"test_id"], $a_user_id)
602 if (trim(
$row[
'clientip']) !=
"")
604 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"",
$row[
'clientip']);
605 $row[
'clientip'] = str_replace(
".",
"\\.",
$row[
'clientip']);
606 $row[
'clientip'] = str_replace(Array(
"?",
"*",
","), Array(
"[0-9]",
"[0-9]*",
"|"),
$row[
'clientip']);
607 if (!preg_match(
"/^".
$row[
'clientip'].
"$/", $_SERVER[
"REMOTE_ADDR"]))
609 return $lng->txt(
"tst_user_wrong_clientip");
623 return $lng->txt(
"tst_user_not_invited");
648 $result = $ilDB->queryF(
"SELECT * FROM tst_active WHERE active_id = %s",
653 $user_id =
$row[
"user_fi"];
654 $test_id =
$row[
"test_fi"];
655 $importname =
$row[
'importname'];
657 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
662 $obj_id =
$row[
"obj_fi"];
664 include_once
"./Modules/Test/classes/class.ilObjTest.php";
667 include_once
'./Services/User/classes/class.ilObjUser.php';
671 if (strlen($importname))
673 $name = $importname .
' (' . $lng->txt(
'imported') .
')';
675 else if (strlen($uname[
"firstname"].$uname[
"lastname"]) == 0)
677 $name = $lng->txt(
"deleted_user");
681 if ($user_id == ANONYMOUS_USER_ID)
687 $name = trim($uname[
"lastname"] .
", " . $uname[
"firstname"] .
" " . $uname[
"title"]);
691 $name = $lng->txt(
"anonymous");
707 $result = $ilDB->queryF(
"SELECT user_fi FROM tst_active WHERE active_id = %s",
712 return $row[
"user_fi"];
734 $passed_users = array();
736 $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",
740 $all_participants = array();
741 while (
$row = $ilDB->fetchAssoc($userresult))
743 array_push($all_participants,
$row[
'active_id']);
746 $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'));
747 $found_all = (
$result->numRows() == count($all_participants)) ?
true :
false;
751 $found_participants = array();
754 array_push($found_participants,
$data[
'active_fi']);
756 foreach ($all_participants as $active_id)
758 if (!in_array($active_id, $found_participants))
760 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
764 $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'));
769 array_push($passed_users,
$data);
771 return $passed_users;
781 $t_arr = explode(
"_", $a_target);
783 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0)
788 if ($ilAccess->checkAccess(
"visible",
"", $t_arr[1]))
825 AND online_status = 1
828 $result = $ilDB->queryF(
$query, array(
'integer'), array($a_obj_id) );
830 return $result->numRows() == 1;