5 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
6 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
47 $this->errortext =
"";
48 $this->textsize = 100.0;
49 $this->errordata = array();
59 if (strlen($this->title) and ($this->author) and ($this->question) and ($this->
getMaximumPoints() > 0))
80 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
85 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, errortext, textsize, points_wrong) VALUES (%s, %s, %s, %s)",
86 array(
"integer",
"text",
"float",
"float"),
95 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_errortext WHERE question_fi = %s",
101 foreach ($this->errordata as $object)
103 $next_id = $ilDB->nextId(
'qpl_a_errortext');
104 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_errortext (answer_id, question_fi, text_wrong, text_correct, points, sequence) VALUES (%s, %s, %s, %s, %s, %s)",
105 array(
'integer',
'integer',
'text',
'text',
'float',
'integer'),
110 $object->text_correct,
137 $this->
setId($question_id);
146 include_once(
"./Services/RTE/classes/class.ilRTE.php");
154 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_errortext WHERE question_fi = %s ORDER BY sequence ASC",
158 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
181 $this_id = $this->
getId();
183 if( (
int)$testObjId > 0 )
189 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
193 if( (
int)$testObjId > 0 )
195 $clone->setObjId($testObjId);
221 $clone->copyPageOfQuestion($this_id);
223 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
225 $clone->duplicateGenericFeedback($this_id);
227 $clone->duplicateSpecificFeedback($this_id);
229 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
245 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
248 $source_questionpool = $this->
getObjId();
249 $clone->setObjId($target_questionpool);
278 foreach ($this->errordata as $object)
280 if ($object->points > 0) $maxpoints += $object->points;
299 throw new ilTestException(
'return details not implemented for '.__METHOD__);
304 $found_values = array();
309 $result = $ilDB->queryF(
"SELECT value1 FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
310 array(
'integer',
'integer',
'integer'),
315 array_push($found_values,
$row[
'value1']);
331 include_once
"./Modules/Test/classes/class.ilObjTest.php";
335 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s AND value1 = %s",
336 array(
'integer',
'integer',
'integer',
'text'),
337 array($active_id, $this->
getId(),
$pass, $position)
339 if ($affectedRows == 0)
341 $next_id = $ilDB->nextId(
'tst_solutions');
342 $affectedRows = $ilDB->insert(
"tst_solutions", array(
343 "solution_id" => array(
"integer", $next_id),
344 "active_fi" => array(
"integer", $active_id),
345 "question_fi" => array(
"integer", $this->
getId()),
346 "value1" => array(
"clob", $position),
347 "value2" => array(
"clob", null),
348 "pass" => array(
"integer",
$pass),
349 "tstamp" => array(
"integer", time())
352 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
375 include_once
"./Modules/Test/classes/class.ilObjTest.php";
379 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
380 array(
'integer',
'integer',
'integer'),
384 $entered_values =
false;
387 $selected = split(
",",
$_POST[
"qst_" . $this->
getId()]);
388 foreach ($selected as $position)
390 $next_id = $ilDB->nextId(
'tst_solutions');
391 $affectedRows = $ilDB->insert(
"tst_solutions", array(
392 "solution_id" => array(
"integer", $next_id),
393 "active_fi" => array(
"integer", $active_id),
394 "question_fi" => array(
"integer", $this->
getId()),
395 "value1" => array(
"clob", $position),
396 "value2" => array(
"clob", null),
397 "pass" => array(
"integer",
$pass),
398 "tstamp" => array(
"integer", time())
401 $entered_values =
true;
405 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
413 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
443 return "assErrorText";
453 return "qpl_qst_errortext";
463 return "qpl_a_errortext";
489 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
494 $selections = array();
496 if (is_array($solutions))
498 foreach ($solutions as $solution)
500 array_push($selections, $solution[
'value1']);
502 $errortext_value = join(
",", $selections);
509 return $startrow + $i + 1;
524 public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
526 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assErrorTextImport.php";
528 $import->fromXML($item, $questionpool_id, $tst_id, $tst_object, $question_counter, $import_mapping);
537 public function toXML($a_include_header =
true, $a_include_binary =
true, $a_shuffle =
false, $test_output =
false, $force_image_references =
false)
539 include_once
"./Modules/TestQuestionPool/classes/export/qti12/class.assErrorTextExport.php";
541 return $export->toXML($a_include_header, $a_include_binary, $a_shuffle, $test_output, $force_image_references);
551 $user_solution = array();
552 return $user_solution;
557 if (strlen($a_text) == 0) $a_text = $this->
getErrorText();
558 preg_match_all(
"/#([^\s]+)/is", $a_text, $matches);
559 if (is_array($matches[1]))
571 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
573 $this->errordata = array();
574 foreach ($a_data as $error)
578 foreach ($temp as $object)
580 if (strcmp($object->text_wrong, $error) == 0)
582 $text_correct = $object->text_correct;
595 include_once
"./Services/Utilities/classes/class.ilStr.php";
596 if (!is_array($selections)) $selections = array();
597 $textarray = preg_split(
"/[\n\r]+/", $this->
getErrorText());
598 foreach ($textarray as $textidx => $text)
600 $items = preg_split(
"/\s+/", $text);
601 foreach ($items as $idx => $item)
603 if (strpos($item,
'#') === 0)
605 $item = ilStr::substr($item, 1, ilStr::strlen($item));
606 if ($correct_solution)
608 $errorobject = $this->errordata[$errorcounter];
609 if (is_object($errorobject))
611 $item = strlen($errorobject->text_correct) ? $errorobject->text_correct :
' ';
618 if (in_array($counter, $selections))
620 $class =
' class="sel"';
621 if ($graphicalOutput)
625 $img =
' <img src="' .
ilUtil::getImagePath(
"icon_ok.png") .
'" alt="' . $this->lng->txt(
"answer_is_right") .
'" title="' . $this->lng->txt(
"answer_is_right") .
'" /> ';
629 $img =
' <img src="' .
ilUtil::getImagePath(
"icon_not_ok.png") .
'" alt="' . $this->lng->txt(
"answer_is_wrong") .
'" title="' . $this->lng->txt(
"answer_is_wrong") .
'" /> ';
633 $items[$idx] =
'<a' . $class .
' href="#HREF' . $idx .
'" onclick="javascript: return false;">' . ($item ==
' ' ? $item :
ilUtil::prepareFormOutput($item)) .
'</a>' .
$img;
636 $textarray[$textidx] =
'<p>' . join($items,
" ") .
'</p>';
638 return join($textarray,
"\n");
645 include_once
"./Services/Utilities/classes/class.ilStr.php";
646 if (!is_array($selections)) $selections = array();
647 $textarray = preg_split(
"/[\n\r]+/", $this->
getErrorText());
648 foreach ($textarray as $textidx => $text)
650 $items = preg_split(
"/\s+/", $text);
651 foreach ($items as $idx => $item)
653 if (strpos($item,
'#') === 0)
655 $item = ilStr::substr($item, 1, ilStr::strlen($item));
656 if ($correct_solution)
658 $errorobject = $this->errordata[$errorcounter];
659 if (is_object($errorobject))
661 $item = $errorobject->text_correct;
667 if (in_array($counter, $selections))
672 if (in_array($counter, $selections))
676 $items[$idx] = $word;
679 $textarray[$textidx] = join($items,
" ");
681 return join($textarray,
"\n");
689 $textarray = preg_split(
"/[\n\r]+/", $this->
getErrorText());
690 foreach ($textarray as $textidx => $text)
692 $items = preg_split(
"/\s+/", $text);
693 foreach ($items as $word)
696 $isErrorItem =
false;
697 if (strpos($word,
'#') === 0)
699 $errorobject = $this->errordata[$errorcounter];
700 if (is_object($errorobject))
702 $points = $errorobject->points;
707 $words[$counter] = array(
"word" => $word,
"points" =>
$points,
"isError" => $isErrorItem);
711 $selections = array();
712 foreach ($words as $idx => $word)
714 if (!$withPositivePointsOnly && $word[
'isError'] || $withPositivePointsOnly && $word[
'points'] > 0)
716 array_push($selections, $idx);
727 $textarray = preg_split(
"/[\n\r]+/", $this->
getErrorText());
728 foreach ($textarray as $textidx => $text)
730 $items = preg_split(
"/\s+/", $text);
731 foreach ($items as $word)
734 if (strpos($word,
'#') === 0)
736 $errorobject = $this->errordata[$errorcounter];
737 if (is_object($errorobject))
739 $points = $errorobject->points;
743 $words[$counter] = array(
"word" => $word,
"points" =>
$points);
748 foreach ($positions as $position)
750 $total += $words[$position][
'points'];
760 $this->errordata = array();
765 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
796 $this->errortext = $a_value;
817 if($a_value === null)
821 $this->textsize = $a_value;
841 $this->points_wrong = $a_value;
894 include_once(
"./Services/RTE/classes/class.ilRTE.php");
911 array_push($answers, array(
912 "answertext_wrong" => (
string) $answer_obj->text_wrong,
913 "answertext_correct" => (
string) $answer_obj->text_correct,
914 "points" => (
float)$answer_obj->points,
915 "order" => (
int)$idx+1
918 $result[
'correct_answers'] = $answers;
921 $textarray = preg_split(
"/[\n\r]+/", $this->
getErrorText());
922 foreach ($textarray as $textidx => $text)
924 $items = preg_split(
"/\s+/", trim($text));
925 foreach ($items as $idx => $item)
927 if(substr($item, 0, 1) ==
"#")
929 $item = substr($item, 1);
932 foreach(
$result[
"correct_answers"] as $aidx => $answer)
934 if($answer[
"answertext_wrong"] == $item && !$answer[
"pos"])
936 $result[
"correct_answers"][$aidx][
"pos"] = $textidx.
"_".($idx+1);
941 array_push($answers, array(
943 "order" => $textidx.
"_".($idx+1)
946 if($textidx !=
sizeof($textarray)-1)
948 array_push($answers, array(
949 "answertext" =>
"###",
950 "order" => $textidx.
"_".($idx+2)
969 function saveFeedbackSingleAnswer($answer_index, $feedback)
973 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_errortext WHERE question_fi = %s AND answer = %s",
974 array(
'integer',
'integer'),
975 array($this->
getId(), $answer_index)
977 if (strlen($feedback))
979 include_once(
"./Services/RTE/classes/class.ilRTE.php");
980 $next_id = $ilDB->nextId(
'qpl_fb_errortext');
983 $ilDB->insert(
'qpl_fb_errortext', array(
984 'feedback_id' => array(
'integer', $next_id ),
985 'question_fi' => array(
'integer', $this->
getId() ),
986 'answer' => array(
'integer', $answer_index ),
988 'tstamp' => array(
'integer', time() ),
1006 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_errortext WHERE question_fi = %s AND answer = %s",
1007 array(
'integer',
'integer'),
1008 array($this->
getId(), $answer_index)
1013 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1030 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_errortext WHERE question_fi = %s",
1038 $next_id = $ilDB->nextId(
'qpl_fb_errortext');
1040 $ilDB->insert(
'qpl_fb_errortext', array(
1041 'feedback_id' => array(
'integer', $next_id ),
1042 'question_fi' => array(
'integer', $this->
getId() ),
1043 'answer' => array(
'integer',
$row[
"answer"] ),
1044 'feedback' => array(
'clob',
$row[
"feedback"] ),
1045 'tstamp' => array(
'integer', time() ),
1057 FROM qpl_fb_errortext
1058 WHERE question_fi = %s',