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';
8 require_once
'./Modules/TestQuestionPool/interfaces/interface.iQuestionCondition.php';
9 require_once
'./Modules/TestQuestionPool/classes/class.ilUserQuestionResult.php';
111 $this->thumb_size = 150;
112 $this->answers = array();
124 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
145 $this->ensureNoInvalidObligation($this->
getId());
158 if (strlen($answer->getImage()))
186 switch (strtoupper($path_info[
'extension']))
218 $data = $ilDB->fetchAssoc(
$result);
219 $this->
setId($question_id);
228 include_once(
"./Services/RTE/classes/class.ilRTE.php");
230 $shuffle = (is_null($data[
'shuffle'])) ?
true : $data[
'shuffle'];
232 $this->
setEstimatedWorkingTime(substr($data[
"working_time"], 0, 2), substr($data[
"working_time"], 3, 2), substr($data[
"working_time"], 6, 2));
234 $this->isSingleline = ($data[
'allow_images']) ?
false :
true;
235 $this->lastChange = $data[
'tstamp'];
236 $this->feedback_setting = $data[
'feedback_setting'];
247 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
251 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
254 while ($data = $ilDB->fetchAssoc(
$result))
256 $imagefilename = $this->
getImagePath() . $data[
"imagefile"];
257 if (!@file_exists($imagefilename))
259 $data[
"imagefile"] =
"";
261 include_once(
"./Services/RTE/classes/class.ilRTE.php");
263 array_push($this->answers,
new ASS_AnswerMultipleResponseImage($data[
"answertext"], $data[
"points"], $data[
"aorder"], $data[
"points_unchecked"], $data[
"imagefile"]));
281 $this_id = $this->
getId();
285 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
289 if( (
int)$testObjId > 0 )
291 $clone->setObjId($testObjId);
318 $clone->copyPageOfQuestion($this_id);
320 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
322 $clone->duplicateImages($this_id, $thisObjId);
324 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
341 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
344 $source_questionpool_id = $this->
getObjId();
345 $clone->setObjId($target_questionpool_id);
356 $clone->copyImages(
$original_id, $source_questionpool_id);
358 $clone->onCopy($source_questionpool_id,
$original_id, $clone->getObjId(), $clone->getId());
371 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
374 $sourceParentId = $this->
getObjId();
380 $clone->setObjId($targetParentId);
382 if ($targetQuestionTitle)
384 $clone->setTitle($targetQuestionTitle);
389 $clone->copyPageOfQuestion($sourceQuestionId);
391 $clone->copyXHTMLMediaObjectsOfQuestion($sourceQuestionId);
393 $clone->copyImages($sourceQuestionId, $sourceParentId);
395 $clone->onCopy($sourceParentId, $sourceQuestionId, $clone->getObjId(), $clone->getId());
439 $points_unchecked = 0.0,
444 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
445 if (array_key_exists($order, $this->answers))
449 $newchoices = array();
450 for ($i = 0; $i < $order; $i++)
452 array_push($newchoices, $this->answers[$i]);
454 array_push($newchoices, $answer);
455 for ($i = $order; $i < count($this->answers); $i++)
461 $this->answers = $newchoices;
467 array_push($this->answers, $answer);
479 return count($this->answers);
492 if ($index < 0)
return NULL;
493 if (count($this->answers) < 1)
return NULL;
494 if ($index >= count($this->answers))
return NULL;
496 return $this->answers[$index];
508 if ($index < 0)
return;
509 if (count($this->answers) < 1)
return;
510 if ($index >= count($this->answers))
return;
511 $answer = $this->answers[$index];
512 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
513 unset($this->answers[$index]);
514 $this->answers = array_values($this->answers);
515 for ($i = 0; $i < count($this->answers); $i++)
517 if ($this->answers[$i]->getOrder() > $index)
519 $this->answers[$i]->setOrder($i);
531 $this->answers = array();
543 foreach ($this->answers as $key => $value)
545 if ($value->getPoints() > $value->getPointsUnchecked())
547 $allpoints += $value->getPoints();
551 $allpoints += $value->getPointsUnchecked();
572 throw new ilTestException(
'return details not implemented for '.__METHOD__);
577 $found_values = array();
582 $result = $this->getCurrentSolutionResultSet($active_id,
$pass);
583 while ($data = $ilDB->fetchAssoc(
$result))
585 if (strcmp($data[
"value1"],
"") != 0)
587 array_push($found_values, $data[
"value1"]);
611 include_once
"./Modules/Test/classes/class.ilObjTest.php";
619 $this->removeCurrentSolution($active_id,
$pass);
623 foreach($solutionSubmit as $value)
627 $this->saveCurrentSolution($active_id,
$pass, $value, null);
636 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
644 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
663 ) .
" WHERE question_fi = %s",
665 array( $this->
getId() )
669 $data = $ilDB->fetchAssoc(
$result );
670 $oldthumbsize = $data[
'thumb_size'];
674 if (!$this->isSingleline)
682 array( $this->
getId() )
686 .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
687 array(
"integer",
"text",
"text",
"integer" ),
691 ($this->isSingleline) ?
"0" :
"1",
701 $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
703 array( $this->
getId() )
706 foreach ($this->answers as $key => $value)
708 $answer_obj = $this->answers[$key];
709 $next_id = $ilDB->nextId(
'qpl_a_mc' );
710 $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)",
711 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer' ),
716 $answer_obj->getPoints(),
717 $answer_obj->getPointsUnchecked(),
718 $answer_obj->getOrder(),
719 $answer_obj->getImage(),
755 return "assMultipleChoice";
785 public function setImageFile($image_filename, $image_tempfilename =
"")
788 if (!empty($image_tempfilename))
790 $image_filename = str_replace(
" ",
"_", $image_filename);
792 if (!file_exists($imagepath))
802 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
804 if (!preg_match(
"/^image/", $mimetype))
806 unlink($imagepath . $image_filename);
830 @unlink($imagepath . $image_filename);
831 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
839 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
841 if( (
int)$objectId > 0 )
843 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
846 foreach ($this->answers as $answer)
851 if (!file_exists($imagepath))
855 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
857 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
858 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
860 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
864 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
865 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
876 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
877 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
878 foreach ($this->answers as $answer)
883 if (!file_exists($imagepath))
887 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
889 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
890 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
892 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
896 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
897 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
915 $imagepath_original = $this->
getImagePath($question_id, $originalObjId);
918 foreach ($this->answers as $answer)
923 if (@file_exists($imagepath .
$filename))
925 if (!file_exists($imagepath))
929 if (!file_exists($imagepath_original))
933 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
935 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
936 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
939 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
943 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
944 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
957 foreach ($this->answers as $index => $answer)
959 $text .= $this->feedbackOBJ->getSpecificAnswerFeedbackContent($this->
getId(), $index);
960 $answer_obj = $this->answers[$index];
961 $text .= $answer_obj->getAnswertext();
988 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
997 foreach ($solution as $solutionvalue)
999 if (
$id == $solutionvalue[
"value1"])
1006 $worksheet->write($startrow + $i, 1, 1);
1010 $worksheet->write($startrow + $i, 1, 0);
1014 return $startrow + $i + 1;
1024 $this->thumb_size = $a_size;
1032 require_once
'./Services/RTE/classes/class.ilRTE.php';
1041 'onenotcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
false)),
1042 'allcorrect' => $this->
formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(),
true))
1047 foreach ($this->
getAnswers() as $key => $answer_obj)
1049 if((
string) $answer_obj->getImage())
1053 array_push($answers, array(
1054 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1055 "points_checked" => (
float) $answer_obj->getPointsChecked(),
1056 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1057 "order" => (int) $answer_obj->getOrder(),
1058 "image" => (string) $answer_obj->getImage(),
1060 $this->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation($this->getId(), $key), 0
1080 $answer = $this->answers[$index];
1081 if (is_object($answer))
1084 $answer->setImage(
'');
1092 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1093 if ($multilineAnswerSetting != 1)
1095 $multilineAnswerSetting = 0;
1097 return $multilineAnswerSetting;
1103 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1117 $this->feedback_setting = $a_feedback_setting;
1131 if ($this->feedback_setting)
1156 return $numExistingSolutionRecords > 0;
1176 SELECT SUM(points) points_for_checked_answers
1178 WHERE question_fi = %s AND points > 0
1181 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1185 return $row[
'points_for_checked_answers'] > 0;
1196 public function ensureNoInvalidObligation($questionId)
1202 SELECT SUM(qpl_a_mc.points) points_for_checked_answers,
1205 FROM tst_test_question
1208 ON qpl_a_mc.question_fi = tst_test_question.question_fi
1210 WHERE tst_test_question.question_fi = %s
1211 AND tst_test_question.obligatory = 1
1213 GROUP BY test_question_id
1216 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1218 $updateTestQuestionIds = array();
1220 while(
$row = $ilDB->fetchAssoc(
$res) )
1222 if(
$row[
'points_for_checked_answers'] <= 0 )
1224 $updateTestQuestionIds[] =
$row[
'test_question_id'];
1228 if( count($updateTestQuestionIds) )
1230 $test_question_id__IN__updateTestQuestionIds = $ilDB->in(
1231 'test_question_id', $updateTestQuestionIds,
false,
'integer'
1235 UPDATE tst_test_question
1237 WHERE $test_question_id__IN__updateTestQuestionIds
1240 $ilDB->manipulate(
$query);
1249 $solutionSubmit = array();
1250 foreach(
$_POST as $key => $value)
1252 if(preg_match(
"/^multiple_choice_result_(\d+)/", $key))
1256 $solutionSubmit[] = $value;
1260 return $solutionSubmit;
1271 foreach($this->answers as $key => $answer)
1273 if(in_array($key, $found_values))
1275 $points += $answer->getPoints();
1278 $points += $answer->getPointsUnchecked();
1283 include_once
"./Modules/Test/classes/class.ilObjTest.php";
1285 if(($mc_scoring == 0) && (count($found_values) == 0))
1303 require_once
"./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php";
1335 $data = $ilDB->queryF(
1336 "SELECT value1+1 as value1 FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s AND step = (
1337 SELECT MAX(step) FROM tst_solutions WHERE active_fi = %s AND pass = %s AND question_fi = %s
1339 array(
"integer",
"integer",
"integer",
"integer",
"integer",
"integer"),
1343 while(
$row = $ilDB->fetchAssoc($data))