5 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
6 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
74 $this->thumb_size = 150;
75 $this->answers = array();
87 if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
115 array($this->
getId())
120 $oldthumbsize =
$data[
'thumb_size'];
123 if (!$this->isSingleline)
129 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
131 array($this->
getId())
134 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
135 array(
"integer",
"text",
"text",
"integer"),
139 ($this->isSingleline) ?
"0" :
"1",
144 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_mc WHERE question_fi = %s",
146 array($this->
getId())
149 foreach ($this->answers as $key => $value)
151 $answer_obj = $this->answers[$key];
152 $next_id = $ilDB->nextId(
'qpl_a_mc');
153 $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)",
154 array(
'integer',
'integer',
'text',
'float',
'float',
'integer',
'text',
'integer'),
159 $answer_obj->getPoints(),
160 $answer_obj->getPointsUnchecked(),
161 $answer_obj->getOrder(),
162 $answer_obj->getImage(),
180 SET feedback_setting = ' . $ilDB->quote($a_feedback_setting,
'integer') .
'
181 WHERE question_fi = ' .$ilDB->quote($this->
getId(),
'integer'));
193 if (strlen($answer->getImage()))
214 switch (strtoupper($path_info[
'extension']))
248 $this->
setId($question_id);
257 include_once(
"./Services/RTE/classes/class.ilRTE.php");
263 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
264 $this->lastChange =
$data[
'tstamp'];
265 $this->feedback_setting =
$data[
'feedback_setting'];
268 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_mc WHERE question_fi = %s ORDER BY aorder ASC",
272 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
278 if (!@file_exists($imagefilename))
280 $data[
"imagefile"] =
"";
282 include_once(
"./Services/RTE/classes/class.ilRTE.php");
304 $this_id = $this->
getId();
306 if( (
int)$testObjId > 0 )
312 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
316 if( (
int)$testObjId > 0 )
318 $clone->setObjId($testObjId);
345 $clone->copyPageOfQuestion($this_id);
347 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
349 $clone->duplicateImages($this_id, $thisObjId);
351 $clone->duplicateGenericFeedback($this_id);
353 $clone->duplicateFeedbackAnswer($this_id);
355 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
374 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
377 $source_questionpool = $this->
getObjId();
378 $clone->setObjId($target_questionpool);
396 $clone->onDuplicate($source_questionpool, $this->
getId(), $clone->getObjId(), $clone->getId());
442 $points_unchecked = 0.0,
447 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
448 if (array_key_exists($order, $this->answers))
452 $newchoices = array();
453 for ($i = 0; $i < $order; $i++)
455 array_push($newchoices, $this->answers[$i]);
457 array_push($newchoices, $answer);
458 for ($i = $order; $i < count($this->answers); $i++)
464 $this->answers = $newchoices;
470 array_push($this->answers, $answer);
483 return count($this->answers);
497 if ($index < 0)
return NULL;
498 if (count($this->answers) < 1)
return NULL;
499 if ($index >= count($this->answers))
return NULL;
501 return $this->answers[$index];
514 if ($index < 0)
return;
515 if (count($this->answers) < 1)
return;
516 if ($index >= count($this->answers))
return;
517 $answer = $this->answers[$index];
518 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
519 unset($this->answers[$index]);
520 $this->answers = array_values($this->answers);
521 for ($i = 0; $i < count($this->answers); $i++)
523 if ($this->answers[$i]->getOrder() > $index)
525 $this->answers[$i]->setOrder($i);
538 $this->answers = array();
551 foreach ($this->answers as $key => $value)
553 if ($value->getPoints() > $value->getPointsUnchecked())
555 $allpoints += $value->getPoints();
559 $allpoints += $value->getPointsUnchecked();
579 throw new ilTestException(
'return details not implemented for '.__METHOD__);
584 $found_values = array();
589 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
590 array(
'integer',
'integer',
'integer'),
595 if (strcmp(
$data[
"value1"],
"") != 0)
597 array_push($found_values,
$data[
"value1"]);
601 foreach ($this->answers as $key => $answer)
603 if (in_array($key, $found_values))
605 $points += $answer->getPoints();
609 $points += $answer->getPointsUnchecked();
612 include_once
"./Modules/Test/classes/class.ilObjTest.php";
614 if (($mc_scoring == 0) && (count($found_values) == 0))
636 include_once
"./Modules/Test/classes/class.ilObjTest.php";
641 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
642 array(
'integer',
'integer',
'integer'),
645 foreach (
$_POST as $key => $value)
647 if (preg_match(
"/^multiple_choice_result_(\d+)/", $key, $matches))
651 $next_id = $ilDB->nextId(
'tst_solutions');
652 $affectedRows = $ilDB->insert(
"tst_solutions", array(
653 "solution_id" => array(
"integer", $next_id),
654 "active_fi" => array(
"integer", $active_id),
655 "question_fi" => array(
"integer", $this->
getId()),
656 "value1" => array(
"clob", $value),
657 "value2" => array(
"clob", null),
658 "pass" => array(
"integer",
$pass),
659 "tstamp" => array(
"integer", time())
667 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
675 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
703 function syncFeedbackSingleAnswers()
710 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_mc WHERE question_fi = %s",
712 array($this->original_id)
716 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
718 array($this->
getId())
725 $next_id = $ilDB->nextId(
'qpl_fb_mc');
727 $ilDB->insert(
'qpl_fb_mc', array(
728 'feedback_id' => array(
'integer', $next_id ),
729 'question_fi' => array(
'integer', $this->original_id ),
730 'answer' => array(
'integer',
$row[
"answer"] ),
731 'feedback' => array(
'clob',
$row[
"feedback"] ),
732 'tstamp' => array(
'integer', time() ),
743 $this->syncFeedbackSingleAnswers();
757 return "assMultipleChoice";
793 if (!empty($image_tempfilename))
795 $image_filename = str_replace(
" ",
"_", $image_filename);
797 if (!file_exists($imagepath))
808 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
810 if (!preg_match(
"/^image/", $mimetype))
812 unlink($imagepath . $image_filename);
837 @unlink($imagepath . $image_filename);
838 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
846 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
848 if( (
int)$objectId > 0 )
850 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
853 foreach ($this->answers as $answer)
858 if (!file_exists($imagepath))
862 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
864 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
865 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
867 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
871 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
872 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
883 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
884 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
885 foreach ($this->answers as $answer)
890 if (!file_exists($imagepath))
894 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
896 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
897 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
899 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
903 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
904 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
922 $imagepath_original = $this->
getImagePath($question_id, $originalObjId);
925 foreach ($this->answers as $answer)
930 if (@file_exists($imagepath .
$filename))
932 if (!file_exists($imagepath))
936 if (!file_exists($imagepath_original))
940 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
942 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
943 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
946 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
950 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
951 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
965 function saveFeedbackSingleAnswer($answer_index, $feedback)
969 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
970 array(
'integer',
'integer'),
971 array($this->
getId(), $answer_index)
973 if (strlen($feedback))
975 include_once(
"./Services/RTE/classes/class.ilRTE.php");
976 $next_id = $ilDB->nextId(
'qpl_fb_mc');
978 $ilDB->insert(
'qpl_fb_mc', array(
979 'feedback_id' => array(
'integer', $next_id ),
980 'question_fi' => array(
'integer', $this->
getId() ),
981 'answer' => array(
'integer', $answer_index ),
983 'tstamp' => array(
'integer', time() ),
1001 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s AND answer = %s",
1002 array(
'integer',
'integer'),
1003 array($this->
getId(), $answer_index)
1008 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1025 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_mc WHERE question_fi = %s",
1033 $next_id = $ilDB->nextId(
'qpl_fb_mc');
1035 $ilDB->insert(
'qpl_fb_mc', array(
1036 'feedback_id' => array(
'integer', $next_id ),
1037 'question_fi' => array(
'integer', $this->
getId() ),
1038 'answer' => array(
'integer',
$row[
"answer"] ),
1039 'feedback' => array(
'clob',
$row[
"feedback"] ),
1040 'tstamp' => array(
'integer', time() ),
1054 foreach ($this->answers as $index => $answer)
1057 $answer_obj = $this->answers[$index];
1058 $text .= $answer_obj->getAnswertext();
1085 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1094 foreach ($solution as $solutionvalue)
1096 if (
$id == $solutionvalue[
"value1"])
1103 $worksheet->write($startrow + $i, 1, 1);
1107 $worksheet->write($startrow + $i, 1, 0);
1111 return $startrow + $i + 1;
1121 $this->thumb_size = $a_size;
1129 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1144 foreach ($this->
getAnswers() as $key => $answer_obj)
1146 if((
string) $answer_obj->getImage())
1151 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1152 "points_checked" => (
float) $answer_obj->getPointsChecked(),
1153 "points_unchecked" => (float) $answer_obj->getPointsUnchecked(),
1154 "order" => (int) $answer_obj->getOrder(),
1155 "image" => (string) $answer_obj->getImage(),
1175 $answer = $this->answers[$index];
1176 if (is_object($answer))
1179 $answer->setImage(
'');
1187 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1188 if ($multilineAnswerSetting != 1)
1190 $multilineAnswerSetting = 0;
1192 return $multilineAnswerSetting;
1198 $ilUser->writePref(
"tst_multiline_answers", $a_setting);
1212 $this->feedback_setting = $a_feedback_setting;
1226 if ($this->feedback_setting)
1228 return $this->feedback_setting;
1269 SELECT SUM(points) points_for_checked_answers
1271 WHERE question_fi = %s
1274 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1278 return $row[
'points_for_checked_answers'] > 0;
1295 SELECT SUM(qpl_a_mc.points) points_for_checked_answers,
1298 FROM tst_test_question
1301 ON qpl_a_mc.question_fi = tst_test_question.question_fi
1303 WHERE tst_test_question.question_fi = %s
1304 AND tst_test_question.obligatory = 1
1306 GROUP BY test_question_id
1309 $res = $ilDB->queryF(
$query, array(
'integer'), array($questionId));
1311 $updateTestQuestionIds = array();
1313 while(
$row = $ilDB->fetchAssoc(
$res) )
1315 if(
$row[
'points_for_checked_answers'] <= 0 )
1317 $updateTestQuestionIds[] =
$row[
'test_question_id'];
1321 if( count($updateTestQuestionIds) )
1323 $test_question_id__IN__updateTestQuestionIds = $ilDB->in(
1324 'test_question_id', $updateTestQuestionIds,
false,
'integer'
1328 UPDATE tst_test_question
1330 WHERE $test_question_id__IN__updateTestQuestionIds
1333 $ilDB->manipulate(
$query);