4 require_once
'./Modules/TestQuestionPool/classes/class.assQuestion.php';
5 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
6 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
7 require_once
'./Modules/TestQuestionPool/interfaces/interface.ilObjAnswerScoringAdjustable.php';
109 $this->thumb_size = 150;
110 $this->answers = array();
122 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
143 $this->ensureNoInvalidObligation($this->
getId());
156 if (strlen($answer->getImage()))
184 switch (strtoupper($path_info[
'extension']))
216 $data = $ilDB->fetchAssoc(
$result);
217 $this->
setId($question_id);
226 include_once(
"./Services/RTE/classes/class.ilRTE.php");
228 $shuffle = (is_null($data[
'shuffle'])) ?
true : $data[
'shuffle'];
230 $this->
setEstimatedWorkingTime(substr($data[
"working_time"], 0, 2), substr($data[
"working_time"], 3, 2), substr($data[
"working_time"], 6, 2));
232 $this->isSingleline = ($data[
'allow_images']) ?
false :
true;
233 $this->lastChange = $data[
'tstamp'];
234 $this->feedback_setting = $data[
'feedback_setting'];
245 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
249 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
252 while ($data = $ilDB->fetchAssoc(
$result))
254 $imagefilename = $this->
getImagePath() . $data[
"imagefile"];
255 if (!@file_exists($imagefilename))
257 $data[
"imagefile"] =
"";
259 include_once(
"./Services/RTE/classes/class.ilRTE.php");
261 array_push($this->answers,
new ASS_AnswerMultipleResponseImage($data[
"answertext"], $data[
"points"], $data[
"aorder"], $data[
"points_unchecked"], $data[
"imagefile"]));
279 $this_id = $this->
getId();
283 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
287 if( (
int)$testObjId > 0 )
289 $clone->setObjId($testObjId);
316 $clone->copyPageOfQuestion($this_id);
318 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
320 $clone->duplicateImages($this_id, $thisObjId);
322 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
339 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
342 $source_questionpool_id = $this->
getObjId();
343 $clone->setObjId($target_questionpool_id);
354 $clone->copyImages(
$original_id, $source_questionpool_id);
356 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
369 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
372 $sourceParentId = $this->
getObjId();
378 $clone->setObjId($targetParentId);
380 if ($targetQuestionTitle)
382 $clone->setTitle($targetQuestionTitle);
387 $clone->copyPageOfQuestion($sourceQuestionId);
389 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
391 $clone->copyImages($sourceQuestionId, $sourceParentId);
393 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
437 $points_unchecked = 0.0,
442 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
443 if (array_key_exists($order, $this->answers))
447 $newchoices = array();
448 for ($i = 0; $i < $order; $i++)
450 array_push($newchoices, $this->answers[$i]);
452 array_push($newchoices, $answer);
453 for ($i = $order; $i < count($this->answers); $i++)
459 $this->answers = $newchoices;
465 array_push($this->answers, $answer);
477 return count($this->answers);
490 if ($index < 0)
return NULL;
491 if (count($this->answers) < 1)
return NULL;
492 if ($index >= count($this->answers))
return NULL;
494 return $this->answers[$index];
506 if ($index < 0)
return;
507 if (count($this->answers) < 1)
return;
508 if ($index >= count($this->answers))
return;
509 $answer = $this->answers[$index];
510 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
511 unset($this->answers[$index]);
512 $this->answers = array_values($this->answers);
513 for ($i = 0; $i < count($this->answers); $i++)
515 if ($this->answers[$i]->getOrder() > $index)
517 $this->answers[$i]->setOrder($i);
529 $this->answers = array();
541 foreach ($this->answers as $key => $value)
543 if ($value->getPoints() > $value->getPointsUnchecked())
545 $allpoints += $value->getPoints();
549 $allpoints += $value->getPointsUnchecked();
570 throw new ilTestException(
'return details not implemented for '.__METHOD__);
575 $found_values = array();
580 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
581 array(
'integer',
'integer',
'integer'),
584 while ($data = $ilDB->fetchAssoc(
$result))
586 if (strcmp($data[
"value1"],
"") != 0)
588 array_push($found_values, $data[
"value1"]);
592 foreach ($this->answers as $key => $answer)
594 if (in_array($key, $found_values))
596 $points += $answer->getPoints();
600 $points += $answer->getPointsUnchecked();
603 include_once
"./Modules/Test/classes/class.ilObjTest.php";
605 if (($mc_scoring == 0) && (count($found_values) == 0))
627 include_once
"./Modules/Test/classes/class.ilObjTest.php";
635 $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
636 array(
'integer',
'integer',
'integer'),
639 foreach (
$_POST as $key => $value)
641 if (preg_match(
"/^multiple_choice_result_(\d+)/", $key, $matches))
645 $next_id = $ilDB->nextId(
'tst_solutions');
646 $ilDB->insert(
"tst_solutions", array(
647 "solution_id" => array(
"integer", $next_id),
648 "active_fi" => array(
"integer", $active_id),
649 "question_fi" => array(
"integer", $this->
getId()),
650 "value1" => array(
"clob", $value),
651 "value2" => array(
"clob", null),
652 "pass" => array(
"integer",
$pass),
653 "tstamp" => array(
"integer", time())
664 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
672 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
691 ) .
" WHERE question_fi = %s",
693 array( $this->
getId() )
697 $data = $ilDB->fetchAssoc(
$result );
698 $oldthumbsize = $data[
'thumb_size'];
702 if (!$this->isSingleline)
710 array( $this->
getId() )
714 .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
715 array(
"integer",
"text",
"text",
"integer" ),
719 ($this->isSingleline) ?
"0" :
"1",
729 $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
731 array( $this->
getId() )
734 foreach ($this->answers as $key => $value)
736 $answer_obj = $this->answers[$key];
737 $next_id = $ilDB->nextId(
'qpl_a_mc' );
738 $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)",
739 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer' ),
744 $answer_obj->getPoints(),
745 $answer_obj->getPointsUnchecked(),
746 $answer_obj->getOrder(),
747 $answer_obj->getImage(),
783 return "assMultipleChoice";
813 public function setImageFile($image_filename, $image_tempfilename =
"")
816 if (!empty($image_tempfilename))
818 $image_filename = str_replace(
" ",
"_", $image_filename);
820 if (!file_exists($imagepath))
830 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
832 if (!preg_match(
"/^image/", $mimetype))
834 unlink($imagepath . $image_filename);
858 @unlink($imagepath . $image_filename);
859 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
867 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
869 if( (
int)$objectId > 0 )
871 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
874 foreach ($this->answers as $answer)
879 if (!file_exists($imagepath))
883 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
885 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
886 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
888 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
892 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
893 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
904 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
905 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
906 foreach ($this->answers as $answer)
911 if (!file_exists($imagepath))
915 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
917 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
918 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
920 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
924 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
925 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
943 $imagepath_original = $this->
getImagePath($question_id, $originalObjId);
946 foreach ($this->answers as $answer)
951 if (@file_exists($imagepath .
$filename))
953 if (!file_exists($imagepath))
957 if (!file_exists($imagepath_original))
961 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
963 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
964 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
967 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
971 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
972 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
985 foreach ($this->answers as $index => $answer)
987 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), $index);
988 $answer_obj = $this->answers[$index];
989 $text .= $answer_obj->getAnswertext();
1016 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1025 foreach ($solution as $solutionvalue)
1027 if (
$id == $solutionvalue[
"value1"])
1034 $worksheet->write($startrow + $i, 1, 1);
1038 $worksheet->write($startrow + $i, 1, 0);
1042 return $startrow + $i + 1;
1052 $this->thumb_size = $a_size;
1060 require_once
'./Services/RTE/classes/class.ilRTE.php';
1069 "onenotcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false),
1070 "allcorrect" => $this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true)
1075 foreach ($this->
getAnswers() as $key => $answer_obj)
1077 if((
string) $answer_obj->getImage())
1082 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1083 "points_checked" => (
float) $answer_obj->getPointsChecked(),
1084 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1085 "order" => (int) $answer_obj->getOrder(),
1086 "image" => (string) $answer_obj->getImage(),
1088 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1108 $answer = $this->answers[$index];
1109 if (is_object($answer))
1112 $answer->setImage(
'');
1120 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1121 if ($multilineAnswerSetting != 1)
1123 $multilineAnswerSetting = 0;
1125 return $multilineAnswerSetting;
1131 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1145 $this->feedback_setting = $a_feedback_setting;
1159 if ($this->feedback_setting)
1204 SELECT SUM(points) points_for_checked_answers
1206 WHERE question_fi = %s
1209 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1213 return $row[
'points_for_checked_answers'] > 0;
1224 public function ensureNoInvalidObligation($questionId)
1230 SELECT SUM(qpl_a_mc.points) points_for_checked_answers,
1233 FROM tst_test_question
1236 ON qpl_a_mc.question_fi = tst_test_question.question_fi
1238 WHERE tst_test_question.question_fi = %s
1239 AND tst_test_question.obligatory = 1
1241 GROUP BY test_question_id
1244 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1246 $updateTestQuestionIds = array();
1248 while(
$row = $ilDB->fetchAssoc(
$res) )
1250 if(
$row[
'points_for_checked_answers'] <= 0 )
1252 $updateTestQuestionIds[] =
$row[
'test_question_id'];
1256 if( count($updateTestQuestionIds) )
1258 $test_question_id__IN__updateTestQuestionIds = $ilDB->in(
1259 'test_question_id', $updateTestQuestionIds,
false,
'integer'
1263 UPDATE tst_test_question
1265 WHERE $test_question_id__IN__updateTestQuestionIds
1268 $ilDB->manipulate(
$query);