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

assessment/classes/class.assQuestion.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 
00024 include_once "./assessment/classes/inc.AssessmentConstants.php";
00025 
00037 class assQuestion
00038 {
00046         var $id;
00047 
00055         var $title;
00056 
00064         var $comment;
00065 
00074         var $owner;
00075 
00084         var $author;
00085 
00095         var $points;
00096 
00104         var $est_working_time;
00105 
00113         var $shuffle;
00114 
00122         var $test_id;
00123 
00131         var $obj_id;
00132 
00140         var $ilias;
00141 
00149         var $tpl;
00150 
00158         var $lng;
00159 
00167         var $domxml;
00168 
00176         var $outputType;
00177 
00178         var $suggested_solutions;
00190         function assQuestion(
00191                 $title = "",
00192                 $comment = "",
00193                 $author = "",
00194                 $owner = -1
00195         )
00196         {
00197                 global $ilias;
00198                 global $lng;
00199                 global $tpl;
00200 
00201                 $this->ilias =& $ilias;
00202                 $this->lng =& $lng;
00203                 $this->tpl =& $tpl;
00204 
00205                 $this->title = $title;
00206                 $this->comment = $comment;
00207                 $this->author = $author;
00208                 if (!$this->author)
00209                 {
00210                         $this->author = $this->ilias->account->fullname;
00211                 }
00212                 $this->owner = $owner;
00213                 if ($this->owner == -1)
00214                 {
00215                         $this->owner = $this->ilias->account->id;
00216                 }
00217                 $this->id = -1;
00218                 $this->test_id = -1;
00219                 $this->suggested_solutions = array();
00220                 $this->shuffle = 1;
00221                 $this->setEstimatedWorkingTime(0,1,0);
00222                 $this->outputType = OUTPUT_HTML;
00223                 register_shutdown_function(array(&$this, '_assQuestion'));
00224         }
00225 
00226         function _assQuestion()
00227         {
00228                 if (!empty($this->domxml))
00229                 {
00230                         $this->domxml->free();
00231                 }
00232         }
00233 
00243         function to_xml()
00244         {
00245                 // to be implemented in the successor classes of assQuestion
00246         }
00247 
00256         function isComplete()
00257         {
00258                 return false;
00259         }
00260 
00270         function questionTitleExists($questionpool_id, $title)
00271         {
00272                 global $ilDB;
00273                 
00274                 $query = sprintf("SELECT * FROM qpl_questions WHERE obj_fi = %s AND title = %s",
00275                         $ilDB->quote($questionpool_id . ""),
00276                         $ilDB->quote($title)
00277                         );
00278                 $result = $ilDB->query($query);
00279                 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00280                 {
00281                         if ($result->numRows() == 1)
00282                         {
00283                                 return TRUE;
00284                         }
00285                 }
00286                 return FALSE;
00287         }
00288 
00298         function setTitle($title = "")
00299         {
00300                 $this->title = $title;
00301         }
00302 
00312         function setId($id = -1)
00313         {
00314                 $this->id = $id;
00315         }
00316 
00326         function setTestId($id = -1)
00327         {
00328                 $this->test_id = $id;
00329         }
00330 
00340         function setComment($comment = "")
00341         {
00342                 $this->comment = $comment;
00343         }
00344 
00354         function setOutputType($outputType = OUTPUT_HTML)
00355         {
00356                 $this->outputType = $outputType;
00357         }
00358 
00359 
00369         function setShuffle($shuffle = true)
00370         {
00371                 if ($shuffle)
00372                 {
00373                         $this->shuffle = 1;
00374                 }
00375                         else
00376                 {
00377                         $this->shuffle = 0;
00378                 }
00379         }
00380 
00392         function setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
00393         {
00394                 $this->est_working_time = array("h" => (int)$hour, "m" => (int)$min, "s" => (int)$sec);
00395         }
00396 
00406         function keyInArray($searchkey, $array)
00407         {
00408                 if ($searchKey)
00409                 {
00410                         foreach ($array as $key => $value)
00411                         {
00412                                 if (strcmp($key, $searchkey)==0)
00413                                 {
00414                                         return true;
00415                                 }
00416                         }
00417                 }
00418                 return false;
00419         }
00420 
00430         function setAuthor($author = "")
00431         {
00432                 if (!$author)
00433                 {
00434                         $author = $this->ilias->account->fullname;
00435                 }
00436                 $this->author = $author;
00437         }
00438 
00448         function setOwner($owner = "")
00449         {
00450                 $this->owner = $owner;
00451         }
00452 
00462         function getTitle()
00463         {
00464                 return $this->title;
00465         }
00466 
00476         function getId()
00477         {
00478                 return $this->id;
00479         }
00480 
00490         function getShuffle()
00491         {
00492                 return $this->shuffle;
00493         }
00494 
00504         function getTestId()
00505         {
00506                 return $this->test_id;
00507         }
00508 
00518         function getComment()
00519         {
00520                 return $this->comment;
00521         }
00522 
00532         function getOutputType()
00533         {
00534                 return $this->outputType;
00535         }
00536 
00546         function getEstimatedWorkingTime()
00547         {
00548                 if (!$this->est_working_time)
00549                 {
00550                         $this->est_working_time = array("h" => 0, "m" => 0, "s" => 0);
00551                 }
00552                 return $this->est_working_time;
00553         }
00554 
00564         function getAuthor()
00565         {
00566                 return $this->author;
00567         }
00568 
00578         function getOwner()
00579         {
00580                 return $this->owner;
00581         }
00582 
00592         function getObjId()
00593         {
00594                 return $this->obj_id;
00595         }
00596 
00606         function setObjId($obj_id = 0)
00607         {
00608                 $this->obj_id = $obj_id;
00609         }
00610 
00614         function createPageObject()
00615         {
00616                 $qpl_id = $this->getObjId();
00617 
00618                 include_once "./content/classes/Pages/class.ilPageObject.php";
00619                 $this->page = new ilPageObject("qpl", 0);
00620                 $this->page->setId($this->getId());
00621                 $this->page->setParentId($qpl_id);
00622                 $this->page->setXMLContent("<PageObject><PageContent>".
00623                         "<Question QRef=\"il__qst_".$this->getId()."\"/>".
00624                         "</PageContent></PageObject>");
00625                 $this->page->create();
00626         }
00627 
00636         function insertIntoTest($test_id)
00637         {
00638                 global $ilDB;
00639                 
00640                 // get maximum sequence index in test
00641                 $query = sprintf("SELECT MAX(sequence) AS seq FROM dum_test_question WHERE test_fi=%s",
00642                         $ilDB->quote($test_id)
00643                         );
00644                 $result = $ilDB->query($query);
00645                 $sequence = 1;
00646                 if ($result->numRows() == 1)
00647                 {
00648                         $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00649                         $sequence = $data->seq + 1;
00650                 }
00651                 $query = sprintf("INSERT INTO dum_test_question (test_question_id, test_fi, question_fi, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00652                         $ilDB->quote($test_id),
00653                         $ilDB->quote($this->getId()),
00654                         $ilDB->quote($sequence)
00655                         );
00656                 $result = $ilDB->query($query);
00657                 if ($result != DB_OK)
00658                 {
00659                 // Fehlermeldung
00660                 }
00661         }
00662 
00672   function _getMaximumPoints($question_id) 
00673         {
00674                 global $ilDB;
00675 
00676                 $points = 0;
00677                 $query = sprintf("SELECT points FROM qpl_questions WHERE question_id = %s",
00678                         $ilDB->quote($question_id . "")
00679                 );
00680                 $result = $ilDB->query($query);
00681                 if ($result->numRows() == 1)
00682                 {
00683                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00684                         $points = $row["points"];
00685                 }
00686                 return $points;
00687   }
00688 
00698         function &_getQuestionInfo($question_id)
00699         {
00700                 global $ilDB;
00701 
00702                 $query = sprintf("SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_question_type, qpl_questions WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_question_type.question_type_id",
00703                         $ilDB->quote($question_id . "")
00704                 );
00705                 $result = $ilDB->query($query);
00706                 if ($result->numRows())
00707                 {
00708                         return $result->fetchRow(DB_FETCHMODE_ASSOC);
00709                 }
00710                 else return array();
00711         }
00712         
00722         function _getSuggestedSolutionCount($question_id)
00723         {
00724                 global $ilDB;
00725 
00726                 $query = sprintf("SELECT suggested_solution_id FROM qpl_suggested_solutions WHERE question_fi = %s",
00727                         $ilDB->quote($question_id . "")
00728                 );
00729                 $result = $ilDB->query($query);
00730                 return $result->numRows();
00731         }
00732 
00743         function &_getSuggestedSolution($question_id, $subquestion_index = 0)
00744         {
00745                 global $ilDB;
00746 
00747                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s AND subquestion_index = %s",
00748                         $ilDB->quote($question_id . ""),
00749                         $ilDB->quote($subquestion_index . "")
00750                 );
00751                 $result = $ilDB->query($query);
00752                 if ($result->numRows() == 1)
00753                 {
00754                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00755                         return array(
00756                                 "internal_link" => $row["internal_link"],
00757                                 "import_id" => $row["import_id"]
00758                         );
00759                 }
00760                 else
00761                 {
00762                         return array();
00763                 }
00764         }
00765         
00776         function _getReachedPoints($active_id, $question_id, $pass = NULL)
00777         {
00778                 global $ilDB;
00779 
00780                 $points = 0;
00781                 if (is_null($pass))
00782                 {
00783                         include_once "./assessment/classes/class.assQuestion.php";
00784                         $pass = assQuestion::_getSolutionMaxPass($question_id, $active_id);
00785                 }
00786                 $query = sprintf("SELECT * FROM tst_test_result WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00787                         $ilDB->quote($active_id . ""),
00788                         $ilDB->quote($question_id . ""),
00789                         $ilDB->quote($pass . "")
00790                 );
00791                 $result = $ilDB->query($query);
00792                 if ($result->numRows() == 1)
00793                 {
00794                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00795                         $points = $row["points"];
00796                 }
00797                 return $points;
00798         }
00799 
00810         function getReachedPoints($active_id, $pass = NULL)
00811         {
00812                 global $ilDB;
00813 
00814                 $points = 0;
00815                 if (is_null($pass))
00816                 {
00817                         $pass = $this->getSolutionMaxPass($active_id);
00818                 }
00819                 $query = sprintf("SELECT * FROM tst_test_result WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00820                         $ilDB->quote($active_id . ""),
00821                         $ilDB->quote($this->getId() . ""),
00822                         $ilDB->quote($pass . "")
00823                 );
00824                 $result = $ilDB->query($query);
00825                 if ($result->numRows() == 1)
00826                 {
00827                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00828                         $points = $row["points"];
00829                 }
00830                 return $points;
00831         }
00832         
00841         function getMaximumPoints()
00842         {
00843                 return 0;
00844         }
00845 
00855         function saveWorkingData($active_id, $pass = NULL)
00856         {
00857                 global $ilDB;
00858                 global $ilUser;
00859                 include_once "./assessment/classes/class.ilObjTest.php";
00860                 $pass = ilObjTest::_getPass($active_id);
00861                 $reached_points = $this->calculateReachedPoints($active_id, $pass);
00862                 $query = sprintf("REPLACE INTO tst_test_result (active_fi, question_fi, pass, points) VALUES (%s, %s, %s, %s)",
00863                         $ilDB->quote($active_id . ""),
00864                         $ilDB->quote($this->getId() . ""),
00865                         $ilDB->quote($pass . ""),
00866                         $ilDB->quote($reached_points . "")
00867                 );
00868                 $result = $ilDB->query($query);
00869                 include_once ("./classes/class.ilObjAssessmentFolder.php");
00870                 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00871                 {
00872                         $this->logAction(sprintf($this->lng->txtlng("assessment", "log_user_answered_question", ilObjAssessmentFolder::_getLogLanguage()), $reached_points), $active_id, $this->getId());
00873                 }
00874 
00875                 // Update objective status
00876                 include_once 'course/classes/class.ilCourseObjectiveResult.php';
00877 
00878                 ilCourseObjectiveResult::_updateObjectiveResult($ilUser->getId(),$active_id,$this->getId());
00879                 
00880         }
00881 
00891         function logAction($logtext = "", $active_id = "", $question_id = "")
00892         {
00893                 global $ilUser;
00894 
00895                 $original_id = "";
00896                 if (strcmp($question_id, "") != 0)
00897                 {
00898                         include_once "./assessment/classes/class.assQuestion.php";
00899                         $original_id = assQuestion::_getOriginalId($question_id);
00900                 }
00901                 include_once "./classes/class.ilObjAssessmentFolder.php";
00902                 include_once "./assessment/classes/class.ilObjTest.php";
00903                 ilObjAssessmentFolder::_addLog($ilUser->id, ilObjTest::_getObjectIDFromActiveID($active_id), $logtext, $question_id, $original_id);
00904         }
00905         
00914         function getJavaPath() {
00915                 return CLIENT_WEB_DIR . "/assessment/$this->obj_id/$this->id/java/";
00916         }
00917 
00926         function getImagePath()
00927         {
00928                 return CLIENT_WEB_DIR . "/assessment/$this->obj_id/$this->id/images/";
00929         }
00930 
00939         function getJavaPathWeb()
00940         {
00941                 include_once "./classes/class.ilUtil.php";
00942                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/$this->obj_id/$this->id/java/";
00943                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00944         }
00945 
00954         function getImagePathWeb()
00955         {
00956                 include_once "./classes/class.ilUtil.php";
00957                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/$this->obj_id/$this->id/images/";
00958                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00959         }
00960 
00970         function &getSolutionValues($active_id, $pass = NULL)
00971         {
00972                 global $ilDB;
00973 
00974                 $values = array();
00975                 
00976                 if (is_null($pass))
00977                 {
00978                         $query = sprintf("SELECT MAX(pass) AS maxpass FROM tst_test_result WHERE active_fi = %s AND question_fi = %s",
00979                                 $ilDB->quote($active_id . ""),
00980                                 $ilDB->quote($this->getId() . "")
00981                         );
00982                         $result = $ilDB->query($query);
00983                         if ($result->numRows())
00984                         {
00985                                 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00986                                 $pass = $row["maxpass"];
00987                         }
00988                         else
00989                         {
00990                                 return $values;
00991                         }
00992                 }               
00993 
00994                 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00995                         $ilDB->quote($active_id . ""),
00996                         $ilDB->quote($this->getId() . ""),
00997                         $ilDB->quote($pass . "")
00998                 );
00999                 $result = $ilDB->query($query);
01000                 while   ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01001                 {
01002                         array_push($values, $row);
01003                 }
01004 
01005                 return $values;
01006         }
01007 
01016         function isInUse($question_id = "")
01017         {
01018                 global $ilDB;
01019                 
01020                 if ($question_id < 1) $question_id = $this->id;
01021                 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE original_id = %s",
01022                         $ilDB->quote($question_id . "")
01023                 );
01024                 $result = $ilDB->query($query);
01025                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
01026                 return $row->question_count;
01027         }
01028 
01037         function isClone($question_id = "")
01038         {
01039                 global $ilDB;
01040                 
01041                 if ($question_id < 1) $question_id = $this->id;
01042                 $query = sprintf("SELECT original_id FROM qpl_questions WHERE question_id = %s",
01043                         $ilDB->quote($question_id . "")
01044                 );
01045                 $result = $ilDB->query($query);
01046                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
01047                 if ($row->original_id > 0)
01048                 {
01049                         return TRUE;
01050                 }
01051                 else
01052                 {
01053                         return FALSE;
01054                 }
01055         }
01056 
01065         function pcArrayShuffle($array)
01066         {
01067                 mt_srand((double)microtime()*1000000);
01068                 $i = count($array);
01069                 if ($i > 0)
01070                 {
01071                         while(--$i)
01072                         {
01073                                 $j = mt_rand(0, $i);
01074                                 if ($i != $j)
01075                                 {
01076                                         // swap elements
01077                                         $tmp = $array[$j];
01078                                         $array[$j] = $array[$i];
01079                                         $array[$i] = $tmp;
01080                                 }
01081                         }
01082                 }
01083                 return $array;
01084         }
01085 
01091         function getQuestionTypeFromDb($question_id)
01092         {
01093                 global $ilDB;
01094 
01095                 $query = sprintf("SELECT qpl_question_type.type_tag FROM qpl_question_type, qpl_questions WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_question_type.question_type_id",
01096                         $ilDB->quote($question_id));
01097 
01098                 $result = $ilDB->query($query);
01099                 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01100 
01101                 return $data->type_tag;
01102         }
01103 
01112         function getAdditionalTableName()
01113         {
01114                 return "";
01115         }
01116         
01125         function getAnswerTableName()
01126         {
01127                 return "";
01128         }
01129 
01138         function deleteAnswers($question_id)
01139         {
01140                 global $ilDB;
01141                 $answer_table_name = $this->getAnswerTableName();
01142                 if (strlen($answer_table_name))
01143                 {
01144                         $query = sprintf("DELETE FROM $answer_table_name WHERE question_fi = %s",
01145                                 $ilDB->quote($question_id . "")
01146                         );
01147                         $result = $ilDB->query($query);
01148                 }
01149         }
01150 
01159         function deleteAdditionalTableData($question_id)
01160         {
01161                 global $ilDB;
01162                 $additional_table_name = $this->getAdditionalTableName();
01163                 $query = sprintf("DELETE FROM $additional_table_name WHERE question_fi = %s",
01164                         $ilDB->quote($question_id . "")
01165                 );
01166                 $result = $ilDB->query($query);
01167         }
01168 
01177         function delete($question_id)
01178         {
01179                 global $ilDB;
01180                 
01181                 if ($question_id < 1)
01182                 return;
01183 
01184                 $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
01185                         $ilDB->quote($question_id)
01186                         );
01187         $result = $ilDB->query($query);
01188                 if ($result->numRows() == 1)
01189                 {
01190                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01191                         $obj_id = $row["obj_fi"];
01192                 }
01193                 else
01194                 {
01195                         return;
01196                 }
01197 
01198                 include_once "./content/classes/Pages/class.ilPageObject.php";
01199                 $page = new ilPageObject("qpl", $question_id);
01200                 $page->delete();
01201                 
01202                 $query = sprintf("DELETE FROM qpl_questions WHERE question_id = %s",
01203                         $ilDB->quote($question_id)
01204                 );
01205                 $result = $ilDB->query($query);
01206                 
01207                 $this->deleteAdditionalTableData($question_id);
01208                 $this->deleteAnswers($question_id);
01209 
01210                 // delete the question in the tst_test_question table (list of test questions)
01211                 $querydelete = sprintf("DELETE FROM tst_test_question WHERE question_fi = %s", $ilDB->quote($question_id));
01212                 $deleteresult = $ilDB->query($querydelete);
01213 
01214                 // delete suggested solutions contained in the question
01215                 $querydelete = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s", $ilDB->quote($question_id));
01216                 $deleteresult = $ilDB->query($querydelete);
01217                                 
01218                 $directory = CLIENT_WEB_DIR . "/assessment/" . $obj_id . "/$question_id";
01219                 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
01220                 {
01221                         include_once "./classes/class.ilUtil.php";
01222                         ilUtil::delDir($directory);
01223                 }
01224 
01225                 include_once("./content/classes/Media/class.ilObjMediaObject.php");
01226                 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id);
01227                 // remaining usages are not in text anymore -> delete them
01228                 // and media objects (note: delete method of ilObjMediaObject
01229                 // checks whether object is used in another context; if yes,
01230                 // the object is not deleted!)
01231                 foreach($mobs as $mob)
01232                 {
01233                         ilObjMediaObject::_removeUsage($mob, "qpl:html", $question_id);
01234                         $mob_obj =& new ilObjMediaObject($mob);
01235                         $mob_obj->delete();
01236                 }
01237                 // update question count of question pool
01238                 include_once "./assessment/classes/class.ilObjQuestionPool.php";
01239                 ilObjQuestionPool::_updateQuestionCount($this->obj_id);
01240         }
01241 
01245         function getTotalAnswers()
01246         {
01247                 return $this->_getTotalAnswers($this->id);
01248         }
01249 
01256         function _getTotalAnswers($a_q_id)
01257         {
01258                 global $ilDB;
01259 
01260                 // get all question references to the question id
01261                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
01262                         $ilDB->quote($a_q_id),
01263                         $ilDB->quote($a_q_id)
01264                 );
01265 
01266                 $result = $ilDB->query($query);
01267 
01268                 if ($result->numRows() == 0)
01269                 {
01270                         return 0;
01271                 }
01272                 $found_id = array();
01273                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01274                 {
01275                         array_push($found_id, $row->question_id);
01276                 }
01277 
01278                 $query = sprintf("SELECT * FROM tst_test_result WHERE question_fi IN (%s)",
01279                         join($found_id, ","));
01280                 $result = $ilDB->query($query);
01281 
01282                 return $result->numRows();
01283         }
01284 
01285 
01292         function _getTotalRightAnswers($a_q_id)
01293         {
01294                 global $ilDB;
01295                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
01296                         $ilDB->quote($a_q_id),
01297                         $ilDB->quote($a_q_id)
01298                 );
01299                 $result = $ilDB->query($query);
01300                 if ($result->numRows() == 0)
01301                 {
01302                         return 0;
01303                 }
01304                 $found_id = array();
01305                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01306                 {
01307                         array_push($found_id, $row->question_id);
01308                 }
01309                 $query = sprintf("SELECT * FROM tst_test_result WHERE question_fi IN (%s)",
01310                         join($found_id, ","));
01311                 $result = $ilDB->query($query);
01312                 $answers = array();
01313                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01314                 {
01315                         $reached = $row->points; 
01316                         include_once "./assessment/classes/class.assQuestion.php";
01317                         $max = assQuestion::_getMaximumPoints($row->question_fi);
01318                         array_push($answers, array("reached" => $reached, "max" => $max));
01319                 }
01320                 $max = 0.0;
01321                 $reached = 0.0;
01322                 foreach ($answers as $key => $value)
01323                 {
01324                         $max += $value["max"];
01325                         $reached += $value["reached"];
01326                 }
01327                 if ($max > 0)
01328                 {
01329                         return $reached / $max;
01330                 }
01331                 else
01332                 {
01333                         return 0;
01334                 }
01335         }
01336 
01342         function _getTitle($a_q_id)
01343         {
01344                 global $ilDB;
01345                 $query = sprintf("SELECT title FROM qpl_questions WHERE question_id = %s",
01346                         $ilDB->quote($a_q_id)
01347                 );
01348                 $result = $ilDB->query($query);
01349                 if ($result->numRows() == 1)
01350                 {
01351                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01352                         return $row["title"];
01353                 }
01354                 else
01355                 {
01356                         return "";
01357                 }
01358         }
01359         
01360         function copyXHTMLMediaObjectsOfQuestion($a_q_id)
01361         {
01362                 include_once("./content/classes/Media/class.ilObjMediaObject.php");
01363                 $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $a_q_id);
01364                 foreach ($mobs as $mob)
01365                 {
01366                         ilObjMediaObject::_saveUsage($mob, "qpl:html", $this->getId());
01367                 }
01368         }
01369         
01370         function copyPageOfQuestion($a_q_id)
01371         {
01372                 if ($a_q_id > 0)
01373                 {
01374                         include_once "./content/classes/Pages/class.ilPageObject.php";
01375                         $page = new ilPageObject("qpl", $a_q_id);
01376 
01377                         $xml = str_replace("il__qst_".$a_q_id, "il__qst_".$this->id,
01378                                 $page->getXMLContent());
01379                         $this->page->setXMLContent($xml);
01380                         $this->page->saveMobUsage($xml);
01381                         $this->page->updateFromXML();
01382                 }
01383         }
01384 
01385         function getPageOfQuestion()
01386         {
01387                 include_once "./content/classes/Pages/class.ilPageObject.php";
01388                 $page = new ilPageObject("qpl", $this->id);
01389                 return $page->getXMLContent();
01390         }
01391 
01401   function _getQuestionType($question_id) {
01402                 global $ilDB;
01403 
01404     if ($question_id < 1)
01405       return "";
01406 
01407     $query = sprintf("SELECT type_tag FROM qpl_questions, qpl_question_type WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_question_type.question_type_id",
01408       $ilDB->quote($question_id)
01409     );
01410     $result = $ilDB->query($query);
01411     if ($result->numRows() == 1) {
01412       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01413       return $data->type_tag;
01414     } else {
01415       return "";
01416     }
01417   }
01418 
01428   function _getQuestionTitle($question_id) {
01429                 global $ilDB;
01430 
01431     if ($question_id < 1)
01432       return "";
01433 
01434     $query = sprintf("SELECT title FROM qpl_questions WHERE qpl_questions.question_id = %s",
01435       $ilDB->quote($question_id)
01436     );
01437     $result = $ilDB->query($query);
01438     if ($result->numRows() == 1) {
01439       $data = $result->fetchRow(DB_FETCHMODE_ASSOC);
01440       return $data["title"];
01441     } else {
01442       return "";
01443     }
01444   }
01445 
01454         function loadFromDb($question_id)
01455         {
01456                 global $ilDB;
01457                 
01458                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01459                         $ilDB->quote($this->getId() . "")
01460                 );
01461                 $result = $ilDB->query($query);
01462                 $this->suggested_solutions = array();
01463                 if ($result->numRows())
01464                 {
01465                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01466                         {
01467                                 $this->suggested_solutions[$row["subquestion_index"]] = array(
01468                                         "internal_link" => $row["internal_link"],
01469                                         "import_id" => $row["import_id"]
01470                                 );
01471                         }
01472                 }
01473         }
01474 
01483         function saveToDb($original_id = "")
01484         {
01485                 global $ilDB;
01486                 
01487                 include_once "./content/classes/Pages/class.ilInternalLink.php";
01488                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01489                         $ilDB->quote($this->getId() . "")
01490                 );
01491                 $result = $ilDB->query($query);
01492                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->getId());
01493                 foreach ($this->suggested_solutions as $index => $solution)
01494                 {
01495                         $query = sprintf("INSERT INTO qpl_suggested_solutions (suggested_solution_id, question_fi, internal_link, import_id, subquestion_index, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01496                                 $ilDB->quote($this->getId() . ""),
01497                                 $ilDB->quote($solution["internal_link"] . ""),
01498                                 $ilDB->quote($solution["import_id"] . ""),
01499                                 $ilDB->quote($index . "")
01500                         );
01501                         $ilDB->query($query);
01502                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
01503                         {
01504                                 ilInternalLink::_saveLink("qst", $this->getId(), $matches[2], $matches[3], $matches[1]);
01505                         }
01506                 }
01507                 // update question count of question pool
01508                 include_once "./assessment/classes/class.ilObjQuestionPool.php";
01509                 ilObjQuestionPool::_updateQuestionCount($this->obj_id);
01510         }
01511         
01519         function deleteSuggestedSolutions()
01520         {
01521                 global $ilDB;
01522                 // delete the links in the qpl_suggested_solutions table
01523                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01524                         $ilDB->quote($this->getId() . "")
01525                 );
01526                 $result = $ilDB->query($query);
01527                 // delete the links in the int_link table
01528                 include_once "./content/classes/Pages/class.ilInternalLink.php";
01529                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->getId());
01530         }
01531         
01541         function getSuggestedSolution($subquestion_index = 0)
01542         {
01543                 if (array_key_exists($subquestion_index, $this->suggested_solutions))
01544                 {
01545                         return $this->suggested_solutions[$subquestion_index];
01546                 }
01547                 else
01548                 {
01549                         return array();
01550                 }
01551         }
01552 
01563         function getSuggestedSolutionTitle($subquestion_index = 0)
01564         {
01565                 if (array_key_exists($subquestion_index, $this->suggested_solutions))
01566                 {
01567                         $title = $this->suggested_solutions[$subquestion_index]["internal_link"];
01568                         // TO DO: resolve internal link an get link type and title
01569                 }
01570                 else
01571                 {
01572                         $title = "";
01573                 }
01574                 return $title;
01575         }
01576 
01588         function setSuggestedSolution($solution_id = "", $subquestion_index = 0, $is_import = false)
01589         {
01590                 if (strcmp($solution_id, "") != 0)
01591                 {
01592                         $import_id = "";
01593                         if ($is_import)
01594                         {
01595                                 $import_id = $solution_id;
01596                                 $solution_id = $this->_resolveInternalLink($import_id);
01597                         }
01598                         $this->suggested_solutions[$subquestion_index] = array(
01599                                 "internal_link" => $solution_id,
01600                                 "import_id" => $import_id
01601                         );
01602                 }
01603         }
01604         
01605         function _resolveInternalLink($internal_link)
01606         {
01607                 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01608                 {
01609                         include_once "./content/classes/Pages/class.ilInternalLink.php";
01610                         include_once "./content/classes/class.ilLMObject.php";
01611                         include_once "./content/classes/class.ilGlossaryTerm.php";
01612                         switch ($matches[2])
01613                         {
01614                                 case "lm":
01615                                         $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01616                                         break;
01617                                 case "pg":
01618                                         $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01619                                         break;
01620                                 case "st":
01621                                         $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01622                                         break;
01623                                 case "git":
01624                                         $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01625                                         break;
01626                                 case "mob":
01627                                         $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01628                                         break;
01629                         }
01630                         if (strcmp($resolved_link, "") == 0)
01631                         {
01632                                 $resolved_link = $internal_link;
01633                         }
01634                 }
01635                 else
01636                 {
01637                         $resolved_link = $internal_link;
01638                 }
01639                 return $resolved_link;
01640         }
01641         
01642         function _resolveIntLinks($question_id)
01643         {
01644                 global $ilDB;
01645                 $resolvedlinks = 0;
01646                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01647                         $ilDB->quote($question_id . "")
01648                 );
01649                 $result = $ilDB->query($query);
01650                 if ($result->numRows())
01651                 {
01652                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01653                         {
01654                                 $internal_link = $row["internal_link"];
01655                                 include_once "./assessment/classes/class.assQuestion.php";
01656                                 $resolved_link = assQuestion::_resolveInternalLink($internal_link);
01657                                 if (strcmp($internal_link, $resolved_link) != 0)
01658                                 {
01659                                         // internal link was resolved successfully
01660                                         $queryupdate = sprintf("UPDATE qpl_suggested_solutions SET internal_link = %s WHERE suggested_solution_id = %s",
01661                                                 $ilDB->quote($resolved_link),
01662                                                 $ilDB->quote($row["suggested_solution_id"] . "")
01663                                         );
01664                                         $updateresult = $ilDB->query($queryupdate);
01665                                         $resolvedlinks++;
01666                                 }
01667                         }
01668                 }
01669                 if ($resolvedlinks)
01670                 {
01671                         // there are resolved links -> reenter theses links to the database
01672 
01673                         // delete all internal links from the database
01674                         include_once "./content/classes/Pages/class.ilInternalLink.php";
01675                         ilInternalLink::_deleteAllLinksOfSource("qst", $question_id);
01676 
01677                         $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01678                                 $ilDB->quote($question_id . "")
01679                         );
01680                         $result = $ilDB->query($query);
01681                         if ($result->numRows())
01682                         {
01683                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01684                                 {
01685                                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01686                                         {
01687                                                 ilInternalLink::_saveLink("qst", $question_id, $matches[2], $matches[3], $matches[1]);
01688                                         }
01689                                 }
01690                         }
01691                 }
01692         }
01693         
01694         function _getInternalLinkHref($target = "")
01695         {
01696                 global $ilDB;
01697                 $linktypes = array(
01698                         "lm" => "LearningModule",
01699                         "pg" => "PageObject",
01700                         "st" => "StructureObject",
01701                         "git" => "GlossaryItem",
01702                         "mob" => "MediaObject"
01703                 );
01704                 $href = "";
01705                 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01706                 {
01707                         $type = $matches[1];
01708                         $target_id = $matches[2];
01709                         include_once "./classes/class.ilUtil.php";
01710                         switch($linktypes[$matches[1]])
01711                         {
01712                                 case "LearningModule":
01713                                         $href = "./goto.php?target=" . $type . "_" . $target_id;
01714                                         break;
01715                                 case "PageObject":
01716                                 case "StructureObject":
01717                                         $href = "./goto.php?target=" . $type . "_" . $target_id;
01718                                         break;
01719                                 case "GlossaryItem":
01720                                         $href = "./goto.php?target=" . $type . "_" . $target_id;
01721                                         break;
01722                                 case "MediaObject":
01723                                         $href = "./content/lm_presentation.php?obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=".$_GET["ref_id"]."&mob_id=".$target_id;
01724                                         break;
01725                         }
01726                 }
01727                 return $href;
01728         }
01729         
01739         function _getOriginalId($question_id)
01740         {
01741                 global $ilDB;
01742                 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
01743                         $ilDB->quote($question_id . "")
01744                 );
01745                 $result = $ilDB->query($query);
01746                 if ($result->numRows() > 0)
01747                 {
01748                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01749                         if ($row["original_id"] > 0)
01750                         {
01751                                 return $row["original_id"];
01752                         }
01753                         else
01754                         {
01755                                 return $row["question_id"];
01756                         }
01757                 }
01758                 else
01759                 {
01760                         return "";
01761                 }
01762         }
01763 
01764         function syncWithOriginal()
01765         {
01766                 global $ilDB;
01767                 
01768                 include_once "./content/classes/Pages/class.ilInternalLink.php";
01769                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01770                         $ilDB->quote($this->original_id . "")
01771                 );
01772                 $result = $ilDB->query($query);
01773                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->original_id);
01774                 foreach ($this->suggested_solutions as $index => $solution)
01775                 {
01776                         $query = sprintf("INSERT INTO qpl_suggested_solutions (suggested_solution_id, question_fi, internal_link, import_id, subquestion_index, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
01777                                 $ilDB->quote($this->original_id . ""),
01778                                 $ilDB->quote($solution["internal_link"] . ""),
01779                                 $ilDB->quote($solution["import_id"] . ""),
01780                                 $ilDB->quote($index . "")
01781                         );
01782                         $ilDB->query($query);
01783                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
01784                         {
01785                                 ilInternalLink::_saveLink("qst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01786                         }
01787                 }
01788         }
01789 
01790         function createRandomSolution($test_id, $user_id)
01791         {
01792         }
01793 
01803         function _questionExists($question_id)
01804         {
01805                 global $ilDB;
01806 
01807                 if ($question_id < 1)
01808                 {
01809                         return false;
01810                 }
01811                 
01812                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE question_id = %s",
01813                         $ilDB->quote($question_id)
01814                 );
01815     $result = $ilDB->query($query);
01816                 if ($result->numRows() == 1)
01817                 {
01818                         return true;
01819                 }
01820                 else
01821                 {
01822                         return false;
01823                 }
01824         }
01825 
01835   function &_instanciateQuestion($question_id) 
01836         {
01837                 if (strcmp($question_id, "") != 0)
01838                 {
01839                         include_once "./assessment/classes/class.assQuestion.php";
01840                         $question_type = assQuestion::_getQuestionType($question_id);
01841                         include_once "./assessment/classes/class.".$question_type.".php";
01842                         $question = new $question_type();
01843                         $question->loadFromDb($question_id);
01844                         return $question;
01845                 }
01846   }
01847         
01856         function getPoints()
01857         {
01858                 if (strcmp($this->points, "") == 0)
01859                 {
01860                         return 0;
01861                 }
01862                 else
01863                 {
01864                         return $this->points;
01865                 }
01866         }
01867 
01868         
01877         function setPoints($a_points)
01878         {
01879                 $this->points = $a_points;
01880         }
01881         
01882         function getSolutionCommentMCScoring($active_id)
01883         {
01884                 $result = "";
01885                 include_once "./assessment/classes/class.ilObjTest.php";
01886                 if (ilObjTest::_getMCScoring($active_id) == SCORE_ZERO_POINTS_WHEN_UNANSWERED)
01887                 {
01888                         $result = $this->lng->txt("solution_comment_mc_scoring");
01889                 }
01890                 return $result;
01891         }
01892 
01893         function getSolutionCommentScoreCutting($active_id)
01894         {
01895                 $result = "";
01896                 include_once "./assessment/classes/class.ilObjTest.php";
01897                 if (ilObjTest::_getScoreCutting($active_id) == SCORE_CUT_QUESTION)
01898                 {
01899                         $result = $this->lng->txt("solution_comment_score_cutting");
01900                 }
01901                 return $result;
01902         }
01903 
01904         function getSolutionCommentCountSystem($active_id)
01905         {
01906                 $result = "";
01907                 include_once "./assessment/classes/class.ilObjTest.php";
01908                 if (ilObjTest::_getCountSystem($active_id) == COUNT_CORRECT_SOLUTIONS )
01909                 {
01910                         $result = $this->lng->txt("solution_comment_count_system");
01911                 }
01912                 return $result;
01913         }
01914         
01923         function getSolutionMaxPass($active_id)
01924         {
01925                 return $this->_getSolutionMaxPass($this->getId(), $active_id);
01926         }
01927 
01936         function _getSolutionMaxPass($question_id, $active_id)
01937         {
01938                 global $ilDB;
01939 
01940                 $query = sprintf("SELECT MAX(pass) as maxpass FROM tst_test_result WHERE active_fi = %s AND question_fi = %s",
01941                         $ilDB->quote($active_id . ""),
01942                         $ilDB->quote($question_id . "")
01943                 );
01944     $result = $ilDB->query($query);
01945                 if ($result->numRows() == 1)
01946                 {
01947                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01948                         return $row["maxpass"];
01949                 }
01950                 else
01951                 {
01952                         return 0;
01953                 }
01954         }
01955 
01966         function _isWriteable($question_id, $user_id)
01967         {
01968                 global $ilDB;
01969 
01970                 if (($question_id < 1) || ($user_id < 1))
01971                 {
01972                         return false;
01973                 }
01974                 
01975                 $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
01976                         $ilDB->quote($question_id . "")
01977                 );
01978     $result = $ilDB->query($query);
01979                 if ($result->numRows() == 1)
01980                 {
01981                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01982                         $qpl_object_id = $row["obj_fi"];
01983                         include_once "./assessment/classes/class.ilObjQuestionPool.php";
01984                         return ilObjQuestionPool::_isWriteable($qpl_object_id, $user_id);
01985                 }
01986                 else
01987                 {
01988                         return false;
01989                 }
01990         }
01991 
02000         function _isUsedInRandomTest($question_id = "")
02001         {
02002                 global $ilDB;
02003                 
02004                 if ($question_id < 1) return 0;
02005                 $query = sprintf("SELECT test_random_question_id FROM tst_test_random_question WHERE question_fi = %s",
02006                         $ilDB->quote($question_id . "")
02007                 );
02008                 $result = $ilDB->query($query);
02009                 return $result->numRows();
02010         }
02011 
02023         function calculateReachedPoints($active_id, $pass = NULL, $points = 0)
02024         {
02025                 include_once "./assessment/classes/class.ilObjTest.php";
02026                 $count_system = ilObjTest::_getCountSystem($active_id);
02027                 if ($count_system == 1)
02028                 {
02029                         if ($points != $this->getMaximumPoints())
02030                         {
02031                                 $points = 0;
02032                         }
02033                 }
02034                 $score_cutting = ilObjTest::_getScoreCutting($active_id);
02035                 if ($score_cutting == 0)
02036                 {
02037                         if ($points < 0)
02038                         {
02039                                 $points = 0;
02040                         }
02041                 }
02042                 return $points;
02043         }
02044 
02056         function _isWorkedThrough($active_id, $question_id, $pass = NULL)
02057         {
02058                 global $ilDB;
02059 
02060                 $points = 0;
02061                 if (is_null($pass))
02062                 {
02063                         include_once "./assessment/classes/class.assQuestion.php";
02064                         $pass = assQuestion::_getSolutionMaxPass($question_id, $active_id);
02065                 }
02066                 $query = sprintf("SELECT solution_id FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
02067                         $ilDB->quote($active_id . ""),
02068                         $ilDB->quote($question_id . ""),
02069                         $ilDB->quote($pass . "")
02070                 );
02071                 $result = $ilDB->query($query);
02072                 if ($result->numRows())
02073                 {
02074                         return TRUE;
02075                 }
02076                 else
02077                 {
02078                         return FALSE;
02079                 }
02080         }
02081 
02082         function getMultilineAnswerSetting()
02083         {
02084                 global $ilUser;
02085 
02086                 $multilineAnswerSetting = $ilUser->getPref("tst_multiline_answers");
02087                 if ($multilineAnswerSetting != 1)
02088                 {
02089                         $multilineAnswerSetting = 0;
02090                 }
02091                 return $multilineAnswerSetting;
02092         }
02093         
02094         function setMultilineAnswerSetting($a_setting = 0)
02095         {
02096                 global $ilUser;
02097                 $ilUser->writePref("tst_multiline_answers", $a_setting);
02098         }
02108         function _areAnswered($a_user_id,$a_question_ids)
02109         {
02110                 global $ilDB;
02111 
02112                 $query = "SELECT DISTINCT(question_fi) FROM tst_test_result JOIN tst_active ".
02113                         "ON (active_id = active_fi) ".
02114                         "WHERE question_fi IN ('".implode("','",$a_question_ids)."') ".
02115                         "AND user_fi = '".$a_user_id."'";
02116                 $res = $ilDB->query($query);
02117                 return ($res->numRows() == count($a_question_ids)) ? true : false;
02118         }
02119         
02128         function isHTML($a_text)
02129         {
02130                 if (preg_match("/<[^>]*?>/", $a_text))
02131                 {
02132                         return TRUE;
02133                 }
02134                 else
02135                 {
02136                         return FALSE; 
02137                 }
02138         }
02139         
02146         function prepareTextareaOutput($txt_output, $prepare_for_latex_output = FALSE)
02147         {
02148                 include_once "./classes/class.ilObjAdvancedEditing.php";
02149                 $result = $txt_output;
02150                 $is_html = $this->isHTML($result);
02151                 if ($prepare_for_latex_output)
02152                 {
02153                         $result = ilUtil::insertLatexImages($result, "<span class\=\"latex\">", "<\/span>", URL_TO_LATEX);
02154                         $result = ilUtil::insertLatexImages($result, "\[tex\]", "\[\/tex\]", URL_TO_LATEX);
02155                 }
02156                 if (!$is_html)
02157                 {
02158                         // if the string does not contain HTML code, replace the newlines with HTML line breaks
02159                         $result = preg_replace("/[\n]/", "<br />", $result);
02160                 }
02161                 else
02162                 {
02163                         // patch for problems with the <pre> tags in tinyMCE
02164                         if (preg_match_all("/(<pre>.*?<\/pre>)/ims", $result, $matches))
02165                         {
02166                                 foreach ($matches[0] as $found)
02167                                 {
02168                                         $replacement = "";
02169                                         if (strpos("\n", $found) === FALSE)
02170                                         {
02171                                                 $replacement = "\n";
02172                                         }
02173                                         $removed = preg_replace("/<br\s*?\/>/ims", $replacement, $found);
02174                                         $result = str_replace($found, $removed, $result);
02175                                 }
02176                         }
02177                 }
02178                 $result = str_replace("{", "&#123;", $result);
02179                 $result = str_replace("}", "&#125;", $result);
02180                 $result = str_replace("\\", "&#92;", $result);
02181                 return $result;
02182         }
02183 
02191         function QTIMaterialToString($a_material)
02192         {
02193                 $result = "";
02194                 for ($i = 0; $i < $a_material->getMaterialCount(); $i++)
02195                 {
02196                         $material = $a_material->getMaterial($i);
02197                         if (strcmp($material["type"], "mattext") == 0)
02198                         {
02199                                 $result .= $material["material"]->getContent();
02200                         }
02201                         if (strcmp($material["type"], "matimage") == 0)
02202                         {
02203                                 $matimage = $material["material"];
02204                                 if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $matimage->getLabel(), $matches))
02205                                 {
02206                                         // import an mediaobject which was inserted using tiny mce
02207                                         if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
02208                                         array_push($_SESSION["import_mob_xhtml"], array("mob" => $matimage->getLabel(), "uri" => $matimage->getUri()));
02209                                 }
02210                         }
02211                 }
02212                 return $result;
02213         }
02214         
02223         function addQTIMaterial(&$a_xml_writer, $a_material, $close_material_tag = TRUE, $add_mobs = TRUE)
02224         {
02225                 include_once "./Services/RTE/classes/class.ilRTE.php";
02226                 include_once("./content/classes/Media/class.ilObjMediaObject.php");
02227 
02228                 $a_xml_writer->xmlStartTag("material");
02229                 $attrs = array(
02230                         "texttype" => "text/plain"
02231                 );
02232                 if ($this->isHTML($a_material))
02233                 {
02234                         $attrs["texttype"] = "text/xhtml";
02235                 }
02236                 $a_xml_writer->xmlElement("mattext", $attrs, ilRTE::_replaceMediaObjectImageSrc($a_material, 0));
02237 
02238                 if ($add_mobs)
02239                 {
02240                         $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $this->getId());
02241                         foreach ($mobs as $mob)
02242                         {
02243                                 $mob_obj =& new ilObjMediaObject($mob);
02244                                 $imgattrs = array(
02245                                         "label" => "il_" . IL_INST_ID . "_mob_" . $mob,
02246                                         "uri" => "objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
02247                                 );
02248                                 $a_xml_writer->xmlElement("matimage", $imgattrs, NULL);
02249                         }
02250                 }               
02251                 if ($close_material_tag) $a_xml_writer->xmlEndTag("material");
02252         }
02253         
02254         function createNewImageFileName($image_filename)
02255         {
02256                 $extension = "";
02257                 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/i", $image_filename, $matches))
02258                 {
02259                         $extension = "." . $matches[1];
02260                 }
02261                 $image_filename = md5($image_filename) . $extension;
02262                 return $image_filename;
02263         }
02264 
02270         function &getInstances()
02271         {
02272                 global $ilDB;
02273                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s",
02274                         $ilDB->quote($this->getId())
02275                 );
02276                 $result = $ilDB->query($query);
02277                 $instances = array();
02278                 $ids = array();
02279                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
02280                 {
02281                         array_push($ids, $row["question_id"]);
02282                 }
02283                 foreach ($ids as $question_id)
02284                 {
02285                         $query = sprintf("SELECT DISTINCT object_data.obj_id, object_data.title FROM tst_test_question, object_data, tst_tests WHERE question_fi = %s AND tst_tests.test_id = tst_test_question.test_fi AND object_data.obj_id = tst_tests.obj_fi",
02286                                 $ilDB->quote($question_id . "")
02287                         );
02288                         $result = $ilDB->query($query);
02289                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
02290                         {
02291                                 $instances[$row["obj_id"]] = $row["title"];
02292                         }
02293                         $query = sprintf("SELECT DISTINCT object_data.obj_id, object_data.title FROM tst_test_random_question, tst_active, object_data, tst_tests WHERE tst_test_random_question.active_fi = tst_active.active_id AND tst_test_random_question.question_fi = %s AND tst_tests.test_id = tst_active.test_fi AND object_data.obj_id = tst_tests.obj_fi",
02294                                 $ilDB->quote($question_id . "")
02295                         );
02296                         $result = $ilDB->query($query);
02297                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
02298                         {
02299                                 $instances[$row["obj_id"]] = $row["title"];
02300                         }
02301                 }
02302                 include_once "./assessment/classes/class.ilObjTest.php";
02303                 foreach ($instances as $key => $value)
02304                 {
02305                         $query = sprintf("SELECT object_reference.ref_id FROM object_reference WHERE obj_id = %s",
02306                                 $ilDB->quote($key . "")
02307                         );
02308                         $result = $ilDB->query($query);
02309                         $refs = array();
02310                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
02311                         {
02312                                 array_push($refs, $row["ref_id"]);
02313                         }
02314                         $instances[$key] = array("obj_id" => $key, "title" => $value, "author" => ilObjTest::_lookupAuthor($key), "refs" => $refs);
02315                 }
02316                 return $instances;
02317         }
02318 
02326         function getActiveUserData($active_id)
02327         {
02328                 global $ilDB;
02329                 $query = sprintf("SELECT * FROM tst_active WHERE active_id = %s",
02330                         $ilDB->quote($active_id . "")
02331                 );
02332                 $result = $ilDB->query($query);
02333                 if ($result->numRows())
02334                 {
02335                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
02336                         return array("user_id" => $row["user_fi"], "test_id" => $row["test_fi"]);
02337                 }
02338                 else
02339                 {
02340                         return array();
02341                 }
02342         }
02343         
02344 }
02345 
02346 ?>

Generated on Fri Dec 13 2013 13:52:05 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1