23 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
24 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
81 $this->answers = array();
94 if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->
getMaximumPoints() > 0))
96 foreach ($this->answers as $answer)
98 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0))
return false;
126 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
137 include_once(
"./Services/RTE/classes/class.ilRTE.php");
142 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
144 $query = sprintf(
"INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
145 $ilDB->quote($this->getQuestionTypeID() .
""),
146 $ilDB->quote($this->obj_id),
147 $ilDB->quote($this->title),
148 $ilDB->quote($this->comment),
149 $ilDB->quote($this->author),
150 $ilDB->quote($this->owner),
153 $ilDB->quote($estw_time),
154 $ilDB->quote(
"$complete"),
155 $ilDB->quote($created),
158 $result = $ilDB->query($query);
159 if (PEAR::isError($result))
162 $ilias->raiseError($result->getMessage());
166 $this->
id = $ilDB->getLastInsertId();
167 $query = sprintf(
"INSERT INTO qpl_question_singlechoice (question_fi, shuffle) VALUES (%s, %s)",
168 $ilDB->quote($this->id .
""),
169 $ilDB->quote(
"$this->shuffle")
171 $ilDB->query($query);
186 $query = sprintf(
"UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
187 $ilDB->quote($this->obj_id.
""),
188 $ilDB->quote($this->title),
189 $ilDB->quote($this->comment),
190 $ilDB->quote($this->author),
193 $ilDB->quote($estw_time),
194 $ilDB->quote(
"$complete"),
195 $ilDB->quote($this->
id)
197 $result = $ilDB->query($query);
198 $query = sprintf(
"UPDATE qpl_question_singlechoice SET shuffle = %s WHERE question_fi = %s",
199 $ilDB->quote(
"$this->shuffle"),
200 $ilDB->quote($this->
id .
"")
202 $result = $ilDB->query($query);
207 $ilias->raiseError(
$result->getMessage());
213 $query = sprintf(
"DELETE FROM qpl_answer_singlechoice WHERE question_fi = %s",
214 $ilDB->quote($this->id)
216 $result = $ilDB->query($query);
219 foreach ($this->answers as $key => $value)
221 $answer_obj = $this->answers[$key];
222 $query = sprintf(
"INSERT INTO qpl_answer_singlechoice (answer_id, question_fi, answertext, points, aorder, imagefile) VALUES (NULL, %s, %s, %s, %s, %s)",
223 $ilDB->quote($this->id),
225 $ilDB->quote($answer_obj->getPoints() .
""),
226 $ilDB->quote($answer_obj->getOrder() .
""),
227 $ilDB->quote($answer_obj->getImage() .
"")
229 $answer_result = $ilDB->query($query);
249 $query = sprintf(
"SELECT qpl_questions.*, qpl_question_singlechoice.* FROM qpl_questions, qpl_question_singlechoice WHERE question_id = %s AND qpl_questions.question_id = qpl_question_singlechoice.question_fi",
250 $ilDB->quote($question_id));
251 $result = $ilDB->query($query);
252 if ($result->numRows() == 1)
254 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
255 $this->
id = $question_id;
256 $this->title =
$data->title;
257 $this->comment =
$data->comment;
258 $this->solution_hint =
$data->solution_hint;
259 $this->original_id =
$data->original_id;
260 $this->obj_id =
$data->obj_fi;
261 $this->author =
$data->author;
262 $this->owner =
$data->owner;
263 $this->points =
$data->points;
264 include_once(
"./Services/RTE/classes/class.ilRTE.php");
269 $query = sprintf(
"SELECT * FROM qpl_answer_singlechoice WHERE question_fi = %s ORDER BY aorder ASC",
270 $ilDB->quote($question_id));
272 $result = $ilDB->query($query);
274 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
275 if ($result->numRows() > 0)
277 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
280 if (!@file_exists($imagefilename))
282 $data->imagefile =
"";
284 include_once(
"./Services/RTE/classes/class.ilRTE.php");
286 if (strlen(
$data->imagefile)) $hasimages = 1;
311 $this_id = $this->
getId();
313 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
340 $clone->copyPageOfQuestion($this_id);
342 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
344 $clone->duplicateImages($this_id);
346 $clone->duplicateFeedbackGeneric($this_id);
348 $clone->duplicateFeedbackAnswer($this_id);
369 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
372 $source_questionpool = $this->
getObjId();
373 $clone->setObjId($target_questionpool);
440 $points_unchecked = 0.0,
446 foreach ($this->answers as $key => $value)
448 if ($value->getOrder() == $order)
453 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
458 array_push($this->answers, $answer);
459 for ($i = $found + 1; $i < count($this->answers); $i++)
461 $this->answers[$i] = $this->answers[$i-1];
463 $this->answers[$found] = $answer;
469 array_push($this->answers, $answer);
484 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];
519 if ($index < 0)
return;
520 if (count($this->answers) < 1)
return;
521 if ($index >= count($this->answers))
return;
522 $answer = $this->answers[$index];
523 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
524 unset($this->answers[$index]);
525 $this->answers = array_values($this->answers);
526 for ($i = 0; $i < count($this->answers); $i++)
528 if ($this->answers[$i]->getOrder() > $index)
530 $this->answers[$i]->setOrder($i);
545 $this->answers = array();
559 foreach ($this->answers as $key => $value)
561 if ($value->getPoints() >
$points)
584 $found_values = array();
589 $query = sprintf(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
590 $ilDB->quote($active_id .
""),
591 $ilDB->quote($this->
getId() .
""),
592 $ilDB->quote(
$pass .
"")
594 $result = $ilDB->query($query);
595 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
597 if (strcmp(
$data->value1,
"") != 0)
599 array_push($found_values,
$data->value1);
603 foreach ($this->answers as $key => $answer)
605 if (count($found_values) > 0)
607 if (in_array($key, $found_values))
609 $points += $answer->getPoints();
635 include_once
"./Modules/Test/classes/class.ilObjTest.php";
640 $query = sprintf(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
641 $ilDB->quote($active_id .
""),
642 $ilDB->quote($this->
getId() .
""),
643 $ilDB->quote(
$pass .
"")
645 $result = $ilDB->query($query);
646 $row = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
647 $update = $row->solution_id;
650 if (strlen($_POST[
"multiple_choice_result"]))
652 $query = sprintf(
"UPDATE tst_solutions SET value1 = %s WHERE solution_id = %s",
653 $ilDB->quote($_POST[
"multiple_choice_result"]),
654 $ilDB->quote($update)
656 $result = $ilDB->query($query);
661 $query = sprintf(
"DELETE FROM tst_solutions WHERE solution_id = %s",
662 $ilDB->quote($update)
664 $result = $ilDB->query($query);
669 if (strlen($_POST[
"multiple_choice_result"]))
671 $query = sprintf(
"INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
672 $ilDB->quote($active_id),
673 $ilDB->quote($this->
getId()),
674 $ilDB->quote($_POST[
"multiple_choice_result"]),
675 $ilDB->quote(
$pass .
"")
677 $result = $ilDB->query($query);
683 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
691 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
715 $deletequery = sprintf(
"DELETE FROM qpl_feedback_singlechoice WHERE question_fi = %s",
716 $ilDB->quote($this->original_id .
"")
718 $result = $ilDB->query($deletequery);
721 $query = sprintf(
"SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s",
722 $ilDB->quote($this->getId() .
"")
724 $result = $ilDB->query($query);
727 if ($result->numRows())
729 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
731 $duplicatequery = sprintf(
"INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
732 $ilDB->quote($this->original_id .
""),
733 $ilDB->quote($row[
"answer"] .
""),
734 $ilDB->quote($row[
"feedback"] .
"")
736 $duplicateresult = $ilDB->query($duplicatequery);
761 return "assSingleChoice";
774 return "qpl_question_singlechoice";
787 return "qpl_answer_singlechoice";
794 $graphicalAnswerSetting = $ilUser->getPref(
"graphicalAnswerSetting");
795 if ($graphicalAnswerSetting != 1)
797 $graphicalAnswerSetting = 0;
799 return $graphicalAnswerSetting;
805 $ilUser->writePref(
"graphicalAnswerSetting", $a_setting);
821 if (!empty($image_tempfilename))
823 $image_filename = str_replace(
" ",
"_", $image_filename);
825 if (!file_exists($imagepath))
836 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
838 if (!preg_match(
"/^image/", $mimetype))
840 unlink($imagepath . $image_filename);
846 $thumbpath = $imagepath . $image_filename .
"." .
"thumb.jpg";
865 unlink($imagepath . $image_filename);
866 $thumbpath = $imagepath . $image_filename .
"." .
"thumb.jpg";
874 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
875 foreach ($this->answers as $answer)
880 if (!file_exists($imagepath))
884 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
886 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
887 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
889 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg"))
891 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
892 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
902 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
903 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
904 foreach ($this->answers as $answer)
909 if (!file_exists($imagepath))
913 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
915 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
916 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
918 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg"))
920 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
921 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
935 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
937 foreach ($this->answers as $answer)
942 if (!file_exists($imagepath))
946 if (!file_exists($imagepath_original))
950 if (@file_exists($imagepath .
$filename))
952 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
954 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
955 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
958 if (@file_exists($imagepath . $filename .
".thumb.jpg"))
960 if (!@copy($imagepath . $filename .
".thumb.jpg", $imagepath_original . $filename .
".thumb.jpg"))
962 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
963 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
983 $query = sprintf(
"DELETE FROM qpl_feedback_singlechoice WHERE question_fi = %s AND answer = %s",
984 $ilDB->quote($this->getId() .
""),
985 $ilDB->quote($answer_index .
"")
987 $result = $ilDB->query($query);
988 if (strlen($feedback))
990 include_once(
"./Services/RTE/classes/class.ilRTE.php");
991 $query = sprintf(
"INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
992 $ilDB->quote($this->getId() .
""),
993 $ilDB->quote($answer_index .
""),
996 $result = $ilDB->query($query);
1014 $query = sprintf(
"SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s AND answer = %s",
1015 $ilDB->quote($this->getId() .
""),
1016 $ilDB->quote($answer_index .
"")
1018 $result = $ilDB->query($query);
1019 if ($result->numRows())
1021 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
1022 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1041 $query = sprintf(
"SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s",
1044 $result = $ilDB->query($query);
1045 if ($result->numRows())
1047 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1049 $duplicatequery = sprintf(
"INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
1050 $ilDB->quote($this->getId() .
""),
1051 $ilDB->quote($row[
"answer"] .
""),
1052 $ilDB->quote($row[
"feedback"] .
"")
1054 $duplicateresult = $ilDB->query($duplicatequery);
1066 foreach ($this->answers as $index => $answer)
1069 $answer_obj = $this->answers[$index];
1070 $text .= $answer_obj->getAnswertext();
1097 include_once (
"./classes/class.ilExcelUtils.php");
1105 if (
$id == $solution[0][
"value1"])
1107 $worksheet->write($startrow + $i, 1, 1);
1111 $worksheet->write($startrow + $i, 1, 0);
1115 return $startrow + $i + 1;