24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
113 $this->start_tag =
"[gap]";
114 $this->end_tag =
"[/gap]";
116 $this->gaps = array();
118 $this->fixedTextLength =
"";
119 $this->identical_scoring = 1;
149 $text = preg_replace(
"/\[gap[^\]]*?\]/",
"[gap]", $text);
150 $text = preg_replace(
"/<gap([^>]*?)>/",
"[gap]", $text);
151 $text = str_replace(
"</gap>",
"[/gap]", $text);
165 if ($question_id < 1)
return;
171 $result = $ilDB->execute($statement,
179 $this->
setId($question_id);
191 include_once(
"./Services/RTE/classes/class.ilRTE.php");
197 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
198 include_once
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
199 $statement = $ilDB->prepare(
"SELECT * FROM qpl_answer_cloze WHERE question_fi = ? ORDER BY gap_id, aorder ASC",
204 $result = $ilDB->execute($statement,
211 $this->gaps = array();
214 switch (
$data[
"cloze_type"])
217 if (!array_key_exists(
$data[
"gap_id"], $this->gaps))
226 $this->gaps[
$data[
"gap_id"]]->addItem($answer);
229 if (!array_key_exists(
$data[
"gap_id"], $this->gaps))
232 $this->gaps[$data[
"gap_id"]]->setShuffle($data[
"shuffle"]);
239 $this->gaps[
$data[
"gap_id"]]->addItem($answer);
242 if (!array_key_exists(
$data[
"gap_id"], $this->gaps))
251 $answer->setLowerBound(
$data[
"lowerlimit"]);
252 $answer->setUpperBound(
$data[
"upperlimit"]);
253 $this->gaps[
$data[
"gap_id"]]->addItem($answer);
274 include_once
"./Services/Math/classes/class.EvalMath.php";
276 $eval->suppress_errors = TRUE;
279 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
282 include_once(
"./Services/RTE/classes/class.ilRTE.php");
286 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
287 $statement = $ilDB->prepareManip(
"INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, points, author, " .
288 "owner, question_text, working_time, complete, created, original_id, TIMESTAMP) " .
289 "VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)",
319 $affectedRows = $ilDB->execute($statement,
$data);
321 $this->
setId($ilDB->getLastInsertId());
322 $statement = $ilDB->prepareManip(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, textgap_rating, identical_scoring, fixed_textlen) VALUES (?, ?, ?, ?)",
336 $affectedRows = $ilDB->execute($statement,
$data);
347 $statement = $ilDB->prepareManip(
"UPDATE qpl_questions SET obj_fi = ?, title = ?, comment = ?, points = ?, author = ?, " .
348 "question_text = ?, working_time = ?, complete = ? WHERE question_id = ?",
372 $affectedRows = $ilDB->execute($statement,
$data);
374 $statement = $ilDB->prepareManip(
"UPDATE " . $this->
getAdditionalTableName() .
" SET textgap_rating = ?, fixed_textlen = ?, identical_scoring = ? WHERE question_fi = ?",
388 $affectedRows = $ilDB->execute($statement,
$data);
391 $statement = $ilDB->prepareManip(
"DELETE FROM qpl_answer_cloze WHERE question_fi = ?",
399 $affectedRows = $ilDB->execute($statement,
$data);
401 foreach ($this->gaps as $key => $gap)
403 foreach ($gap->getItems() as $item)
406 switch ($gap->getType())
409 $statement = $ilDB->prepareManip(
"INSERT INTO qpl_answer_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type) VALUES (NULL, ?, ?, ?, ?, ?, ?)",
422 strlen($item->getAnswertext()) ? $item->getAnswertext() :
"",
429 $statement = $ilDB->prepareManip(
"INSERT INTO qpl_answer_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, shuffle) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)",
443 strlen($item->getAnswertext()) ? $item->getAnswertext() :
"",
447 ($gap->getShuffle()) ?
"1" :
"0"
451 $statement = $ilDB->prepareManip(
"INSERT INTO qpl_answer_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, lowerlimit, upperlimit) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)",
466 strlen($item->getAnswertext()) ? $item->getAnswertext() :
"",
470 ($eval->e($item->getLowerBound() !== FALSE) && strlen($item->getLowerBound()) > 0) ? $item->getLowerBound() :
"0",
471 ($eval->e($item->getUpperBound() !== FALSE) && strlen($item->getUpperBound()) > 0) ? $item->getUpperBound() :
"0"
475 $affectedRows = $ilDB->execute($statement,
$data);
501 $this->gaps = array();
515 $this->gaps = array();
517 $this->question = $cloze_text;
589 include_once
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
590 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
591 $search_pattern =
"|\[gap\](.*?)\[/gap\]|i";
592 preg_match_all($search_pattern, $this->
getClozeText(), $found);
593 $this->gaps = array();
594 if (count($found[0]))
596 foreach ($found[1] as $gap_index => $answers)
600 $textparams = preg_split(
"/(?<!\\\\),/", $answers);
601 foreach ($textparams as $key => $value)
604 $gap->addItem($answer);
606 $this->gaps[$gap_index] = $gap;
618 if (array_key_exists($gap_index, $this->gaps))
620 $this->gaps[$gap_index]->setType($gap_type);
635 if (array_key_exists($gap_index, $this->gaps))
637 $this->gaps[$gap_index]->setShuffle(
$shuffle);
649 foreach ($this->gaps as $gap_index => $gap)
651 $this->gaps[$gap_index]->clearItems();
664 if (is_array($this->gaps))
666 return count($this->gaps);
686 if (array_key_exists($gap_index, $this->gaps))
691 $answer = str_replace(
",",
".", $answer);
693 $this->gaps[$gap_index]->addItem(
new assAnswerCloze($answer, 0, $order));
707 if (array_key_exists($gap_index, $this->gaps))
709 return $this->gaps[$gap_index];
729 if (array_key_exists($gap_index, $this->gaps))
731 $this->gaps[$gap_index]->setItemPoints($order,
$points);
745 if (array_key_exists($gap_index, $this->gaps))
747 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
751 $this->gaps[$gap_index]->getItemCount()
753 $this->gaps[$gap_index]->addItem($answer);
767 $this->gaps[$index] = $gap;
782 if (array_key_exists($gap_index, $this->gaps))
784 $this->gaps[$gap_index]->setItemLowerBound($order, $bound);
800 if (array_key_exists($gap_index, $this->gaps))
802 $this->gaps[$gap_index]->setItemUpperBound($order, $bound);
815 foreach ($this->gaps as $gap_index => $gap)
820 foreach ($gap->getItems() as $item)
822 if ($item->getPoints() > $gap_max_points)
824 $gap_max_points = $item->getPoints();
832 foreach ($gap->getItems() as $item)
834 if ($item->getPoints() > $srpoints)
836 $srpoints = $item->getPoints();
844 foreach ($gap->getItems() as $item)
846 if ($item->getPoints() > $numpoints)
848 $numpoints = $item->getPoints();
870 $this_id = $this->
getId();
872 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
897 $clone->copyPageOfQuestion($this_id);
899 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
901 $clone->duplicateFeedbackGeneric($this_id);
903 return $clone->getId();
913 if ($this->
getId() <= 0)
919 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
922 $source_questionpool = $this->
getObjId();
923 $clone->setObjId($target_questionpool);
937 return $clone->getId();
948 foreach ($this->
getGaps() as $gap_index => $gap)
951 foreach ($gap->getItemsRaw() as $item)
953 array_push($answers, str_replace(
",",
"\\,", $item->getAnswerText()));
955 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/",
"[_gap]" .
ilUtil::prepareFormOutput(join(
",", $answers)) .
"[/_gap]", $output, 1);
957 $output = str_replace(
"_gap]",
"gap]", $output);
958 $this->question = $output;
972 if (array_key_exists($gap_index, $this->gaps))
974 if ($this->gaps[$gap_index]->getItemCount() == 1)
982 $this->gaps[$gap_index]->deleteItem($answer_index);
998 if (array_key_exists($gap_index, $this->gaps))
1001 foreach ($this->
getGaps() as $replace_gap_index => $gap)
1004 foreach ($gap->getItemsRaw() as $item)
1006 array_push($answers, str_replace(
",",
"\\,", $item->getAnswerText()));
1008 if ($replace_gap_index == $gap_index)
1010 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/",
"", $output, 1);
1014 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/",
"[_gap]" . join(
",", $answers) .
"[/_gap]", $output, 1);
1017 $output = str_replace(
"_gap]",
"gap]", $output);
1018 $this->question = $output;
1019 unset($this->gaps[$gap_index]);
1020 $this->gaps = array_values($this->gaps);
1035 include_once
"./Services/Utilities/classes/class.ilStr.php";
1044 if (strcmp($a_original, $a_entered) == 0)
$result = $max_points;
1047 if (levenshtein($a_original, $a_entered) <= 1)
$result = $max_points;
1050 if (levenshtein($a_original, $a_entered) <= 2)
$result = $max_points;
1053 if (levenshtein($a_original, $a_entered) <= 3)
$result = $max_points;
1056 if (levenshtein($a_original, $a_entered) <= 4)
$result = $max_points;
1059 if (levenshtein($a_original, $a_entered) <= 5)
$result = $max_points;
1076 include_once
"./Services/Math/classes/class.EvalMath.php";
1078 $eval->suppress_errors = TRUE;
1080 if (($eval->e($lowerBound) !== FALSE) && ($eval->e($upperBound) !== FALSE))
1082 if (($eval->e($a_entered) >= $eval->e($lowerBound)) && ($eval->e($a_entered) <= $eval->e($upperBound)))
$result = $max_points;
1084 else if ($eval->e($lowerBound) !== FALSE)
1086 if (($eval->e($a_entered) >= $eval->e($lowerBound)) && ($eval->e($a_entered) <= $eval->e($a_original)))
$result = $max_points;
1088 else if ($eval->e($upperBound) !== FALSE)
1090 if (($eval->e($a_entered) >= $eval->e($a_original)) && ($eval->e($a_entered) <= $eval->e($upperBound)))
$result = $max_points;
1094 if ($eval->e($a_entered) == $eval->e($a_original))
$result = $max_points;
1112 $found_value1 = array();
1113 $found_value2 = array();
1114 $detailed = array();
1119 $statement = $ilDB->prepare(
"SELECT * FROM tst_solutions WHERE active_fi = ? AND question_fi = ? AND pass = ?",
1126 $result = $ilDB->execute($statement,
1133 $user_result = array();
1136 if (strcmp(
$data[
"value2"],
"") != 0)
1138 $user_result[
$data[
"value1"]] = array(
1139 "gap_id" => $data[
"value1"],
1140 "value" => $data[
"value2"]
1146 $solution_values_text = array();
1147 $solution_values_select = array();
1148 $solution_values_numeric = array();
1149 foreach ($user_result as $gap_id => $value)
1151 if (array_key_exists($gap_id, $this->gaps))
1153 switch ($this->gaps[$gap_id]->getType())
1157 for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++)
1159 $answer = $this->gaps[$gap_id]->getItem($order);
1160 $gotpoints = $this->
getTextgapPoints($answer->getAnswertext(), $value[
"value"], $answer->getPoints());
1161 if ($gotpoints > $gappoints) $gappoints = $gotpoints;
1166 if ((in_array($value[
"value"], $solution_values_text)) && ($gappoints > 0))
1172 $detailed[$gap_id] = array(
"points" =>$gappoints,
"best" => ($this->
getMaximumGapPoints($gap_id) == $gappoints) ? TRUE : FALSE,
"positive" => ($gappoints > 0) ? TRUE : FALSE);
1173 array_push($solution_values_text, $value[
"value"]);
1177 for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++)
1179 $answer = $this->gaps[$gap_id]->getItem($order);
1180 $gotpoints = $this->
getNumericgapPoints($answer->getAnswertext(), $value[
"value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
1181 if ($gotpoints > $gappoints) $gappoints = $gotpoints;
1186 include_once
"./Services/Math/classes/class.EvalMath.php";
1188 $eval->suppress_errors = TRUE;
1189 $found_value = FALSE;
1190 foreach ($solution_values_numeric as $solval)
1192 if ($eval->e($solval) == $eval->e($value[
"value"]))
1194 $found_value = TRUE;
1197 if ($found_value && ($gappoints > 0))
1203 $detailed[$gap_id] = array(
"points" =>$gappoints,
"best" => ($this->
getMaximumGapPoints($gap_id) == $gappoints) ? TRUE : FALSE,
"positive" => ($gappoints > 0) ? TRUE : FALSE);
1204 array_push($solution_values_numeric, $value[
"value"]);
1207 if ($value[
"value"] >= 0)
1209 for ($order = 0; $order < $this->gaps[$gap_id]->getItemCount(); $order++)
1211 $answer = $this->gaps[$gap_id]->getItem($order);
1212 if ($value[
"value"] == $answer->getOrder())
1214 $answerpoints = $answer->getPoints();
1218 if ((in_array($answer->getAnswertext(), $solution_values_select)) && ($answerpoints > 0))
1224 $detailed[$gap_id] = array(
"points" =>$answerpoints,
"best" => ($this->
getMaximumGapPoints($gap_id) == $answerpoints) ? TRUE : FALSE,
"positive" => ($answerpoints > 0) ? TRUE : FALSE);
1225 array_push($solution_values_select, $answer->getAnswertext());
1258 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1262 $statement = $ilDB->prepareManip(
"DELETE FROM tst_solutions WHERE active_fi = ? AND question_fi = ? AND pass = ?",
1274 $affectedRows = $ilDB->execute($statement,
$data);
1276 $entered_values = 0;
1277 foreach ($_POST as $key => $value)
1279 if (preg_match(
"/^gap_(\d+)/", $key, $matches))
1284 $gap = $this->
getGap($matches[1]);
1285 if (is_object($gap))
1287 if (!(($gap->getType() ==
CLOZE_SELECT) && ($value == -1)))
1291 $value = str_replace(
",",
".", $value);
1293 $statement = $ilDB->prepareManip(
"INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, ?, ?, ?, ?, ?, NULL)",
1309 $affectedRows = $ilDB->execute($statement,
$data);
1316 if ($entered_values)
1318 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1326 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
1344 return "assClozeTest";
1368 switch ($a_textgap_rating)
1377 $this->textgap_rating = $a_textgap_rating;
1394 return ($this->identical_scoring) ? 1 : 0;
1406 $this->identical_scoring = ($a_identical_scoring) ? 1 : 0;
1417 return "qpl_question_cloze";
1428 return "qpl_answer_cloze";
1439 $this->fixedTextLength = $a_text_len;
1464 if (array_key_exists($gap_index, $this->gaps))
1466 $gap =& $this->gaps[$gap_index];
1467 foreach ($gap->getItems() as $answer)
1469 if ($answer->getPoints() > $gap_max_points)
1471 $gap_max_points = $answer->getPoints();
1502 include_once (
"./classes/class.ilExcelUtils.php");
1507 foreach ($this->
getGaps() as $gap_index => $gap)
1511 foreach ($solution as $solutionvalue)
1513 if ($gap_index == $solutionvalue[
"value1"])
1515 switch ($gap->getType())
1518 $worksheet->writeString($startrow + $i, 1, $gap->getItem($solutionvalue[
"value2"])->getAnswertext());
1522 $worksheet->writeString($startrow + $i, 1, $solutionvalue[
"value2"]);
1529 return $startrow + $i + 1;