5 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
6 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
73 $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))
89 foreach ($this->answers as $answer)
91 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0))
return false;
119 array($this->
getId())
124 $oldthumbsize =
$data[
'thumb_size'];
127 if (!$this->isSingleline)
133 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
135 array($this->
getId())
138 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
139 array(
"integer",
"text",
"text",
"integer"),
143 ($this->isSingleline) ?
"0" :
"1",
148 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_sc WHERE question_fi = %s",
150 array($this->
getId())
153 foreach ($this->answers as $key => $value)
155 $answer_obj = $this->answers[$key];
156 $next_id = $ilDB->nextId(
'qpl_a_sc');
157 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_a_sc (answer_id, question_fi, answertext, points, aorder, imagefile, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
158 array(
'integer',
'integer',
'text',
'float',
'integer',
'text',
'integer'),
163 $answer_obj->getPoints(),
164 $answer_obj->getOrder(),
165 $answer_obj->getImage(),
185 if (strlen($answer->getImage()))
206 switch (strtoupper($path_info[
'extension']))
242 $this->
setId($question_id);
251 include_once(
"./Services/RTE/classes/class.ilRTE.php");
257 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
258 $this->lastChange =
$data[
'tstamp'];
261 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
265 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
271 if (!@file_exists($imagefilename))
273 $data[
"imagefile"] =
"";
275 include_once(
"./Services/RTE/classes/class.ilRTE.php");
297 $this_id = $this->
getId();
299 if( (
int)$testObjId > 0 )
305 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
309 if( (
int)$testObjId > 0 )
311 $clone->setObjId($testObjId);
337 $clone->copyPageOfQuestion($this_id);
340 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
342 $clone->duplicateImages($this_id, $thisObjId);
344 $clone->duplicateGenericFeedback($this_id);
346 $clone->duplicateFeedbackAnswer($this_id);
348 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
367 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
370 $source_questionpool = $this->
getObjId();
371 $clone->setObjId($target_questionpool);
436 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
437 if (array_key_exists($order, $this->answers))
441 $newchoices = array();
442 for ($i = 0; $i < $order; $i++)
444 array_push($newchoices, $this->answers[$i]);
446 array_push($newchoices, $answer);
447 for ($i = $order; $i < count($this->answers); $i++)
453 $this->answers = $newchoices;
459 array_push($this->answers, $answer);
472 return count($this->answers);
486 if ($index < 0)
return NULL;
487 if (count($this->answers) < 1)
return NULL;
488 if ($index >= count($this->answers))
return NULL;
490 return $this->answers[$index];
503 if ($index < 0)
return;
504 if (count($this->answers) < 1)
return;
505 if ($index >= count($this->answers))
return;
506 $answer = $this->answers[$index];
507 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
508 unset($this->answers[$index]);
509 $this->answers = array_values($this->answers);
510 for ($i = 0; $i < count($this->answers); $i++)
512 if ($this->answers[$i]->getOrder() > $index)
514 $this->answers[$i]->setOrder($i);
527 $this->answers = array();
539 foreach ($this->answers as $key => $value)
541 if ($value->getPoints() >
$points)
563 throw new ilTestException(
'return details not implemented for '.__METHOD__);
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'),
579 if (strcmp(
$data[
"value1"],
"") != 0)
581 array_push($found_values,
$data[
"value1"]);
585 foreach ($this->answers as $key => $answer)
587 if (count($found_values) > 0)
589 if (in_array($key, $found_values))
591 $points += $answer->getPoints();
614 include_once
"./Modules/Test/classes/class.ilObjTest.php";
619 $result = $ilDB->queryF(
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
620 array(
'integer',
'integer',
'integer'),
624 $update =
$row[
"solution_id"];
628 if (strlen(
$_POST[
"multiple_choice_result"]))
630 $affectedRows = $ilDB->update(
"tst_solutions", array(
631 "value1" => array(
"clob",
$_POST[
"multiple_choice_result"]),
632 "tstamp" => array(
"integer", time())
634 "solution_id" => array(
"integer", $update)
640 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE solution_id = %s",
648 if (strlen(
$_POST[
"multiple_choice_result"]))
650 $next_id = $ilDB->nextId(
'tst_solutions');
651 $affectedRows = $ilDB->insert(
"tst_solutions", array(
652 "solution_id" => array(
"integer", $next_id),
653 "active_fi" => array(
"integer", $active_id),
654 "question_fi" => array(
"integer", $this->
getId()),
655 "value1" => array(
"clob",
$_POST[
'multiple_choice_result']),
656 "value2" => array(
"clob", null),
657 "pass" => array(
"integer",
$pass),
658 "tstamp" => array(
"integer", time())
665 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
673 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
701 function syncFeedbackSingleAnswers()
708 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_sc WHERE question_fi = %s",
710 array($this->original_id)
714 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
716 array($this->
getId())
724 $next_id = $ilDB->nextId(
'qpl_fb_sc');
726 $ilDB->insert(
'qpl_fb_sc', array(
727 'feedback_id' => array(
'integer', $next_id ),
728 'question_fi' => array(
'integer', $this->original_id ),
729 'answer' => array(
'integer',
$row[
"answer"] ),
730 'feedback' => array(
'clob',
$row[
"feedback"] ),
731 'tstamp' => array(
'integer', time() ),
742 $this->syncFeedbackSingleAnswers();
756 return "assSingleChoice";
792 if (!empty($image_tempfilename))
794 $image_filename = str_replace(
" ",
"_", $image_filename);
796 if (!file_exists($imagepath))
807 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
809 if (!preg_match(
"/^image/", $mimetype))
811 unlink($imagepath . $image_filename);
836 @unlink($imagepath . $image_filename);
837 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
845 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
847 if( (
int)$objectId > 0 )
849 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $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);
882 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
883 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
884 foreach ($this->answers as $answer)
889 if (!file_exists($imagepath))
893 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
895 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
896 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
898 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
902 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
903 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
918 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
920 foreach ($this->answers as $answer)
925 if (@file_exists($imagepath .
$filename))
927 if (!file_exists($imagepath))
931 if (!file_exists($imagepath_original))
935 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
937 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
938 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
941 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
945 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
946 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
960 function saveFeedbackSingleAnswer($answer_index, $feedback)
964 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
965 array(
'integer',
'integer'),
966 array($this->
getId(), $answer_index)
968 if (strlen($feedback))
970 include_once(
"./Services/RTE/classes/class.ilRTE.php");
971 $next_id = $ilDB->nextId(
'qpl_fb_sc');
973 $ilDB->insert(
'qpl_fb_sc', array(
974 'feedback_id' => array(
'integer', $next_id ),
975 'question_fi' => array(
'integer', $this->
getId() ),
976 'answer' => array(
'integer', $answer_index ),
978 'tstamp' => array(
'integer', time() ),
996 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
997 array(
'integer',
'integer'),
998 array($this->
getId(), $answer_index)
1003 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1020 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
1028 $next_id = $ilDB->nextId(
'qpl_fb_sc');
1030 $ilDB->insert(
'qpl_fb_sc', array(
1031 'feedback_id' => array(
'integer', $next_id ),
1032 'question_fi' => array(
'integer', $this->
getId() ),
1033 'answer' => array(
'integer',
$row[
"answer"] ),
1034 'feedback' => array(
'clob',
$row[
"feedback"] ),
1035 'tstamp' => array(
'integer', time() ),
1049 foreach ($this->answers as $index => $answer)
1052 $answer_obj = $this->answers[$index];
1053 $text .= $answer_obj->getAnswertext();
1080 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
1088 if (
$id == $solution[0][
"value1"])
1090 $worksheet->write($startrow + $i, 1, 1);
1094 $worksheet->write($startrow + $i, 1, 0);
1098 return $startrow + $i + 1;
1108 $this->thumb_size = $a_size;
1116 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1131 foreach ($this->
getAnswers() as $key => $answer_obj)
1133 if((
string) $answer_obj->getImage())
1138 "answertext" => (
string) $this->
formatSAQuestion($answer_obj->getAnswertext()),
1139 "points" => (
float)$answer_obj->getPoints(),
1140 "order" => (int)$answer_obj->getOrder(),
1141 "image" => (string) $answer_obj->getImage(),
1160 $answer = $this->answers[$index];
1161 if (is_object($answer))
1164 $answer->setImage(
'');
1170 $value = rand(0, count($this->answers)-1);
1171 $_POST[
"multiple_choice_result"] = (strlen($value)) ? (
string)$value :
'0';
1179 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1180 if ($multilineAnswerSetting != 1)
1182 $multilineAnswerSetting = 0;
1184 return $multilineAnswerSetting;
1190 $ilUser->writePref(
"tst_multiline_answers", $a_setting);