/** * Import relevant properties from given test * * @param ilObjTest $a_test * @return object */ public static function createFromTest(ilObjTest $a_test, $a_user_id) { global $lng; $lng->loadLanguageModule("wsp"); $newObj = new self(); $newObj->setTitle($lng->txt("wsp_type_tstv") . " \"" . $a_test->getTitle() . "\""); $newObj->setDescription($a_test->getDescription()); $active_id = $a_test->getActiveIdOfUser($a_user_id); $pass = ilObjTest::_getResultPass($active_id); $date = $a_test->getPassFinishDate($active_id, $pass); $newObj->setProperty("issued_on", new ilDate($date, IL_CAL_UNIX)); // create certificate include_once "Services/Certificate/classes/class.ilCertificate.php"; include_once "Modules/Test/classes/class.ilTestCertificateAdapter.php"; $certificate = new ilCertificate(new ilTestCertificateAdapter($a_test)); $certificate = $certificate->outCertificate(array("active_id" => $active_id, "pass" => $pass), false); // save pdf file if ($certificate) { // we need the object id for storing the certificate file $newObj->create(); $path = self::initStorage($newObj->getId(), "certificate"); $file_name = "tst_" . $a_test->getId() . "_" . $a_user_id . "_" . $active_id . ".pdf"; if (file_put_contents($path . $file_name, $certificate)) { $newObj->setProperty("file", $file_name); $newObj->update(); return $newObj; } // file creation failed, so remove to object, too $newObj->delete(); } }
/** * @param $show_pass_details * @param $show_answers * @param $show_reached_points * @param $show_user_results * * @return ilTemplate */ public function createUserResults($show_pass_details, $show_answers, $show_reached_points, $show_user_results) { $template = new ilTemplate("tpl.il_as_tst_participants_result_output.html", TRUE, TRUE, "Modules/Test"); include_once "./Modules/Test/classes/class.ilTestServiceGUI.php"; $serviceGUI = new ilTestServiceGUI($this->object); $count = 0; foreach ($show_user_results as $key => $active_id) { $count++; $results = ""; if ($this->object->getFixedParticipants()) { $active_id = $this->object->getActiveIdOfUser($active_id); } if ($active_id > 0) { $results = $serviceGUI->getResultsOfUserOutput($this->testSessionFactory->getSession($active_id), $active_id, $this->object->_getResultPass($active_id), $show_pass_details, $show_answers, FALSE, $show_reached_points); } if ($count < count($show_user_results)) { $template->touchBlock("break"); } $template->setCurrentBlock("user_result"); $template->setVariable("USER_RESULT", $results); $template->parseCurrentBlock(); } $template->setVariable("BACK_TEXT", $this->lng->txt("back")); $template->setVariable("BACK_URL", $this->ctrl->getLinkTargetByClass("ilobjtestgui", "participants")); $template->setVariable("PRINT_TEXT", $this->lng->txt("print")); $template->setVariable("PRINT_URL", "javascript:window.print();"); return $template; }
/** * @access public * @global ilObjUser $ilUser * @param integer $active_id * @param boolean $short * @return array $passOverwiewData */ public function getPassOverviewData($active_id, $short = false) { $passOverwiewData = array(); global $ilUser; $scoredPass = $this->object->_getResultPass($active_id); $lastPass = $this->object->_getPass($active_id); $testPercentage = 0; $testReachedPoints = 0; $testMaxPoints = 0; for ($pass = 0; $pass <= $lastPass; $pass++) { $passFinishDate = $this->object->getPassFinishDate($active_id, $pass); if ($passFinishDate <= 0) { continue; } if (!$short) { $resultData =& $this->object->getTestResult($active_id, $pass); if (!$resultData["pass"]["total_max_points"]) { $passPercentage = 0; } else { $passPercentage = $resultData["pass"]["total_reached_points"] / $resultData["pass"]["total_max_points"] * 100; } $passMaxPoints = $resultData["pass"]["total_max_points"]; $passReachedPoints = $resultData["pass"]["total_reached_points"]; $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass); $passTotalQuestions = count($resultData) - 2; if ($pass == $scoredPass) { $isScoredPass = true; if (!$resultData["test"]["total_max_points"]) { $testPercentage = 0; } else { $testPercentage = $resultData["test"]["total_reached_points"] / $resultData["test"]["total_max_points"] * 100; } $testMaxPoints = $resultData["test"]["total_max_points"]; $testReachedPoints = $resultData["test"]["total_reached_points"]; $passOverwiewData['test'] = array('active_id' => $active_id, 'scored_pass' => $scoredPass, 'max_points' => $testMaxPoints, 'reached_points' => $testReachedPoints, 'percentage' => $testPercentage); } else { $isScoredPass = false; } $passOverwiewData['passes'][] = array('active_id' => $active_id, 'pass' => $pass, 'finishdate' => $passFinishDate, 'max_points' => $passMaxPoints, 'reached_points' => $passReachedPoints, 'percentage' => $passPercentage, 'answered_questions' => $passAnsweredQuestions, 'total_questions' => $passTotalQuestions, 'is_scored_pass' => $isScoredPass); } } return $passOverwiewData; }
/** * Creates a HTML representation for the results of a given question in a test * * @param integer $question_id The original id of the question * @param integer $test_id The test id * @return string HTML code of the question results * @access public */ function getQuestionResultForTestUsers($question_id, $test_id) { $foundusers = $this->object->getParticipantsForTestAndQuestion($test_id, $question_id); $output = ""; foreach ($foundusers as $active_id => $passes) { $resultpass = $this->object->_getResultPass($active_id); for ($i = 0; $i < count($passes); $i++) { if ($resultpass != null && $resultpass == $passes[$i]["pass"]) { $question_gui =& $this->object->createQuestionGUI("", $passes[$i]["qid"]); $output .= $this->getResultsHeadUserAndPass($active_id, $resultpass + 1); $output .= $question_gui->getSolutionOutput($active_id, $resultpass, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = FALSE, $show_feedback = FALSE); $output .= "<br /><br /><br />"; } } } $this->object->deliverPDFfromHTML($output, $question_gui->object->getTitle()); }
/** * Creates a HTML representation for the results of a given question in a test * * @param integer $question_id The original id of the question * @param integer $test_id The test id * @return string HTML code of the question results */ public function getQuestionResultForTestUsers($question_id, $test_id) { $foundusers = $this->object->getParticipantsForTestAndQuestion($test_id, $question_id); $output = ""; foreach ($foundusers as $active_id => $passes) { $resultpass = $this->object->_getResultPass($active_id); for ($i = 0; $i < count($passes); $i++) { if ($resultpass !== null && $resultpass == $passes[$i]["pass"]) { $question_gui =& $this->object->createQuestionGUI("", $passes[$i]["qid"]); $output .= $this->getResultsHeadUserAndPass($active_id, $resultpass + 1); $output .= $question_gui->getSolutionOutput($active_id, $resultpass, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = FALSE, $show_feedback = FALSE); $output .= "<br /><br /><br />"; } } } require_once './Modules/Test/classes/class.ilTestPDFGenerator.php'; ilTestPDFGenerator::generatePDF($output, ilTestPDFGenerator::PDF_OUTPUT_DOWNLOAD, $question_gui->object->getTitle()); }
/** * Shows the pass overview of the scored pass for one ore more users * * @access public */ function showUserResults($show_pass_details, $show_answers, $show_reached_points = FALSE) { $template = new ilTemplate("tpl.il_as_tst_participants_result_output.html", TRUE, TRUE, "Modules/Test"); if (count($_SESSION["show_user_results"]) == 0) { ilUtil::sendInfo($this->lng->txt("select_one_user"), TRUE); $this->ctrl->redirect($this, "participants"); } include_once "./Modules/Test/classes/class.ilTestServiceGUI.php"; $serviceGUI =& new ilTestServiceGUI($this->object); $count = 0; foreach ($_SESSION["show_user_results"] as $key => $active_id) { $count++; $results = ""; if ($this->object->getFixedParticipants()) { $active_id = $this->object->getActiveIdOfUser($active_id); } if ($active_id > 0) { $results = $serviceGUI->getResultsOfUserOutput($active_id, $this->object->_getResultPass($active_id), $show_pass_details, $show_answers, FALSE, $show_reached_points); } if ($count < count($_SESSION["show_user_results"])) { $template->touchBlock("break"); } $template->setCurrentBlock("user_result"); $template->setVariable("USER_RESULT", $results); $template->parseCurrentBlock(); } $template->setVariable("BACK_TEXT", $this->lng->txt("back")); $template->setVariable("BACK_URL", $this->ctrl->getLinkTargetByClass("ilobjtestgui", "participants")); $template->setVariable("PRINT_TEXT", $this->lng->txt("print")); $template->setVariable("PRINT_URL", "javascript:window.print();"); $this->tpl->setVariable("ADM_CONTENT", $template->get()); $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print"); if ($this->object->getShowSolutionAnswersOnly()) { $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print"); } }
public function getPassed($active_id) { global $ilDB; $result = $ilDB->queryF("SELECT passed FROM tst_result_cache WHERE active_fi = %s", array('integer'), array($active_id)); if ($result->numRows()) { $row = $ilDB->fetchAssoc($result); return $row['passed']; } else { $counted_pass = ilObjTest::_getResultPass($active_id); $result_array =& $this->getTestResult($active_id, $counted_pass); return $result_array["test"]["passed"]; } }
/** * @param $show_pass_details * @param $show_answers * @param $show_reached_points * @param $show_user_results * * @return ilTemplate */ public function createUserResults($show_pass_details, $show_answers, $show_reached_points, $show_user_results) { global $ilTabs, $ilDB; $ilTabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'participants')); if ($this->getObjectiveOrientedContainer()->isObjectiveOrientedPresentationRequired()) { require_once 'Services/Link/classes/class.ilLink.php'; $courseLink = ilLink::_getLink($this->getObjectiveOrientedContainer()->getRefId()); $ilTabs->setBack2Target($this->lng->txt('back_to_objective_container'), $courseLink); } $template = new ilTemplate("tpl.il_as_tst_participants_result_output.html", TRUE, TRUE, "Modules/Test"); require_once 'Modules/Test/classes/toolbars/class.ilTestResultsToolbarGUI.php'; $toolbar = new ilTestResultsToolbarGUI($this->ctrl, $this->tpl, $this->lng); $this->ctrl->setParameter($this, 'pdf', '1'); $toolbar->setPdfExportLinkTarget($this->ctrl->getLinkTarget($this, $this->ctrl->getCmd())); $this->ctrl->setParameter($this, 'pdf', ''); if ($show_answers) { if (isset($_GET['show_best_solutions'])) { $_SESSION['tst_results_show_best_solutions'] = true; } elseif (isset($_GET['hide_best_solutions'])) { $_SESSION['tst_results_show_best_solutions'] = false; } elseif (!isset($_SESSION['tst_results_show_best_solutions'])) { $_SESSION['tst_results_show_best_solutions'] = false; } if ($_SESSION['tst_results_show_best_solutions']) { $this->ctrl->setParameter($this, 'hide_best_solutions', '1'); $toolbar->setHideBestSolutionsLinkTarget($this->ctrl->getLinkTarget($this, 'showUserAnswers')); $this->ctrl->setParameter($this, 'hide_best_solutions', ''); } else { $this->ctrl->setParameter($this, 'show_best_solutions', '1'); $toolbar->setShowBestSolutionsLinkTarget($this->ctrl->getLinkTarget($this, 'showUserAnswers')); $this->ctrl->setParameterByClass('', 'show_best_solutions', ''); } } require_once 'Modules/Test/classes/class.ilTestParticipantData.php'; $participantData = new ilTestParticipantData($ilDB, $this->lng); if ($this->object->getFixedParticipants()) { $participantData->setUserIds($show_user_results); } else { $participantData->setActiveIds($show_user_results); } $participantData->load($this->object->getTestId()); $toolbar->setParticipantSelectorOptions($participantData->getOptionArray($show_user_results)); $toolbar->build(); $template->setVariable('RESULTS_TOOLBAR', $this->ctrl->getHTML($toolbar)); include_once "./Modules/Test/classes/class.ilTestServiceGUI.php"; $serviceGUI = new ilTestServiceGUI($this->object); $serviceGUI->setObjectiveOrientedContainer($this->getObjectiveOrientedContainer()); $serviceGUI->setParticipantData($participantData); $count = 0; foreach ($show_user_results as $key => $active_id) { $count++; $results = ""; if ($this->object->getFixedParticipants()) { $active_id = $this->object->getActiveIdOfUser($active_id); } if ($active_id > 0) { $results = $serviceGUI->getResultsOfUserOutput($this->testSessionFactory->getSession($active_id), $active_id, $this->object->_getResultPass($active_id), $this, $show_pass_details, $show_answers, FALSE, $show_reached_points); } if ($count < count($show_user_results)) { $template->touchBlock("break"); } $template->setCurrentBlock("user_result"); $template->setVariable("USER_RESULT", $results); $template->parseCurrentBlock(); } if ($this->isPdfDeliveryRequest()) { require_once 'class.ilTestPDFGenerator.php'; ilTestPDFGenerator::generatePDF($template->get(), ilTestPDFGenerator::PDF_OUTPUT_DOWNLOAD, $this->object->getTitle()); } else { return $template; } }
/** * Output of a test certificate */ public function outCertificate() { $testSession = $this->testSessionFactory->getSession(); require_once './Services/Certificate/classes/class.ilCertificate.php'; require_once './Modules/Test/classes/class.ilTestCertificateAdapter.php'; $certificate = new ilCertificate(new ilTestCertificateAdapter($this->object)); $certificate->outCertificate(array("active_id" => $testSession->getActiveId(), "pass" => ilObjTest::_getResultPass($testSession->getActiveId()))); }
/** @TODO Move this to a proper place. */ function _updateTestResultCache($active_id, ilAssQuestionProcessLocker $processLocker = null) { global $ilDB; include_once "./Modules/Test/classes/class.ilObjTest.php"; include_once "./Modules/Test/classes/class.assMarkSchema.php"; $pass = ilObjTest::_getResultPass($active_id); $query = "\n\t\t\tSELECT\t\ttst_pass_result.*\n\t\t\tFROM\t\ttst_pass_result\n\t\t\tWHERE\t\tactive_fi = %s\n\t\t\tAND\t\t\tpass = %s\n\t\t"; $result = $ilDB->queryF($query, array('integer', 'integer'), array($active_id, $pass)); $row = $ilDB->fetchAssoc($result); $max = $row['maxpoints']; $reached = $row['points']; $obligationsAnswered = (int) $row['obligations_answered']; include_once "./Modules/Test/classes/class.assMarkSchema.php"; $percentage = !$max ? 0 : $reached / $max * 100.0; $mark = ASS_MarkSchema::_getMatchingMarkFromActiveId($active_id, $percentage); $isPassed = $mark["passed"] ? 1 : 0; $isFailed = !$mark["passed"] ? 1 : 0; if (is_object($processLocker)) { $processLocker->requestUserTestResultUpdateLock(); } $query = "\n\t\t\tDELETE FROM\t\ttst_result_cache\n\t\t\tWHERE\t\t\tactive_fi = %s\n\t\t"; $affectedRows = $ilDB->manipulateF($query, array('integer'), array($active_id)); $ilDB->insert('tst_result_cache', array('active_fi' => array('integer', $active_id), 'pass' => array('integer', strlen($pass) ? $pass : 0), 'max_points' => array('float', strlen($max) ? $max : 0), 'reached_points' => array('float', strlen($reached) ? $reached : 0), 'mark_short' => array('text', strlen($mark["short_name"]) ? $mark["short_name"] : " "), 'mark_official' => array('text', strlen($mark["official_name"]) ? $mark["official_name"] : " "), 'passed' => array('integer', $isPassed), 'failed' => array('integer', $isFailed), 'tstamp' => array('integer', time()), 'hint_count' => array('integer', $row['hint_count']), 'hint_points' => array('float', $row['hint_points']), 'obligations_answered' => array('integer', $obligationsAnswered))); if (is_object($processLocker)) { $processLocker->releaseUserTestResultUpdateLock(); } }
/** * Output of a test certificate */ public function outCertificate() { global $ilUser; $active_id = $this->object->getTestSession()->getActiveId(); $counted_pass = ilObjTest::_getResultPass($active_id); include_once "./Services/Certificate/classes/class.ilCertificate.php"; include_once "./Modules/Test/classes/class.ilTestCertificateAdapter.php"; $certificate = new ilCertificate(new ilTestCertificateAdapter($this->object)); $certificate->outCertificate(array("active_id" => $active_id, "pass" => $counted_pass)); }