00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00024 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00025
00035 class assSingleChoice extends assQuestion
00036 {
00044 var $answers;
00045
00054 var $output_type;
00055
00070 function assSingleChoice(
00071 $title = "",
00072 $comment = "",
00073 $author = "",
00074 $owner = -1,
00075 $question = "",
00076 $output_type = OUTPUT_ORDER
00077 )
00078 {
00079 $this->assQuestion($title, $comment, $author, $owner, $question);
00080 $this->output_type = $output_type;
00081 $this->answers = array();
00082 }
00083
00092 function isComplete()
00093 {
00094 if (($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
00095 {
00096 foreach ($this->answers as $answer)
00097 {
00098 if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) return false;
00099 }
00100 return true;
00101 }
00102 else
00103 {
00104 return false;
00105 }
00106 }
00107
00116 function saveToDb($original_id = "")
00117 {
00118 global $ilDB;
00119
00120 $complete = 0;
00121 if ($this->isComplete())
00122 {
00123 $complete = 1;
00124 }
00125 $estw_time = $this->getEstimatedWorkingTime();
00126 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00127
00128 if ($original_id)
00129 {
00130 $original_id = $ilDB->quote($original_id);
00131 }
00132 else
00133 {
00134 $original_id = "NULL";
00135 }
00136
00137 include_once("./Services/RTE/classes/class.ilRTE.php");
00138 if ($this->id == -1)
00139 {
00140
00141 $now = getdate();
00142 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00143 $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)",
00144 $ilDB->quote($this->getQuestionTypeID() . ""),
00145 $ilDB->quote($this->obj_id),
00146 $ilDB->quote($this->title),
00147 $ilDB->quote($this->comment),
00148 $ilDB->quote($this->author),
00149 $ilDB->quote($this->owner),
00150 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00151 $ilDB->quote($this->getMaximumPoints() . ""),
00152 $ilDB->quote($estw_time),
00153 $ilDB->quote("$complete"),
00154 $ilDB->quote($created),
00155 $original_id
00156 );
00157 $result = $ilDB->query($query);
00158
00159 if ($result == DB_OK)
00160 {
00161 $this->id = $ilDB->getLastInsertId();
00162 $query = sprintf("INSERT INTO qpl_question_singlechoice (question_fi, shuffle) VALUES (%s, %s)",
00163 $ilDB->quote($this->id . ""),
00164 $ilDB->quote("$this->shuffle")
00165 );
00166 $ilDB->query($query);
00167
00168
00169 $this->createPageObject();
00170
00171 if ($this->getTestId() > 0)
00172 {
00173 $this->insertIntoTest($this->getTestId());
00174 }
00175 }
00176 }
00177 else
00178 {
00179
00180 $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",
00181 $ilDB->quote($this->obj_id. ""),
00182 $ilDB->quote($this->title),
00183 $ilDB->quote($this->comment),
00184 $ilDB->quote($this->author),
00185 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00186 $ilDB->quote($this->getMaximumPoints() . ""),
00187 $ilDB->quote($estw_time),
00188 $ilDB->quote("$complete"),
00189 $ilDB->quote($this->id)
00190 );
00191 $result = $ilDB->query($query);
00192 $query = sprintf("UPDATE qpl_question_singlechoice SET shuffle = %s WHERE question_fi = %s",
00193 $ilDB->quote("$this->shuffle"),
00194 $ilDB->quote($this->id . "")
00195 );
00196 $result = $ilDB->query($query);
00197 }
00198 if ($result == DB_OK)
00199 {
00200
00201
00202 $query = sprintf("DELETE FROM qpl_answer_singlechoice WHERE question_fi = %s",
00203 $ilDB->quote($this->id)
00204 );
00205 $result = $ilDB->query($query);
00206
00207
00208 foreach ($this->answers as $key => $value)
00209 {
00210 $answer_obj = $this->answers[$key];
00211 $query = sprintf("INSERT INTO qpl_answer_singlechoice (answer_id, question_fi, answertext, points, aorder, imagefile) VALUES (NULL, %s, %s, %s, %s, %s)",
00212 $ilDB->quote($this->id),
00213 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0)),
00214 $ilDB->quote($answer_obj->getPoints() . ""),
00215 $ilDB->quote($answer_obj->getOrder() . ""),
00216 $ilDB->quote($answer_obj->getImage() . "")
00217 );
00218 $answer_result = $ilDB->query($query);
00219 }
00220 }
00221 parent::saveToDb($original_id);
00222 }
00223
00233 function loadFromDb($question_id)
00234 {
00235 global $ilDB;
00236
00237 $hasimages = 0;
00238 $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",
00239 $ilDB->quote($question_id));
00240 $result = $ilDB->query($query);
00241 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00242 {
00243 if ($result->numRows() == 1)
00244 {
00245 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00246 $this->id = $question_id;
00247 $this->title = $data->title;
00248 $this->comment = $data->comment;
00249 $this->solution_hint = $data->solution_hint;
00250 $this->original_id = $data->original_id;
00251 $this->obj_id = $data->obj_fi;
00252 $this->author = $data->author;
00253 $this->owner = $data->owner;
00254 $this->points = $data->points;
00255 include_once("./Services/RTE/classes/class.ilRTE.php");
00256 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00257 $this->setShuffle($data->shuffle);
00258 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00259 }
00260
00261 $query = sprintf("SELECT * FROM qpl_answer_singlechoice WHERE question_fi = %s ORDER BY aorder ASC",
00262 $ilDB->quote($question_id));
00263
00264 $result = $ilDB->query($query);
00265
00266 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
00267 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00268 {
00269 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00270 {
00271 $imagefilename = $this->getImagePath() . $data->imagefile;
00272 if (!@file_exists($imagefilename))
00273 {
00274 $data->imagefile = "";
00275 }
00276 include_once("./Services/RTE/classes/class.ilRTE.php");
00277 $data->answertext = ilRTE::_replaceMediaObjectImageSrc($data->answertext, 1);
00278 if (strlen($data->imagefile)) $hasimages = 1;
00279 array_push($this->answers, new ASS_AnswerBinaryStateImage($data->answertext, $data->points, $data->aorder, 1, $data->imagefile));
00280 }
00281 }
00282 }
00283 $this->setGraphicalAnswerSetting($hasimages);
00284 parent::loadFromDb($question_id);
00285 }
00286
00294 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00295 {
00296 if ($this->id <= 0)
00297 {
00298
00299 return;
00300 }
00301
00302 $this_id = $this->getId();
00303 $clone = $this;
00304 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00305 $original_id = assQuestion::_getOriginalId($this->id);
00306 $clone->id = -1;
00307 if ($title)
00308 {
00309 $clone->setTitle($title);
00310 }
00311
00312 if ($author)
00313 {
00314 $clone->setAuthor($author);
00315 }
00316 if ($owner)
00317 {
00318 $clone->setOwner($owner);
00319 }
00320
00321 if ($for_test)
00322 {
00323 $clone->saveToDb($original_id);
00324 }
00325 else
00326 {
00327 $clone->saveToDb();
00328 }
00329
00330
00331 $clone->copyPageOfQuestion($this_id);
00332
00333 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00334
00335 $clone->duplicateImages($this_id);
00336
00337 $clone->duplicateFeedbackGeneric($this_id);
00338
00339 $clone->duplicateFeedbackAnswer($this_id);
00340
00341 return $clone->id;
00342 }
00343
00351 function copyObject($target_questionpool, $title = "")
00352 {
00353 if ($this->id <= 0)
00354 {
00355
00356 return;
00357 }
00358
00359 $clone = $this;
00360 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00361 $original_id = assQuestion::_getOriginalId($this->id);
00362 $clone->id = -1;
00363 $source_questionpool = $this->getObjId();
00364 $clone->setObjId($target_questionpool);
00365 if ($title)
00366 {
00367 $clone->setTitle($title);
00368 }
00369 $clone->saveToDb();
00370
00371
00372 $clone->copyPageOfQuestion($original_id);
00373
00374 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00375
00376 $clone->copyImages($original_id, $source_questionpool);
00377
00378 $clone->duplicateFeedbackGeneric($original_id);
00379
00380 $clone->duplicateFeedbackAnswer($original_id);
00381
00382 return $clone->id;
00383 }
00384
00394 function getOutputType()
00395 {
00396 return $this->output_type;
00397 }
00398
00408 function setOutputType($output_type = OUTPUT_ORDER)
00409 {
00410 $this->output_type = $output_type;
00411 }
00412
00428 function addAnswer(
00429 $answertext = "",
00430 $points = 0.0,
00431 $points_unchecked = 0.0,
00432 $order = 0,
00433 $answerimage = ""
00434 )
00435 {
00436 $found = -1;
00437 foreach ($this->answers as $key => $value)
00438 {
00439 if ($value->getOrder() == $order)
00440 {
00441 $found = $order;
00442 }
00443 }
00444 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
00445 if ($found >= 0)
00446 {
00447
00448 $answer = new ASS_AnswerBinaryStateImage($answertext, $points, $found, 1, $answerimage);
00449 array_push($this->answers, $answer);
00450 for ($i = $found + 1; $i < count($this->answers); $i++)
00451 {
00452 $this->answers[$i] = $this->answers[$i-1];
00453 }
00454 $this->answers[$found] = $answer;
00455 }
00456 else
00457 {
00458
00459 $answer = new ASS_AnswerBinaryStateImage($answertext, $points, count($this->answers), 1, $answerimage);
00460 array_push($this->answers, $answer);
00461 }
00462 }
00463
00473 function getAnswerCount()
00474 {
00475 return count($this->answers);
00476 }
00477
00489 function getAnswer($index = 0)
00490 {
00491 if ($index < 0) return NULL;
00492 if (count($this->answers) < 1) return NULL;
00493 if ($index >= count($this->answers)) return NULL;
00494
00495 return $this->answers[$index];
00496 }
00497
00508 function deleteAnswer($index = 0)
00509 {
00510 if ($index < 0) return;
00511 if (count($this->answers) < 1) return;
00512 if ($index >= count($this->answers)) return;
00513 $answer = $this->answers[$index];
00514 if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
00515 unset($this->answers[$index]);
00516 $this->answers = array_values($this->answers);
00517 for ($i = 0; $i < count($this->answers); $i++)
00518 {
00519 if ($this->answers[$i]->getOrder() > $index)
00520 {
00521 $this->answers[$i]->setOrder($i);
00522 }
00523 }
00524 }
00525
00534 function flushAnswers()
00535 {
00536 $this->answers = array();
00537 }
00538
00547 function getMaximumPoints()
00548 {
00549 $points = 0;
00550 foreach ($this->answers as $key => $value)
00551 {
00552 if ($value->getPoints() > $points)
00553 {
00554 $points = $value->getPoints();
00555 }
00556 }
00557 return $points;
00558 }
00559
00571 function calculateReachedPoints($active_id, $pass = NULL)
00572 {
00573 global $ilDB;
00574
00575 $found_values = array();
00576 if (is_null($pass))
00577 {
00578 $pass = $this->getSolutionMaxPass($active_id);
00579 }
00580 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00581 $ilDB->quote($active_id . ""),
00582 $ilDB->quote($this->getId() . ""),
00583 $ilDB->quote($pass . "")
00584 );
00585 $result = $ilDB->query($query);
00586 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00587 {
00588 if (strcmp($data->value1, "") != 0)
00589 {
00590 array_push($found_values, $data->value1);
00591 }
00592 }
00593 $points = 0;
00594 foreach ($this->answers as $key => $answer)
00595 {
00596 if (count($found_values) > 0)
00597 {
00598 if (in_array($key, $found_values))
00599 {
00600 $points += $answer->getPoints();
00601 }
00602 }
00603 }
00604
00605 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00606 return $points;
00607 }
00608
00619 function saveWorkingData($active_id, $pass = NULL)
00620 {
00621 global $ilDB;
00622 global $ilUser;
00623
00624 if (is_null($pass))
00625 {
00626 include_once "./Modules/Test/classes/class.ilObjTest.php";
00627 $pass = ilObjTest::_getPass($active_id);
00628 }
00629 $entered_values = 0;
00630
00631 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00632 $ilDB->quote($active_id . ""),
00633 $ilDB->quote($this->getId() . ""),
00634 $ilDB->quote($pass . "")
00635 );
00636 $result = $ilDB->query($query);
00637 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00638 $update = $row->solution_id;
00639 if ($update)
00640 {
00641 if (strlen($_POST["multiple_choice_result"]))
00642 {
00643 $query = sprintf("UPDATE tst_solutions SET value1 = %s WHERE solution_id = %s",
00644 $ilDB->quote($_POST["multiple_choice_result"]),
00645 $ilDB->quote($update)
00646 );
00647 $result = $ilDB->query($query);
00648 $entered_values++;
00649 }
00650 else
00651 {
00652 $query = sprintf("DELETE FROM tst_solutions WHERE solution_id = %s",
00653 $ilDB->quote($update)
00654 );
00655 $result = $ilDB->query($query);
00656 }
00657 }
00658 else
00659 {
00660 if (strlen($_POST["multiple_choice_result"]))
00661 {
00662 $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
00663 $ilDB->quote($active_id),
00664 $ilDB->quote($this->getId()),
00665 $ilDB->quote($_POST["multiple_choice_result"]),
00666 $ilDB->quote($pass . "")
00667 );
00668 $result = $ilDB->query($query);
00669 $entered_values++;
00670 }
00671 }
00672 if ($entered_values)
00673 {
00674 include_once ("./classes/class.ilObjAssessmentFolder.php");
00675 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00676 {
00677 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00678 }
00679 }
00680 else
00681 {
00682 include_once ("./classes/class.ilObjAssessmentFolder.php");
00683 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00684 {
00685 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00686 }
00687 }
00688 parent::saveWorkingData($active_id, $pass);
00689 return true;
00690 }
00691
00699 function syncFeedbackSingleAnswers()
00700 {
00701 global $ilDB;
00702
00703 $feedback = "";
00704
00705
00706 $deletequery = sprintf("DELETE FROM qpl_feedback_singlechoice WHERE question_fi = %s",
00707 $ilDB->quote($this->original_id . "")
00708 );
00709 $result = $ilDB->query($deletequery);
00710
00711
00712 $query = sprintf("SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s",
00713 $ilDB->quote($this->getId() . "")
00714 );
00715 $result = $ilDB->query($query);
00716
00717
00718 if ($result->numRows())
00719 {
00720 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00721 {
00722 $duplicatequery = sprintf("INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
00723 $ilDB->quote($this->original_id . ""),
00724 $ilDB->quote($row["answer"] . ""),
00725 $ilDB->quote($row["feedback"] . "")
00726 );
00727 $duplicateresult = $ilDB->query($duplicatequery);
00728 }
00729 }
00730 }
00731
00732 function syncWithOriginal()
00733 {
00734 if ($this->getOriginalId())
00735 {
00736 $this->syncFeedbackSingleAnswers();
00737 $this->syncImages();
00738 parent::syncWithOriginal();
00739 }
00740 }
00741
00750 function getQuestionType()
00751 {
00752 return "assSingleChoice";
00753 }
00754
00763 function getAdditionalTableName()
00764 {
00765 return "qpl_question_singlechoice";
00766 }
00767
00776 function getAnswerTableName()
00777 {
00778 return "qpl_answer_singlechoice";
00779 }
00780
00781 function getGraphicalAnswerSetting()
00782 {
00783 global $ilUser;
00784
00785 $graphicalAnswerSetting = $ilUser->getPref("graphicalAnswerSetting");
00786 if ($graphicalAnswerSetting != 1)
00787 {
00788 $graphicalAnswerSetting = 0;
00789 }
00790 return $graphicalAnswerSetting;
00791 }
00792
00793 function setGraphicalAnswerSetting($a_setting = 0)
00794 {
00795 global $ilUser;
00796 $ilUser->writePref("graphicalAnswerSetting", $a_setting);
00797 }
00798
00809 function setImageFile($image_filename, $image_tempfilename = "")
00810 {
00811 $result = 0;
00812 if (!empty($image_tempfilename))
00813 {
00814 $image_filename = str_replace(" ", "_", $image_filename);
00815 $imagepath = $this->getImagePath();
00816 if (!file_exists($imagepath))
00817 {
00818 ilUtil::makeDirParents($imagepath);
00819 }
00820
00821 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
00822 {
00823 $result = 2;
00824 }
00825 else
00826 {
00827 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
00828 $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
00829 if (!preg_match("/^image/", $mimetype))
00830 {
00831 unlink($imagepath . $image_filename);
00832 $result = 1;
00833 }
00834 else
00835 {
00836
00837 $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
00838 ilUtil::convertImage($imagepath.$image_filename, $thumbpath, "JPEG", 100);
00839 }
00840 }
00841 }
00842 return $result;
00843 }
00844
00853 function deleteImage($image_filename)
00854 {
00855 $imagepath = $this->getImagePath();
00856 unlink($imagepath . $image_filename);
00857 $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
00858 unlink($thumbpath);
00859 }
00860
00861 function duplicateImages($question_id)
00862 {
00863 global $ilLog;
00864 $imagepath = $this->getImagePath();
00865 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00866 if (!file_exists($imagepath))
00867 {
00868 ilUtil::makeDirParents($imagepath);
00869 }
00870 foreach ($this->answers as $answer)
00871 {
00872 $filename = $answer->getImage();
00873 if (strlen($filename))
00874 {
00875 if (!copy($imagepath_original . $filename, $imagepath . $filename))
00876 {
00877 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
00878 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00879 }
00880 if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
00881 {
00882 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
00883 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00884 }
00885 }
00886 }
00887 }
00888
00889 function copyImages($question_id, $source_questionpool)
00890 {
00891 global $ilLog;
00892 $imagepath = $this->getImagePath();
00893 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00894 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
00895 if (!file_exists($imagepath))
00896 {
00897 ilUtil::makeDirParents($imagepath);
00898 }
00899 foreach ($this->answers as $answer)
00900 {
00901 $filename = $answer->getImage();
00902 if (strlen($filename))
00903 {
00904 if (!copy($imagepath_original . $filename, $imagepath . $filename))
00905 {
00906 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
00907 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00908 }
00909 if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
00910 {
00911 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
00912 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00913 }
00914 }
00915 }
00916 }
00917
00921 protected function syncImages()
00922 {
00923 global $ilLog;
00924 $question_id = $this->getOriginalId();
00925 $imagepath = $this->getImagePath();
00926 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00927 if (!file_exists($imagepath))
00928 {
00929 ilUtil::makeDirParents($imagepath);
00930 }
00931 ilUtil::delDir($imagepath_original);
00932 ilUtil::makeDirParents($imagepath_original);
00933 foreach ($this->answers as $answer)
00934 {
00935 $filename = $answer->getImage();
00936 if (strlen($filename))
00937 {
00938 if (@file_exists($imagepath . $filename))
00939 {
00940 if (!@copy($imagepath . $filename, $imagepath_original . $filename))
00941 {
00942 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
00943 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00944 }
00945 }
00946 if (@file_exists($imagepath . $filename . ".thumb.jpg"))
00947 {
00948 if (!@copy($imagepath . $filename . ".thumb.jpg", $imagepath_original . $filename . ".thumb.jpg"))
00949 {
00950 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
00951 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00952 }
00953 }
00954 }
00955 }
00956 }
00957
00967 function saveFeedbackSingleAnswer($answer_index, $feedback)
00968 {
00969 global $ilDB;
00970
00971 $query = sprintf("DELETE FROM qpl_feedback_singlechoice WHERE question_fi = %s AND answer = %s",
00972 $ilDB->quote($this->getId() . ""),
00973 $ilDB->quote($answer_index . "")
00974 );
00975 $result = $ilDB->query($query);
00976 if (strlen($feedback))
00977 {
00978 include_once("./Services/RTE/classes/class.ilRTE.php");
00979 $query = sprintf("INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
00980 $ilDB->quote($this->getId() . ""),
00981 $ilDB->quote($answer_index . ""),
00982 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($feedback, 0))
00983 );
00984 $result = $ilDB->query($query);
00985 }
00986 }
00987
00997 function getFeedbackSingleAnswer($answer_index)
00998 {
00999 global $ilDB;
01000
01001 $feedback = "";
01002 $query = sprintf("SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s AND answer = %s",
01003 $ilDB->quote($this->getId() . ""),
01004 $ilDB->quote($answer_index . "")
01005 );
01006 $result = $ilDB->query($query);
01007 if ($result->numRows())
01008 {
01009 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01010 include_once("./Services/RTE/classes/class.ilRTE.php");
01011 $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
01012 }
01013 return $feedback;
01014 }
01015
01024 function duplicateFeedbackAnswer($original_id)
01025 {
01026 global $ilDB;
01027
01028 $feedback = "";
01029 $query = sprintf("SELECT * FROM qpl_feedback_singlechoice WHERE question_fi = %s",
01030 $ilDB->quote($original_id . "")
01031 );
01032 $result = $ilDB->query($query);
01033 if ($result->numRows())
01034 {
01035 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01036 {
01037 $duplicatequery = sprintf("INSERT INTO qpl_feedback_singlechoice VALUES (NULL, %s, %s, %s, NULL)",
01038 $ilDB->quote($this->getId() . ""),
01039 $ilDB->quote($row["answer"] . ""),
01040 $ilDB->quote($row["feedback"] . "")
01041 );
01042 $duplicateresult = $ilDB->query($duplicatequery);
01043 }
01044 }
01045 }
01046
01051 function getRTETextWithMediaObjects()
01052 {
01053 $text = parent::getRTETextWithMediaObjects();
01054 foreach ($this->answers as $index => $answer)
01055 {
01056 $text .= $this->getFeedbackSingleAnswer($index);
01057 $answer_obj = $this->answers[$index];
01058 $text .= $answer_obj->getAnswertext();
01059 }
01060 return $text;
01061 }
01062
01066 function &getAnswers()
01067 {
01068 return $this->answers;
01069 }
01070 }
01071
01072 ?>