4 include_once
"./Services/Object/classes/class.ilObjectAccess.php";
5 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
6 include_once
'./Services/AccessControl/interfaces/interface.ilConditionHandling.php';
37 function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id =
"")
43 $a_user_id = $ilUser->getId();
46 $is_admin = $rbacsystem->checkAccessOfUser($a_user_id,
'write',$a_ref_id);
49 if(!self::_isOnline($a_obj_id) && !$is_admin)
55 switch ($a_permission)
98 $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",
99 array(
'integer',
'integer',
'integer'),
100 array($test_id,
$pass, $user_id)
105 $max =
$row[
"maxpoints"];
110 $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",
117 $max =
$row[
"maxpoints"];
133 $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",
134 array(
'integer',
'integer'),
135 array($user_id, $a_obj_id)
139 $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",
140 array(
'integer',
'integer'),
141 array($user_id, $a_obj_id)
144 if (
$row[
'active_id'] > 0)
146 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
154 $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",
155 array(
'integer',
'integer'),
156 array($user_id, $a_obj_id)
160 $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",
161 array(
'integer',
'integer'),
162 array($user_id, $a_obj_id)
167 array_push($points,
$row);
171 if ($points[0][
"pass_scoring"] == 0)
173 $reached = $points[count($points)-1][
"points"];
174 $max = $points[count($points)-1][
"maxpoints"];
177 $active_id = $points[count($points)-1][
"active_fi"];
178 $pass = $points[count($points)-1][
"pass"];
179 if (strlen($active_id) && strlen(
$pass))
181 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
182 $res = assQuestion::_updateTestPassResults($active_id,
$pass, null, $a_obj_id);
183 $max =
$res[
'maxpoints'];
184 $reached =
$res[
'points'];
190 foreach ($points as
$row)
192 if ($row[
"points"] > $reached)
194 $reached = $row[
"points"];
195 $max = $row[
"maxpoints"];
198 $active_id = $row[
"active_fi"];
199 $pass = $row[
"pass"];
200 if (strlen($active_id) && strlen(
$pass))
202 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
203 $res = assQuestion::_updateTestPassResults($active_id,
$pass, null, $a_obj_id);
204 $max =
$res[
'maxpoints'];
205 $reached =
$res[
'points'];
211 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
212 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
214 return ($mark[
"passed"]) ? TRUE : FALSE;
219 return (
$row[
'passed']) ?
true :
false;
230 public static function isFailed($user_id, $a_obj_id)
241 $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",
242 array(
'integer',
'integer'),
243 array($user_id, $a_obj_id)
248 $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",
249 array(
'integer',
'integer'),
250 array($user_id, $a_obj_id)
255 array_push($points,
$row);
259 if ($points[0][
"pass_scoring"] == 0)
261 $reached = $points[count($points)-1][
"points"];
262 $max = $points[count($points)-1][
"maxpoints"];
265 $active_id = $points[count($points)-1][
"active_fi"];
266 $pass = $points[count($points)-1][
"pass"];
267 if (strlen($active_id) && strlen(
$pass))
269 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
270 $res = assQuestion::_updateTestPassResults($active_id,
$pass, null, $a_obj_id);
271 $max =
$res[
'maxpoints'];
272 $reached =
$res[
'points'];
278 foreach ($points as
$row)
280 if ($row[
"points"] > $reached)
282 $reached = $row[
"points"];
283 $max = $row[
"maxpoints"];
286 $active_id = $row[
"active_fi"];
287 $pass = $row[
"pass"];
288 if (strlen($active_id) && strlen(
$pass))
290 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
291 $res = assQuestion::_updateTestPassResults($active_id,
$pass, null, $a_obj_id);
292 $max =
$res[
'maxpoints'];
293 $reached =
$res[
'points'];
299 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
300 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
302 return ($mark[
"failed"]) ? TRUE : FALSE;
307 return (
$row[
'failed']) ? TRUE : FALSE;
321 "SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests ".
322 "WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s ".
323 "AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
324 array(
'integer',
'integer'),
325 array($a_user_id, $a_obj_id)
329 $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",
330 array(
'integer',
'integer'),
331 array($a_user_id, $a_obj_id)
334 if (
$row[
'active_id'] > 0)
336 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
358 include_once
'./Services/AccessControl/classes/class.ilConditionHandler.php';
373 public static function checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id)
375 include_once
'./Services/AccessControl/classes/class.ilConditionHandler.php';
414 array(
"permission" =>
"write",
"cmd" =>
"questionsTabGateway",
"lang_var" =>
"tst_edit_questions"),
415 array(
"permission" =>
"write",
"cmd" =>
"ilObjTestSettingsGeneralGUI::showForm",
"lang_var" =>
"settings"),
416 array(
"permission" =>
"read",
"cmd" =>
"infoScreen",
"lang_var" =>
"tst_run",
419 array(
"permission" =>
"tst_statistics",
"cmd" =>
"outEvaluation",
"lang_var" =>
"tst_statistical_evaluation"),
436 $result = $ilDB->queryF(
"SELECT complete FROM tst_tests WHERE obj_fi=%s",
445 return (
$row[
'complete']) ?
true :
false;
464 if( !isset(self::$hasFinishedCache[
"{$a_user_id}:{$a_obj_id}"]) )
466 require_once
'Modules/Test/classes/class.ilTestParticipantData.php';
467 require_once
'Modules/Test/classes/class.ilTestSessionFactory.php';
468 require_once
'Modules/Test/classes/class.ilTestPassesSelector.php';
475 $partData->setUserIds(array($a_user_id));
476 $partData->load($testOBJ->getTestId());
478 $activeId = $partData->getActiveIdByUserId($a_user_id);
481 $testSession = $testSessionFactory->getSession($activeId);
484 $testPassesSelector->setActiveId($activeId);
485 $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass());
487 self::$hasFinishedCache[
"{$a_user_id}:{$a_obj_id}"] = count($testPassesSelector->getClosedPasses());
490 return self::$hasFinishedCache[
"{$a_user_id}:{$a_obj_id}"];
504 $result = $ilDB->queryF(
"SELECT test_id FROM tst_tests WHERE obj_fi = %s",
511 $test_id =
$row[
"test_id"];
522 $questions = array();
525 $result = $ilDB->queryF(
"SELECT test_fi FROM tst_active WHERE active_id = %s",
533 $test_id =
$row[
"test_fi"];
539 $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",
548 array_push($questions,
$row);
554 $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",
555 array(
'integer',
'integer'),
556 array($active_id,
$pass)
562 array_push($questions,
$row);
580 SELECT tst_tests.complete
583 ON tst_tests.obj_fi = object_data.obj_id
584 WHERE object_data.obj_id = %s
587 $res = $ilDB->queryF(
$query, array(
'integer'), array($a_obj_id));
589 while(
$row = $ilDB->fetchAssoc(
$res) )
591 return (
bool)
$row[
'complete'];
607 $result = $ilDB->queryF(
"SELECT * FROM tst_tests WHERE test_id = %s",
615 return $ilDB->fetchAssoc(
$result);
628 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
634 return $row[
"obj_fi"];
649 SELECT DISTINCT t.obj_fi
651 INNER JOIN tst_rnd_quest_set_qpls r
652 ON t.test_id = r.test_fi
656 $result = $ilDB->queryF(
$query, array(
'integer'), array($qpl_id));
678 $result = $ilDB->queryF(
"SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
685 if (
$row[
"fixed_participants"])
687 $result = $ilDB->queryF(
"SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
688 array(
'integer',
'integer'),
689 array(
$row[
"test_id"], $a_user_id)
694 if (trim(
$row[
'clientip']) !=
"")
696 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"",
$row[
'clientip']);
697 $row[
'clientip'] = str_replace(
".",
"\\.",
$row[
'clientip']);
698 $row[
'clientip'] = str_replace(Array(
"?",
"*",
","), Array(
"[0-9]",
"[0-9]*",
"|"),
$row[
'clientip']);
699 if (!preg_match(
"/^".
$row[
'clientip'].
"$/", $_SERVER[
"REMOTE_ADDR"]))
701 return $lng->txt(
"tst_user_wrong_clientip");
715 return $lng->txt(
"tst_user_not_invited");
740 $result = $ilDB->queryF(
"SELECT * FROM tst_active WHERE active_id = %s",
745 $user_id =
$row[
"user_fi"];
746 $test_id =
$row[
"test_fi"];
747 $importname =
$row[
'importname'];
749 $result = $ilDB->queryF(
"SELECT obj_fi FROM tst_tests WHERE test_id = %s",
754 $obj_id =
$row[
"obj_fi"];
756 include_once
"./Modules/Test/classes/class.ilObjTest.php";
759 include_once
'./Services/User/classes/class.ilObjUser.php';
763 if (strlen($importname))
765 $name = $importname .
' (' . $lng->txt(
'imported') .
')';
767 else if (strlen($uname[
"firstname"].$uname[
"lastname"]) == 0)
769 $name = $lng->txt(
"deleted_user");
773 if ($user_id == ANONYMOUS_USER_ID)
779 $name = trim($uname[
"lastname"] .
", " . $uname[
"firstname"] .
" " . $uname[
"title"]);
783 $name = $lng->txt(
"anonymous");
799 $result = $ilDB->queryF(
"SELECT user_fi FROM tst_active WHERE active_id = %s",
804 return $row[
"user_fi"];
826 $passed_users = array();
828 $userresult = $ilDB->queryF(
"
829 SELECT tst_active.active_id, COUNT(tst_sequence.active_fi) sequences
831 INNER JOIN tst_active
832 ON tst_active.test_fi = tst_tests.test_id
833 LEFT JOIN tst_sequence
834 ON tst_sequence.active_fi = tst_active.active_id
835 WHERE tst_tests.obj_fi = %s
836 GROUP BY tst_active.active_id
838 array(
'integer'), array($a_obj_id)
840 $all_participants = array();
841 $notAttempted = array();
842 while (
$row = $ilDB->fetchAssoc($userresult))
844 if(
$row[
'sequences'] == 0)
846 $notAttempted[
$row[
'active_id']] = $row[
'active_id'];
849 $all_participants[
$row[
'active_id']] = $row[
'active_id'];
852 $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'));
853 $found_all = (
$result->numRows() == count($all_participants)) ?
true :
false;
857 $found_participants = array();
858 while ($data = $ilDB->fetchAssoc(
$result))
860 array_push($found_participants, $data[
'active_fi']);
862 foreach ($all_participants as $active_id)
864 if (!in_array($active_id, $found_participants))
866 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
870 $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'));
872 while ($data = $ilDB->fetchAssoc(
$result))
874 if( isset($notAttempted[$data[
'active_fi']]) )
880 $data[
'user_id'] = $data[
'user_fi'];
881 array_push($passed_users, $data);
883 return $passed_users;
893 $t_arr = explode(
"_", $a_target);
895 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0)
900 if ($ilAccess->checkAccess(
"read",
"", $t_arr[1]))
937 AND online_status = 1
940 $result = $ilDB->queryF(
$query, array(
'integer'), array($a_obj_id) );
942 return $result->numRows() == 1;