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 (($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;
131 $result = $ilDB->queryF(
"SELECT thumb_size FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
133 array($this->
getId())
135 if ($result->numRows() == 1)
137 $data = $ilDB->fetchAssoc($result);
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(),
198 if (strlen($answer->getImage()))
219 switch (strtoupper($path_info[
'extension']))
252 if ($result->numRows() == 1)
254 $data = $ilDB->fetchAssoc($result);
255 $this->
setId($question_id);
264 include_once(
"./Services/RTE/classes/class.ilRTE.php");
270 $this->isSingleline = (
$data[
'allow_images']) ?
false :
true;
271 $this->lastChange =
$data[
'tstamp'];
274 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
278 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
279 if ($result->numRows() > 0)
281 while (
$data = $ilDB->fetchAssoc($result))
284 if (!@file_exists($imagefilename))
286 $data[
"imagefile"] =
"";
288 include_once(
"./Services/RTE/classes/class.ilRTE.php");
310 $this_id = $this->
getId();
312 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
338 $clone->copyPageOfQuestion($this_id);
341 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
343 $clone->duplicateImages($this_id);
345 $clone->duplicateFeedbackGeneric($this_id);
347 $clone->duplicateFeedbackAnswer($this_id);
348 $clone->onDuplicate($this_id);
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)
562 $found_values = array();
567 $result = $ilDB->queryF(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
568 array(
'integer',
'integer',
'integer'),
571 while (
$data = $ilDB->fetchAssoc($result))
573 if (strcmp(
$data[
"value1"],
"") != 0)
575 array_push($found_values,
$data[
"value1"]);
579 foreach ($this->answers as $key => $answer)
581 if (count($found_values) > 0)
583 if (in_array($key, $found_values))
585 $points += $answer->getPoints();
609 include_once
"./Modules/Test/classes/class.ilObjTest.php";
614 $result = $ilDB->queryF(
"SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
615 array(
'integer',
'integer',
'integer'),
618 $row = $ilDB->fetchAssoc($result);
619 $update =
$row[
"solution_id"];
623 if (strlen(
$_POST[
"multiple_choice_result"]))
625 $affectedRows = $ilDB->update(
"tst_solutions", array(
626 "value1" => array(
"clob",
$_POST[
"multiple_choice_result"]),
627 "tstamp" => array(
"integer", time())
629 "solution_id" => array(
"integer", $update)
635 $affectedRows = $ilDB->manipulateF(
"DELETE FROM tst_solutions WHERE solution_id = %s",
643 if (strlen(
$_POST[
"multiple_choice_result"]))
645 $next_id = $ilDB->nextId(
'tst_solutions');
646 $affectedRows = $ilDB->insert(
"tst_solutions", array(
647 "solution_id" => array(
"integer", $next_id),
648 "active_fi" => array(
"integer", $active_id),
649 "question_fi" => array(
"integer", $this->
getId()),
650 "value1" => array(
"clob",
$_POST[
'multiple_choice_result']),
651 "value2" => array(
"clob", null),
652 "pass" => array(
"integer",
$pass),
653 "tstamp" => array(
"integer", time())
660 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
668 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
690 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_sc WHERE question_fi = %s",
692 array($this->original_id)
696 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
698 array($this->
getId())
702 if ($result->numRows())
704 while (
$row = $ilDB->fetchAssoc($result))
706 $next_id = $ilDB->nextId(
'qpl_fb_sc');
707 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_fb_sc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
708 array(
'integer',
'integer',
'integer',
'text',
'integer'),
739 return "assSingleChoice";
775 if (!empty($image_tempfilename))
777 $image_filename = str_replace(
" ",
"_", $image_filename);
779 if (!file_exists($imagepath))
790 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
792 if (!preg_match(
"/^image/", $mimetype))
794 unlink($imagepath . $image_filename);
819 @unlink($imagepath . $image_filename);
820 $thumbpath = $imagepath . $this->
getThumbPrefix() . $image_filename;
828 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
829 foreach ($this->answers as $answer)
834 if (!file_exists($imagepath))
838 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
840 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
841 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
843 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
847 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
848 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
859 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
860 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
861 foreach ($this->answers as $answer)
866 if (!file_exists($imagepath))
870 if (!@copy($imagepath_original .
$filename, $imagepath . $filename))
872 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
873 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
875 if (@file_exists($imagepath_original. $this->getThumbPrefix().
$filename))
879 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
880 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
895 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
897 foreach ($this->answers as $answer)
902 if (@file_exists($imagepath .
$filename))
904 if (!file_exists($imagepath))
908 if (!file_exists($imagepath_original))
912 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
914 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
915 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
918 if (@file_exists($imagepath . $this->
getThumbPrefix() . $filename))
922 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
923 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
941 $affectedRows = $ilDB->manipulateF(
"DELETE FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
942 array(
'integer',
'integer'),
943 array($this->
getId(), $answer_index)
945 if (strlen($feedback))
947 include_once(
"./Services/RTE/classes/class.ilRTE.php");
948 $next_id = $ilDB->nextId(
'qpl_fb_sc');
949 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_fb_sc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
950 array(
'integer',
'integer',
'integer',
'text',
'integer'),
974 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s AND answer = %s",
975 array(
'integer',
'integer'),
976 array($this->
getId(), $answer_index)
978 if ($result->numRows())
980 $row = $ilDB->fetchAssoc($result);
981 include_once(
"./Services/RTE/classes/class.ilRTE.php");
998 $result = $ilDB->queryF(
"SELECT * FROM qpl_fb_sc WHERE question_fi = %s",
1002 if ($result->numRows())
1004 while (
$row = $ilDB->fetchAssoc($result))
1006 $next_id = $ilDB->nextId(
'qpl_fb_sc');
1007 $affectedRows = $ilDB->manipulateF(
"INSERT INTO qpl_fb_sc (feedback_id, question_fi, answer, feedback, tstamp) VALUES (%s, %s, %s, %s, %s)",
1008 array(
'integer',
'integer',
'integer',
'text',
'integer'),
1028 foreach ($this->answers as $index => $answer)
1031 $answer_obj = $this->answers[$index];
1032 $text .= $answer_obj->getAnswertext();
1049 $result = $ilDB->queryF(
"SELECT * FROM qpl_a_sc WHERE question_fi = %s ORDER BY aorder ASC",
1054 if ($result->numRows() > 0)
1056 while (
$data = $ilDB->fetchAssoc($result))
1076 $adapter->setCellValue($startrow, 0, $this->lng->txt($this->getQuestionType()),
CELL_FORMAT_TITLE);
1081 $adapter->setCellValue($startrow+$i, 0, $answer->getAnswertext(),
CELL_FORMAT_BOLD);
1082 if (
$id == $solution[0][
"value1"] && strlen($solution[0][
"value1"]) > 0)
1084 $adapter->setCellValue($startrow+$i, 1, 1);
1088 $adapter->setCellValue($startrow+$i, 1, 0);
1092 return $startrow + $i + 1;
1102 $this->thumb_size = $a_size;
1110 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1112 $result[
'id'] = (int) $this->
getId();
1114 $result[
'title'] = (string) $this->
getTitle();
1117 $result[
'shuffle'] = (bool) $this->
getShuffle();
1118 $result[
'feedback'] = array(
1123 foreach ($this->
getAnswers() as $key => $answer_obj)
1126 "answertext" => (
string) $answer_obj->getAnswertext(),
1127 "points" => (float)$answer_obj->getPoints(),
1128 "order" => (int)$answer_obj->getOrder(),
1129 "image" => $answer_obj->getImage(),
1135 $result[
'mobs'] =
$mobs;
1136 return json_encode($result);
1141 $answer = $this->answers[$index];
1142 if (is_object($answer))
1145 $answer->setImage(
'');
1151 $value = rand(0, count($this->answers)-1);
1152 $_POST[
"multiple_choice_result"] = (strlen($value)) ? (
string)$value :
'0';
1160 $multilineAnswerSetting = $ilUser->getPref(
"tst_multiline_answers");
1161 if ($multilineAnswerSetting != 1)
1163 $multilineAnswerSetting = 0;
1165 return $multilineAnswerSetting;
1171 $ilUser->writePref(
"tst_multiline_answers", $a_setting);