• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/TestQuestionPool/classes/class.assMultipleChoice.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00024 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00025 
00035 class assMultipleChoice extends assQuestion
00036 {
00044         var $answers;
00045 
00054         var $output_type;
00055 
00070         function assMultipleChoice(
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                         return true;
00097                 }
00098                         else
00099                 {
00100                         return false;
00101                 }
00102         }
00103 
00112         function saveToDb($original_id = "")
00113         {
00114                 global $ilDB;
00115 
00116                 $complete = 0;
00117                 if ($this->isComplete())
00118                 {
00119                         $complete = 1;
00120                 }
00121 
00122                 $estw_time = $this->getEstimatedWorkingTime();
00123                 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00124 
00125                 if ($original_id)
00126                 {
00127                         $original_id = $ilDB->quote($original_id);
00128                 }
00129                 else
00130                 {
00131                         $original_id = "NULL";
00132                 }
00133                 
00134                 include_once("./Services/RTE/classes/class.ilRTE.php");
00135 
00136                 if ($this->id == -1)
00137                 {
00138                         // Neuen Datensatz schreiben
00139                         $now = getdate();
00140                         $question_type = $this->getQuestionTypeID();
00141                         $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00142                         $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)",
00143                                 $ilDB->quote($question_type),
00144                                 $ilDB->quote($this->obj_id),
00145                                 $ilDB->quote($this->title),
00146                                 $ilDB->quote($this->comment),
00147                                 $ilDB->quote($this->author),
00148                                 $ilDB->quote($this->owner),
00149                                 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00150                                 $ilDB->quote($this->getMaximumPoints() . ""),
00151                                 $ilDB->quote($estw_time),
00152                                 $ilDB->quote("$complete"),
00153                                 $ilDB->quote($created),
00154                                 $original_id
00155                         );
00156                         $result = $ilDB->query($query);
00157                         
00158                         if ($result == DB_OK)
00159                         {
00160                                 $this->id = $ilDB->getLastInsertId();
00161                                 $query = sprintf("INSERT INTO qpl_question_multiplechoice (question_fi, shuffle) VALUES (%s, %s)",
00162                                         $ilDB->quote($this->id . ""),
00163                                         $ilDB->quote("$this->shuffle")
00164                                 );
00165                                 $ilDB->query($query);
00166 
00167                                 // create page object of question
00168                                 $this->createPageObject();
00169 
00170                                 // Falls die Frage in einen Test eingefügt werden soll, auch diese Verbindung erstellen
00171                                 if ($this->getTestId() > 0)
00172                                 {
00173                                 $this->insertIntoTest($this->getTestId());
00174                                 }
00175                         }
00176                 }
00177                 else
00178                 {
00179                         // Vorhandenen Datensatz aktualisieren
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_multiplechoice 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                 
00199                 if ($result == DB_OK)
00200                 {
00201                         // Antworten schreiben
00202                         // alte Antworten löschen
00203                         $query = sprintf("DELETE FROM qpl_answer_multiplechoice WHERE question_fi = %s",
00204                                 $ilDB->quote($this->id)
00205                         );
00206                         $result = $ilDB->query($query);
00207 
00208                         // Anworten wegschreiben
00209                         foreach ($this->answers as $key => $value)
00210                         {
00211                                 $answer_obj = $this->answers[$key];
00212 
00213                                 $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)",
00214                                         $ilDB->quote($this->id),
00215                                         $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 0)),
00216                                         $ilDB->quote($answer_obj->getPoints() . ""),
00217                                         $ilDB->quote($answer_obj->getPointsUnchecked() . ""),
00218                                         $ilDB->quote($answer_obj->getOrder() . ""),
00219                                         $ilDB->quote($answer_obj->getImage() . "")
00220                                 );
00221                                 $answer_result = $ilDB->query($query);
00222                         }
00223                 }
00224 
00225                 parent::saveToDb($original_id);
00226         }
00227 
00237         function loadFromDb($question_id)
00238         {
00239                 global $ilDB;
00240 
00241                 $hasimages = 0;
00242     $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",
00243                 $ilDB->quote($question_id));
00244                 $result = $ilDB->query($query);
00245                 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00246                 {
00247                         if ($result->numRows() == 1)
00248                         {
00249                                 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00250                                 $this->id = $question_id;
00251                                 $this->title = $data->title;
00252                                 $this->comment = $data->comment;
00253                                 $this->solution_hint = $data->solution_hint;
00254                                 $this->original_id = $data->original_id;
00255                                 $this->obj_id = $data->obj_fi;
00256                                 $this->author = $data->author;
00257                                 $this->owner = $data->owner;
00258                                 $this->points = $data->points;
00259                                 include_once("./Services/RTE/classes/class.ilRTE.php");
00260                                 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00261                                 $this->setShuffle($data->shuffle);
00262                                 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00263                         }
00264 
00265                         $query = sprintf("SELECT * FROM qpl_answer_multiplechoice WHERE question_fi = %s ORDER BY aorder ASC",
00266                                 $ilDB->quote($question_id));
00267 
00268                         $result = $ilDB->query($query);
00269 
00270                         include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
00271                         if (strcmp(strtolower(get_class($result)), db_result) == 0)
00272                         {
00273                                 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00274                                 {
00275                                         $imagefilename = $this->getImagePath() . $data->imagefile;
00276                                         if (!@file_exists($imagefilename))
00277                                         {
00278                                                 $data->imagefile = "";
00279                                         }
00280                                         include_once("./Services/RTE/classes/class.ilRTE.php");
00281                                         $data->answertext = ilRTE::_replaceMediaObjectImageSrc($data->answertext, 1);
00282                                         if (strlen($data->imagefile)) $hasimages = 1;
00283                                         array_push($this->answers, new ASS_AnswerMultipleResponseImage($data->answertext, $data->points, $data->aorder, $data->points_unchecked, $data->imagefile));
00284                                 }
00285                         }
00286                 }
00287                 $this->setGraphicalAnswerSetting($hasimages);
00288                 parent::loadFromDb($question_id);
00289         }
00290 
00298         /*function addAnswer($answertext, $points, $answerorder, $correctness)
00299         {
00300                 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryState.php";
00301                 array_push($this->answers, new ASS_AnswerBinaryState($answertext, $points, $answerorder, $correctness));
00302         }*/
00303         
00311         function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00312         {
00313                 if ($this->id <= 0)
00314                 {
00315                         // The question has not been saved. It cannot be duplicated
00316                         return;
00317                 }
00318                 // duplicate the question in database
00319                 $this_id = $this->getId();
00320                 $clone = $this;
00321                 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00322                 $original_id = assQuestion::_getOriginalId($this->id);
00323                 $clone->id = -1;
00324                 if ($title)
00325                 {
00326                         $clone->setTitle($title);
00327                 }
00328 
00329                 if ($author)
00330                 {
00331                         $clone->setAuthor($author);
00332                 }
00333                 if ($owner)
00334                 {
00335                         $clone->setOwner($owner);
00336                 }
00337 
00338                 if ($for_test)
00339                 {
00340                         $clone->saveToDb($original_id);
00341                 }
00342                 else
00343                 {
00344                         $clone->saveToDb();
00345                 }
00346 
00347                 // copy question page content
00348                 $clone->copyPageOfQuestion($this_id);
00349                 // copy XHTML media objects
00350                 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00351                 // duplicate the images
00352                 $clone->duplicateImages($this_id);
00353                 // duplicate the generic feedback
00354                 $clone->duplicateFeedbackGeneric($this_id);
00355                 // duplicate the answer specific feedback
00356                 $clone->duplicateFeedbackAnswer($this_id);
00357 
00358                 return $clone->id;
00359         }
00360 
00368         function copyObject($target_questionpool, $title = "")
00369         {
00370                 if ($this->id <= 0)
00371                 {
00372                         // The question has not been saved. It cannot be duplicated
00373                         return;
00374                 }
00375                 // duplicate the question in database
00376                 $clone = $this;
00377                 include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
00378                 $original_id = assQuestion::_getOriginalId($this->id);
00379                 $clone->id = -1;
00380                 $source_questionpool = $this->getObjId();
00381                 $clone->setObjId($target_questionpool);
00382                 if ($title)
00383                 {
00384                         $clone->setTitle($title);
00385                 }
00386                 $clone->saveToDb();
00387 
00388                 // copy question page content
00389                 $clone->copyPageOfQuestion($original_id);
00390                 // copy XHTML media objects
00391                 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00392                 // duplicate the image
00393                 $clone->copyImages($original_id, $source_questionpool);
00394                 // duplicate the generic feedback
00395                 $clone->duplicateFeedbackGeneric($original_id);
00396                 // duplicate the answer specific feedback
00397                 $clone->duplicateFeedbackAnswer($original_id);
00398 
00399                 return $clone->id;
00400         }
00401 
00411         function getOutputType()
00412         {
00413                 return $this->output_type;
00414         }
00415 
00425         function setOutputType($output_type = OUTPUT_ORDER)
00426         {
00427                 $this->output_type = $output_type;
00428         }
00429 
00445         function addAnswer(
00446                 $answertext = "",
00447                 $points = 0.0,
00448                 $points_unchecked = 0.0,
00449                 $order = 0,
00450                 $answerimage = ""
00451         )
00452         {
00453                 $found = -1;
00454                 foreach ($this->answers as $key => $value)
00455                 {
00456                         if ($value->getOrder() == $order)
00457                         {
00458                                 $found = $order;
00459                         }
00460                 }
00461                 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php";
00462                 if ($found >= 0)
00463                 {
00464                         // Antwort einfügen
00465                         $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, $found, $points_unchecked, $answerimage);
00466                         array_push($this->answers, $answer);
00467                         for ($i = $found + 1; $i < count($this->answers); $i++)
00468                         {
00469                                 $this->answers[$i] = $this->answers[$i-1];
00470                         }
00471                         $this->answers[$found] = $answer;
00472                 }
00473                 else
00474                 {
00475                         // Anwort anhängen
00476                         $answer = new ASS_AnswerMultipleResponseImage($answertext, $points, count($this->answers), $points_unchecked, $answerimage);
00477                         array_push($this->answers, $answer);
00478                 }
00479         }
00480 
00490         function getAnswerCount()
00491         {
00492                 return count($this->answers);
00493         }
00494 
00506         function getAnswer($index = 0)
00507         {
00508                 if ($index < 0) return NULL;
00509                 if (count($this->answers) < 1) return NULL;
00510                 if ($index >= count($this->answers)) return NULL;
00511 
00512                 return $this->answers[$index];
00513         }
00514 
00525         function deleteAnswer($index = 0)
00526         {
00527                 if ($index < 0) return;
00528                 if (count($this->answers) < 1) return;
00529                 if ($index >= count($this->answers)) return;
00530                 $answer = $this->answers[$index];
00531                 if (strlen($answer->getImage())) $this->deleteImage($answer->getImage());
00532                 unset($this->answers[$index]);
00533                 $this->answers = array_values($this->answers);
00534                 for ($i = 0; $i < count($this->answers); $i++)
00535                 {
00536                         if ($this->answers[$i]->getOrder() > $index)
00537                         {
00538                                 $this->answers[$i]->setOrder($i);
00539                         }
00540                 }
00541         }
00542 
00551         function flushAnswers()
00552         {
00553                 $this->answers = array();
00554         }
00555 
00564         function getMaximumPoints()
00565         {
00566                 $points = 0;
00567                 $allpoints = 0;
00568                 foreach ($this->answers as $key => $value) 
00569                 {
00570                         if ($value->getPoints() > $value->getPointsUnchecked())
00571                         {
00572                                 $allpoints += $value->getPoints();
00573                         }
00574                         else
00575                         {
00576                                 $allpoints += $value->getPointsUnchecked();
00577                         }
00578                 }
00579                 return $allpoints;
00580         }
00581 
00593         function calculateReachedPoints($active_id, $pass = NULL)
00594         {
00595                 global $ilDB;
00596                 
00597                 $found_values = array();
00598                 if (is_null($pass))
00599                 {
00600                         $pass = $this->getSolutionMaxPass($active_id);
00601                 }
00602                 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00603                         $ilDB->quote($active_id . ""),
00604                         $ilDB->quote($this->getId() . ""),
00605                         $ilDB->quote($pass . "")
00606                 );
00607                 $result = $ilDB->query($query);
00608                 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00609                 {
00610                         if (strcmp($data->value1, "") != 0)
00611                         {
00612                                 array_push($found_values, $data->value1);
00613                         }
00614                 }
00615                 $points = 0;
00616                 foreach ($this->answers as $key => $answer)
00617                 {
00618                         if (in_array($key, $found_values))
00619                         {
00620                                 $points += $answer->getPoints();
00621                         }
00622                         else
00623                         {
00624                                 $points += $answer->getPointsUnchecked();
00625                         }
00626                 }
00627                 include_once "./Modules/Test/classes/class.ilObjTest.php";
00628                 $mc_scoring = ilObjTest::_getMCScoring($active_id);
00629                 if (($mc_scoring == 0) && (count($found_values) == 0))
00630                 {
00631                         $points = 0;
00632                 }
00633                 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00634                 return $points;
00635         }
00636         
00647         function saveWorkingData($active_id, $pass = NULL)
00648         {
00649                 global $ilDB;
00650                 global $ilUser;
00651 
00652                 if (is_null($pass))
00653                 {
00654                         include_once "./Modules/Test/classes/class.ilObjTest.php";
00655                         $pass = ilObjTest::_getPass($active_id);
00656                 }
00657 
00658                 $entered_values = 0;
00659                 $query = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00660                         $ilDB->quote($active_id . ""),
00661                         $ilDB->quote($this->getId() . ""),
00662                         $ilDB->quote($pass . "")
00663                 );
00664                 $result = $ilDB->query($query);
00665                 foreach ($_POST as $key => $value)
00666                 {
00667                         if (preg_match("/^multiple_choice_result_(\d+)/", $key, $matches))
00668                         {
00669                                 if (strlen($value))
00670                                 {
00671                                         $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
00672                                                 $ilDB->quote($active_id),
00673                                                 $ilDB->quote($this->getId()),
00674                                                 $ilDB->quote($value),
00675                                                 $ilDB->quote($pass . "")
00676                                         );
00677                                         $result = $ilDB->query($query);
00678                                         $entered_values++;
00679                                 }
00680                         }
00681                 }
00682                 if ($entered_values)
00683                 {
00684                         include_once ("./classes/class.ilObjAssessmentFolder.php");
00685                         if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00686                         {
00687                                 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00688                         }
00689                 }
00690                 else
00691                 {
00692                         include_once ("./classes/class.ilObjAssessmentFolder.php");
00693                         if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00694                         {
00695                                 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00696                         }
00697                 }
00698     parent::saveWorkingData($active_id, $pass);
00699                 return true;
00700         }
00701 
00709         function syncFeedbackSingleAnswers()
00710         {
00711                 global $ilDB;
00712 
00713                 $feedback = "";
00714 
00715                 // delete generic feedback of the original
00716                 $deletequery = sprintf("DELETE FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
00717                         $ilDB->quote($this->original_id . "")
00718                 );
00719                 $result = $ilDB->query($deletequery);
00720                         
00721                 // get generic feedback of the actual question
00722                 $query = sprintf("SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
00723                         $ilDB->quote($this->getId() . "")
00724                 );
00725                 $result = $ilDB->query($query);
00726 
00727                 // save generic feedback to the original
00728                 if ($result->numRows())
00729                 {
00730                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00731                         {
00732                                 $duplicatequery = sprintf("INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
00733                                         $ilDB->quote($this->original_id . ""),
00734                                         $ilDB->quote($row["answer"] . ""),
00735                                         $ilDB->quote($row["feedback"] . "")
00736                                 );
00737                                 $duplicateresult = $ilDB->query($duplicatequery);
00738                         }
00739                 }
00740         }
00741 
00742         function syncWithOriginal()
00743         {
00744                 if ($this->getOriginalId())
00745                 {
00746                         $this->syncFeedbackSingleAnswers();
00747                         $this->syncImages();
00748                         parent::syncWithOriginal();
00749                 }
00750         }
00751 
00760         function getQuestionType()
00761         {
00762                 return "assMultipleChoice";
00763         }
00764         
00773         function getAdditionalTableName()
00774         {
00775                 return "qpl_question_multiplechoice";
00776         }
00777         
00786         function getAnswerTableName()
00787         {
00788                 return "qpl_answer_multiplechoice";
00789         }
00790         
00791         function getGraphicalAnswerSetting()
00792         {
00793                 global $ilUser;
00794 
00795                 $graphicalAnswerSetting = $ilUser->getPref("graphicalAnswerSetting");
00796                 if ($graphicalAnswerSetting != 1)
00797                 {
00798                         $graphicalAnswerSetting = 0;
00799                 }
00800                 return $graphicalAnswerSetting;
00801         }
00802         
00803         function setGraphicalAnswerSetting($a_setting = 0)
00804         {
00805                 global $ilUser;
00806                 $ilUser->writePref("graphicalAnswerSetting", $a_setting);
00807         }
00808 
00819         function setImageFile($image_filename, $image_tempfilename = "")
00820         {
00821                 $result = 0;
00822                 if (!empty($image_tempfilename))
00823                 {
00824                         $image_filename = str_replace(" ", "_", $image_filename);
00825                         $imagepath = $this->getImagePath();
00826                         if (!file_exists($imagepath))
00827                         {
00828                                 ilUtil::makeDirParents($imagepath);
00829                         }
00830                         //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
00831                         if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
00832                         {
00833                                 $result = 2;
00834                         }
00835                         else
00836                         {
00837                                 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
00838                                 $mimetype = ilObjMediaObject::getMimeType($imagepath . $image_filename);
00839                                 if (!preg_match("/^image/", $mimetype))
00840                                 {
00841                                         unlink($imagepath . $image_filename);
00842                                         $result = 1;
00843                                 }
00844                                 else
00845                                 {
00846                                         // create thumbnail file
00847                                         $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
00848                                         ilUtil::convertImage($imagepath.$image_filename, $thumbpath, "JPEG", 100);
00849                                 }
00850                         }
00851                 }
00852                 return $result;
00853         }
00854         
00863         function deleteImage($image_filename)
00864         {
00865                 $imagepath = $this->getImagePath();
00866                 unlink($imagepath . $image_filename);
00867                 $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
00868                 unlink($thumbpath);
00869         }
00870 
00871         function duplicateImages($question_id)
00872         {
00873                 global $ilLog;
00874                 $imagepath = $this->getImagePath();
00875                 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00876                 if (!file_exists($imagepath))
00877                 {
00878                         ilUtil::makeDirParents($imagepath);
00879                 }
00880                 foreach ($this->answers as $answer)
00881                 {
00882                         $filename = $answer->getImage();
00883                         if (strlen($filename))
00884                         {
00885                                 if (!copy($imagepath_original . $filename, $imagepath . $filename))
00886                                 {
00887                                         $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
00888                                         $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00889                                 }
00890                                 if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
00891                                 {
00892                                         $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
00893                                         $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00894                                 }
00895                         }
00896                 }
00897         }
00898 
00899         function copyImages($question_id, $source_questionpool)
00900         {
00901                 global $ilLog;
00902                 $imagepath = $this->getImagePath();
00903                 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00904                 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
00905                 if (!file_exists($imagepath))
00906                 {
00907                         ilUtil::makeDirParents($imagepath);
00908                 }
00909                 foreach ($this->answers as $answer)
00910                 {
00911                         $filename = $answer->getImage();
00912                         if (strlen($filename))
00913                         {
00914                                 if (!copy($imagepath_original . $filename, $imagepath . $filename))
00915                                 {
00916                                         $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
00917                                         $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00918                                 }
00919                                 if (!copy($imagepath_original . $filename . ".thumb.jpg", $imagepath . $filename . ".thumb.jpg"))
00920                                 {
00921                                         $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
00922                                         $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00923                                 }
00924                         }
00925                 }
00926         }
00927 
00931         protected function syncImages()
00932         {
00933                 global $ilLog;
00934                 $question_id = $this->getOriginalId();
00935                 $imagepath = $this->getImagePath();
00936                 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00937                 if (!file_exists($imagepath))
00938                 {
00939                         ilUtil::makeDirParents($imagepath);
00940                 }
00941                 ilUtil::delDir($imagepath_original);
00942                 ilUtil::makeDirParents($imagepath_original);
00943                 foreach ($this->answers as $answer)
00944                 {
00945                         $filename = $answer->getImage();
00946                         if (strlen($filename))
00947                         {
00948                                 if (@file_exists($imagepath . $filename))
00949                                 {
00950                                         if (!@copy($imagepath . $filename, $imagepath_original . $filename))
00951                                         {
00952                                                 $ilLog->write("image could not be duplicated!!!!", $ilLog->ERROR);
00953                                                 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00954                                         }
00955                                 }
00956                                 if (@file_exists($imagepath . $filename . ".thumb.jpg"))
00957                                 {
00958                                         if (!@copy($imagepath . $filename . ".thumb.jpg", $imagepath_original . $filename . ".thumb.jpg"))
00959                                         {
00960                                                 $ilLog->write("image thumbnail could not be duplicated!!!!", $ilLog->ERROR);
00961                                                 $ilLog->write("object: " . print_r($this, TRUE), $ilLog->ERROR);
00962                                         }
00963                                 }
00964                         }
00965                 }
00966         }
00967 
00977         function saveFeedbackSingleAnswer($answer_index, $feedback)
00978         {
00979                 global $ilDB;
00980                 
00981                 $query = sprintf("DELETE FROM qpl_feedback_multiplechoice WHERE question_fi = %s AND answer = %s",
00982                         $ilDB->quote($this->getId() . ""),
00983                         $ilDB->quote($answer_index . "")
00984                 );
00985                 $result = $ilDB->query($query);
00986                 if (strlen($feedback))
00987                 {
00988                         include_once("./Services/RTE/classes/class.ilRTE.php");
00989                         $query = sprintf("INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
00990                                 $ilDB->quote($this->getId() . ""),
00991                                 $ilDB->quote($answer_index . ""),
00992                                 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($feedback, 0))
00993                         );
00994                         $result = $ilDB->query($query);
00995                 }
00996         }
00997 
01007         function getFeedbackSingleAnswer($answer_index)
01008         {
01009                 global $ilDB;
01010                 
01011                 $feedback = "";
01012                 $query = sprintf("SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s AND answer = %s",
01013                         $ilDB->quote($this->getId() . ""),
01014                         $ilDB->quote($answer_index . "")
01015                 );
01016                 $result = $ilDB->query($query);
01017                 if ($result->numRows())
01018                 {
01019                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01020                         include_once("./Services/RTE/classes/class.ilRTE.php");
01021                         $feedback = ilRTE::_replaceMediaObjectImageSrc($row["feedback"], 1);
01022                 }
01023                 return $feedback;
01024         }
01025 
01034         function duplicateFeedbackAnswer($original_id)
01035         {
01036                 global $ilDB;
01037                 
01038                 $feedback = "";
01039                 $query = sprintf("SELECT * FROM qpl_feedback_multiplechoice WHERE question_fi = %s",
01040                         $ilDB->quote($original_id . "")
01041                 );
01042                 $result = $ilDB->query($query);
01043                 if ($result->numRows())
01044                 {
01045                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01046                         {
01047                                 $duplicatequery = sprintf("INSERT INTO qpl_feedback_multiplechoice VALUES (NULL, %s, %s, %s, NULL)",
01048                                         $ilDB->quote($this->getId() . ""),
01049                                         $ilDB->quote($row["answer"] . ""),
01050                                         $ilDB->quote($row["feedback"] . "")
01051                                 );
01052                                 $duplicateresult = $ilDB->query($duplicatequery);
01053                         }
01054                 }
01055         }
01056 
01061         function getRTETextWithMediaObjects()
01062         {
01063                 $text = parent::getRTETextWithMediaObjects();
01064                 foreach ($this->answers as $index => $answer)
01065                 {
01066                         $text .= $this->getFeedbackSingleAnswer($index);
01067                         $answer_obj = $this->answers[$index];
01068                         $text .= $answer_obj->getAnswertext();
01069                 }
01070                 return $text;
01071         }
01072         
01076         function &getAnswers()
01077         {
01078                 return $this->answers;
01079         }
01080 }
01081 
01082 ?>

Generated on Fri Dec 13 2013 17:56:54 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1