private function stageQuestionsFromSourcePool($sourcePoolId)
 {
     $questionIdMapping = array();
     $query = 'SELECT question_id FROM qpl_questions WHERE obj_fi = %s AND complete = %s AND original_id IS NULL';
     $res = $this->db->queryF($query, array('integer', 'text'), array($sourcePoolId, 1));
     while ($row = $this->db->fetchAssoc($res)) {
         $question = assQuestion::_instanciateQuestion($row['question_id']);
         $duplicateId = $question->duplicate(true, null, null, null, $this->testOBJ->getId());
         $nextId = $this->db->nextId('tst_rnd_cpy');
         $this->db->insert('tst_rnd_cpy', array('copy_id' => array('integer', $nextId), 'tst_fi' => array('integer', $this->testOBJ->getTestId()), 'qst_fi' => array('integer', $duplicateId), 'qpl_fi' => array('integer', $sourcePoolId)));
         $questionIdMapping[$row['question_id']] = $duplicateId;
     }
     return $questionIdMapping;
 }
Example #2
0
 /**
  * Copy question from pool into page
  *
  * @param
  * @return
  */
 function copyPoolQuestionIntoPage($a_q_id, $a_hier_id)
 {
     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
     $question = assQuestion::_instanciateQuestion($a_q_id);
     $duplicate_id = $question->copyObject(0, $question->getTitle());
     $duplicate = assQuestion::_instanciateQuestion($duplicate_id);
     $duplicate->setObjId(0);
     // we remove everything not supported by the non-tiny self
     // assessment question editor
     $q = $duplicate->getQuestion();
     // we try to save all latex tags
     $try = true;
     $ls = '<span class="latex">';
     $le = '</span>';
     while ($try) {
         // search position of start tag
         $pos1 = strpos($q, $ls);
         if (is_int($pos1)) {
             $pos2 = strpos($q, $le, $pos1);
             if (is_int($pos2)) {
                 // both found: replace end tag
                 $q = substr($q, 0, $pos2) . "[/tex]" . substr($q, $pos2 + 7);
                 $q = substr($q, 0, $pos1) . "[tex]" . substr($q, $pos1 + 20);
             } else {
                 $try = false;
             }
         } else {
             $try = false;
         }
     }
     $tags = assQuestionGUI::getSelfAssessmentTags();
     $tstr = "";
     foreach ($tags as $t) {
         $tstr .= "<" . $t . ">";
     }
     $q = ilUtil::secureString($q, true, $tstr);
     // self assessment uses nl2br, not p
     $duplicate->setQuestion($q);
     $duplicate->saveQuestionDataToDb();
     $this->q_node->set_attribute("QRef", "il__qst_" . $duplicate_id);
 }
 /**
  * removes all question set config related data for cloned/copied test
  *
  * @param ilObjTest $cloneTestOBJ
  */
 public function cloneQuestionSetRelatedData($cloneTestOBJ)
 {
     global $ilLog;
     require_once 'Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
     require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
     $cwo = ilCopyWizardOptions::_getInstance($cloneTestOBJ->getId());
     foreach ($this->questions as $key => $question_id) {
         $question = assQuestion::_instanciateQuestion($question_id);
         $cloneTestOBJ->questions[$key] = $question->duplicate(true, null, null, null, $cloneTestOBJ->getId());
         $original_id = assQuestion::_getOriginalId($question_id);
         $question = assQuestion::_instanciateQuestion($cloneTestOBJ->questions[$key]);
         $question->saveToDb($original_id);
         // Save the mapping of old question id <-> new question id
         // This will be used in class.ilObjCourse::cloneDependencies to copy learning objectives
         $originalKey = $this->testOBJ->getRefId() . '_' . $question_id;
         $mappedKey = $cloneTestOBJ->getRefId() . '_' . $cloneTestOBJ->questions[$key];
         $cwo->appendMapping($originalKey, $mappedKey);
         $ilLog->write(__METHOD__ . ": Added mapping {$originalKey} <-> {$mappedKey}");
     }
 }
Example #4
0
 /**
  * Exports the evaluation data to the Microsoft Excel file format
  *
  * @param bool    $deliver
  * @param string  $filterby
  * @param string  $filtertext Filter text for the user data
  * @param boolean $passedonly TRUE if only passed user datasets should be exported, FALSE otherwise
  *
  * @return string
  */
 public function exportToExcel($deliver = TRUE, $filterby = "", $filtertext = "", $passedonly = FALSE)
 {
     if (strcmp($this->mode, "aggregated") == 0) {
         return $this->aggregatedResultsToExcel($deliver);
     }
     require_once './Services/Excel/classes/class.ilExcelWriterAdapter.php';
     $excelfile = ilUtil::ilTempnam();
     $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
     $testname = $this->test_obj->getTitle();
     switch ($this->mode) {
         case 'results':
             $testname .= '_results';
             break;
     }
     $testname = ilUtil::getASCIIFilename(preg_replace("/\\s/", "_", $testname)) . ".xls";
     $workbook = $adapter->getWorkbook();
     $workbook->setVersion(8);
     // Use Excel97/2000 Format
     // Creating a worksheet
     $format_bold =& $workbook->addFormat();
     $format_bold->setBold();
     $format_percent =& $workbook->addFormat();
     $format_percent->setNumFormat("0.00%");
     $format_datetime =& $workbook->addFormat();
     $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
     $format_title =& $workbook->addFormat();
     $format_title->setBold();
     $format_title->setColor('black');
     $format_title->setPattern(1);
     $format_title->setFgColor('silver');
     require_once './Services/Excel/classes/class.ilExcelUtils.php';
     $worksheet =& $workbook->addWorksheet(ilExcelUtils::_convert_text($this->lng->txt("tst_results")));
     $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
     $row = 0;
     $col = 0;
     if ($this->test_obj->getAnonymity()) {
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("counter")), $format_title);
     } else {
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("name")), $format_title);
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("login")), $format_title);
     }
     if (count($additionalFields)) {
         foreach ($additionalFields as $fieldname) {
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt($fieldname)), $format_title);
         }
     }
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_resultspoints")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("maximum_points")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_resultsmarks")), $format_title);
     if ($this->test_obj->getECTSOutput()) {
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("ects_grade")), $format_title);
     }
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_qworkedthrough")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_qmax")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_pworkedthrough")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_timeofwork")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_atimeofwork")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_firstvisit")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_lastvisit")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_mark_median")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_rank_participant")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_rank_median")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_total_participants")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_median")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("scored_pass")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("pass")), $format_title);
     $counter = 1;
     $data =& $this->test_obj->getCompleteEvaluationData(TRUE, $filterby, $filtertext);
     $firstrowwritten = false;
     foreach ($data->getParticipants() as $active_id => $userdata) {
         $remove = FALSE;
         if ($passedonly) {
             if ($data->getParticipant($active_id)->getPassed() == FALSE) {
                 $remove = TRUE;
             }
         }
         if (!$remove) {
             $row++;
             if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) {
                 $row++;
             }
             $col = 0;
             if ($this->test_obj->getAnonymity()) {
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($counter));
             } else {
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getName()));
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getLogin()));
             }
             if (count($additionalFields)) {
                 $userfields = ilObjUser::_lookupFields($userdata->getUserID());
                 foreach ($additionalFields as $fieldname) {
                     if (strcmp($fieldname, "gender") == 0) {
                         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("gender_" . $userfields[$fieldname])));
                     } else {
                         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($userfields[$fieldname]));
                     }
                 }
             }
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getReached()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getMaxpoints()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getMark()));
             if ($this->test_obj->getECTSOutput()) {
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getECTSMark()));
             }
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getQuestionsWorkedThrough()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getNumberOfQuestions()));
             $worksheet->write($row, $col++, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0, $format_percent);
             $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;
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text(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;
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text(sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)));
             $fv = getdate($data->getParticipant($active_id)->getFirstVisit());
             $firstvisit = ilUtil::excelTime($fv["year"], $fv["mon"], $fv["mday"], $fv["hours"], $fv["minutes"], $fv["seconds"]);
             $worksheet->write($row, $col++, $firstvisit, $format_datetime);
             $lv = getdate($data->getParticipant($active_id)->getLastVisit());
             $lastvisit = ilUtil::excelTime($lv["year"], $lv["mon"], $lv["mday"], $lv["hours"], $lv["minutes"], $lv["seconds"]);
             $worksheet->write($row, $col++, $lastvisit, $format_datetime);
             $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();
             }
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($mark_short_name));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached())));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getStatistics()->getStatistics()->rank_median()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getStatistics()->getStatistics()->count()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($median));
             if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) {
                 $worksheet->write($row, $col++, $data->getParticipant($active_id)->getBestPass() + 1);
             } else {
                 $worksheet->write($row, $col++, $data->getParticipant($active_id)->getLastPass() + 1);
             }
             $startcol = $col;
             for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) {
                 $col = $startcol;
                 $finishdate = $this->test_obj->getPassFinishDate($active_id, $pass);
                 if ($finishdate > 0) {
                     if ($pass > 0) {
                         $row++;
                         if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) {
                             $row++;
                         }
                     }
                     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($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"]);
                             $worksheet->write($row, $col, ilExcelUtils::_convert_text($question_data["reached"]));
                             if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) {
                                 $worksheet->write($row - 1, $col, ilExcelUtils::_convert_text(preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))), $format_title);
                             } else {
                                 if ($pass == 0 && !$firstrowwritten) {
                                     $worksheet->write(0, $col, ilExcelUtils::_convert_text(preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))), $format_title);
                                 }
                             }
                             $col++;
                         }
                         $firstrowwritten = true;
                     }
                 }
             }
             $counter++;
         }
     }
     if ($this->test_obj->getExportSettingsSingleChoiceShort() && !$this->test_obj->isRandomTest() && $this->test_obj->hasSingleChoiceQuestions()) {
         // special tab for single choice tests
         $titles =& $this->test_obj->getQuestionTitlesAndIndexes();
         $positions = array();
         $pos = 0;
         $row = 0;
         foreach ($titles as $id => $title) {
             $positions[$id] = $pos;
             $pos++;
         }
         $usernames = array();
         $participantcount = count($data->getParticipants());
         $allusersheet = false;
         $pages = 0;
         $resultsheet =& $workbook->addWorksheet($this->lng->txt("eval_all_users"));
         $col = 0;
         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('name')), $format_title);
         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('login')), $format_title);
         if (count($additionalFields)) {
             foreach ($additionalFields as $fieldname) {
                 if (strcmp($fieldname, "matriculation") == 0) {
                     $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('matriculation')), $format_title);
                 }
             }
         }
         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('test')), $format_title);
         foreach ($titles as $title) {
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($title), $format_title);
         }
         $row++;
         foreach ($data->getParticipants() as $active_id => $userdata) {
             $username = !is_null($userdata) && ilExcelUtils::_convert_text($userdata->getName()) ? ilExcelUtils::_convert_text($userdata->getName()) : "ID {$active_id}";
             if (array_key_exists($username, $usernames)) {
                 $usernames[$username]++;
                 $username .= " ({$i})";
             } else {
                 $usernames[$username] = 1;
             }
             $col = 0;
             $resultsheet->write($row, $col++, $username);
             $resultsheet->write($row, $col++, $userdata->getLogin());
             if (count($additionalFields)) {
                 $userfields = ilObjUser::_lookupFields($userdata->getUserID());
                 foreach ($additionalFields as $fieldname) {
                     if (strcmp($fieldname, "matriculation") == 0) {
                         if (strlen($userfields[$fieldname])) {
                             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($userfields[$fieldname]));
                         } else {
                             $col++;
                         }
                     }
                 }
             }
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->test_obj->getTitle()));
             $pass = $userdata->getScoredPass();
             if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
                 foreach ($userdata->getQuestions($pass) as $question) {
                     $objQuestion =& $this->test_obj->_instanciateQuestion($question["aid"]);
                     if (is_object($objQuestion) && strcmp($objQuestion->getQuestionType(), 'assSingleChoice') == 0) {
                         $solution = $objQuestion->getSolutionValues($active_id, $pass);
                         $pos = $positions[$question["aid"]];
                         $selectedanswer = "x";
                         foreach ($objQuestion->getAnswers() as $id => $answer) {
                             if (strlen($solution[0]["value1"]) && $id == $solution[0]["value1"]) {
                                 $selectedanswer = $answer->getAnswertext();
                             }
                         }
                         $resultsheet->write($row, $col + $pos, ilExcelUtils::_convert_text($selectedanswer));
                     }
                 }
             }
             $row++;
         }
         if ($this->test_obj->isSingleChoiceTestWithoutShuffle()) {
             // special tab for single choice tests without shuffle option
             $pos = 0;
             $row = 0;
             $usernames = array();
             $allusersheet = false;
             $pages = 0;
             $resultsheet =& $workbook->addWorksheet($this->lng->txt("eval_all_users") . " (2)");
             $col = 0;
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('name')), $format_title);
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('login')), $format_title);
             if (count($additionalFields)) {
                 foreach ($additionalFields as $fieldname) {
                     if (strcmp($fieldname, "matriculation") == 0) {
                         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('matriculation')), $format_title);
                     }
                 }
             }
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('test')), $format_title);
             foreach ($titles as $title) {
                 $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($title), $format_title);
             }
             $row++;
             foreach ($data->getParticipants() as $active_id => $userdata) {
                 $username = !is_null($userdata) && ilExcelUtils::_convert_text($userdata->getName()) ? ilExcelUtils::_convert_text($userdata->getName()) : "ID {$active_id}";
                 if (array_key_exists($username, $usernames)) {
                     $usernames[$username]++;
                     $username .= " ({$i})";
                 } else {
                     $usernames[$username] = 1;
                 }
                 $col = 0;
                 $resultsheet->write($row, $col++, $username);
                 $resultsheet->write($row, $col++, $userdata->getLogin());
                 if (count($additionalFields)) {
                     $userfields = ilObjUser::_lookupFields($userdata->getUserID());
                     foreach ($additionalFields as $fieldname) {
                         if (strcmp($fieldname, "matriculation") == 0) {
                             if (strlen($userfields[$fieldname])) {
                                 $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($userfields[$fieldname]));
                             } else {
                                 $col++;
                             }
                         }
                     }
                 }
                 $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->test_obj->getTitle()));
                 $pass = $userdata->getScoredPass();
                 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
                     foreach ($userdata->getQuestions($pass) as $question) {
                         $objQuestion =& $this->test_obj->_instanciateQuestion($question["aid"]);
                         if (is_object($objQuestion) && strcmp($objQuestion->getQuestionType(), 'assSingleChoice') == 0) {
                             $solution = $objQuestion->getSolutionValues($active_id, $pass);
                             $pos = $positions[$question["aid"]];
                             $selectedanswer = chr(65 + $solution[0]["value1"]);
                             $resultsheet->write($row, $col + $pos, ilExcelUtils::_convert_text($selectedanswer));
                         }
                     }
                 }
                 $row++;
             }
         }
     } else {
         // test participant result export
         $usernames = array();
         $participantcount = count($data->getParticipants());
         $allusersheet = false;
         $pages = 0;
         $i = 0;
         foreach ($data->getParticipants() as $active_id => $userdata) {
             $i++;
             $username = !is_null($userdata) && ilExcelUtils::_convert_text($userdata->getName()) ? ilExcelUtils::_convert_text($userdata->getName()) : "ID {$active_id}";
             if (array_key_exists($username, $usernames)) {
                 $usernames[$username]++;
                 $username .= " ({$i})";
             } else {
                 $usernames[$username] = 1;
             }
             if ($participantcount > 250) {
                 if (!$allusersheet || $pages - 1 < floor($row / 64000)) {
                     $resultsheet =& $workbook->addWorksheet($this->lng->txt("eval_all_users") . ($pages > 0 ? " (" . ($pages + 1) . ")" : ""));
                     $allusersheet = true;
                     $row = 0;
                     $pages++;
                 }
             } else {
                 $resultsheet =& $workbook->addWorksheet($username);
             }
             if (method_exists($resultsheet, "writeString")) {
                 $pass = $userdata->getScoredPass();
                 $row = $allusersheet ? $row : 0;
                 $resultsheet->writeString($row, 0, ilExcelUtils::_convert_text(sprintf($this->lng->txt("tst_result_user_name_pass"), $pass + 1, $userdata->getName())), $format_bold);
                 $row += 2;
                 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
                     foreach ($userdata->getQuestions($pass) as $question) {
                         require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                         $question = assQuestion::_instanciateQuestion($question["id"]);
                         if (is_object($question)) {
                             $row = $question->setExportDetailsXLS($resultsheet, $row, $active_id, $pass, $format_title, $format_bold);
                         }
                     }
                 }
             }
         }
     }
     $workbook->close();
     if ($deliver) {
         ilUtil::deliverFile($excelfile, $testname, "application/vnd.ms-excel", false, true);
         exit;
     } else {
         return $excelfile;
     }
 }
Example #5
0
 /**
  * Replaces existing question content elements with
  * new copies
  */
 function newQuestionCopies(&$temp_dom)
 {
     // Get question IDs
     $path = "//Question";
     $xpc = xpath_new_context($temp_dom);
     $res =& xpath_eval($xpc, $path);
     $q_ids = array();
     include_once "./Services/Link/classes/class.ilInternalLink.php";
     for ($i = 0; $i < count($res->nodeset); $i++) {
         $qref = $res->nodeset[$i]->get_attribute("QRef");
         $inst_id = ilInternalLink::_extractInstOfTarget($qref);
         $q_id = ilInternalLink::_extractObjIdOfTarget($qref);
         if (!($inst_id > 0)) {
             if ($q_id > 0) {
                 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                 $question = assQuestion::_instanciateQuestion($q_id);
                 // check if page for question exists
                 // due to a bug in early 4.2.x version this is possible
                 if (!ilPageObject::_exists("qpl", $q_id)) {
                     $question->createPageObject();
                 }
                 // now copy this question and change reference to
                 // new question id
                 $duplicate_id = $question->duplicate(false);
                 $res->nodeset[$i]->set_attribute("QRef", "il__qst_" . $duplicate_id);
             }
         }
     }
 }
 /**
  * Deletes a question from the question pool
  *
  * @param integer $question_id The database id of the question
  * @access private
  */
 function deleteQuestion($question_id)
 {
     include_once "./Modules/Test/classes/class.ilObjTest.php";
     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     $question = assQuestion::_instanciateQuestion($question_id);
     $this->addQuestionChangeListeners($question);
     $question->delete($question_id);
 }
Example #7
0
 /**
 * Creates an instance of a question with a given question id
 *
 * @param integer $question_id The question id
 * @return object The question instance
 * @access public
  * 
  * @deprecated use assQuestion::_instanciateQuestion($question_id) instead
 */
 function &_instanciateQuestion($question_id)
 {
     if (strcmp($question_id, "") != 0) {
         include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
         return assQuestion::_instanciateQuestion($question_id);
     }
 }
 /**
  * Save the solution of a question
  *
  * @param string $sid Session ID
  * @param long $active_id Active user ID
  * @param integer $question_id Question ID
  * @param integer $pass Test pass
  * @param string $solution XML string containing the solution
  *
  * @return array String array containing the question solution (in triplets of value1, value2, points)
  */
 function saveQuestionSolution($sid, $active_id, $question_id, $pass, $solution)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!$this->isAllowedCall($sid, $active_id)) {
         return $this->__raiseError("The required user information is only available for active users.", "");
     }
     $solutions = array();
     if (preg_match("/<values>(.*?)<\\/values>/is", $solution, $matches)) {
         if (preg_match_all("/<value>(.*?)<\\/value><value>(.*?)<\\/value><points>(.*?)<\\/points>/is", $solution, $matches, PREG_SET_ORDER)) {
             foreach ($matches as $match) {
                 if (count($match) == 4) {
                     for ($i = 1; $i < count($match); $i++) {
                         array_push($solutions, trim($match[$i]));
                     }
                 }
             }
         }
     }
     if (count($solutions) == 0) {
         return $this->__raiseError("Wrong solution data. ILIAS did not find one or more solution triplets: {$solution}", "");
     }
     // Include main header
     $ilDB = $GLOBALS['ilDB'];
     if ($active_id > 0 && $question_id > 0 && strlen($pass) > 0) {
         $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s", array('integer', 'integer', 'integer'), array($active_id, $question_id, $pass));
     }
     $totalrows = 0;
     for ($i = 0; $i < count($solutions); $i += 3) {
         $next_id = $ilDB->nextId('tst_solutions');
         $affectedRows = $ilDB->insert("tst_solutions", array("solution_id" => array("integer", $next_id), "active_fi" => array("integer", $active_id), "question_fi" => array("integer", $question_id), "value1" => array("clob", $solutions[$i]), "value2" => array("clob", $solutions[$i + 1]), "points" => array("float", $solutions[$i + 2]), "pass" => array("integer", $pass), "tstamp" => array("integer", time())));
         $totalrows += $affectedRows;
     }
     if (count($totalrows) == 0) {
         return $this->__raiseError("Wrong solution data. ILIAS did not execute any database queries");
     } else {
         include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
         $question = assQuestion::_instanciateQuestion($question_id);
         $question->calculateResultsFromSolution($active_id, $pass);
     }
     return "TRUE";
 }
Example #9
0
 /**
  * @global ilObjectDataCache $ilObjDataCache
  */
 public function copyAndLinkQuestionsToPoolObject()
 {
     global $ilObjDataCache;
     $qplId = $ilObjDataCache->lookupObjId($_REQUEST['sel_qpl']);
     $result = $this->copyQuestionsToPool($_REQUEST['q_id'], $qplId);
     foreach ($result->ids as $oldId => $newId) {
         $questionInstance = assQuestion::_instanciateQuestion($oldId);
         if (assQuestion::originalQuestionExists($questionInstance->getOriginalId())) {
             $oldOriginal = assQuestion::_instanciateQuestion($questionInstance->getOriginalId());
             $oldOriginal->delete($oldOriginal->getId());
         }
         $questionInstance->setNewOriginalId($newId);
     }
     $this->ctrl->redirect($this, 'questions');
 }
Example #10
0
 function exportXMLPageObjects($a_target_dir, &$a_xml_writer, $a_inst, &$expLog)
 {
     global $ilBench;
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
     $tree = new ilTree($this->slm_id);
     $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
     $tree->setTreeTablePK("slm_id");
     $pages = $tree->getSubTree($tree->getNodeData($this->getId()), true, 'page');
     foreach ($pages as $page) {
         $expLog->write(date("[y-m-d H:i:s] ") . "Page Object " . $page["obj_id"]);
         // export xml to writer object
         $page_obj = new ilSCORM2004Page($page["obj_id"]);
         $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
         //collect media objects
         $mob_ids = $page_obj->getMediaObjectIds();
         foreach ($mob_ids as $mob_id) {
             $this->mob_ids[$mob_id] = $mob_id;
         }
         // collect all file items
         $file_ids = $page_obj->getFileItemIds();
         foreach ($file_ids as $file_id) {
             $this->file_ids[$file_id] = $file_id;
         }
         include_once "./Services/COPage/classes/class.ilPCQuestion.php";
         $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
         if (count($q_ids) > 0) {
             include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
             foreach ($q_ids as $q_id) {
                 $q_obj =& assQuestion::_instanciateQuestion($q_id);
                 $qti_file = fopen($a_target_dir . "/qti_" . $q_id . ".xml", "w");
                 fwrite($qti_file, $q_obj->toXML());
                 fclose($qti_file);
             }
         }
         unset($page_obj);
     }
 }
 /**
  * Creates user results for single questions
  *
  */
 public function singleResults()
 {
     global $ilAccess;
     if (!$ilAccess->checkAccess("tst_statistics", "", $this->ref_id) && !$ilAccess->checkAccess("write", "", $this->ref_id)) {
         // allow only evaluation access
         ilUtil::sendInfo($this->lng->txt("cannot_edit_test"), true);
         $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
     }
     $data =& $this->object->getCompleteEvaluationData();
     $color_class = array("tblrow1", "tblrow2");
     $counter = 0;
     $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_eval_single_answers.html", "Modules/Test");
     $foundParticipants =& $data->getParticipants();
     if (count($foundParticipants) == 0) {
         ilUtil::sendInfo($this->lng->txt("tst_no_evaluation_data"));
         return;
     } else {
         $rows = array();
         foreach ($data->getQuestionTitles() as $question_id => $question_title) {
             $answered = 0;
             $reached = 0;
             $max = 0;
             foreach ($foundParticipants as $userdata) {
                 $pass = $userdata->getScoredPass();
                 if (is_object($userdata->getPass($pass))) {
                     $question =& $userdata->getPass($pass)->getAnsweredQuestionByQuestionId($question_id);
                     if (is_array($question)) {
                         $answered++;
                     }
                 }
             }
             $counter++;
             $this->ctrl->setParameter($this, "qid", $question_id);
             require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
             $question_object = assQuestion::_instanciateQuestion($question_id);
             $download = "";
             if ($question_object instanceof ilObjFileHandlingQuestionType) {
                 if ($question_object->hasFileUploads($this->object->getTestId())) {
                     $download = "<a href=\"" . $this->ctrl->getLinkTarget($this, "exportFileUploadsForAllParticipants") . "\">" . $this->lng->txt("download") . "</a>";
                 }
             }
             array_push($rows, array('qid' => $question_id, 'question_title' => $question_title, 'number_of_answers' => $answered, 'output' => "<a href=\"" . $this->ctrl->getLinkTarget($this, "exportQuestionForAllParticipants") . "\">" . $this->lng->txt("pdf_export") . "</a>", 'file_uploads' => $download));
         }
         if (count($rows)) {
             require_once './Modules/Test/classes/tables/class.ilResultsByQuestionTableGUI.php';
             $table_gui = new ilResultsByQuestionTableGUI($this, "singleResults");
             $table_gui->setTitle($this->lng->txt("tst_answered_questions_test"));
             $table_gui->setData($rows);
             $this->tpl->setVariable("TBL_SINGLE_ANSWERS", $table_gui->getHTML());
         } else {
             $this->tpl->setVariable("TBL_SINGLE_ANSWERS", $this->lng->txt("adm_no_special_users"));
         }
     }
 }
Example #12
0
 /**
  * Returns the output of the suggested solution
  *
  * @param integer $question_id The database Id of the question
  * @return string Suggested solution
  */
 public static function _getSuggestedSolutionOutput($question_id)
 {
     $question =& assQuestion::_instanciateQuestion($question_id);
     if (!is_object($question)) {
         return "";
     }
     return $question->getSuggestedSolutionOutput();
 }
 public function copyAndLinkToQuestionpoolObject()
 {
     global $lng;
     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     foreach ($_REQUEST['q_id'] as $q_id) {
         $questionInstance = assQuestion::_instanciateQuestion($q_id);
         $type = ilObject::_lookupType($questionInstance->getObjId());
         if ($type !== 'tst') {
             ilUtil::sendFailure($lng->txt('tst_link_only_unassigned'), true);
             $this->backObject();
             return;
         }
     }
     $this->createQuestionpoolTargetObject('copyAndLinkQuestionsToPool');
 }
 function exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, &$expLog, &$a_xml_writer)
 {
     $this->exportHTML4PDF($a_inst, $a_target_dir, $expLog);
     global $tpl, $lng, $ilCtrl;
     $this->exportXMLPageObjects($a_target_dir, $a_xml_writer, $a_inst, $expLog);
     $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
     $this->exportFileItems($a_target_dir, $expLog);
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
     $tree = new ilTree($this->slm_id);
     $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
     $tree->setTreeTablePK("slm_id");
     foreach ($tree->getSubTree($tree->getNodeData($this->getId()), true, 'page') as $page) {
         $page_obj = new ilSCORM2004Page($page["obj_id"]);
         include_once "./Services/COPage/classes/class.ilPCQuestion.php";
         $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
         if (count($q_ids) > 0) {
             include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
             foreach ($q_ids as $q_id) {
                 $q_obj =& assQuestion::_instanciateQuestion($q_id);
                 $qti_file = fopen($a_target_dir . "/qti_" . $q_id . ".xml", "w");
                 fwrite($qti_file, $q_obj->toXML());
                 fclose($qti_file);
                 $x = file_get_contents($a_target_dir . "/qti_" . $q_id . ".xml");
                 $x = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $x);
                 $a_xml_writer->appendXML($x);
             }
         }
         unset($page_obj);
     }
 }
Example #15
0
 private function getQuestionListNew($questionList)
 {
     $questions = array();
     foreach ($questionList as $question) {
         //get the question type
         $assQuestion = assQuestion::_instanciateQuestion($question["question_id"]);
         array_push($questions, $this->calculateQuestion($question, $assQuestion));
     }
     return $questions;
 }