5 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
198 $this->original_id = null;
206 $this->author = $this->ilias->account->fullname;
209 if ($this->owner <= 0)
211 $this->owner = $this->ilias->account->id;
215 $this->suggested_solutions = array();
217 $this->nr_of_tries =
"";
220 $this->arrData = array();
234 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
236 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class." . $this->
getQuestionType() .
"Import.php";
238 $import =
new $classname($this);
239 $import->fromXML($item, $questionpool_id, $tst_id, $tst_object, $question_counter, $import_mapping);
248 function toXML($a_include_header =
true, $a_include_binary =
true, $a_shuffle =
false, $test_output =
false, $force_image_references =
false)
250 include_once
"./Modules/TestQuestionPool/classes/export/qti12/class." . $this->
getQuestionType() .
"Export.php";
252 $export =
new $classname($this);
253 return $export->toXML($a_include_header, $a_include_binary, $a_shuffle, $test_output, $force_image_references);
278 $result = $ilDB->queryF(
"SELECT * FROM qpl_questions WHERE obj_fi = %s AND title = %s",
279 array(
'integer',
'text'),
280 array($questionpool_id,
$title)
282 return (
$result->numRows() == 1) ? TRUE : FALSE;
318 $this->test_id =
$id;
376 $this->est_working_time = array(
"h" => (
int)$hour,
"m" => (
int)$min,
"s" => (
int)$sec);
390 foreach ($array as $key => $value)
392 if (strcmp($key, $searchkey)==0)
412 $author = $this->ilias->account->fullname;
521 if (!$this->est_working_time)
523 $this->est_working_time = array(
"h" => 0,
"m" => 0,
"s" => 0);
587 $result = $ilDB->queryF(
"SELECT points FROM qpl_questions WHERE question_id = %s",
609 $result = $ilDB->queryF(
"SELECT qpl_questions.*, qpl_qst_type.type_tag FROM qpl_qst_type, qpl_questions WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_qst_type.question_type_id",
615 return $ilDB->fetchAssoc(
$result);
630 $result = $ilDB->queryF(
"SELECT suggested_solution_id FROM qpl_sol_sug WHERE question_fi = %s",
647 return $question->getSuggestedSolutionOutput();
653 foreach ($this->suggested_solutions as $solution)
655 switch ($solution[
"type"])
664 $possible_texts = array_values(array_filter(array(
667 $this->lng->txt(
'tst_show_solution_suggested')
669 array_push($output,
'<a href="' . $this->
getSuggestedSolutionPathWeb() . $solution[
"value"][
"name"] .
'">' . $possible_texts[0] .
'</a>');
676 return join($output,
"<br />");
691 $result = $ilDB->queryF(
"SELECT * FROM qpl_sol_sug WHERE question_fi = %s AND subquestion_index = %s",
692 array(
'integer',
'integer'),
693 array($question_id, $subquestion_index)
699 "internal_link" =>
$row[
"internal_link"],
700 "import_id" =>
$row[
"import_id"]
733 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
736 $result = $ilDB->queryF(
"SELECT * FROM tst_test_result WHERE active_fi = %s AND question_fi = %s AND pass = %s",
737 array(
'integer',
'integer',
'integer'),
738 array($active_id, $question_id,
$pass)
787 include_once
"./Modules/Test/classes/class.ilObjTest.php";
795 require_once
'Modules/TestQuestionPool/classes/class.ilAssQuestionHintTracking.php';
797 $reached_points = $reached_points - $requestsStatisticData->getRequestsPoints();
802 return $reached_points;
820 include_once
"./Modules/Test/classes/class.ilObjTest.php";
828 require_once
'Modules/TestQuestionPool/classes/class.ilAssQuestionHintTracking.php';
830 $reached_points = $reached_points - $requestsStatisticData->getRequestsPoints();
844 if( is_null($reached_points) ) $reached_points = 0;
847 DELETE FROM tst_test_result
854 $affectedRows = $ilDB->manipulateF(
855 $query, array(
"integer",
"integer",
"integer"), array($active_id, $this->
getId(),
$pass)
858 $next_id = $ilDB->nextId(
"tst_test_result");
860 $ilDB->insert(
'tst_test_result', array(
861 'test_result_id' => array(
'integer', $next_id),
862 'active_fi' => array(
'integer', $active_id),
863 'question_fi' => array(
'integer', $this->
getId()),
864 'pass' => array(
'integer',
$pass),
865 'points' => array(
'float', $reached_points),
866 'tstamp' => array(
'integer', time()),
867 'hint_count' => array(
'integer', $requestsStatisticData->getRequestsCount()),
868 'hint_points' => array(
'float', $requestsStatisticData->getRequestsPoints()),
869 'answered' => array(
'integer', $isAnswered)
872 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
892 include_once
'Modules/Course/classes/class.ilCourseObjectiveResult.php';
908 require_once
'Modules/Test/classes/class.ilObjTest.php';
947 include_once
"./Modules/Test/classes/class.ilObjTest.php";
948 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
953 SELECT tst_pass_result.*
960 $query, array(
'integer',
'integer'), array($active_id,
$pass)
965 $max =
$row[
'maxpoints'];
966 $reached =
$row[
'points'];
968 $obligationsAnswered = (int)
$row[
'obligations_answered'];
970 include_once
"./Modules/Test/classes/class.assMarkSchema.php";
972 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
976 $isPassed = ( $mark[
"passed"] ? 1 : 0 );
977 $isFailed = ( !$mark[
"passed"] ? 1 : 0 );
980 DELETE FROM tst_result_cache
984 $affectedRows = $ilDB->manipulateF(
985 $query, array(
'integer'), array($active_id)
988 $ilDB->insert(
'tst_result_cache', array(
989 'active_fi'=> array(
'integer', $active_id),
990 'pass'=> array(
'integer', strlen(
$pass) ?
$pass : 0),
991 'max_points'=> array(
'float', strlen($max) ? $max : 0),
992 'reached_points'=> array(
'float', strlen($reached) ? $reached : 0),
993 'mark_short'=> array(
'text', strlen($mark[
"short_name"]) ? $mark[
"short_name"] :
" "),
994 'mark_official'=> array(
'text', strlen($mark[
"official_name"]) ? $mark[
"official_name"] :
" "),
995 'passed'=> array(
'integer', $isPassed),
996 'failed'=> array(
'integer', $isFailed),
997 'tstamp'=> array(
'integer', time()),
998 'hint_count'=> array(
'integer',
$row[
'hint_count']),
999 'hint_points'=> array(
'float',
$row[
'hint_points']),
1000 'obligations_answered' => array(
'integer', $obligationsAnswered)
1008 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1016 SELECT SUM(points) reachedpoints,
1017 SUM(hint_count) hint_count,
1018 SUM(hint_points) hint_points,
1019 COUNT(question_fi) answeredquestions
1020 FROM tst_test_result
1021 WHERE active_fi = %s
1024 array(
'integer',
'integer'),
1025 array($active_id,
$pass)
1030 if( $obligationsEnabled )
1033 SELECT count(*) cnt,
1034 min( answered ) answ
1035 FROM tst_test_question
1036 INNER JOIN tst_active
1038 AND tst_test_question.test_fi = tst_active.test_fi
1039 LEFT JOIN tst_test_result
1040 ON tst_test_result.active_fi = %s
1041 AND tst_test_result.pass = %s
1042 AND tst_test_question.question_fi = tst_test_result.question_fi
1043 WHERE obligatory = 1';
1045 $result_obligatory = $ilDB->queryF(
1046 $query, array(
'integer',
'integer',
'integer'), array($active_id, $active_id,
$pass)
1049 $row_obligatory = $ilDB->fetchAssoc($result_obligatory);
1051 if ($row_obligatory[
'cnt'] == 0)
1053 $obligations_answered = 1;
1057 $obligations_answered = (int) $row_obligatory[
'answ'];
1062 $obligations_answered = 1;
1067 if(
$row[
'hint_count'] === null )
$row[
'hint_count'] = 0;
1068 if(
$row[
'hint_points'] === null )
$row[
'hint_points'] = 0;
1071 DELETE FROM tst_pass_result
1073 WHERE active_fi = %s
1077 $affectedRows = $ilDB->manipulateF(
1078 $query, array(
'integer',
'integer'), array($active_id,
$pass)
1081 $ilDB->insert(
'tst_pass_result', array(
1082 'active_fi' => array(
'integer', $active_id),
1083 'pass' => array(
'integer', strlen(
$pass) ?
$pass : 0),
1084 'points' => array(
'float',
$row[
'reachedpoints'] ?
$row[
'reachedpoints'] : 0),
1085 'maxpoints' => array(
'float',
$data[
'points']),
1086 'questioncount' => array(
'integer',
$data[
'count']),
1087 'answeredquestions' => array(
'integer', $row[
'answeredquestions']),
1088 'workingtime' => array(
'integer', $time),
1089 'tstamp' => array(
'integer', time()),
1090 'hint_count' => array(
'integer', $row[
'hint_count']),
1091 'hint_points' => array(
'float', $row[
'hint_points']),
1092 'obligations_answered' => array(
'integer', $obligations_answered)
1099 'active_fi' => $active_id,
1101 'points' => (
$row[
"reachedpoints"]) ?
$row[
"reachedpoints"] : 0,
1102 'maxpoints' =>
$data[
"points"],
1103 'questioncount' =>
$data[
"count"],
1104 'answeredquestions' => $row[
"answeredquestions"],
1105 'workingtime' => $time,
1107 'hint_count' => $row[
'hint_count'],
1108 'hint_points' => $row[
'hint_points'],
1109 'obligations_answered' => $obligations_answered
1120 function logAction($logtext =
"", $active_id =
"", $question_id =
"")
1125 if (strcmp($question_id,
"") != 0)
1127 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
1130 include_once
"./Modules/Test/classes/class.ilObjAssessmentFolder.php";
1131 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1142 function _logAction($logtext =
"", $active_id =
"", $question_id =
"")
1147 if (strcmp($question_id,
"") != 0)
1149 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
1152 include_once
"./Modules/Test/classes/class.ilObjAssessmentFolder.php";
1153 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1166 $mediatempdir = CLIENT_WEB_DIR .
"/assessment/temp";
1168 $temp_name = tempnam($mediatempdir, $name .
"_____");
1169 $temp_name = str_replace(
"\\",
"/", $temp_name);
1170 @unlink($temp_name);
1187 return CLIENT_WEB_DIR .
"/assessment/$this->obj_id/$this->id/solution/";
1197 return CLIENT_WEB_DIR .
"/assessment/$this->obj_id/$this->id/java/";
1208 if( $question_id === null)
1213 if( $object_id === null)
1218 return CLIENT_WEB_DIR .
"/assessment/$object_id/$question_id/images/";
1229 return CLIENT_WEB_DIR .
"/assessment/$this->obj_id/$this->id/flash/";
1240 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1252 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1265 if(!$this->export_image_path)
1267 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1285 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1308 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s ORDER BY solution_id",
1309 array(
'integer',
'integer',
'integer'),
1314 array_push($values,
$row);
1330 if ($question_id < 1) $question_id = $this->
getId();
1331 $result = $ilDB->queryF(
"SELECT COUNT(qpl_questions.question_id) question_count FROM qpl_questions, tst_test_question WHERE qpl_questions.original_id = %s AND qpl_questions.question_id = tst_test_question.question_fi",
1336 $count =
$row[
"question_count"];
1338 $result = $ilDB->queryF(
"SELECT DISTINCT tst_active.test_fi, qpl_questions.question_id FROM qpl_questions, tst_test_rnd_qst, tst_active WHERE qpl_questions.original_id = %s AND qpl_questions.question_id = tst_test_rnd_qst.question_fi AND tst_test_rnd_qst.active_fi = tst_active.active_id",
1357 if ($question_id < 1) $question_id =
$this->id;
1358 $result = $ilDB->queryF(
"SELECT original_id FROM qpl_questions WHERE question_id = %s",
1363 return (
$row[
"original_id"] > 0) ? TRUE : FALSE;
1374 $keys = array_keys($array);
1377 foreach ($keys as $key)
1393 $result = $ilDB->queryF(
"SELECT qpl_qst_type.type_tag FROM qpl_qst_type, qpl_questions WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_qst_type.question_type_id",
1398 return $data[
"type_tag"];
1433 if (is_array($answer_table_name))
1435 foreach ($answer_table_name as $table)
1439 $affectedRows = $ilDB->manipulateF(
"DELETE FROM $table WHERE question_fi = %s",
1448 if (strlen($answer_table_name))
1450 $affectedRows = $ilDB->manipulateF(
"DELETE FROM $answer_table_name WHERE question_fi = %s",
1468 if (is_array($additional_table_name))
1470 foreach ($additional_table_name as $table)
1474 $affectedRows = $ilDB->manipulateF(
"DELETE FROM $table WHERE question_fi = %s",
1483 if (strlen($additional_table_name))
1485 $affectedRows = $ilDB->manipulateF(
"DELETE FROM $additional_table_name WHERE question_fi = %s",
1501 include_once
"./Services/COPage/classes/class.ilPageObject.php";
1513 public function delete($question_id)
1517 if ($question_id < 1)
return true;
1519 $result = $ilDB->queryF(
"SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
1538 $ilLog->write(
"EXCEPTION: Could not delete page of question $question_id: $e");
1542 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_questions WHERE question_id = %s",
1546 if ($affectedRows == 0)
return false;
1557 $ilLog->write(
"EXCEPTION: Could not delete additional table data of question $question_id: $e");
1564 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_test_question WHERE question_fi = %s",
1571 $ilLog->write(
"EXCEPTION: Could not delete delete question $question_id from a test: $e");
1578 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_sol_sug WHERE question_fi = %s",
1585 $ilLog->write(
"EXCEPTION: Could not delete suggested solutions of question $question_id: $e");
1591 $directory = CLIENT_WEB_DIR .
"/assessment/" .
$obj_id .
"/$question_id";
1592 if (preg_match(
"/\d+/",
$obj_id) and preg_match(
"/\d+/", $question_id) and is_dir($directory))
1594 include_once
"./Services/Utilities/classes/class.ilUtil.php";
1600 $ilLog->write(
"EXCEPTION: Could not delete question file directory $directory of question $question_id: $e");
1606 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1612 foreach(
$mobs as $mob)
1624 $ilLog->write(
"EXCEPTION: Error deleting the media objects of question $question_id: $e");
1628 require_once
'Modules/TestQuestionPool/classes/class.ilAssQuestionHintTracking.php';
1631 require_once
'Modules/TestQuestionPool/classes/class.ilAssQuestionHintList.php';
1637 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
1642 $ilLog->write(
"EXCEPTION: Error updating the question pool question count of question pool " . $this->
getObjId() .
" when deleting question $question_id: $e");
1667 $result = $ilDB->queryF(
"SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
1668 array(
'integer',
'integer'),
1669 array($a_q_id, $a_q_id)
1675 $found_id = array();
1678 array_push($found_id,
$row[
"question_id"]);
1681 $result = $ilDB->query(
"SELECT * FROM tst_test_result WHERE " . $ilDB->in(
'question_fi', $found_id,
false,
'integer'));
1696 $result = $ilDB->queryF(
"SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
1697 array(
'integer',
'integer'),
1698 array($a_q_id, $a_q_id)
1704 $found_id = array();
1707 array_push($found_id,
$row[
"question_id"]);
1709 $result = $ilDB->query(
"SELECT * FROM tst_test_result WHERE " . $ilDB->in(
'question_fi', $found_id,
false,
'integer'));
1713 $reached =
$row[
"points"];
1714 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
1716 array_push($answers, array(
"reached" => $reached,
"max" => $max));
1720 foreach ($answers as $key => $value)
1722 $max += $value[
"max"];
1723 $reached += $value[
"reached"];
1727 return $reached / $max;
1743 $result = $ilDB->queryF(
"SELECT title FROM qpl_questions WHERE question_id = %s",
1750 return $row[
"title"];
1766 $result = $ilDB->queryF(
"SELECT question_text FROM qpl_questions WHERE question_id = %s",
1773 return $row[
"question_text"];
1784 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1786 foreach (
$mobs as $mob)
1794 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1796 foreach (
$mobs as $mob)
1809 include_once
"./Services/COPage/classes/class.ilPageObject.php";
1811 $this->page->setId($this->
getId());
1812 $this->page->setParentId($qpl_id);
1813 $this->page->setXMLContent(
"<PageObject><PageContent>".
1814 "<Question QRef=\"il__qst_".$this->
getId().
"\"/>".
1815 "</PageContent></PageObject>");
1816 $this->page->create();
1823 include_once
"./Services/COPage/classes/class.ilPageObject.php";
1826 $xml = str_replace(
"il__qst_".$a_q_id,
"il__qst_".$this->
id,
$page->getXMLContent());
1827 $this->page->setXMLContent($xml);
1828 $this->page->saveMobUsage($xml);
1829 $this->page->updateFromXML();
1835 include_once
"./Services/COPage/classes/class.ilPageObject.php";
1837 return $page->getXMLContent();
1851 if ($question_id < 1)
return "";
1852 $result = $ilDB->queryF(
"SELECT type_tag FROM qpl_questions, qpl_qst_type WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_qst_type.question_type_id",
1859 return $data[
"type_tag"];
1878 if ($question_id < 1)
return "";
1880 $result = $ilDB->queryF(
"SELECT title FROM qpl_questions WHERE qpl_questions.question_id = %s",
1887 return $data[
"title"];
1915 $result = $ilDB->queryF(
"SELECT * FROM qpl_sol_sug WHERE question_fi = %s",
1917 array($this->
getId())
1919 $this->suggested_solutions = array();
1922 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1926 $this->suggested_solutions[
$row[
"subquestion_index"]] = array(
1927 "type" => $row[
"type"],
1929 "internal_link" => $row[
"internal_link"],
1930 "import_id" => $row[
"import_id"]
1948 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
1962 $next_id = $ilDB->nextId(
'qpl_questions');
1963 $affectedRows = $ilDB->insert(
"qpl_questions", array(
1964 "question_id" => array(
"integer", $next_id),
1966 "obj_fi" => array(
"integer",
$obj_id),
1967 "title" => array(
"text", NULL),
1968 "description" => array(
"text", NULL),
1969 "author" => array(
"text", $this->
getAuthor()),
1970 "owner" => array(
"integer", $ilUser->getId()),
1971 "question_text" => array(
"clob", NULL),
1972 "points" => array(
"float", 0),
1973 "nr_of_tries" => array(
"integer", 1),
1974 "working_time" => array(
"text", $estw_time),
1975 "complete" => array(
"text", $complete),
1976 "created" => array(
"integer", time()),
1977 "original_id" => array(
"integer", NULL),
1978 "tstamp" => array(
"integer", $tstamp)
1980 $this->
setId($next_id);
1988 return $this->
getId();
1996 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
1999 include_once(
"./Services/RTE/classes/class.ilRTE.php");
2000 if ($this->
getId() == -1)
2003 $next_id = $ilDB->nextId(
'qpl_questions');
2004 $affectedRows = $ilDB->insert(
"qpl_questions", array(
2005 "question_id" => array(
"integer", $next_id),
2007 "obj_fi" => array(
"integer", $this->
getObjId()),
2008 "title" => array(
"text", $this->
getTitle()),
2009 "description" => array(
"text", $this->
getComment()),
2010 "author" => array(
"text", $this->
getAuthor()),
2011 "owner" => array(
"integer", $this->
getOwner()),
2014 "working_time" => array(
"text", $estw_time),
2016 "created" => array(
"integer", time()),
2018 "tstamp" => array(
"integer", time())
2020 $this->
setId($next_id);
2027 $affectedRows = $ilDB->update(
"qpl_questions", array(
2028 "obj_fi" => array(
"integer", $this->
getObjId()),
2029 "title" => array(
"text", $this->
getTitle()),
2030 "description" => array(
"text", $this->
getComment()),
2031 "author" => array(
"text", $this->
getAuthor()),
2035 "working_time" => array(
"text", $estw_time),
2036 "tstamp" => array(
"integer", time())
2038 "question_id" => array(
"integer", $this->
getId())
2053 $this->updateSuggestedSolutions();
2065 $affectedRows = $ilDB->manipulateF(
"UPDATE qpl_questions SET tstamp = %s, owner = %s, complete = %s WHERE question_id = %s",
2066 array(
'integer',
'integer',
'integer',
'text'),
2067 array(time(), ($this->
getOwner() <= 0) ? $this->ilias->account->id : $this->getOwner(), $complete, $this->
getId())
2071 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
2077 $ilDB->manipulateF(
"UPDATE qpl_questions SET tstamp = %s, original_id = %s WHERE question_id = %s",
2078 array(
'integer',
'integer',
'text'),
2079 array(time(), $newId, $this->
getId())
2086 protected function onDuplicate($originalParentId, $originalQuestionId, $duplicateParentId, $duplicateQuestionId)
2097 protected function onCopy($source_questionpool_id, $source_question_id)
2109 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_sol_sug WHERE question_fi = %s",
2111 array($this->
getId())
2114 include_once
"./Services/COPage/classes/class.ilInternalLink.php";
2116 $this->suggested_solutions = array();
2129 if (array_key_exists($subquestion_index, $this->suggested_solutions))
2131 return $this->suggested_solutions[$subquestion_index];
2149 if (array_key_exists($subquestion_index, $this->suggested_solutions))
2151 $title = $this->suggested_solutions[$subquestion_index][
"internal_link"];
2172 if (strcmp($solution_id,
"") != 0)
2177 $import_id = $solution_id;
2180 $this->suggested_solutions[$subquestion_index] = array(
2181 "internal_link" => $solution_id,
2182 "import_id" => $import_id
2194 foreach ($this->suggested_solutions as $index => $solution)
2196 if (strcmp($solution[
"type"],
"file") == 0)
2199 $filepath_original = str_replace(
2200 "/{$this->obj_id}/{$this->id}/solution",
2201 "/$parent_id/$question_id/solution",
2204 if (!file_exists($filepath))
2211 if (!copy($filepath_original .
$filename, $filepath . $filename))
2213 $ilLog->write(
"File could not be duplicated!!!!", $ilLog->ERROR);
2214 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
2229 $filepath_original = str_replace(
"/$this->id/solution",
"/$original_id/solution", $filepath);
2231 foreach ($this->suggested_solutions as $index => $solution)
2233 if (strcmp($solution[
"type"],
"file") == 0)
2235 if (!file_exists($filepath_original))
2242 if (!@copy($filepath .
$filename, $filepath_original . $filename))
2244 $ilLog->write(
"File could not be duplicated!!!!", $ilLog->ERROR);
2245 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
2256 foreach ($this->suggested_solutions as $index => $solution)
2258 if (strcmp($solution[
"type"],
"file") == 0)
2261 $filepath_original = str_replace(
"/$this->obj_id/$this->id/solution",
"/$source_questionpool_id/$source_question_id/solution", $filepath);
2262 if (!file_exists($filepath))
2269 if (!copy($filepath_original .
$filename, $filepath . $filename))
2271 $ilLog->write(
"File could not be copied!!!!", $ilLog->ERROR);
2272 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
2282 public function updateSuggestedSolutions(
$original_id =
"")
2287 include_once
"./Services/COPage/classes/class.ilInternalLink.php";
2288 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_sol_sug WHERE question_fi = %s",
2293 include_once(
"./Services/RTE/classes/class.ilRTE.php");
2294 foreach ($this->suggested_solutions as $index => $solution)
2296 $next_id = $ilDB->nextId(
'qpl_sol_sug');
2299 $ilDB->insert(
'qpl_sol_sug', array(
2300 'suggested_solution_id' => array(
'integer', $next_id ),
2301 'question_fi' => array(
'integer',
$id ),
2302 'type' => array(
'text', $solution[
'type'] ),
2304 'internal_link' => array(
'text', $solution[
'internal_link'] ),
2305 'import_id' => array(
'text', null ),
2306 'subquestion_index' => array(
'integer', $index ),
2307 'tstamp' => array(
'integer', time() ),
2311 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
2329 function saveSuggestedSolution($type, $solution_id =
"", $subquestion_index = 0, $value =
"")
2333 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_sol_sug WHERE question_fi = %s AND subquestion_index = %s",
2334 array(
"integer",
"integer"),
2341 $next_id = $ilDB->nextId(
'qpl_sol_sug');
2342 include_once(
"./Services/RTE/classes/class.ilRTE.php");
2344 $affectedRows = $ilDB->insert(
'qpl_sol_sug', array(
2345 'suggested_solution_id' => array(
'integer', $next_id ),
2346 'question_fi' => array(
'integer', $this->
getId() ),
2347 'type' => array(
'text', $type ),
2349 'internal_link' => array(
'text', $solution_id ),
2350 'import_id' => array(
'text', null ),
2351 'subquestion_index' => array(
'integer', $subquestion_index ),
2352 'tstamp' => array(
'integer', time() ),
2356 if ($affectedRows == 1)
2358 $this->suggested_solutions[
"subquestion_index"] = array(
2361 "internal_link" => $solution_id,
2370 if (preg_match(
"/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
2372 include_once
"./Services/COPage/classes/class.ilInternalLink.php";
2373 include_once
"./Modules/LearningModule/classes/class.ilLMObject.php";
2374 include_once
"./Modules/Glossary/classes/class.ilGlossaryTerm.php";
2375 switch ($matches[2])
2393 if (strcmp($resolved_link,
"") == 0)
2395 $resolved_link = $internal_link;
2400 $resolved_link = $internal_link;
2402 return $resolved_link;
2409 $result = $ilDB->queryF(
"SELECT * FROM qpl_sol_sug WHERE question_fi = %s",
2417 $internal_link =
$row[
"internal_link"];
2418 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
2420 if (strcmp($internal_link, $resolved_link) != 0)
2423 $affectedRows = $ilDB->manipulateF(
"UPDATE qpl_sol_sug SET internal_link = %s WHERE suggested_solution_id = %s",
2424 array(
'text',
'integer'),
2425 array($resolved_link,
$row[
"suggested_solution_id"])
2436 include_once
"./Services/COPage/classes/class.ilInternalLink.php";
2439 $result = $ilDB->queryF(
"SELECT * FROM qpl_sol_sug WHERE question_fi = %s",
2447 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/",
$row[
"internal_link"], $matches))
2460 "lm" =>
"LearningModule",
2461 "pg" =>
"PageObject",
2462 "st" =>
"StructureObject",
2463 "git" =>
"GlossaryItem",
2464 "mob" =>
"MediaObject"
2467 if (preg_match(
"/il__(\w+)_(\d+)/", $target, $matches))
2469 $type = $matches[1];
2471 include_once
"./Services/Utilities/classes/class.ilUtil.php";
2472 switch($linktypes[$matches[1]])
2474 case "LearningModule":
2475 $href =
"./goto.php?target=" . $type .
"_" .
$target_id;
2478 case "StructureObject":
2479 $href =
"./goto.php?target=" . $type .
"_" .
$target_id;
2481 case "GlossaryItem":
2482 $href =
"./goto.php?target=" . $type .
"_" .
$target_id;
2485 $href =
"./ilias.php?baseClass=ilLMPresentationGUI&obj_type=" . $linktypes[$type] .
"&cmd=media&ref_id=".$_GET[
"ref_id"].
"&mob_id=".
$target_id;
2502 $result = $ilDB->queryF(
"SELECT * FROM qpl_questions WHERE question_id = %s",
2509 if (
$row[
"original_id"] > 0)
2511 return $row[
"original_id"];
2515 return $row[
"question_id"];
2535 if ( !$originalObjId )
2553 $this->updateSuggestedSolutions($original);
2554 $this->syncFeedbackGeneric();
2570 $query =
"SELECT obj_fi FROM qpl_questions WHERE question_id = %s";
2572 $res = $ilDB->queryF(
$query, array(
'integer'), array((
int)$originalQuestionId));
2575 return $row[
'obj_fi'];
2593 if ($question_id < 1)
2598 $result = $ilDB->queryF(
"SELECT question_id FROM qpl_questions WHERE question_id = %s",
2623 if ($question_id < 1)
2628 $result = $ilDB->queryF(
"SELECT question_id FROM qpl_questions INNER JOIN object_data ON obj_fi = obj_id WHERE question_id = %s AND type = 'qpl'",
2656 if (strcmp($question_id,
"") != 0)
2659 if (!strlen($question_type))
return null;
2675 if (strcmp($this->points,
"") == 0)
2694 $this->points = $a_points;
2725 $result = $ilDB->queryF(
"SELECT MAX(pass) maxpass FROM tst_test_result WHERE active_fi = %s AND question_fi = %s",
2726 array(
'integer',
'integer'),
2727 array($active_id, $question_id)
2732 return $row[
"maxpass"];
2752 if (($question_id < 1) || ($user_id < 1))
2757 $result = $ilDB->queryF(
"SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
2764 $qpl_object_id =
$row[
"obj_fi"];
2765 include_once
"./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
2784 if ($question_id < 1)
return 0;
2785 $result = $ilDB->queryF(
"SELECT test_random_question_id FROM tst_test_rnd_qst WHERE question_fi = %s",
2817 include_once
"./Modules/Test/classes/class.ilObjTest.php";
2819 if ($count_system == 1)
2827 if ($score_cutting == 0)
2852 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
2855 $result = $ilDB->queryF(
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
2856 array(
'integer',
'integer',
'integer'),
2857 array($active_id, $question_id,
$pass)
2880 $res = $ilDB->queryF(
"SELECT DISTINCT(question_fi) FROM tst_test_result JOIN tst_active ".
2881 "ON (active_id = active_fi) ".
2882 "WHERE " . $ilDB->in(
'question_fi', $a_question_ids,
false,
'integer') .
2883 " AND user_fi = %s",
2887 return (
$res->numRows() == count($a_question_ids)) ?
true :
false;
2900 if (preg_match(
"/<[^>]*?>/", $a_text))
2918 include_once
"./Services/Utilities/classes/class.ilUtil.php";
2932 for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
2934 $material = $a_material->getMaterial($i);
2935 if (strcmp($material[
"type"],
"mattext") == 0)
2937 $result .= $material[
"material"]->getContent();
2939 if (strcmp($material[
"type"],
"matimage") == 0)
2941 $matimage = $material[
"material"];
2942 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
2945 if (!is_array(
$_SESSION[
"import_mob_xhtml"]))
$_SESSION[
"import_mob_xhtml"] = array();
2946 array_push(
$_SESSION[
"import_mob_xhtml"], array(
"mob" => $matimage->getLabel(),
"uri" => $matimage->getUri()));
2961 function addQTIMaterial(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE)
2963 include_once
"./Services/RTE/classes/class.ilRTE.php";
2964 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2966 $a_xml_writer->xmlStartTag(
"material");
2968 "texttype" =>
"text/plain"
2970 if ($this->
isHTML($a_material))
2972 $attrs[
"texttype"] =
"text/xhtml";
2978 foreach (
$mobs as $mob)
2980 $moblabel =
"il_" . IL_INST_ID .
"_mob_" . $mob;
2981 if (strpos($a_material,
"mm_$mob") !== FALSE)
2987 "label" => $moblabel,
2988 "uri" =>
"objects/" .
"il_" . IL_INST_ID .
"_mob_" . $mob .
"/" . $mob_obj->getTitle()
2991 $a_xml_writer->xmlElement(
"matimage", $imgattrs, NULL);
2995 if ($close_material_tag) $a_xml_writer->xmlEndTag(
"material");
3001 if (preg_match(
"/.*\.(png|jpg|gif|jpeg)$/i", $image_filename, $matches))
3003 $extension =
"." . $matches[1];
3005 $image_filename = md5($image_filename) . $extension;
3006 return $image_filename;
3032 $result = $ilDB->queryF(
"SELECT points FROM tst_test_result WHERE active_fi = %s AND question_fi = %s AND pass = %s",
3033 array(
'integer',
'integer',
'integer'),
3034 array($active_id, $question_id,
$pass)
3036 $manual = ($manualscoring) ? 1 : 0;
3040 $old_points =
$row[
"points"];
3041 $affectedRows = $ilDB->manipulateF(
"UPDATE tst_test_result SET points = %s, manual = %s, tstamp = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
3042 array(
'float',
'integer',
'integer',
'integer',
'integer',
'integer'),
3043 array(
$points, $manual, time(), $active_id, $question_id,
$pass)
3048 $next_id = $ilDB->nextId(
'tst_test_result');
3049 $affectedRows = $ilDB->manipulateF(
"INSERT INTO tst_test_result (test_result_id, active_fi, question_fi, points, pass, manual, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
3050 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer'),
3051 array($next_id, $active_id, $question_id,
$points,
$pass, $manual, time())
3056 include_once
"./Modules/Test/classes/class.ilObjTest.php";
3057 include_once
'./Modules/Course/classes/class.ilCourseObjectiveResult.php';
3060 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
3064 include_once
"./Modules/Test/classes/class.ilObjTestAccess.php";
3125 $result = $ilDB->queryF(
"SELECT question_type_id FROM qpl_qst_type WHERE type_tag = %s",
3132 return $row[
"question_type_id"];
3146 function saveFeedbackGeneric($correctness, $feedback)
3150 switch ($correctness)
3160 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_generic WHERE question_fi = %s AND correctness = %s",
3161 array(
'integer',
'text'),
3162 array($this->
getId(), $correctness)
3164 if (strlen($feedback))
3166 include_once(
"./Services/RTE/classes/class.ilRTE.php");
3167 $next_id = $ilDB->nextId(
'qpl_fb_generic');
3170 $ilDB->insert(
'qpl_fb_generic', array(
3171 'feedback_id' => array(
'integer', $next_id ),
3172 'question_fi' => array(
'integer', $this->
getId() ),
3173 'correctness' => array(
'text', $correctness ),
3175 'tstamp' => array(
'integer', time() ),
3196 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_generic WHERE question_fi = %s AND correctness = %s",
3197 array(
'integer',
'text'),
3198 array($this->
getId(), $correctness)
3203 include_once(
"./Services/RTE/classes/class.ilRTE.php");
3220 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_generic WHERE question_fi = %s",
3228 $next_id = $ilDB->nextId(
'qpl_fb_generic');
3231 $ilDB->insert(
'qpl_fb_generic', array(
3232 'feedback_id' => array(
'integer', $next_id ),
3233 'question_fi' => array(
'integer', $this->
getId() ),
3234 'correctness' => array(
'text',
$row[
"correctness"] ),
3235 'feedback' => array(
'clob',
$row[
"feedback"] ),
3236 'tstamp' => array(
'integer', time() ),
3243 function syncFeedbackGeneric()
3250 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_generic WHERE question_fi = %s",
3252 array($this->original_id)
3256 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_generic WHERE question_fi = %s",
3258 array($this->
getId())
3266 $next_id = $ilDB->nextId(
'qpl_fb_generic');
3268 $ilDB->insert(
'qpl_fb_generic', array(
3269 'feedback_id' => array(
'integer', $next_id ),
3270 'question_fi' => array(
'integer', $this->original_id ),
3271 'correctness' => array(
'text',
$row[
"correctness"] ),
3272 'feedback' => array(
'clob',
$row[
"feedback"] ),
3273 'tstamp' => array(
'integer', time() ),
3280 public function syncHints()
3285 $ilDB->manipulateF(
"DELETE FROM qpl_hints WHERE qht_question_fi = %s",
3287 array($this->original_id)
3291 $result = $ilDB->queryF(
"SELECT * FROM qpl_hints WHERE qht_question_fi = %s",
3293 array($this->
getId())
3301 $next_id = $ilDB->nextId(
'qpl_hints');
3303 $ilDB->insert(
'qpl_hints', array(
3304 'qht_hint_id' => array(
'integer', $next_id),
3305 'qht_question_fi' => array(
'integer', $this->original_id),
3306 'qht_hint_index' => array(
'integer',
$row[
"qht_hint_index"]),
3307 'qht_hint_points' => array(
'integer',
$row[
"qht_hint_points"]),
3308 'qht_hint_text' => array(
'text',
$row[
"qht_hint_text"]),
3330 foreach ($this->suggested_solutions as $solution_array)
3332 $collected .= $solution_array[
"value"];
3349 include_once(
"./Services/RTE/classes/class.ilRTE.php");
3362 $result = $ilDB->queryF(
"SELECT question_id FROM qpl_questions WHERE original_id = %s",
3364 array($this->
getId())
3366 $instances = array();
3370 array_push($ids,
$row[
"question_id"]);
3372 foreach ($ids as $question_id)
3375 $result = $ilDB->queryF(
"SELECT tst_tests.obj_fi FROM tst_tests, tst_test_question WHERE tst_test_question.question_fi = %s AND tst_test_question.test_fi = tst_tests.test_id",
3384 $result = $ilDB->queryF(
"SELECT tst_tests.obj_fi FROM tst_tests, tst_test_rnd_qst, tst_active WHERE tst_test_rnd_qst.active_fi = tst_active.active_id AND tst_test_rnd_qst.question_fi = %s AND tst_tests.test_id = tst_active.test_fi",
3393 include_once
"./Modules/Test/classes/class.ilObjTest.php";
3394 foreach ($instances as $key => $value)
3403 include_once
"./Modules/Test/classes/class.ilObjAssessmentFolder.php";
3406 if (in_array($questiontype, $scoring))
3426 $result = $ilDB->queryF(
"SELECT * FROM tst_active WHERE active_id = %s",
3433 return array(
"user_id" =>
$row[
"user_fi"],
"test_id" =>
$row[
"test_fi"]);
3450 $type = $question_type;
3451 if ($gui) $type .=
"GUI";
3452 if (file_exists(
"./Modules/TestQuestionPool/classes/class.".$type.
".php"))
3454 include_once
"./Modules/TestQuestionPool/classes/class.".$type.
".php";
3458 global $ilPluginAdmin;
3459 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"TestQuestionPool",
"qst");
3460 foreach ($pl_names as $pl_name)
3463 if (strcmp($pl->getQuestionType(), $question_type) == 0)
3465 $pl->includeClass(
"class.".$type.
".php");
3479 if (file_exists(
"./Modules/TestQuestionPool/classes/class.".$type_tag.
".php"))
3482 return $lng->txt($type_tag);
3486 global $ilPluginAdmin;
3487 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_MODULE,
"TestQuestionPool",
"qst");
3488 foreach ($pl_names as $pl_name)
3491 if (strcmp($pl->getQuestionType(), $type_tag) == 0)
3493 return $pl->getQuestionTypeTranslation();
3509 if (strcmp($question_id,
"") != 0)
3512 $question_type_gui = $question_type .
"GUI";
3514 $question_gui =
new $question_type_gui();
3515 $question_gui->object->loadFromDb($question_id);
3516 return $question_gui;
3545 return $this->
getId();
3565 case "est_working_time":
3589 case "suggested_solutions":
3596 if (array_key_exists($value, $this->arrData))
3598 return $this->arrData[$value];
3616 $this->
setId($value);
3636 case "est_working_time":
3637 if (is_array($value))
3658 $this->page =& $value;
3661 $this->arrData[$key] = $value;
3673 $this->nr_of_tries = $a_nr_of_tries;
3678 $this->export_image_path = (string)$a_path;
3685 if ($question_id < 1)
3690 $result = $ilDB->queryF(
"SELECT question_fi FROM tst_test_question WHERE question_fi = %s AND test_fi = %s",
3691 array(
'integer',
'integer'),
3712 include_once(
"./Services/RTE/classes/class.ilRTE.php");
3714 $a_q = str_replace(
"</li><br />",
"</li>", $a_q);
3715 $a_q = str_replace(
"</li><br>",
"</li>", $a_q);
3720 $a_q = str_replace(
'{',
'{', $a_q);
3721 $a_q = str_replace(
'}',
'}', $a_q);
3728 require_once
'Modules/TestQuestionPool/classes/class.ilAssQuestionHintList.php';
3741 'DELETE FROM qpl_fb_generic WHERE question_fi = %s',
3825 SELECT count(active_fi) cnt
3829 WHERE active_fi = %s
3830 AND question_fi = %s
3834 $res = $ilDB->queryF(
3835 $query, array(
'integer',
'integer',
'integer'),
3836 array($activeId, $questionId,
$pass)
3841 $solutionRecordsExist = (
3842 0 < (int)
$row[
'cnt'] ?
true :
false
3845 return $solutionRecordsExist;
3853 require_once
'Services/Html/classes/class.ilHtmlPurifierFactory.php';