19 declare(strict_types=1);
53 $this->db = $DIC[
'ilDB'];
54 $this->
user = $DIC[
'ilUser'];
55 $this->
lng = $DIC[
'lng'];
56 $this->rbac_system = $DIC[
'rbacsystem'];
57 $this->
access = $DIC[
'ilAccess'];
71 return !$can_it->isOk() || $can_it->value();
78 ),
new Error(
'Not a known path.'));
88 public function _checkAccess(
string $cmd,
string $permission,
int $ref_id,
int $obj_id,
int $user_id = null): bool
90 if (is_null($user_id)) {
91 $user_id = $this->
user->getId();
94 $is_admin = $this->rbac_system->checkAccessOfUser($user_id,
'write', $ref_id);
97 switch ($permission) {
128 public static function _isPassed($user_id, $a_obj_id): bool
131 $ilDB = $DIC[
'ilDB'];
135 $result =
$ilDB->queryF(
136 "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",
137 [
'integer',
'integer'],
138 [$user_id, $a_obj_id]
140 if (!$result->numRows()) {
141 $result =
$ilDB->queryF(
142 "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",
143 [
'integer',
'integer'],
144 [$user_id, $a_obj_id]
146 $row =
$ilDB->fetchAssoc($result);
147 if ($row !== null && $row[
'active_id'] > 0) {
148 $test->updateTestResultCache($row[
'active_id']);
153 $result =
$ilDB->queryF(
154 "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 [
'integer',
'integer'],
156 [$user_id, $a_obj_id]
158 if (!$result->numRows()) {
159 $result =
$ilDB->queryF(
160 "SELECT tst_pass_result.*, tst_tests.pass_scoring, 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 [
'integer',
'integer'],
162 [$user_id, $a_obj_id]
165 if (!$result->numRows()) {
170 while ($row =
$ilDB->fetchAssoc($result)) {
171 array_push($points, $row);
175 if ($points[0][
"pass_scoring"] == 0) {
176 $reached = $points[count($points) - 1][
"points"];
177 $max = $points[count($points) - 1][
"maxpoints"];
179 $active_id = $points[count($points) - 1][
"active_fi"];
180 $pass = $points[count($points) - 1][
"pass"];
181 if (strlen($active_id) && strlen($pass)) {
182 $res = $test->updateTestPassResults($active_id, $pass,
false, null, $a_obj_id);
183 $max =
$res[
'maxpoints'];
184 $reached =
$res[
'points'];
188 foreach ($points as $row) {
189 if ($row[
"points"] > $reached) {
190 $reached = $row[
"points"];
191 $max = $row[
"maxpoints"];
193 $active_id = $row[
"active_fi"];
194 $pass = $row[
"pass"];
195 if (strlen($active_id) && strlen($pass)) {
196 $res = $test->updateTestPassResults($active_id, $pass,
false, null, $a_obj_id);
197 $max =
$res[
'maxpoints'];
198 $reached =
$res[
'points'];
204 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
205 return $test->getMarkSchema()->getMatchingMark($percentage)->getPassed() === 1;
207 $row =
$ilDB->fetchAssoc($result);
208 return ($row[
'passed']) ? true :
false;
219 public static function isFailed($user_id, $a_obj_id): bool
222 $ilDB = $DIC[
'ilDB'];
224 $ret = self::updateTestResultCache($user_id, $a_obj_id);
232 $result =
$ilDB->queryF(
233 "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",
234 [
'integer',
'integer'],
235 [$user_id, $a_obj_id]
238 if (!$result->numRows()) {
239 $result =
$ilDB->queryF(
240 "SELECT tst_pass_result.*, tst_tests.pass_scoring 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",
241 [
'integer',
'integer'],
242 [$user_id, $a_obj_id]
245 while ($row =
$ilDB->fetchAssoc($result)) {
246 array_push($points, $row);
250 if ($points[0][
"pass_scoring"] == 0) {
251 $reached = $points[count($points) - 1][
"points"];
252 $max = $points[count($points) - 1][
"maxpoints"];
254 $active_id = $points[count($points) - 1][
"active_fi"];
255 $pass = $points[count($points) - 1][
"pass"];
256 if (strlen($active_id) && strlen($pass)) {
257 $res = $test->updateTestPassResults($active_id, $pass,
false, null, $a_obj_id);
258 $max =
$res[
'maxpoints'];
259 $reached =
$res[
'points'];
263 foreach ($points as $row) {
264 if ($row[
"points"] > $reached) {
265 $reached = $row[
"points"];
266 $max = $row[
"maxpoints"];
268 $active_id = $row[
"active_fi"];
269 $pass = $row[
"pass"];
270 if (strlen($active_id) && strlen($pass)) {
271 $res = $test->updateTestPassResults($active_id, $pass,
false, null, $a_obj_id);
272 $max =
$res[
'maxpoints'];
273 $reached =
$res[
'points'];
279 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
280 return $test->getMarkSchema()->getMatchingMark($percentage)->getPassed() === 0;
282 $row =
$ilDB->fetchAssoc($result);
283 return ($row[
'failed']) ? true :
false;
290 $ilDB = $DIC[
'ilDB'];
292 $result =
$ilDB->queryF(
293 "SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests " .
294 "WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s " .
295 "AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
296 [
'integer',
'integer'],
297 [$a_user_id, $a_obj_id]
299 if (!$result->numRows()) {
300 $result =
$ilDB->queryF(
301 "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",
302 [
'integer',
'integer'],
303 [$a_user_id, $a_obj_id]
305 $row =
$ilDB->fetchAssoc($result);
306 if ($row !== null && $row[
'active_id'] > 0) {
308 $test->updateTestResultCache($row[
'active_id']);
338 public static function checkCondition(
int $a_trigger_obj_id,
string $a_operator,
string $a_value,
int $a_usr_id): bool
340 switch ($a_operator) {
349 return ilObjTestAccess::hasFinished($a_usr_id, $a_trigger_obj_id);
352 return !ilObjTestAccess::hasFinished($a_usr_id, $a_trigger_obj_id);
363 $DIC->language()->loadLanguageModule(
'assessment');
366 [
"permission" =>
"write",
"cmd" =>
"questionsTabGateway",
"lang_var" =>
"tst_edit_questions"],
367 [
"permission" =>
"write",
"cmd" =>
"ilObjTestSettingsMainGUI::showForm",
"lang_var" =>
"settings"],
368 [
"permission" =>
"read",
"cmd" =>
"ilTestScreenGUI::testScreen",
"lang_var" =>
"tst_run",
"default" =>
true],
369 [
"permission" =>
"tst_statistics",
"cmd" =>
"outEvaluation",
"lang_var" =>
"tst_statistical_evaluation"],
370 [
"permission" =>
"read",
"cmd" =>
"userResultsGateway",
"lang_var" =>
"tst_user_results"],
371 [
"permission" =>
"write",
"cmd" =>
"testResultsGateway",
"lang_var" =>
"results"],
372 [
"permission" =>
"eval_a",
"cmd" =>
"testResultsGateway",
"lang_var" =>
"results"]
388 $ilDB = $DIC[
'ilDB'];
390 $result =
$ilDB->queryF(
391 "SELECT complete FROM tst_tests WHERE obj_fi=%s",
395 if ($result->numRows() == 1) {
396 $row =
$ilDB->fetchAssoc($result);
399 return isset($row[
'complete']) && $row[
'complete'];
416 public static function hasFinished($a_user_id, $a_obj_id): bool
421 $ilDB = $DIC[
'ilDB'];
423 $ilUser = $DIC[
'ilUser'];
425 if (!isset(self::$hasFinishedCache[
"{$a_user_id}:{$a_obj_id}"])) {
429 $partData->setUserIdsFilter([$a_user_id]);
430 $partData->load($testOBJ->getTestId());
432 $activeId = $partData->getActiveIdByUserId($a_user_id);
436 $testSession = $testSessionFactory->getSession($activeId);
439 $testPassesSelector->setActiveId($activeId);
440 $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass());
442 self::$hasFinishedCache[
"{$a_user_id}:{$a_obj_id}"] = count($testPassesSelector->getClosedPasses());
445 return (
bool) self::$hasFinishedCache[
"{$a_user_id}:{$a_obj_id}"];
458 $ilDB = $DIC[
'ilDB'];
460 $result =
$ilDB->queryF(
461 "SELECT test_id FROM tst_tests WHERE obj_fi = %s",
465 if ($result->numRows()) {
466 $row =
$ilDB->fetchAssoc($result);
467 $test_id = $row[
"test_id"];
481 $ilDB = $DIC[
'ilDB'];
483 $result =
$ilDB->queryF(
484 "SELECT obj_fi FROM tst_tests WHERE test_id = %s",
489 $row =
$ilDB->fetchAssoc($result);
490 return $row[
"obj_fi"];
503 $ilDB = $DIC[
'ilDB'];
506 SELECT DISTINCT t.obj_fi 508 INNER JOIN tst_rnd_quest_set_qpls r 509 ON t.test_id = r.test_fi 513 $result =
$ilDB->queryF($query, [
'integer'], [$qpl_id]);
516 while ($row =
$ilDB->fetchAssoc($result)) {
517 $tests[] = $row[
'obj_fi'];
533 $ilDB = $DIC[
'ilDB'];
536 $result =
$ilDB->queryF(
537 "SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
541 if ($result->numRows()) {
542 $row =
$ilDB->fetchAssoc($result);
543 if ($row[
"fixed_participants"]) {
544 $result =
$ilDB->queryF(
545 "SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
546 [
'integer',
'integer'],
547 [$row[
"test_id"], $a_user_id]
549 if ($result->numRows()) {
550 $row =
$ilDB->fetchAssoc($result);
551 if ($row[
'clientip'] !== null && trim($row[
'clientip']) !=
"") {
552 $row[
'clientip'] = preg_replace(
"/[^0-9.?*,:]+/",
"", $row[
'clientip']);
553 $row[
'clientip'] = str_replace(
".",
"\\.", $row[
'clientip']);
554 $row[
'clientip'] = str_replace([
"?",
"*",
","], [
"[0-9]",
"[0-9]*",
"|"], $row[
'clientip']);
555 if (!preg_match(
"/^" . $row[
'clientip'] .
"$/",
$_SERVER[
"REMOTE_ADDR"])) {
557 return $lng->
txt(
"user_wrong_clientip");
565 return $lng->
txt(
"tst_user_not_invited");
586 $ilDB = $DIC[
'ilDB'];
588 $result_active =
$ilDB->queryF(
589 'SELECT * FROM tst_active WHERE active_id = %s',
593 $row_active =
$ilDB->fetchAssoc($result_active);
594 $importname = $row_active[
'importname'];
596 if ($importname !== null
597 && $importname !==
'') {
598 return $importname .
' (' . $lng->
txt(
'imported') .
')';
607 $result_test =
$ilDB->queryF(
608 "SELECT obj_fi FROM tst_tests WHERE test_id = %s",
610 [$row_active[
'test_fi']]
612 $row_test =
$ilDB->fetchAssoc($result_test);
613 $obj_id = $row_test[
"obj_fi"];
616 return $lng->
txt(
"anonymous");
619 if ($uname[
'firstname'] . $uname[
'lastname'] ===
'') {
620 return $lng->
txt(
'deleted_user');
623 return trim($uname[
'lastname'] .
', ' . $uname[
'firstname']);
636 $ilDB = $DIC[
'ilDB'];
638 $result =
$ilDB->queryF(
639 "SELECT user_fi FROM tst_active WHERE active_id = %s",
643 $row =
$ilDB->fetchAssoc($result);
644 return $row[
"user_fi"];
665 $ilDB = $DIC[
'ilDB'];
669 $userresult =
$ilDB->queryF(
671 SELECT tst_active.active_id, COUNT(tst_sequence.active_fi) sequences, tst_active.last_finished_pass, 673 (tst_tests.nr_of_tries - 1) = tst_active.last_finished_pass 678 INNER JOIN tst_active 679 ON tst_active.test_fi = tst_tests.test_id 680 LEFT JOIN tst_sequence 681 ON tst_sequence.active_fi = tst_active.active_id 682 WHERE tst_tests.obj_fi = %s 683 GROUP BY tst_active.active_id 688 $all_participants = [];
691 while ($row =
$ilDB->fetchAssoc($userresult)) {
692 if ($row[
'sequences'] == 0) {
693 $notAttempted[$row[
'active_id']] = $row[
'active_id'];
695 if ($row[
'is_last_pass']) {
696 $lastPassUsers[$row[
'active_id']] = $row[
'active_id'];
699 $all_participants[$row[
'active_id']] = $row[
'active_id'];
702 $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'));
703 $found_all = ($result->numRows() == count($all_participants)) ?
true :
false;
707 $found_participants = [];
709 array_push($found_participants,
$data[
'active_fi']);
711 foreach ($all_participants as $active_id) {
712 if (!in_array($active_id, $found_participants)) {
713 $test->updateTestResultCache($active_id);
716 $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'));
719 if (isset($notAttempted[
$data[
'active_fi']])) {
722 $data[
'not_attempted'] = 1;
725 $data[
'user_id'] = $data[
'user_fi'];
726 array_push($passed_users, $data);
728 return $passed_users;
737 $ilAccess = $DIC[
'ilAccess'];
739 $t_arr = explode(
"_", $target);
741 if ($t_arr[0] !=
"tst" || ((
int) $t_arr[1]) <= 0) {
745 if ($ilAccess->checkAccess(
"read",
"", (
int) $t_arr[1]) ||
746 $ilAccess->checkAccess(
"visible",
"", (
int) $t_arr[1])) {
766 $ilDB = $DIC[
'ilDB'];
767 $ilUser = $DIC[
'ilUser'];
776 $test_session = $test_session_factory->getSessionByUserId($user_id);
778 return $test_obj->canShowTestResults($test_session);
const IL_NO_OBJECT_ACCESS
static _lookupCreationComplete($a_obj_id)
checks wether all necessary parts of the test are given
static _getParticipantData($active_id)
Retrieves a participant name from active id.
static _getParticipantId($active_id)
Get user id for active id.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
except(callable $f)
Feed the error into a callable and replace this with the result or do nothing if this is a value...
A result encapsulates a value or an error and simplifies the handling of those.
static _lookupName(int $a_user_id)
lookup user name
Interface for condition handling.
loadLanguageModule(string $a_module)
Load language module.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isPassed($user_id, $a_obj_id)
Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id...
static _lookupAnonymity($a_obj_id)
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.
static _lookupOnlineTestAccess($a_test_id, $a_user_id)
Checks if a user is allowd to run an online exam.
static _getRandomTestsForQuestionPool($qpl_id)
Get all tests using a question pool for random selection.
static _lookupObjIdForTestId($a_test_id)
Lookup object id for test id.
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, int $user_id=null)
Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcce...
canBeDelivered(ilWACPath $ilWACPath)
static _getPassedUsers($a_obj_id)
Returns an array containing the users who passed the test.
static _getTestIDFromObjectID($object_id)
Returns the ILIAS test id for a given object id.
static isFailed($user_id, $a_obj_id)
Returns TRUE if the user with the user id $user_id failed the test with the object id $a_obj_id...
static checkCondition(int $a_trigger_obj_id, string $a_operator, string $a_value, int $a_usr_id)
check condition
findMatch(string $path, array $array)
const OPERATOR_NOT_FINISHED
static _checkGoto(string $target)
check whether goto script will succeed
static getConditionOperators()
Get possible conditions operators.
static _isOffline(int $obj_id)
returns the objects's OFFline status
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
ilRbacSystem $rbac_system
isPermitted(string $path)
static updateTestResultCache($a_user_id, $a_obj_id)
static visibleUserResultExists($test_obj_id, $user_id)