/**
  * 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 user data for a test results output
  *
  * @param ilTestSession|ilTestSessionDynamicQuestionSet
  * @param integer $user_id The user ID of the user
  * @param boolean $overwrite_anonymity TRUE if the anonymity status should be overwritten, FALSE otherwise
  * @return string HTML code of the user data for the test results
  * @access public
  */
 function getResultsUserdata($testSession, $active_id, $overwrite_anonymity = FALSE)
 {
     if (!is_object($testSession)) {
         throw new TestException();
     }
     $template = new ilTemplate("tpl.il_as_tst_results_userdata.html", TRUE, TRUE, "Modules/Test");
     include_once './Services/User/classes/class.ilObjUser.php';
     $user_id = $this->object->_getUserIdFromActiveId($active_id);
     if (strlen(ilObjUser::_lookupLogin($user_id)) > 0) {
         $user = new ilObjUser($user_id);
     } else {
         $user = new ilObjUser();
         $user->setLastname($this->lng->txt("deleted_user"));
     }
     $t = $testSession->getSubmittedTimestamp();
     if (!$t) {
         $t = $this->object->_getLastAccess($testSession->getActiveId());
     }
     $print_date = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"));
     $title_matric = "";
     if (strlen($user->getMatriculation()) && ($this->object->getAnonymity() == FALSE || $overwrite_anonymity)) {
         $template->setCurrentBlock("user_matric");
         $template->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
         $template->parseCurrentBlock();
         $template->setCurrentBlock("user_matric_value");
         $template->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
         $template->parseCurrentBlock();
         $template->touchBlock("user_matric_separator");
         $title_matric = " - " . $this->lng->txt("matriculation") . ": " . $user->getMatriculation();
     }
     $invited_user = array_pop($this->object->getInvitedUsers($user_id));
     if (strlen($invited_user["clientip"])) {
         $template->setCurrentBlock("user_clientip");
         $template->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
         $template->parseCurrentBlock();
         $template->setCurrentBlock("user_clientip_value");
         $template->setVariable("VALUE_CLIENT_IP", $invited_user["clientip"]);
         $template->parseCurrentBlock();
         $template->touchBlock("user_clientip_separator");
         $title_client = " - " . $this->lng->txt("clientip") . ": " . $invited_user["clientip"];
     }
     $template->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
     $template->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
     $template->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
     $uname = $this->object->userLookupFullName($user_id, $overwrite_anonymity);
     $template->setVariable("VALUE_USR_NAME", $uname);
     $template->setVariable("TXT_TEST_DATE", $this->lng->txt("tst_tst_date"));
     $template->setVariable("TXT_PRINT_DATE", $this->lng->txt("tst_print_date"));
     $old_value = ilDatePresentation::useRelativeDates();
     ilDatePresentation::setUseRelativeDates(false);
     $template->setVariable("VALUE_TEST_DATE", ilDatePresentation::formatDate(new ilDateTime(ilUtil::date_mysql2time($t), IL_CAL_UNIX)));
     $template->setVariable("VALUE_PRINT_DATE", ilDatePresentation::formatDate(new ilDateTime($print_date, IL_CAL_UNIX)));
     ilDatePresentation::setUseRelativeDates($old_value);
     // change the pagetitle
     $pagetitle = ": " . $this->object->getTitle() . $title_matric . $title_client;
     $this->tpl->setHeaderPageTitle($pagetitle);
     return $template->get();
 }
Exemplo n.º 3
0
 /**
  * @param string $content
  */
 protected function populateContent($content)
 {
     if ($this->isPdfDeliveryRequest()) {
         require_once 'class.ilTestPDFGenerator.php';
         ilTestPDFGenerator::generatePDF($content, ilTestPDFGenerator::PDF_OUTPUT_DOWNLOAD, $this->object->getTitle());
     } else {
         $this->tpl->setContent($content);
     }
 }
Exemplo n.º 4
0
 function addLocatorItems()
 {
     global $ilLocator;
     switch ($this->ctrl->getCmd()) {
         case "run":
         case "infoScreen":
         case "redirectToInfoScreen":
         case "start":
         case "resume":
         case "previous":
         case "next":
         case "summary":
         case "finishTest":
         case "outCorrectSolution":
         case "passDetails":
         case "showAnswersOfUser":
         case "outUserResultsOverview":
         case "backFromSummary":
         case "show_answers":
         case "setsolved":
         case "resetsolved":
         case "outTestSummary":
         case "outQuestionSummary":
         case "gotoQuestion":
         case "selectImagemapRegion":
         case "confirmSubmitAnswers":
         case "finalSubmission":
         case "postpone":
         case "redirectQuestion":
         case "outUserPassDetails":
         case "checkPassword":
             $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
             break;
         case "eval_stat":
         case "evalAllUsers":
         case "evalUserDetail":
             $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "eval_stat"), "", $_GET["ref_id"]);
             break;
         case "create":
         case "save":
         case "cancel":
         case "importFile":
         case "cloneAll":
         case "importVerifiedFile":
         case "cancelImport":
             break;
         default:
             $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
             break;
     }
 }
 /**
  * Get all completed tests
  */
 protected function getItems()
 {
     global $ilUser;
     include_once "Modules/Test/classes/class.ilObjTest.php";
     include_once "Modules/Test/classes/class.ilTestSessionFactory.php";
     $data = array();
     foreach (ilObjTest::getTestObjIdsWithActiveForUserId($ilUser->getId()) as $test_id) {
         // #11210 - only available certificates!
         $test = new ilObjTest($test_id, false);
         $session = new ilTestSessionFactory($test);
         $session = $session->getSession(null);
         if ($test->canShowCertificate($session, $session->getUserId(), $session->getActiveId())) {
             $data[] = array("id" => $test_id, "title" => $test->getTitle(), "passed" => $test->getPassed($session->getActiveId()));
         }
     }
     $this->setData($data);
 }
Exemplo n.º 6
0
 /**
  * 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 true, if a test is complete for use
 *
 * @return boolean True, if the test is complete for use, otherwise false
 * @access public
 */
 function _isComplete($a_obj_id)
 {
     global $ilDB;
     $test_id = ilObjTestAccess::_getTestIDFromObjectID($a_obj_id);
     $result = $ilDB->queryF("SELECT tst_mark.*, tst_tests.* FROM tst_tests, tst_mark WHERE tst_mark.test_fi = tst_tests.test_id AND tst_tests.test_id = %s", array('integer'), array($test_id));
     $found = $result->numRows();
     if ($found) {
         $row = $ilDB->fetchAssoc($result);
         // check for at least: title, author and minimum of 1 mark step
         if (strlen($row["title"]) && strlen($row["author"]) && $found) {
             // check also for minmum of 1 question
             if (ilObjTestAccess::_getQuestionCount($test_id) > 0) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
     $test = new ilObjTest($obj_id, false);
     $test->loadFromDb();
     if ($test->getTitle() and $test->author and count($test->mark_schema->mark_steps) and count($test->questions)) {
         return true;
     } else {
         return false;
     }
 }