24 include_once
"./Services/Object/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 =
"")
62 $a_user_id = $ilUser->getId();
65 $is_admin = $rbacsystem->checkAccessOfUser($a_user_id,
'write',$a_ref_id);
68 if(!self::_isOnline($a_obj_id) && !$is_admin)
74 switch ($a_permission)
117 $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",
118 array(
'integer',
'integer',
'integer'),
119 array($test_id,
$pass, $user_id)
124 $max =
$row[
"maxpoints"];
129 $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",
136 $max =
$row[
"maxpoints"];
153 $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",
154 array(
'integer',
'integer'),
155 array($user_id, $a_obj_id)
159 $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",
160 array(
'integer',
'integer'),
161 array($user_id, $a_obj_id)
164 if (
$row[
'active_id'] > 0)
166 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
174 $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",
175 array(
'integer',
'integer'),
176 array($user_id, $a_obj_id)
180 $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",
181 array(
'integer',
'integer'),
182 array($user_id, $a_obj_id)
187 array_push($points,
$row);
191 if ($points[0][
"pass_scoring"] == 0)
193 $reached = $points[count($points)-1][
"points"];
194 $max = $points[count($points)-1][
"maxpoints"];
197 $active_id = $points[count($points)-1][
"active_fi"];
198 $pass = $points[count($points)-1][
"pass"];
199 if (strlen($active_id) && strlen(
$pass))
201 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
203 $max =
$res[
'maxpoints'];
204 $reached =
$res[
'points'];
210 foreach ($points as
$row)
212 if ($row[
"points"] > $reached)
214 $reached = $row[
"points"];
215 $max = $row[
"maxpoints"];
218 $active_id = $row[
"active_fi"];
219 $pass = $row[
"pass"];
220 if (strlen($active_id) && strlen(
$pass))
222 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
224 $max =
$res[
'maxpoints'];
225 $reached =
$res[
'points'];
231 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
232 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
234 return ($mark[
"passed"]) ? TRUE : FALSE;
239 return (
$row[
'passed']) ?
true :
false;
252 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
288 array(
"permission" =>
"write",
"cmd" =>
"showPage",
"lang_var" =>
"tst_edit_questions"),
289 array(
"permission" =>
"write",
"cmd" =>
"properties",
"lang_var" =>
"settings"),
290 array(
"permission" =>
"read",
"cmd" =>
"infoScreen",
"lang_var" =>
"tst_run",
293 array(
"permission" =>
"tst_statistics",
"cmd" =>
"outEvaluation",
"lang_var" =>
"tst_statistical_evaluation"),
310 $result = $ilDB->queryF(
"SELECT complete FROM tst_tests WHERE obj_fi=%s",
319 return (
$row[
'complete']) ?
true :
false;
335 $res = $ilDB->queryF(
"SELECT active_id FROM tst_active WHERE user_fi = %s AND test_fi = %s AND tries > '0'",
336 array(
'integer',
'integer'),
339 return $res->numRows() ?
true :
false;
353 $result = $ilDB->queryF(
"SELECT test_id FROM tst_tests WHERE obj_fi = %s",
360 $test_id =
$row[
"test_id"];
371 $questions = array();
374 $result = $ilDB->queryF(
"SELECT test_fi FROM tst_active WHERE active_id = %s",
382 $test_id =
$row[
"test_fi"];
388 $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",
397 array_push($questions,
$row);
403 $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",
404 array(
'integer',
'integer'),
405 array($active_id,
$pass)
411 array_push($questions,
$row);
429 $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",
438 if ((strlen(
$row[
"title"])) &&
439 (strlen(
$row[
"author"])) &&
463 if ((
$test->getTitle()) and (
$test->author) and (count(
$test->mark_schema->mark_steps)) and (count(
$test->questions)))
483 $result = $ilDB->queryF(
"SELECT * FROM tst_tests WHERE test_id = %s",
491 return $ilDB->fetchAssoc(
$result);
504 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
510 return $row[
"obj_fi"];
527 if (
$test[
"random_test"] == 1)
529 if (
$test[
"random_question_count"] > 0)
531 $num =
$test[
"random_question_count"];
535 $result = $ilDB->queryF(
"SELECT SUM(num_of_q) questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id",
542 $num =
$row[
"questioncount"];
548 $result = $ilDB->queryF(
"SELECT test_question_id FROM tst_test_question WHERE test_fi = %s",
568 $query =
'SELECT DISTINCT t.obj_fi '
570 .
'INNER JOIN tst_test_random r '
571 .
'ON t.test_id = r.test_fi '
572 .
'WHERE r.questionpool_fi = '
573 . $ilDB->quote($qpl_id,
'integer');
597 $result = $ilDB->queryF(
"SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
604 if (
$row[
"fixed_participants"])
606 $result = $ilDB->queryF(
"SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
607 array(
'integer',
'integer'),
608 array(
$row[
"test_id"], $a_user_id)
613 if (trim(
$row[
'clientip']) !=
"")
615 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"",
$row[
'clientip']);
616 $row[
'clientip'] = str_replace(
".",
"\\.",
$row[
'clientip']);
617 $row[
'clientip'] = str_replace(Array(
"?",
"*",
","), Array(
"[0-9]",
"[0-9]*",
"|"),
$row[
'clientip']);
618 if (!preg_match(
"/^".
$row[
'clientip'].
"$/", $_SERVER[
"REMOTE_ADDR"]))
620 return $lng->txt(
"tst_user_wrong_clientip");
634 return $lng->txt(
"tst_user_not_invited");
659 $result = $ilDB->queryF(
"SELECT * FROM tst_active WHERE active_id = %s",
664 $user_id =
$row[
"user_fi"];
665 $test_id =
$row[
"test_fi"];
666 $importname =
$row[
'importname'];
668 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
673 $obj_id =
$row[
"obj_fi"];
675 include_once
"./Modules/Test/classes/class.ilObjTest.php";
678 include_once
'./Services/User/classes/class.ilObjUser.php';
682 if (strlen($importname))
684 $name = $importname .
' (' . $lng->txt(
'imported') .
')';
686 else if (strlen($uname[
"firstname"].$uname[
"lastname"]) == 0)
688 $name = $lng->txt(
"deleted_user");
692 if ($user_id == ANONYMOUS_USER_ID)
698 $name = trim($uname[
"lastname"] .
", " . $uname[
"firstname"] .
" " . $uname[
"title"]);
702 $name = $lng->txt(
"anonymous");
718 $result = $ilDB->queryF(
"SELECT user_fi FROM tst_active WHERE active_id = %s",
723 return $row[
"user_fi"];
745 $passed_users = array();
747 $userresult = $ilDB->queryF(
"
748 SELECT tst_active.active_id, COUNT(tst_sequence.active_fi) sequences
750 INNER JOIN tst_active
751 ON tst_active.test_fi = tst_tests.test_id
752 LEFT JOIN tst_sequence
753 ON tst_sequence.active_fi = tst_active.active_id
754 WHERE tst_tests.obj_fi = %s
755 GROUP BY tst_active.active_id
757 array(
'integer'), array($a_obj_id)
759 $all_participants = array();
760 $notAttempted = array();
761 while (
$row = $ilDB->fetchAssoc($userresult))
763 if(
$row[
'sequences'] == 0)
765 $notAttempted[
$row[
'active_id']] = $row[
'active_id'];
768 $all_participants[
$row[
'active_id']] = $row[
'active_id'];
771 $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'));
772 $found_all = (
$result->numRows() == count($all_participants)) ?
true :
false;
776 $found_participants = array();
779 array_push($found_participants,
$data[
'active_fi']);
781 foreach ($all_participants as $active_id)
783 if (!in_array($active_id, $found_participants))
785 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
789 $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'));
793 if( isset($notAttempted[
$data[
'active_fi']]) )
799 $data[
'user_id'] = $data[
'user_fi'];
800 array_push($passed_users, $data);
802 return $passed_users;
812 $t_arr = explode(
"_", $a_target);
814 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0)
819 if ($ilAccess->checkAccess(
"visible",
"", $t_arr[1]))
856 AND online_status = 1
859 $result = $ilDB->queryF(
$query, array(
'integer'), array($a_obj_id) );
861 return $result->numRows() == 1;