23 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
24 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
88 $this->thumb_size = 150;
89 $this->answers = array();
101 if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
127 $result = $ilDB->queryF(
"SELECT thumb_size FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
129 array($this->
getId())
131 if ($result->numRows() == 1)
133 $data = $ilDB->fetchAssoc($result);
134 $oldthumbsize =
$data[
'thumb_size'];
137 if (!$this->isSingleline)
143 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
145 array($this->
getId())
148 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
149 array(
"integer",
"text",
"text",
"integer"),
153 ($this->isSingleline) ?
"0" :
"1",
158 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
160 array($this->
getId())
163 foreach ($this->answers as $key => $value)
165 $answer_obj = $this->answers[$key];
166 $next_id = $ilDB->nextId(
'qpl_a_mc');
167 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_mc (answer_id, question_fi, answertext, points, points_unchecked, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
168 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer'),
173 $answer_obj->getPoints(),
174 $answer_obj->getPointsUnchecked(),
175 $answer_obj->getOrder(),
176 $answer_obj->getImage(),
196 if (strlen($answer->getImage()))
217 switch (strtoupper($path_info[
'extension']))
248 if ($result->numRows() == 1)
250 $data = $ilDB->fetchAssoc($result);
251 $this->
setId($question_id);
260 include_once(
"./Services/RTE/classes/class.ilRTE.php");
266 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
267 $this->lastChange =
$data[
'tstamp'];
270 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
274 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
275 if ($result->numRows() > 0)
277 while (
$data = $ilDB->fetchAssoc($result))
280 if (!@file_exists($imagefilename))
282 $data[
"imagefile"] =
"";
284 include_once(
"./Services/RTE/classes/class.ilRTE.php");
306 $this_id = $this->
getId();
308 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
335 $clone->copyPageOfQuestion($this_id);
337 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
339 $clone->duplicateImages($this_id);
341 $clone->duplicateFeedbackGeneric($this_id);
343 $clone->duplicateFeedbackAnswer($this_id);
345 $clone->onDuplicate($this_id);
364 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
367 $source_questionpool = $this->
getObjId();
368 $clone->setObjId($target_questionpool);
386 $clone->onDuplicate($source_questionpool, $this->
getId());
432 $points_unchecked = 0.0,
437 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
438 if (array_key_exists($order, $this->answers))
442 $newchoices = array();
443 for ($i = 0; $i < $order; $i++)
445 array_push($newchoices, $this->answers[$i]);
447 array_push($newchoices, $answer);
448 for ($i = $order; $i < count($this->answers); $i++)
454 $this->answers = $newchoices;
460 array_push($this->answers, $answer);
473 return count($this->answers);
487 if ($index < 0)
return NULL;
488 if (count($this->answers) < 1)
return NULL;
489 if ($index >= count($this->answers))
return NULL;
491 return $this->answers[$index];
504 if ($index < 0)
return;
505 if (count($this->answers) < 1)
return;
506 if ($index >= count($this->answers))
return;
507 $answer = $this->answers[$index];
508 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
509 unset($this->answers[$index]);
510 $this->answers = array_values($this->answers);
511 for ($i = 0; $i < count($this->answers); $i++)
513 if ($this->answers[$i]->getOrder() > $index)
515 $this->answers[$i]->setOrder($i);
528 $this->answers = array();
541 foreach ($this->answers as $key => $value)
543 if ($value->getPoints() > $value->getPointsUnchecked())
545 $allpoints += $value->getPoints();
549 $allpoints += $value->getPointsUnchecked();
568 $found_values = array();
573 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
574 array(
'integer',
'integer',
'integer'),
577 while (
$data = $ilDB->fetchAssoc($result))
579 if (strcmp(
$data[
"value1"],
"") != 0)
581 array_push($found_values,
$data[
"value1"]);
585 foreach ($this->answers as $key => $answer)
587 if (in_array($key, $found_values))
589 $points += $answer->getPoints();
593 $points += $answer->getPointsUnchecked();
596 include_once
"./Modules/Test/classes/class.ilObjTest.php";
598 if (($mc_scoring == 0) && (count($found_values) == 0))
621 include_once
"./Modules/Test/classes/class.ilObjTest.php";
626 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
627 array(
'integer',
'integer',
'integer'),
630 foreach (
$_POST as $key => $value)
632 if (preg_match(
"/^multiple_choice_result_(\d+)/", $key, $matches))
636 $next_id = $ilDB->nextId(
'tst_solutions');
637 $affectedRows = $ilDB->insert(
"tst_solutions", array(
638 "solution_id" => array(
"integer", $next_id),
639 "active_fi" => array(
"integer", $active_id),
640 "question_fi" => array(
"integer", $this->
getId()),
641 "value1" => array(
"clob", $value),
642 "value2" => array(
"clob", null),
643 "pass" => array(
"integer",
$pass),
644 "tstamp" => array(
"integer", time())
652 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
660 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
682 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_mc WHERE question_fi = %s",
684 array($this->original_id)
688 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
690 array($this->
getId())
693 if ($result->numRows())
695 while (
$row = $ilDB->fetchAssoc($result))
697 $next_id = $ilDB->nextId(
'qpl_fb_mc');
698 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_fb_mc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
699 array(
'integer',
'integer',
'integer',
'text',
'integer'),
730 return "assMultipleChoice";
766 if (!empty($image_tempfilename))
768 $image_filename = str_replace(
" ",
"_", $image_filename);
770 if (!file_exists($imagepath))
781 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
783 if (!preg_match(
"/^image/", $mimetype))
785 unlink($imagepath . $image_filename);
810 @unlink($imagepath . $image_filename);
811 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
819 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
820 foreach ($this->answers as $answer)
825 if (!file_exists($imagepath))
829 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
831 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
832 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
834 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
838 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
839 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
850 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
851 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
852 foreach ($this->answers as $answer)
857 if (!file_exists($imagepath))
861 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
863 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
864 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
866 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
870 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
871 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
886 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
888 foreach ($this->answers as $answer)
893 if (@file_exists($imagepath .
$filename))
895 if (!file_exists($imagepath))
899 if (!file_exists($imagepath_original))
903 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
905 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
906 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
909 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
913 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
914 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
932 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
933 array(
'integer',
'integer'),
934 array($this->
getId(), $answer_index)
936 if (strlen($feedback))
938 include_once(
"./Services/RTE/classes/class.ilRTE.php");
939 $next_id = $ilDB->nextId(
'qpl_fb_mc');
940 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_fb_mc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
941 array(
'integer',
'integer',
'integer',
'text',
'integer'),
965 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
966 array(
'integer',
'integer'),
967 array($this->
getId(), $answer_index)
969 if ($result->numRows())
971 $row = $ilDB->fetchAssoc($result);
972 include_once(
"./Services/RTE/classes/class.ilRTE.php");
989 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
993 if ($result->numRows())
995 while (
$row = $ilDB->fetchAssoc($result))
997 $next_id = $ilDB->nextId(
'qpl_fb_mc');
998 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_fb_mc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
999 array(
'integer',
'integer',
'integer',
'text',
'integer'),
1019 foreach ($this->answers as $index => $answer)
1022 $answer_obj = $this->answers[$index];
1023 $text .= $answer_obj->getAnswertext();
1048 $adapter->setCellValue($startrow, 0, $this->lng->txt($this->getQuestionType()),
CELL_FORMAT_TITLE);
1053 $adapter->setCellValue($startrow + $i, 0, $answer->getAnswertext(),
CELL_FORMAT_BOLD);
1055 foreach ($solution as $solutionvalue)
1057 if (
$id == $solutionvalue[
"value1"])
1064 $adapter->setCellValue($startrow + $i, 1, 1);
1068 $adapter->setCellValue($startrow + $i, 1, 0);
1072 return $startrow + $i + 1;
1082 $this->thumb_size = $a_size;
1090 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1092 $result[
'id'] = (int) $this->
getId();
1094 $result[
'title'] = (string) $this->
getTitle();
1097 $result[
'shuffle'] = (bool) $this->
getShuffle();
1098 $result[
'feedback'] = array(
1103 foreach ($this->
getAnswers() as $key => $answer_obj)
1106 "answertext" => (
string) $answer_obj->getAnswertext(),
1107 "points_checked" => (float) $answer_obj->getPointsChecked(),
1108 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1109 "order" => (int) $answer_obj->getOrder(),
1110 "image" => $answer_obj->getImage(),
1116 $result[
'mobs'] =
$mobs;
1117 return json_encode($result);
1122 $answer = $this->answers[$index];
1123 if (is_object($answer))
1126 $answer->setImage(
'');
1134 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1135 if ($multilineAnswerSetting != 1)
1137 $multilineAnswerSetting = 0;
1139 return $multilineAnswerSetting;
1145 $ilUser->writePref(
"tst_multiline_answers", $a_setting);