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))
123 $estw_time = sprintf(
"%02d:%02d:%02d", $estw_time[
'h'], $estw_time[
'm'], $estw_time[
's']);
134 include_once(
"./Services/RTE/classes/class.ilRTE.php");
141 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
142 $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)",
143 $ilDB->quote($question_type),
144 $ilDB->quote($this->obj_id),
145 $ilDB->quote($this->title),
146 $ilDB->quote($this->comment),
147 $ilDB->quote($this->author),
148 $ilDB->quote($this->owner),
151 $ilDB->quote($estw_time),
152 $ilDB->quote(
"$complete"),
153 $ilDB->quote($created),
156 $result = $ilDB->query($query);
158 if (PEAR::isError($result))
161 $ilias->raiseError($result->getMessage());
165 $this->
id = $ilDB->getLastInsertId();
166 $query = sprintf(
"INSERT INTO qpl_question_multiplechoice (question_fi, shuffle) VALUES (%s, %s)",
167 $ilDB->quote($this->id .
""),
168 $ilDB->quote(
"$this->shuffle")
170 $ilDB->query($query);
185 $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",
186 $ilDB->quote($this->obj_id.
""),
187 $ilDB->quote($this->title),
188 $ilDB->quote($this->comment),
189 $ilDB->quote($this->author),
192 $ilDB->quote($estw_time),
193 $ilDB->quote(
"$complete"),
194 $ilDB->quote($this->
id)
196 $result = $ilDB->query($query);
197 $query = sprintf(
"UPDATE qpl_question_multiplechoice SET shuffle = %s WHERE question_fi = %s",
198 $ilDB->quote(
"$this->shuffle"),
199 $ilDB->quote($this->
id .
"")
201 $result = $ilDB->query($query);
207 $ilias->raiseError(
$result->getMessage());
213 $query = sprintf(
"DELETE FROM qpl_answer_multiplechoice 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];
223 $query = sprintf(
"INSERT INTO qpl_answer_multiplechoice (answer_id, question_fi, answertext, points, points_unchecked, aorder, imagefile) VALUES (NULL, %s, %s, %s, %s, %s, %s)",
224 $ilDB->quote($this->id),
226 $ilDB->quote($answer_obj->getPoints() .
""),
227 $ilDB->quote($answer_obj->getPointsUnchecked() .
""),
228 $ilDB->quote($answer_obj->getOrder() .
""),
229 $ilDB->quote($answer_obj->getImage() .
"")
231 $answer_result = $ilDB->query($query);
252 $query = sprintf(
"SELECT qpl_questions.*, qpl_question_multiplechoice.* FROM qpl_questions, qpl_question_multiplechoice WHERE question_id = %s AND qpl_questions.question_id = qpl_question_multiplechoice.question_fi",
253 $ilDB->quote($question_id));
254 $result = $ilDB->query($query);
255 if ($result->numRows() == 1)
257 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
258 $this->
id = $question_id;
259 $this->title =
$data->title;
260 $this->comment =
$data->comment;
261 $this->solution_hint =
$data->solution_hint;
262 $this->original_id =
$data->original_id;
263 $this->obj_id =
$data->obj_fi;
264 $this->author =
$data->author;
265 $this->owner =
$data->owner;
266 $this->points =
$data->points;
267 include_once(
"./Services/RTE/classes/class.ilRTE.php");
272 $query = sprintf(
"SELECT * FROM qpl_answer_multiplechoice WHERE question_fi = %s ORDER BY aorder ASC",
273 $ilDB->quote($question_id));
275 $result = $ilDB->query($query);
277 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
278 if ($result->numRows() > 0)
280 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
283 if (!@file_exists($imagefilename))
285 $data->imagefile =
"";
287 include_once(
"./Services/RTE/classes/class.ilRTE.php");
289 if (strlen(
$data->imagefile)) $hasimages = 1;
326 $this_id = $this->
getId();
328 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
355 $clone->copyPageOfQuestion($this_id);
357 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
359 $clone->duplicateImages($this_id);
361 $clone->duplicateFeedbackGeneric($this_id);
363 $clone->duplicateFeedbackAnswer($this_id);
384 include_once (
"./Modules/TestQuestionPool/classes/class.assQuestion.php");
387 $source_questionpool = $this->
getObjId();
388 $clone->setObjId($target_questionpool);
455 $points_unchecked = 0.0,
461 foreach ($this->answers as $key => $value)
463 if ($value->getOrder() == $order)
468 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
473 array_push($this->answers, $answer);
474 for ($i = $found + 1; $i < count($this->answers); $i++)
476 $this->answers[$i] = $this->answers[$i-1];
478 $this->answers[$found] = $answer;
484 array_push($this->answers, $answer);
499 return count($this->answers);
515 if ($index < 0)
return NULL;
516 if (count($this->answers) < 1)
return NULL;
517 if ($index >= count($this->answers))
return NULL;
519 return $this->answers[$index];
534 if ($index < 0)
return;
535 if (count($this->answers) < 1)
return;
536 if ($index >= count($this->answers))
return;
537 $answer = $this->answers[$index];
538 if (strlen($answer->getImage())) $this->
deleteImage($answer->getImage());
539 unset($this->answers[$index]);
540 $this->answers = array_values($this->answers);
541 for ($i = 0; $i < count($this->answers); $i++)
543 if ($this->answers[$i]->getOrder() > $index)
545 $this->answers[$i]->setOrder($i);
560 $this->answers = array();
575 foreach ($this->answers as $key => $value)
577 if ($value->getPoints() > $value->getPointsUnchecked())
579 $allpoints += $value->getPoints();
583 $allpoints += $value->getPointsUnchecked();
604 $found_values = array();
609 $query = sprintf(
"SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
610 $ilDB->quote($active_id .
""),
611 $ilDB->quote($this->
getId() .
""),
612 $ilDB->quote(
$pass .
"")
614 $result = $ilDB->query($query);
615 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
617 if (strcmp(
$data->value1,
"") != 0)
619 array_push($found_values,
$data->value1);
623 foreach ($this->answers as $key => $answer)
625 if (in_array($key, $found_values))
627 $points += $answer->getPoints();
631 $points += $answer->getPointsUnchecked();
634 include_once
"./Modules/Test/classes/class.ilObjTest.php";
636 if (($mc_scoring == 0) && (count($found_values) == 0))
661 include_once
"./Modules/Test/classes/class.ilObjTest.php";
666 $query = sprintf(
"DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
667 $ilDB->quote($active_id .
""),
668 $ilDB->quote($this->
getId() .
""),
669 $ilDB->quote(
$pass .
"")
671 $result = $ilDB->query($query);
672 foreach ($_POST as $key => $value)
674 if (preg_match(
"/^multiple_choice_result_(\d+)/", $key, $matches))
678 $query = sprintf(
"INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
679 $ilDB->quote($active_id),
680 $ilDB->quote($this->
getId()),
681 $ilDB->quote($value),
682 $ilDB->quote(
$pass .
"")
684 $result = $ilDB->query($query);
691 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
699 include_once (
"./Modules/Test/classes/class.ilObjAssessmentFolder.php");
723 $deletequery = sprintf(
"DELETE FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
724 $ilDB->quote($this->original_id .
"")
726 $result = $ilDB->query($deletequery);
729 $query = sprintf(
"SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
730 $ilDB->quote($this->getId() .
"")
732 $result = $ilDB->query($query);
735 if ($result->numRows())
737 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
739 $duplicatequery = sprintf(
"INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
740 $ilDB->quote($this->original_id .
""),
741 $ilDB->quote($row[
"answer"] .
""),
742 $ilDB->quote($row[
"feedback"] .
"")
744 $duplicateresult = $ilDB->query($duplicatequery);
769 return "assMultipleChoice";
782 return "qpl_question_multiplechoice";
795 return "qpl_answer_multiplechoice";
802 $graphicalAnswerSetting = $ilUser->getPref(
"graphicalAnswerSetting");
803 if ($graphicalAnswerSetting != 1)
805 $graphicalAnswerSetting = 0;
807 return $graphicalAnswerSetting;
813 $ilUser->writePref(
"graphicalAnswerSetting", $a_setting);
829 if (!empty($image_tempfilename))
831 $image_filename = str_replace(
" ",
"_", $image_filename);
833 if (!file_exists($imagepath))
844 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
846 if (!preg_match(
"/^image/", $mimetype))
848 unlink($imagepath . $image_filename);
854 $thumbpath = $imagepath . $image_filename .
"." .
"thumb.jpg";
873 unlink($imagepath . $image_filename);
874 $thumbpath = $imagepath . $image_filename .
"." .
"thumb.jpg";
882 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
883 foreach ($this->answers as $answer)
888 if (!file_exists($imagepath))
892 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
894 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
895 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
897 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg"))
899 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
900 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
910 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
911 $imagepath_original = str_replace(
"/$this->obj_id/",
"/$source_questionpool/", $imagepath_original);
912 foreach ($this->answers as $answer)
917 if (!file_exists($imagepath))
921 if (!copy($imagepath_original .
$filename, $imagepath . $filename))
923 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
924 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
926 if (!copy($imagepath_original . $filename .
".thumb.jpg", $imagepath . $filename .
".thumb.jpg"))
928 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
929 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
943 $imagepath_original = str_replace(
"/$this->id/images",
"/$question_id/images", $imagepath);
945 foreach ($this->answers as $answer)
950 if (!file_exists($imagepath))
954 if (!file_exists($imagepath_original))
958 if (@file_exists($imagepath .
$filename))
960 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
962 $ilLog->write(
"image could not be duplicated!!!!", $ilLog->ERROR);
963 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
966 if (@file_exists($imagepath . $filename .
".thumb.jpg"))
968 if (!@copy($imagepath . $filename .
".thumb.jpg", $imagepath_original . $filename .
".thumb.jpg"))
970 $ilLog->write(
"image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
971 $ilLog->write(
"object: " . print_r($this, TRUE), $ilLog->ERROR);
991 $query = sprintf(
"DELETE FROM qpl_feedback_multiplechoice WHERE question_fi = %s AND answer = %s",
992 $ilDB->quote($this->getId() .
""),
993 $ilDB->quote($answer_index .
"")
995 $result = $ilDB->query($query);
996 if (strlen($feedback))
998 include_once(
"./Services/RTE/classes/class.ilRTE.php");
999 $query = sprintf(
"INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
1000 $ilDB->quote($this->getId() .
""),
1001 $ilDB->quote($answer_index .
""),
1004 $result = $ilDB->query($query);
1022 $query = sprintf(
"SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s AND answer = %s",
1023 $ilDB->quote($this->getId() .
""),
1024 $ilDB->quote($answer_index .
"")
1026 $result = $ilDB->query($query);
1027 if ($result->numRows())
1029 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
1030 include_once(
"./Services/RTE/classes/class.ilRTE.php");
1049 $query = sprintf(
"SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
1052 $result = $ilDB->query($query);
1053 if ($result->numRows())
1055 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
1057 $duplicatequery = sprintf(
"INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
1058 $ilDB->quote($this->getId() .
""),
1059 $ilDB->quote($row[
"answer"] .
""),
1060 $ilDB->quote($row[
"feedback"] .
"")
1062 $duplicateresult = $ilDB->query($duplicatequery);
1074 foreach ($this->answers as $index => $answer)
1077 $answer_obj = $this->answers[$index];
1078 $text .= $answer_obj->getAnswertext();
1105 include_once (
"./classes/class.ilExcelUtils.php");
1114 foreach ($solution as $solutionvalue)
1116 if (
$id == $solutionvalue[
"value1"])
1123 $worksheet->write($startrow + $i, 1, 1);
1127 $worksheet->write($startrow + $i, 1, 0);
1131 return $startrow + $i + 1;