23 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
24 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
87 $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))
103 foreach ($this->answers as $answer)
105 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0))
return false;
133 array($this->
getId())
138 $oldthumbsize =
$data[
'thumb_size'];
141 if (!$this->isSingleline)
147 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
149 array($this->
getId())
152 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, shuffle, allow_images, thumb_size) VALUES (%s, %s, %s, %s)",
153 array(
"integer",
"text",
"text",
"integer"),
157 ($this->isSingleline) ?
"0" :
"1",
162 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_a_sc WHERE question_fi = %s",
164 array($this->
getId())
167 foreach ($this->answers as $key => $value)
169 $answer_obj = $this->answers[$key];
170 $next_id = $ilDB->nextId(
'qpl_a_sc');
171 $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)",
172 array(
'integer',
'integer',
'text',
'float',
'integer',
'text',
'integer'),
177 $answer_obj->getPoints(),
178 $answer_obj->getOrder(),
179 $answer_obj->getImage(),
199 if (strlen($answer->getImage()))
220 switch (strtoupper($path_info[
'extension']))
256 $this->
setId($question_id);
265 include_once(
"./Services/RTE/classes/class.ilRTE.php");
271 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
272 $this->lastChange =
$data[
'tstamp'];
275 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
279 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
285 if (!@file_exists($imagefilename))
287 $data[
"imagefile"] =
"";
289 include_once(
"./Services/RTE/classes/class.ilRTE.php");
311 $this_id = $this->
getId();
313 if( (
int)$testObjId > 0 )
319 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
323 if( (
int)$testObjId > 0 )
325 $clone->setObjId($testObjId);
351 $clone->copyPageOfQuestion($this_id);
354 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
356 $clone->duplicateImages($this_id, $thisObjId);
358 $clone->duplicateFeedbackGeneric($this_id);
360 $clone->duplicateFeedbackAnswer($this_id);
362 $clone->onDuplicate($thisObjId, $this_id, $clone->getObjId(), $clone->getId());
381 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
384 $source_questionpool = $this->
getObjId();
385 $clone->setObjId($target_questionpool);
450 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
451 if (array_key_exists($order, $this->answers))
455 $newchoices = array();
456 for ($i = 0; $i < $order; $i++)
458 array_push($newchoices, $this->answers[$i]);
460 array_push($newchoices, $answer);
461 for ($i = $order; $i < count($this->answers); $i++)
467 $this->answers = $newchoices;
473 array_push($this->answers, $answer);
486 return count($this->answers);
500 if ($index < 0)
return NULL;
501 if (count($this->answers) < 1)
return NULL;
502 if ($index >= count($this->answers))
return NULL;
504 return $this->answers[$index];
517 if ($index < 0)
return;
518 if (count($this->answers) < 1)
return;
519 if ($index >= count($this->answers))
return;
520 $answer = $this->answers[$index];
521 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
522 unset($this->answers[$index]);
523 $this->answers = array_values($this->answers);
524 for ($i = 0; $i < count($this->answers); $i++)
526 if ($this->answers[$i]->getOrder() > $index)
528 $this->answers[$i]->setOrder($i);
541 $this->answers = array();
553 foreach ($this->answers as $key => $value)
555 if ($value->getPoints() >
$points)
576 $found_values = array();
581 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
582 array(
'integer',
'integer',
'integer'),
587 if (strcmp(
$data[
"value1"],
"") != 0)
589 array_push($found_values,
$data[
"value1"]);
593 foreach ($this->answers as $key => $answer)
595 if (count($found_values) > 0)
597 if (in_array($key, $found_values))
599 $points += $answer->getPoints();
623 include_once
"./Modules/Test/classes/class.ilObjTest.php";
628 $result = $ilDB->queryF(
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
629 array(
'integer',
'integer',
'integer'),
633 $update =
$row[
"solution_id"];
637 if (strlen(
$_POST[
"multiple_choice_result"]))
639 $affectedRows = $ilDB->update(
"tst_solutions", array(
640 "value1" => array(
"clob",
$_POST[
"multiple_choice_result"]),
641 "tstamp" => array(
"integer", time())
643 "solution_id" => array(
"integer", $update)
649 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE solution_id = %s",
657 if (strlen(
$_POST[
"multiple_choice_result"]))
659 $next_id = $ilDB->nextId(
'tst_solutions');
660 $affectedRows = $ilDB->insert(
"tst_solutions", array(
661 "solution_id" => array(
"integer", $next_id),
662 "active_fi" => array(
"integer", $active_id),
663 "question_fi" => array(
"integer", $this->
getId()),
664 "value1" => array(
"clob",
$_POST[
'multiple_choice_result']),
665 "value2" => array(
"clob", null),
666 "pass" => array(
"integer",
$pass),
667 "tstamp" => array(
"integer", time())
674 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
682 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
697 function syncFeedbackSingleAnswers()
704 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_sc WHERE question_fi = %s",
706 array($this->original_id)
710 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
712 array($this->
getId())
720 $next_id = $ilDB->nextId(
'qpl_fb_sc');
723 $ilDB->insert(
'qpl_fb_sc', array(
724 'feedback_id' => array(
'integer', $next_id ),
725 'question_fi' => array(
'integer', $this->original_id ),
726 'answer' => array(
'integer',
$row[
"answer"] ),
727 'feedback' => array(
'clob',
$row[
"feedback"] ),
728 'tstamp' => array(
'integer', time() ),
740 $this->syncFeedbackSingleAnswers();
754 return "assSingleChoice";
790 if (!empty($image_tempfilename))
792 $image_filename = str_replace(
" ",
"_", $image_filename);
794 if (!file_exists($imagepath))
805 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
807 if (!preg_match(
"/^image/", $mimetype))
809 unlink($imagepath . $image_filename);
834 @unlink($imagepath . $image_filename);
835 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
843 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
845 if( (
int)$objectId > 0 )
847 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$objectId/", $imagepath_original);
850 foreach ($this->answers as $answer)
855 if (!file_exists($imagepath))
859 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
861 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
862 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
864 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
868 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
869 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
880 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
881 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
882 foreach ($this->answers as $answer)
887 if (!file_exists($imagepath))
891 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
893 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
894 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
896 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
900 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
901 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
916 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
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);
958 function saveFeedbackSingleAnswer($answer_index, $feedback)
962 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
963 array(
'integer',
'integer'),
964 array($this->
getId(), $answer_index)
966 if (strlen($feedback))
968 include_once(
"./Services/RTE/classes/class.ilRTE.php");
969 $next_id = $ilDB->nextId(
'qpl_fb_sc');
972 $ilDB->insert(
'qpl_fb_sc', array(
973 'feedback_id' => array(
'integer', $next_id ),
974 'question_fi' => array(
'integer', $this->
getId() ),
975 'answer' => array(
'integer', $answer_index ),
977 'tstamp' => array(
'integer', time() ),
995 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
996 array(
'integer',
'integer'),
997 array($this->
getId(), $answer_index)
1002 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1019 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
1027 $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) $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);