/** * Returns (request cached) information if a specific user has finished at least one test pass * * @param integer $user_id obj_id of the user * @param integer $a_obj_id obj_id of the test * @return bool */ public static function hasFinished($a_user_id, $a_obj_id) { if (!isset(self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"])) { require_once 'Modules/Test/classes/class.ilTestParticipantData.php'; require_once 'Modules/Test/classes/class.ilTestSessionFactory.php'; require_once 'Modules/Test/classes/class.ilTestPassesSelector.php'; global $ilDB, $lng; $testOBJ = ilObjectFactory::getInstanceByObjId($a_obj_id); $partData = new ilTestParticipantData($ilDB, $lng); $partData->setUserIds(array($a_user_id)); $partData->load($testOBJ->getTestId()); $activeId = $partData->getActiveIdByUserId($a_user_id); $testSessionFactory = new ilTestSessionFactory($testOBJ); $testSession = $testSessionFactory->getSession($activeId); $testPassesSelector = new ilTestPassesSelector($ilDB, $testOBJ); $testPassesSelector->setActiveId($activeId); $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass()); self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"] = count($testPassesSelector->getClosedPasses()); } return self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"]; }
/** * Checks if the test is executable by the given user * * @param ilTestSession|ilTestSessionDynamicQuestionSet * @param integer $user_id The user id * @return array Result array * @access public */ function isExecutable($testSession, $user_id, $allowPassIncrease = FALSE) { $result = array("executable" => true, "errormessage" => ""); if (!$this->startingTimeReached()) { $result["executable"] = false; $result["errormessage"] = sprintf($this->lng->txt("detail_starting_time_not_reached"), ilFormat::ftimestamp2datetimeDB($this->getStartingTime())); return $result; } if ($this->endingTimeReached()) { $result["executable"] = false; $result["errormessage"] = sprintf($this->lng->txt("detail_ending_time_reached"), ilFormat::ftimestamp2datetimeDB($this->getEndingTime())); return $result; } $active_id = $this->getActiveIdOfUser($user_id); if ($this->getEnableProcessingTime()) { if ($active_id > 0) { $starting_time = $this->getStartingTimeOfUser($active_id); if ($starting_time !== FALSE) { if ($this->isMaxProcessingTimeReached($starting_time, $active_id)) { if ($allowPassIncrease && $this->getResetProcessingTime() && ($this->getNrOfTries() == 0 || $this->getNrOfTries() > $this->_getPass($active_id) + 1)) { // a test pass was quitted because the maximum processing time was reached, but the time // will be resetted for future passes, so if there are more passes allowed, the participant may // start the test again. // This code block is only called when $allowPassIncrease is TRUE which only happens when // the test info page is opened. Otherwise this will lead to unexpected results! $testSession->increasePass(); $testSession->setLastSequence(0); $testSession->saveToDb(); } else { $result["executable"] = false; $result["errormessage"] = $this->lng->txt("detail_max_processing_time_reached"); } return $result; } } } } if ($this->hasNrOfTriesRestriction() && $active_id > 0) { require_once 'Modules/Test/classes/class.ilTestPassesSelector.php'; $testPassesSelector = new ilTestPassesSelector($GLOBALS['ilDB'], $this); $testPassesSelector->setActiveId($active_id); $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass()); $closedPasses = $testPassesSelector->getClosedPasses(); if (count($closedPasses) >= $this->getNrOfTries()) { $result["executable"] = false; $result["errormessage"] = $this->lng->txt("maximum_nr_of_tries_reached"); return $result; } } return $result; }
/** * show information screen */ function infoScreen($session_lock = "") { /** * @var $ilAccess ilAccessHandler * @var $ilUser ilObjUser * @var $ilToolbar ilToolbarGUI */ global $ilAccess, $ilUser, $ilToolbar; require_once 'Modules/Test/classes/class.ilTestDynamicQuestionSetFilterSelection.php'; require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php'; require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php'; $testQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfig(); $testSession = $this->testSessionFactory->getSession(); $testSequence = $this->testSequenceFactory->getSequence($testSession); $testSequence->loadFromDb(); $testSequence->loadQuestions($testQuestionSetConfig, new ilTestDynamicQuestionSetFilterSelection()); $testPlayerGUI = $this->testPlayerFactory->getPlayerGUI(); if ($_GET['createRandomSolutions']) { $this->object->createRandomSolutions($_GET['createRandomSolutions']); } if (!$ilAccess->checkAccess("read", "", $this->ref_id)) { $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"), $this->ilias->error_obj->MESSAGE); } include_once "./Services/InfoScreen/classes/class.ilInfoScreenGUI.php"; $info = new ilInfoScreenGUI($this); if ($this->isCommandClassAnyInfoScreenChild()) { return $this->ctrl->forwardCommand($info); } $this->ctrl->setParameter($testPlayerGUI, "sequence", $testSession->getLastSequence()); $info->setFormAction($this->ctrl->getFormAction($testPlayerGUI)); if (strlen($session_lock)) { $info->addHiddenElement("lock", $session_lock); } else { $info->addHiddenElement("lock", md5($_COOKIE['PHPSESSID'] . time())); } $online_access = false; if ($this->object->getFixedParticipants()) { include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; $online_access_result = ilObjTestAccess::_lookupOnlineTestAccess($this->object->getId(), $ilUser->getId()); if ($online_access_result === true) { $online_access = true; } else { ilUtil::sendInfo($online_access_result); } } $enter_anonymous_code = false; if ($this->object->isOnline() && $this->object->isComplete($this->testQuestionSetConfigFactory->getQuestionSetConfig())) { if ((!$this->object->getFixedParticipants() || $online_access) && $ilAccess->checkAccess("read", "", $this->ref_id)) { $executable = $this->object->isExecutable($testSession, $ilUser->getId(), $allowPassIncrease = TRUE); if ($executable["executable"]) { if ($this->object->areObligationsEnabled() && $this->object->hasObligations($this->object->getTestId())) { ilUtil::sendInfo($GLOBALS['lng']->txt('tst_test_contains_obligatory_questions')); } if ($testSession->getActiveId() > 0) { // resume test require_once 'Modules/Test/classes/class.ilTestPassesSelector.php'; $testPassesSelector = new ilTestPassesSelector($GLOBALS['ilDB'], $this->object); $testPassesSelector->setActiveId($testSession->getActiveId()); $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass()); $closedPasses = $testPassesSelector->getClosedPasses(); $existingPasses = $testPassesSelector->getExistingPasses(); if ($existingPasses > $closedPasses) { $btn = ilSubmitButton::getInstance(); $btn->setCaption('tst_resume_test'); $btn->setCommand('resumePlayer'); $btn->setPrimary(true); $big_button[] = $btn; } else { $btn = ilSubmitButton::getInstance(); $btn->setCaption($this->object->getStartTestLabel($testSession->getActiveId()), false); $btn->setCommand('startPlayer'); $btn->setPrimary(true); $big_button[] = $btn; } } else { // start new test $btn = ilSubmitButton::getInstance(); $btn->setCaption($this->object->getStartTestLabel($testSession->getActiveId()), false); $btn->setCommand('startPlayer'); $btn->setPrimary(true); $big_button[] = $btn; } } else { ilUtil::sendInfo($executable["errormessage"]); } if ($testSession->getActiveId() > 0) { // test results button require_once 'Modules/Test/classes/class.ilTestPassesSelector.php'; $testPassesSelector = new ilTestPassesSelector($GLOBALS['ilDB'], $this->object); $testPassesSelector->setActiveId($testSession->getActiveId()); $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass()); if ($this->object->canShowTestResults($testSession, $ilUser->getId()) && count($testPassesSelector->getReportablePasses())) { $btn = ilLinkButton::getInstance(); $btn->setCaption('tst_show_results'); $btn->setUrl($this->ctrl->getLinkTargetByClass('ilTestEvaluationGUI', 'outUserResultsOverview')); $btn->setPrimary(false); $big_button[] = $btn; if ($this->object->getHighscoreEnabled()) { // Can also compare results then $btn = ilSubmitButton::getInstance(); $btn->setCaption('tst_show_toplist'); $btn->setCommand('outResultsToplist'); $btn->setPrimary(false); $big_button[] = $btn; } if ($this->object->isSkillServiceToBeConsidered()) { require_once 'Modules/Test/classes/class.ilTestSkillEvaluationGUI.php'; $btn = ilLinkButton::getInstance(); $btn->setCaption('tst_show_comp_results'); $btn->setUrl($this->ctrl->getLinkTargetByClass('ilTestSkillEvaluationGUI', ilTestSkillEvaluationGUI::CMD_SHOW)); $btn->setPrimary(false); $big_button[] = $btn; } } } } if ($testSession->getActiveId() > 0) { if ($this->object->canShowSolutionPrintview($ilUser->getId())) { $btn = ilSubmitButton::getInstance(); $btn->setCaption('tst_list_of_answers_show'); $btn->setCommand('outUserListOfAnswerPasses'); $btn->setPrimary(false); $big_button[] = $btn; } } if ($this->isDeleteDynamicTestResultsButtonRequired($testSession, $testSequence)) { $this->populateDeleteDynamicTestResultsButton($testSession, $big_button); } if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID) { $enter_anonymous_code = true; } } if (!$this->object->isOnline() && !$testQuestionSetConfig->areDepenciesBroken()) { $message = $this->lng->txt("test_is_offline"); if ($ilAccess->checkAccess("write", "", $this->ref_id)) { $message .= "<br /><a href=\"" . $this->ctrl->getLinkTargetByClass('ilobjtestsettingsgeneralgui') . "\">" . $this->lng->txt("test_edit_settings") . "</a>"; } ilUtil::sendInfo($message); } if ($ilAccess->checkAccess("write", "", $this->ref_id)) { $testQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfig(); if ($testQuestionSetConfig->areDepenciesBroken()) { ilUtil::sendFailure($testQuestionSetConfig->getDepenciesBrokenMessage($this->lng)); $big_button = array(); $enter_anonymous_code = false; } elseif ($testQuestionSetConfig->areDepenciesInVulnerableState()) { ilUtil::sendInfo($testQuestionSetConfig->getDepenciesInVulnerableStateMessage($this->lng)); } } if ($this->object->getShowInfo()) { $info->enablePrivateNotes(); } if ($big_button || $enter_anonymous_code) { $ilToolbar->setFormAction($this->ctrl->getFormAction($testPlayerGUI)); foreach ($big_button as $button) { $ilToolbar->addButtonInstance($button); } if ($enter_anonymous_code) { if ($big_button) { $ilToolbar->addSeparator(); } require_once 'Services/Form/classes/class.ilTextInputGUI.php'; $anonymous_id = new ilTextInputGUI($this->lng->txt('enter_anonymous_code'), 'anonymous_id'); $anonymous_id->setSize(8); $ilToolbar->addInputItem($anonymous_id, true); $ilToolbar->addFormButton($this->lng->txt('submit'), 'setAnonymousId'); } $ilToolbar->setCloseFormTag(false); $info->setOpenFormTag(false); } if (strlen($this->object->getIntroduction())) { $info->addSection($this->lng->txt("tst_introduction")); $info->addProperty("", $this->object->prepareTextareaOutput($this->object->getIntroduction(), true) . $info->getHiddenToggleButton()); } else { $info->addSection(""); $info->addProperty("", $info->getHiddenToggleButton()); } $info->addSection($this->lng->txt("tst_general_properties")); if ($this->object->getShowInfo()) { $info->addProperty($this->lng->txt("author"), $this->object->getAuthor()); $info->addProperty($this->lng->txt("title"), $this->object->getTitle()); } if ($this->object->isOnline() && $this->object->isComplete($this->testQuestionSetConfigFactory->getQuestionSetConfig())) { if ((!$this->object->getFixedParticipants() || $online_access) && $ilAccess->checkAccess("read", "", $this->ref_id)) { if ($this->object->getShowInfo() || !$this->object->getForceJS()) { // use javascript $checked_javascript = false; if ($this->object->getJavaScriptOutput()) { $checked_javascript = true; } } // hide previous results if (!$this->object->isRandomTest()) { if ($this->object->getNrOfTries() != 1) { if ($this->object->getUsePreviousAnswers() == 0) { if ($this->object->getShowInfo()) { $info->addProperty($this->lng->txt("tst_use_previous_answers"), $this->lng->txt("tst_dont_use_previous_answers")); } } else { $use_previous_answers = FALSE; if ($ilUser->prefs["tst_use_previous_answers"]) { $checked_previous_answers = TRUE; } $info->addPropertyCheckbox($this->lng->txt("tst_use_previous_answers"), "chb_use_previous_answers", 1, $this->lng->txt("tst_use_previous_answers_user"), $checked_previous_answers); } } } } } $info->hideFurtherSections(false); if ($this->object->getShowInfo()) { $info->addSection($this->lng->txt("tst_sequence_properties")); $info->addProperty($this->lng->txt("tst_sequence"), $this->lng->txt($this->object->getSequenceSettings() == TEST_FIXED_SEQUENCE ? "tst_sequence_fixed" : "tst_sequence_postpone")); $info->addSection($this->lng->txt("tst_heading_scoring")); $info->addProperty($this->lng->txt("tst_text_count_system"), $this->lng->txt($this->object->getCountSystem() == COUNT_PARTIAL_SOLUTIONS ? "tst_count_partial_solutions" : "tst_count_correct_solutions")); $info->addProperty($this->lng->txt("tst_score_mcmr_questions"), $this->lng->txt($this->object->getMCScoring() == SCORE_ZERO_POINTS_WHEN_UNANSWERED ? "tst_score_mcmr_zero_points_when_unanswered" : "tst_score_mcmr_use_scoring_system")); if ($this->object->isRandomTest()) { $info->addProperty($this->lng->txt("tst_pass_scoring"), $this->lng->txt($this->object->getPassScoring() == SCORE_BEST_PASS ? "tst_pass_best_pass" : "tst_pass_last_pass")); } $info->addSection($this->lng->txt("tst_score_reporting")); $score_reporting_text = ""; switch ($this->object->getScoreReporting()) { case REPORT_AFTER_TEST: $score_reporting_text = $this->lng->txt("tst_report_after_test"); break; case REPORT_ALWAYS: $score_reporting_text = $this->lng->txt("tst_report_after_first_question"); break; case REPORT_AFTER_DATE: $score_reporting_text = $this->lng->txt("tst_report_after_date"); break; case 4: $score_reporting_text = $this->lng->txt("tst_report_never"); break; } $info->addProperty($this->lng->txt("tst_score_reporting"), $score_reporting_text); $reporting_date = $this->object->getReportingDate(); if ($reporting_date) { #preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $reporting_date, $matches); #$txt_reporting_date = date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1])); #$info->addProperty($this->lng->txt("tst_score_reporting_date"), $txt_reporting_date); $info->addProperty($this->lng->txt('tst_score_reporting_date'), ilDatePresentation::formatDate(new ilDateTime($reporting_date, IL_CAL_TIMESTAMP))); } $info->addSection($this->lng->txt("tst_session_settings")); $info->addProperty($this->lng->txt("tst_nr_of_tries"), $this->object->getNrOfTries() == 0 ? $this->lng->txt("unlimited") : $this->object->getNrOfTries()); if ($this->object->getNrOfTries() != 1) { $info->addProperty($this->lng->txt("tst_nr_of_tries_of_user"), $testSession->getPass() == false ? $this->lng->txt("tst_no_tries") : $testSession->getPass()); } if ($this->object->getEnableProcessingTime()) { $info->addProperty($this->lng->txt("tst_processing_time"), $this->object->getProcessingTime()); } if (strlen($this->object->getAllowedUsers()) && $this->object->getAllowedUsersTimeGap()) { $info->addProperty($this->lng->txt("tst_allowed_users"), $this->object->getAllowedUsers()); } $starting_time = $this->object->getStartingTime(); if ($starting_time && $this->object->isStartingTimeEnabled()) { $info->addProperty($this->lng->txt("tst_starting_time"), ilDatePresentation::formatDate(new ilDateTime($starting_time, IL_CAL_TIMESTAMP))); } $ending_time = $this->object->getEndingTime(); if ($ending_time && $this->object->isEndingTimeEnabled()) { $info->addProperty($this->lng->txt("tst_ending_time"), ilDatePresentation::formatDate(new ilDateTime($ending_time, IL_CAL_TIMESTAMP))); } $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType()); // forward the command } $this->ctrl->forwardCommand($info); }