/** * 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(); } }
/** * Returns the pass overview for a given active ID * * @return string HTML code of the pass overview * @access public * * @deprecated */ public function getPassOverview($active_id, $targetclass = "", $targetcommand = "", $short = FALSE, $hide_details = FALSE) { require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php'; require_once 'Modules/Test/classes/tables/class.ilTestPassOverviewTableGUI.php'; $table = new ilTestPassOverviewTableGUI($this, '', $short ? ilTestPassOverviewTableGUI::CONTEXT_SHORT : ilTestPassOverviewTableGUI::CONTEXT_LONG, isset($_GET['pdf']) && $_GET['pdf'] == 1); $data = array(); $counted_pass = $this->object->_getResultPass($active_id); $reached_pass = $this->object->_getPass($active_id); for ($pass = 0; $pass <= $reached_pass; $pass++) { $row = array(); $finishdate = $this->object->getPassFinishDate($active_id, $pass); if ($finishdate > 0) { if (!$short) { $result_array =& $this->object->getTestResult($active_id, $pass); if (!$result_array['pass']['total_max_points']) { $percentage = 0; } else { $percentage = $result_array['pass']['total_reached_points'] / $result_array['pass']['total_max_points'] * 100; } $total_max = $result_array['pass']['total_max_points']; $total_reached = $result_array['pass']['total_reached_points']; $total_requested_hints = $result_array['pass']['total_requested_hints']; } if (!$hide_details) { if (strlen($targetclass) && strlen($targetcommand)) { $this->ctrl->setParameterByClass($targetclass, 'active_id', $active_id); $this->ctrl->setParameterByClass($targetclass, 'pass', $pass); $aslgui = new ilAdvancedSelectionListGUI(); $aslgui->setListTitle($this->lng->txt('actions')); $aslgui->setId($pass); $aslgui->addItem($this->lng->txt('tst_pass_details'), 'tst_pass_details', $this->ctrl->getLinkTargetByClass($targetclass, $targetcommand)); if ($this->object->isPassDeletionAllowed()) { $aslgui->addItem($this->lng->txt('delete'), 'tst_pass_delete', $this->ctrl->getLinkTargetByClass($targetclass, 'confirmDeletePass')); } $row['pass_details'] = $aslgui->getHTML(); } } if (!$short) { if ($pass == $counted_pass) { $row['scored'] = '⊗'; } else { $row['scored'] = ''; } } $row['pass'] = $pass + 1; $row['date'] = $finishdate; if (!$short) { $row['answered'] = $this->object->getAnsweredQuestionCount($active_id, $pass) . ' ' . strtolower($this->lng->txt('of')) . ' ' . (count($result_array) - 2); if ($this->object->isOfferingQuestionHintsEnabled()) { $row['hints'] = $total_requested_hints; } $row['reached'] = $total_reached . ' ' . strtolower($this->lng->txt('of')) . ' ' . $total_max; $row['percentage'] = $percentage; } $data[] = $row; } } $table->setData($data); return $table->getHTML(); }
/** * @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; }
/** * Exports the evaluation data to the CSV file format * * Exports the evaluation data to the CSV file format * * @param string $filtertext Filter text for the user data * @param boolean $passedonly TRUE if only passed user datasets should be exported, FALSE otherwise * @access public */ function exportToCSV($deliver = TRUE, $filterby = "", $filtertext = "", $passedonly = FALSE) { global $ilLog; if (strcmp($this->mode, "aggregated") == 0) { return $this->aggregatedResultsToCSV($deliver); } $rows = array(); $datarow = array(); $col = 1; if ($this->test_obj->getAnonymity()) { array_push($datarow, $this->lng->txt("counter")); $col++; } else { array_push($datarow, $this->lng->txt("name")); $col++; array_push($datarow, $this->lng->txt("login")); $col++; } $additionalFields = $this->test_obj->getEvaluationAdditionalFields(); if (count($additionalFields)) { foreach ($additionalFields as $fieldname) { array_push($datarow, $this->lng->txt($fieldname)); $col++; } } array_push($datarow, $this->lng->txt("tst_stat_result_resultspoints")); $col++; array_push($datarow, $this->lng->txt("maximum_points")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_resultsmarks")); $col++; if ($this->test_obj->getECTSOutput()) { array_push($datarow, $this->lng->txt("ects_grade")); $col++; } array_push($datarow, $this->lng->txt("tst_stat_result_qworkedthrough")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_qmax")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_pworkedthrough")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_timeofwork")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_atimeofwork")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_firstvisit")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_lastvisit")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_mark_median")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_rank_participant")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_rank_median")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_total_participants")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_median")); $col++; array_push($datarow, $this->lng->txt("scored_pass")); $col++; array_push($datarow, $this->lng->txt("pass")); $col++; $data =& $this->test_obj->getCompleteEvaluationData(TRUE, $filterby, $filtertext); $headerrow = $datarow; $counter = 1; foreach ($data->getParticipants() as $active_id => $userdata) { $datarow = $headerrow; $remove = FALSE; if ($passedonly) { if ($data->getParticipant($active_id)->getPassed() == FALSE) { $remove = TRUE; } } if (!$remove) { $datarow2 = array(); if ($this->test_obj->getAnonymity()) { array_push($datarow2, $counter); } else { array_push($datarow2, $data->getParticipant($active_id)->getName()); array_push($datarow2, $data->getParticipant($active_id)->getLogin()); } if (count($additionalFields)) { $userfields = ilObjUser::_lookupFields($userdata->getUserID()); foreach ($additionalFields as $fieldname) { if (strcmp($fieldname, "gender") == 0) { array_push($datarow2, $this->lng->txt("gender_" . $userfields[$fieldname])); } else { array_push($datarow2, $userfields[$fieldname]); } } } array_push($datarow2, $data->getParticipant($active_id)->getReached()); array_push($datarow2, $data->getParticipant($active_id)->getMaxpoints()); array_push($datarow2, $data->getParticipant($active_id)->getMark()); if ($this->test_obj->getECTSOutput()) { array_push($datarow2, $data->getParticipant($active_id)->getECTSMark()); } array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThrough()); array_push($datarow2, $data->getParticipant($active_id)->getNumberOfQuestions()); array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0); $time = $data->getParticipant($active_id)->getTimeOfWork(); $time_seconds = $time; $time_hours = floor($time_seconds / 3600); $time_seconds -= $time_hours * 3600; $time_minutes = floor($time_seconds / 60); $time_seconds -= $time_minutes * 60; array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)); $time = $data->getParticipant($active_id)->getQuestionsWorkedThrough() ? $data->getParticipant($active_id)->getTimeOfWork() / $data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0; $time_seconds = $time; $time_hours = floor($time_seconds / 3600); $time_seconds -= $time_hours * 3600; $time_minutes = floor($time_seconds / 60); $time_seconds -= $time_minutes * 60; array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)); $fv = $data->getParticipant($active_id)->getFirstVisit(); $lv = $data->getParticipant($active_id)->getLastVisit(); foreach (array($fv, $lv) as $ts) { if ($ts) { $visit = ilFormat::formatDate(date('Y-m-d H:i:s', $ts), "datetime", false, false); array_push($datarow2, $visit); } else { array_push($datarow2, ""); } } $median = $data->getStatistics()->getStatistics()->median(); $pct = $data->getParticipant($active_id)->getMaxpoints() ? $median / $data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0; $mark = $this->test_obj->mark_schema->getMatchingMark($pct); $mark_short_name = ""; if (is_object($mark)) { $mark_short_name = $mark->getShortName(); } array_push($datarow2, $mark_short_name); array_push($datarow2, $data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached())); array_push($datarow2, $data->getStatistics()->getStatistics()->rank_median()); array_push($datarow2, $data->getStatistics()->getStatistics()->count()); array_push($datarow2, $median); if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) { array_push($datarow2, $data->getParticipant($active_id)->getBestPass() + 1); } else { array_push($datarow2, $data->getParticipant($active_id)->getLastPass() + 1); } for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) { $finishdate = $this->test_obj->getPassFinishDate($active_id, $pass); if ($finishdate > 0) { if ($pass > 0) { for ($i = 1; $i < $col - 1; $i++) { array_push($datarow2, ""); array_push($datarow, ""); } array_push($datarow, ""); } array_push($datarow2, $pass + 1); if (is_object($data->getParticipant($active_id)) && is_array($data->getParticipant($active_id)->getQuestions($pass))) { foreach ($data->getParticipant($active_id)->getQuestions($pass) as $question) { $question_data = $data->getParticipant($active_id)->getPass($pass)->getAnsweredQuestionByQuestionId($question["id"]); array_push($datarow2, $question_data["reached"]); array_push($datarow, preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))); } } if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions() || $counter == 1 && $pass == 0) { array_push($rows, $datarow); } $datarow = array(); array_push($rows, $datarow2); $datarow2 = array(); } } $counter++; } } $csv = ""; $separator = ";"; foreach ($rows as $evalrow) { $csvrow =& $this->test_obj->processCSVRow($evalrow, TRUE, $separator); $csv .= join($csvrow, $separator) . "\n"; } if ($deliver) { ilUtil::deliverData($csv, ilUtil::getASCIIFilename($this->test_obj->getTitle() . "_results.csv")); exit; } else { return $csv; } }
/** * Returns the pass overview for a given active ID * * @return string HTML code of the pass overview * @access public * * @deprecated */ function getPassOverview($active_id, $targetclass = "", $targetcommand = "", $short = FALSE, $hide_details = FALSE) { global $ilUser; if ($short) { $template = new ilTemplate("tpl.il_as_tst_pass_overview_short.html", TRUE, TRUE, "Modules/Test"); } else { $template = new ilTemplate("tpl.il_as_tst_pass_overview.html", TRUE, TRUE, "Modules/Test"); } $color_class = array("tblrow1", "tblrow2"); $counter = 0; $user_id = $this->object->_getUserIdFromActiveId($active_id); $counted_pass = $this->object->_getResultPass($active_id); $reached_pass = $this->object->_getPass($active_id); $result_percentage = 0; $result_total_reached = 0; $result_total_max = 0; for ($pass = 0; $pass <= $reached_pass; $pass++) { $finishdate = $this->object->getPassFinishDate($active_id, $pass); if ($finishdate > 0) { if (!$short) { $result_array =& $this->object->getTestResult($active_id, $pass); if (!$result_array["pass"]["total_max_points"]) { $percentage = 0; } else { $percentage = $result_array["pass"]["total_reached_points"] / $result_array["pass"]["total_max_points"] * 100; } $total_max = $result_array["pass"]["total_max_points"]; $total_reached = $result_array["pass"]["total_reached_points"]; $total_requested_hints = $result_array["pass"]["total_requested_hints"]; } if (!$hide_details) { if (strlen($targetclass) && strlen($targetcommand)) { $this->ctrl->setParameterByClass($targetclass, "active_id", $active_id); $this->ctrl->setParameterByClass($targetclass, "pass", $pass); $template->setCurrentBlock("pass_details"); require_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php'; $aslgui = new ilAdvancedSelectionListGUI(); $aslgui->setListTitle($this->lng->txt("actions")); $aslgui->setId($pass); $aslgui->addItem($this->lng->txt("tst_pass_details"), 'tst_pass_details', $this->ctrl->getLinkTargetByClass($targetclass, $targetcommand)); if ($this->object->isPassDeletionAllowed()) { $aslgui->addItem($this->lng->txt("delete"), 'tst_pass_delete', $this->ctrl->getLinkTargetByClass($targetclass, 'confirmDeletePass')); } // Suppress output of advanced selection list for pdf-generation as solution for Mantis #9359 if (!($_GET['pdf'] == 1)) { $template->setVariable("TEXT_PASS_DETAILS", $aslgui->getHTML()); } $template->parseCurrentBlock(); } } $template->setCurrentBlock("result_row"); if ($pass == $counted_pass && !$short) { $template->setVariable("COLOR_CLASS", "tblrowmarked"); $template->setVariable("VALUE_SCORED", "⊗"); if (!$result_array["test"]["total_max_points"]) { $result_percentage = 0; } else { $result_percentage = $result_array["test"]["total_reached_points"] / $result_array["test"]["total_max_points"] * 100; } $result_total_max = $result_array["test"]["total_max_points"]; $result_total_reached = $result_array["test"]["total_reached_points"]; } else { $template->setVariable("COLOR_CLASS", $color_class[$pass % 2]); } $template->setVariable("VALUE_PASS", $pass + 1); $template->setVariable("VALUE_DATE", ilDatePresentation::formatDate(new ilDate($finishdate, IL_CAL_UNIX))); if (!$short) { $template->setVariable("VALUE_ANSWERED", $this->object->getAnsweredQuestionCount($active_id, $pass) . " " . strtolower($this->lng->txt("of")) . " " . (count($result_array) - 2)); if ($this->object->isOfferingQuestionHintsEnabled()) { $template->setVariable("VALUE_HINTS", $total_requested_hints); } $template->setVariable("VALUE_REACHED", $total_reached . " " . strtolower($this->lng->txt("of")) . " " . $total_max); $template->setVariable("VALUE_PERCENTAGE", sprintf("%.2f", $percentage) . "%"); } $template->parseCurrentBlock(); } } $template->setVariable("PASS_COUNTER", $this->lng->txt("pass")); $template->setVariable("DATE", $this->lng->txt("date")); if (!$short) { $template->setVariable("PASS_SCORED", $this->lng->txt("scored_pass")); $template->setVariable("ANSWERED_QUESTIONS", $this->lng->txt("tst_answered_questions")); if ($this->object->isOfferingQuestionHintsEnabled()) { $template->setVariable("REQUESTED_HINTS", $this->lng->txt("tst_question_hints_requested_hint_count_header")); } $template->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points")); $template->setVariable("PERCENTAGE_CORRECT", $this->lng->txt("tst_percent_solved")); } $template->parseCurrentBlock(); return $template->get(); }
/** * Returns the pass overview for a given active ID * * @return string HTML code of the pass overview * @access public * * @deprecated */ public function getPassOverview(ilTestSession $testSession, $targetclass = "", $targetcommand = "", $short = FALSE, $hide_details = FALSE) { $active_id = $testSession->getActiveId(); require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php'; require_once 'Modules/Test/classes/tables/class.ilTestPassOverviewTableGUI.php'; $table = new ilTestPassOverviewTableGUI($this, '', $short ? ilTestPassOverviewTableGUI::CONTEXT_SHORT : ilTestPassOverviewTableGUI::CONTEXT_LONG, isset($_GET['pdf']) && $_GET['pdf'] == 1); $considerHiddenQuestions = true; if ($this->getObjectiveOrientedContainer()->isObjectiveOrientedPresentationRequired()) { $considerHiddenQuestions = false; $table->setObjectiveOrientedPresentationEnabled(true); require_once 'Modules/Course/classes/Objectives/class.ilLOTestQuestionAdapter.php'; $objectivesAdapter = ilLOTestQuestionAdapter::getInstance($testSession); } $table->init(); $data = array(); $counted_pass = $this->object->_getResultPass($active_id); $reached_pass = $this->object->_getPass($active_id); require_once 'Modules/Test/classes/class.ilTestPassesSelector.php'; $testPassesSelector = new ilTestPassesSelector($GLOBALS['ilDB'], $this->object); $testPassesSelector->setActiveId($active_id); $lastFinishedPass = $this->testSessionFactory->getSession($active_id)->getLastFinishedPass(); $testPassesSelector->setLastFinishedPass($lastFinishedPass); foreach ($testPassesSelector->getReportablePasses() as $pass) { $row = array(); $considerOptionalQuestions = true; if ($this->getObjectiveOrientedContainer()->isObjectiveOrientedPresentationRequired()) { $testSequence = $this->testSequenceFactory->getSequenceByActiveIdAndPass($active_id, $pass); $testSequence->loadFromDb(); $testSequence->loadQuestions(); if ($this->object->isRandomTest() && !$testSequence->isAnsweringOptionalQuestionsConfirmed()) { $considerOptionalQuestions = false; } $testSequence->setConsiderHiddenQuestionsEnabled($considerHiddenQuestions); $testSequence->setConsiderOptionalQuestionsEnabled($considerOptionalQuestions); $objectivesList = $this->buildQuestionRelatedObjectivesList($objectivesAdapter, $testSequence); $objectivesList->loadObjectivesTitles(); $row['objectives'] = $objectivesList->getUniqueObjectivesStringForQuestions($testSequence->getUserSequenceQuestions()); } if (!$short) { $result_array =& $this->object->getTestResult($active_id, $pass, false, $considerHiddenQuestions, $considerOptionalQuestions); if (!$result_array['pass']['total_max_points']) { $percentage = 0; } else { $percentage = $result_array['pass']['total_reached_points'] / $result_array['pass']['total_max_points'] * 100; } $total_max = $result_array['pass']['total_max_points']; $total_reached = $result_array['pass']['total_reached_points']; $total_requested_hints = $result_array['pass']['total_requested_hints']; } if (!$hide_details) { if (strlen($targetclass) && strlen($targetcommand)) { $this->ctrl->setParameterByClass($targetclass, 'active_id', $active_id); $this->ctrl->setParameterByClass($targetclass, 'pass', $pass); $aslgui = new ilAdvancedSelectionListGUI(); $aslgui->setListTitle($this->lng->txt('actions')); $aslgui->setId($pass); $aslgui->addItem($this->lng->txt('tst_pass_details'), 'tst_pass_details', $this->ctrl->getLinkTargetByClass($targetclass, $targetcommand)); if ($this->object->isPassDeletionAllowed() && $pass != $counted_pass) { $aslgui->addItem($this->lng->txt('delete'), 'tst_pass_delete', $this->ctrl->getLinkTargetByClass($targetclass, 'confirmDeletePass')); } $row['pass_details'] = $aslgui->getHTML(); } } if (!$short) { if ($pass == $counted_pass) { $row['scored'] = '⊗'; } else { $row['scored'] = ''; } } $row['pass'] = $pass + 1; $row['date'] = $this->object->getPassFinishDate($active_id, $pass); if (!$short) { $row['answered'] = $result_array['pass']['num_workedthrough'] . ' ' . strtolower($this->lng->txt('of')) . ' ' . (count($result_array) - 2); if ($this->object->isOfferingQuestionHintsEnabled()) { $row['hints'] = $total_requested_hints; } $row['reached'] = $total_reached . ' ' . strtolower($this->lng->txt('of')) . ' ' . $total_max; $row['percentage'] = $percentage; } $data[] = $row; } $table->setData($data); return $table->getHTML(); }