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 (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
129 array($this->
getId())
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']))
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";
280 if (!@file_exists($imagefilename))
282 $data[
"imagefile"] =
"";
284 include_once(
"./Services/RTE/classes/class.ilRTE.php");
306 $this_id = $this->
getId();
308 if( (
int)$testObjId > 0 )
314 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
318 if( (
int)$testObjId > 0 )
320 $clone->setObjId($testObjId);
347 $clone->copyPageOfQuestion($this_id);
349 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
351 $clone->duplicateImages($this_id, $thisObjId);
353 $clone->duplicateFeedbackGeneric($this_id);
355 $clone->duplicateFeedbackAnswer($this_id);
357 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
376 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
379 $source_questionpool = $this->
getObjId();
380 $clone->setObjId($target_questionpool);
398 $clone->onDuplicate($source_questionpool, $this->
getId());
444 $points_unchecked = 0.0,
449 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
450 if (array_key_exists($order, $this->answers))
454 $newchoices = array();
455 for ($i = 0; $i < $order; $i++)
457 array_push($newchoices, $this->answers[$i]);
459 array_push($newchoices, $answer);
460 for ($i = $order; $i < count($this->answers); $i++)
466 $this->answers = $newchoices;
472 array_push($this->answers, $answer);
485 return count($this->answers);
499 if ($index < 0)
return NULL;
500 if (count($this->answers) < 1)
return NULL;
501 if ($index >= count($this->answers))
return NULL;
503 return $this->answers[$index];
516 if ($index < 0)
return;
517 if (count($this->answers) < 1)
return;
518 if ($index >= count($this->answers))
return;
519 $answer = $this->answers[$index];
520 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
521 unset($this->answers[$index]);
522 $this->answers = array_values($this->answers);
523 for ($i = 0; $i < count($this->answers); $i++)
525 if ($this->answers[$i]->getOrder() > $index)
527 $this->answers[$i]->setOrder($i);
540 $this->answers = array();
553 foreach ($this->answers as $key => $value)
555 if ($value->getPoints() > $value->getPointsUnchecked())
557 $allpoints += $value->getPoints();
561 $allpoints += $value->getPointsUnchecked();
580 $found_values = array();
585 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
586 array(
'integer',
'integer',
'integer'),
591 if (strcmp(
$data[
"value1"],
"") != 0)
593 array_push($found_values,
$data[
"value1"]);
597 foreach ($this->answers as $key => $answer)
599 if (in_array($key, $found_values))
601 $points += $answer->getPoints();
605 $points += $answer->getPointsUnchecked();
608 include_once
"./Modules/Test/classes/class.ilObjTest.php";
610 if (($mc_scoring == 0) && (count($found_values) == 0))
633 include_once
"./Modules/Test/classes/class.ilObjTest.php";
638 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
639 array(
'integer',
'integer',
'integer'),
642 foreach (
$_POST as $key => $value)
644 if (preg_match(
"/^multiple_choice_result_(\d+)/", $key, $matches))
648 $next_id = $ilDB->nextId(
'tst_solutions');
649 $affectedRows = $ilDB->insert(
"tst_solutions", array(
650 "solution_id" => array(
"integer", $next_id),
651 "active_fi" => array(
"integer", $active_id),
652 "question_fi" => array(
"integer", $this->
getId()),
653 "value1" => array(
"clob", $value),
654 "value2" => array(
"clob", null),
655 "pass" => array(
"integer",
$pass),
656 "tstamp" => array(
"integer", time())
664 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
672 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
687 function syncFeedbackSingleAnswers()
694 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_mc WHERE question_fi = %s",
696 array($this->original_id)
700 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
702 array($this->
getId())
709 $next_id = $ilDB->nextId(
'qpl_fb_mc');
712 $ilDB->insert(
'qpl_fb_mc', array(
713 'feedback_id' => array(
'integer', $next_id ),
714 'question_fi' => array(
'integer', $this->original_id ),
715 'answer' => array(
'integer',
$row[
"answer"] ),
716 'feedback' => array(
'clob',
$row[
"feedback"] ),
717 'tstamp' => array(
'integer', time() ),
728 $this->syncFeedbackSingleAnswers();
742 return "assMultipleChoice";
778 if (!empty($image_tempfilename))
780 $image_filename = str_replace(
" ",
"_", $image_filename);
782 if (!file_exists($imagepath))
793 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
795 if (!preg_match(
"/^image/", $mimetype))
797 unlink($imagepath . $image_filename);
822 @unlink($imagepath . $image_filename);
823 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
831 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
833 if( (
int)$objectId > 0 )
835 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
838 foreach ($this->answers as $answer)
843 if (!file_exists($imagepath))
847 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
849 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
850 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
852 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
856 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
857 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
868 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
869 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
870 foreach ($this->answers as $answer)
875 if (!file_exists($imagepath))
879 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
881 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
882 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
884 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
888 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
889 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
904 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
906 foreach ($this->answers as $answer)
911 if (@file_exists($imagepath .
$filename))
913 if (!file_exists($imagepath))
917 if (!file_exists($imagepath_original))
921 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
923 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
924 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
927 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
931 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
932 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
946 function saveFeedbackSingleAnswer($answer_index, $feedback)
950 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
951 array(
'integer',
'integer'),
952 array($this->
getId(), $answer_index)
954 if (strlen($feedback))
956 include_once(
"./Services/RTE/classes/class.ilRTE.php");
957 $next_id = $ilDB->nextId(
'qpl_fb_mc');
960 $ilDB->insert(
'qpl_fb_mc', array(
961 'feedback_id' => array(
'integer', $next_id ),
962 'question_fi' => array(
'integer', $this->
getId() ),
963 'answer' => array(
'integer', $answer_index ),
965 'tstamp' => array(
'integer', time() ),
983 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
984 array(
'integer',
'integer'),
985 array($this->
getId(), $answer_index)
990 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1007 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
1015 $next_id = $ilDB->nextId(
'qpl_fb_mc');
1018 $ilDB->insert(
'qpl_fb_mc', array(
1019 'feedback_id' => array(
'integer', $next_id ),
1020 'question_fi' => array(
'integer', $this->
getId() ),
1021 'answer' => array(
'integer',
$row[
"answer"] ),
1022 'feedback' => array(
'clob',
$row[
"feedback"] ),
1023 'tstamp' => array(
'integer', time() ),
1038 foreach ($this->answers as $index => $answer)
1041 $answer_obj = $this->answers[$index];
1042 $text .= $answer_obj->getAnswertext();
1069 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1078 foreach ($solution as $solutionvalue)
1080 if (
$id == $solutionvalue[
"value1"])
1087 $worksheet->write($startrow + $i, 1, 1);
1091 $worksheet->write($startrow + $i, 1, 0);
1095 return $startrow + $i + 1;
1105 $this->thumb_size = $a_size;
1113 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1128 foreach ($this->
getAnswers() as $key => $answer_obj)
1130 if((
string) $answer_obj->getImage())
1135 "answertext" => (
string) $answer_obj->getAnswertext(),
1136 "points_checked" => (float) $answer_obj->getPointsChecked(),
1137 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1138 "order" => (int) $answer_obj->getOrder(),
1139 "image" => (string) $answer_obj->getImage(),
1159 $answer = $this->answers[$index];
1160 if (is_object($answer))
1163 $answer->setImage(
'');
1171 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1172 if ($multilineAnswerSetting != 1)
1174 $multilineAnswerSetting = 0;
1176 return $multilineAnswerSetting;
1182 $ilUser->writePref(
"tst_multiline_answers", $a_setting);