• Main Page
  • Related Pages
  • 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 require_once "./assessment/classes/class.assClozeTestGUI.php";
00025 require_once "./assessment/classes/class.assImagemapQuestionGUI.php";
00026 require_once "./assessment/classes/class.assJavaAppletGUI.php";
00027 require_once "./assessment/classes/class.assMatchingQuestionGUI.php";
00028 require_once "./assessment/classes/class.assMultipleChoiceGUI.php";
00029 require_once "./assessment/classes/class.assOrderingQuestionGUI.php";
00030 require_once "./assessment/classes/class.assTextQuestionGUI.php";
00031 require_once "./content/classes/Pages/class.ilPageObject.php";
00032 
00033 define("LIMIT_NO_LIMIT", 0);
00034 define("LIMIT_TIME_ONLY", 1);
00035 
00036 define("OUTPUT_HTML", 0);
00037 define("OUTPUT_JAVASCRIPT", 1);
00038 
00050 class ASS_Question
00051 {
00059         var $id;
00060 
00068         var $title;
00069 
00077         var $comment;
00078 
00087         var $owner;
00088 
00097         var $author;
00098 
00106         var $est_working_time;
00107 
00115         var $shuffle;
00116 
00124         var $test_id;
00125 
00133         var $obj_id;
00134 
00142         var $ilias;
00143 
00151         var $tpl;
00152 
00160         var $lng;
00161 
00169         var $domxml;
00170 
00178         var $outputType;
00179 
00180         var $suggested_solutions;
00192         function ASS_Question(
00193                 $title = "",
00194                 $comment = "",
00195                 $author = "",
00196                 $owner = -1
00197         )
00198         {
00199                 global $ilias;
00200                 global $lng;
00201                 global $tpl;
00202 
00203                 $this->ilias =& $ilias;
00204                 $this->lng =& $lng;
00205                 $this->tpl =& $tpl;
00206 
00207                 $this->title = $title;
00208                 $this->comment = $comment;
00209                 $this->author = $author;
00210                 if (!$this->author)
00211                 {
00212                         $this->author = $this->ilias->account->fullname;
00213                 }
00214                 $this->owner = $owner;
00215                 if ($this->owner == -1)
00216                 {
00217                         $this->owner = $this->ilias->account->id;
00218                 }
00219                 $this->id = -1;
00220                 $this->test_id = -1;
00221                 $this->suggested_solutions = array();
00222                 $this->shuffle = 1;
00223                 $this->setEstimatedWorkingTime(0,1,0);
00224                 $this->outputType = OUTPUT_HTML;
00225                 register_shutdown_function(array(&$this, '_ASS_Question'));
00226         }
00227 
00228         function _ASS_Question()
00229         {
00230                 if (!empty($this->domxml))
00231                 {
00232                         $this->domxml->free();
00233                 }
00234         }
00235 
00245         function to_xml()
00246         {
00247                 // to be implemented in the successor classes of ASS_Question
00248         }
00249 
00258         function isComplete()
00259         {
00260                 return false;
00261         }
00262 
00272         function questionTitleExists($title)
00273         {
00274                 $query = sprintf("SELECT * FROM qpl_questions WHERE title = %s",
00275                         $this->ilias->db->quote($title)
00276                         );
00277                 $result = $this->ilias->db->query($query);
00278                 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00279                 {
00280                         if ($result->numRows() == 1)
00281                         {
00282                                 return TRUE;
00283                         }
00284                 }
00285                 return FALSE;
00286         }
00287 
00297         function setTitle($title = "")
00298         {
00299                 $this->title = $title;
00300         }
00301 
00311         function setId($id = -1)
00312         {
00313                 $this->id = $id;
00314         }
00315 
00325         function setTestId($id = -1)
00326         {
00327                 $this->test_id = $id;
00328         }
00329 
00339         function setComment($comment = "")
00340         {
00341                 $this->comment = $comment;
00342         }
00343 
00353         function setOutputType($outputType = OUTPUT_HTML)
00354         {
00355                 $this->outputType = $outputType;
00356         }
00357 
00358 
00368         function setShuffle($shuffle = true)
00369         {
00370                 if ($shuffle)
00371                 {
00372                         $this->shuffle = 1;
00373                 }
00374                         else
00375                 {
00376                         $this->shuffle = 0;
00377                 }
00378         }
00379 
00391         function setEstimatedWorkingTime($hour=0, $min=0, $sec=0)
00392         {
00393                 $this->est_working_time = array("h" => (int)$hour, "m" => (int)$min, "s" => (int)$sec);
00394         }
00395 
00405         function keyInArray($searchkey, $array)
00406         {
00407                 if ($searchKey)
00408                 {
00409                         foreach ($array as $key => $value)
00410                         {
00411                                 if (strcmp($key, $searchkey)==0)
00412                                 {
00413                                         return true;
00414                                 }
00415                         }
00416                 }
00417                 return false;
00418         }
00419 
00429         function setAuthor($author = "")
00430         {
00431                 if (!$author)
00432                 {
00433                         $author = $this->ilias->account->fullname;
00434                 }
00435                 $this->author = $author;
00436         }
00437 
00447         function setOwner($owner = "")
00448         {
00449                 $this->owner = $owner;
00450         }
00451 
00461         function getTitle()
00462         {
00463                 return $this->title;
00464         }
00465 
00475         function getId()
00476         {
00477                 return $this->id;
00478         }
00479 
00489         function getShuffle()
00490         {
00491                 return $this->shuffle;
00492         }
00493 
00503         function getTestId()
00504         {
00505                 return $this->test_id;
00506         }
00507 
00517         function getComment()
00518         {
00519                 return $this->comment;
00520         }
00521 
00531         function getOutputType()
00532         {
00533                 return $this->outputType;
00534         }
00535 
00545         function getEstimatedWorkingTime()
00546         {
00547                 if (!$this->est_working_time)
00548                 {
00549                         $this->est_working_time = array("h" => 0, "m" => 0, "s" => 0);
00550                 }
00551                 return $this->est_working_time;
00552         }
00553 
00563         function getAuthor()
00564         {
00565                 return $this->author;
00566         }
00567 
00577         function getOwner()
00578         {
00579                 return $this->owner;
00580         }
00581 
00591         function getObjId()
00592         {
00593                 return $this->obj_id;
00594         }
00595 
00605         function setObjId($obj_id = 0)
00606         {
00607                 $this->obj_id = $obj_id;
00608         }
00609 
00613         function createPageObject()
00614         {
00615 //              $qpl_id = ilObject::_lookupObjectId($this->getRefId());
00616                 $qpl_id = $this->getObjId();
00617 
00618                 $this->page = new ilPageObject("qpl", 0);
00619                 $this->page->setId($this->getId());
00620                 $this->page->setParentId($qpl_id);
00621                 $this->page->setXMLContent("<PageObject><PageContent>".
00622                         "<Question QRef=\"il__qst_".$this->getId()."\"/>".
00623                         "</PageContent></PageObject>");
00624                 $this->page->create();
00625         }
00626 
00635         function insertIntoTest($test_id)
00636         {
00637                 // get maximum sequence index in test
00638                 $query = sprintf("SELECT MAX(sequence) AS seq FROM dum_test_question WHERE test_fi=%s",
00639                         $this->ilias->db->quote($test_id)
00640                         );
00641                 $result = $this->ilias->db->query($query);
00642                 $sequence = 1;
00643                 if ($result->numRows() == 1)
00644                 {
00645                         $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00646                         $sequence = $data->seq + 1;
00647                 }
00648                 $query = sprintf("INSERT INTO dum_test_question (test_question_id, test_fi, question_fi, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
00649                         $this->ilias->db->quote($test_id),
00650                         $this->ilias->db->quote($this->getId()),
00651                         $this->ilias->db->quote($sequence)
00652                         );
00653                 $result = $this->ilias->db->query($query);
00654                 if ($result != DB_OK)
00655                 {
00656                 // Fehlermeldung
00657                 }
00658         }
00659 
00669         function _getReachedPoints($user_id, $test_id)
00670         {
00671                 return 0;
00672         }
00673 
00683         function getReachedPoints($user_id, $test_id)
00684         {
00685                 return 0;
00686         }
00687 
00696         function getMaximumPoints()
00697         {
00698                 return 0;
00699         }
00700 
00709         function saveWorkingData($limit_to = LIMIT_NO_LIMIT)
00710         {
00711         /*    global $ilias;
00712                 $db =& $ilias->db;
00713 
00714                 // Increase the number of tries for that question
00715                 $query = sprintf("SELECT * FROM dum_assessment_solution_order WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
00716                 $db->quote($this->ilias->account->id),
00717                 $db->quote($_GET["test"]),
00718                 $db->quote($this->getId())
00719                 );
00720                 $result = $db->query($query);
00721                 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00722                 $query = sprintf("UPDATE dum_assessment_solution_order SET tries = %s WHERE solution_order_id = %s",
00723                 $db->quote($data->tries + 1),
00724                 $db->quote($data->solution_order_id)
00725                 );
00726                 $result = $db->query($query);
00727         */
00728         }
00729 
00738         function getJavaPath() {
00739                 return CLIENT_WEB_DIR . "/assessment/$this->obj_id/$this->id/java/";
00740         }
00741 
00750         function getImagePath()
00751         {
00752                 return CLIENT_WEB_DIR . "/assessment/$this->obj_id/$this->id/images/";
00753         }
00754 
00763         function getJavaPathWeb()
00764         {
00765                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/$this->obj_id/$this->id/java/";
00766                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00767         }
00768 
00777         function getImagePathWeb()
00778         {
00779                 $webdir = ilUtil::removeTrailingPathSeparators(CLIENT_WEB_DIR) . "/assessment/$this->obj_id/$this->id/images/";
00780                 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $webdir);
00781         }
00782 
00792         function &getSolutionValues($test_id)
00793         {
00794                 global $ilDB;
00795                 global $ilUser;
00796 
00797                 $db =& $ilDB->db;
00798 
00799                 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
00800                         $db->quote($ilUser->id),
00801                         $db->quote($test_id),
00802                         $db->quote($this->getId())
00803                         );
00804                 $result = $db->query($query);
00805                 $values = array();
00806                 while   ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00807                 {
00808                         array_push($values, $row);
00809                 }
00810 
00811                 return $values;
00812         }
00813 
00822         function isInUse($question_id = "")
00823         {
00824                 if ($question_id < 1) $question_id = $this->id;
00825                 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE original_id = %s",
00826                         $this->ilias->db->quote($question_id . "")
00827                 );
00828                 $result = $this->ilias->db->query($query);
00829                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00830                 return $row->question_count;
00831         }
00832 
00841         function isClone($question_id = "")
00842         {
00843                 if ($question_id < 1) $question_id = $this->id;
00844                 $query = sprintf("SELECT original_id FROM qpl_questions WHERE question_id = %s",
00845                         $this->ilias->db->quote($question_id . "")
00846                 );
00847                 $result = $this->ilias->db->query($query);
00848                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00849                 if ($row->original_id > 0)
00850                 {
00851                         return TRUE;
00852                 }
00853                 else
00854                 {
00855                         return FALSE;
00856                 }
00857         }
00858 
00867         function pcArrayShuffle($array)
00868         {
00869                 mt_srand((double)microtime()*1000000);
00870                 $i = count($array);
00871                 if ($i > 0)
00872                 {
00873                         while(--$i)
00874                         {
00875                                 $j = mt_rand(0, $i);
00876                                 if ($i != $j)
00877                                 {
00878                                         // swap elements
00879                                         $tmp = $array[$j];
00880                                         $array[$j] = $array[$i];
00881                                         $array[$i] = $tmp;
00882                                 }
00883                         }
00884                 }
00885                 return $array;
00886         }
00887 
00893         function getQuestionTypeFromDb($question_id)
00894         {
00895                 global $ilDB;
00896 
00897                 $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",
00898                         $ilDB->quote($question_id));
00899 
00900                 $result = $ilDB->query($query);
00901                 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00902 
00903                 return $data->type_tag;
00904         }
00905 
00914         function delete($question_id)
00915         {
00916                 if ($question_id < 1)
00917                 return;
00918 
00919                 $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
00920                         $this->ilias->db->quote($question_id)
00921                         );
00922         $result = $this->ilias->db->query($query);
00923                 if ($result->numRows() == 1)
00924                 {
00925                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00926                         $obj_id = $row["obj_fi"];
00927                 }
00928                 else
00929                 {
00930                         return;
00931                 }
00932 
00933                 //if ((!$this->isInUse($question_id)) && (!$this->isClone($question_id)))
00934                 //{
00935                         // delete page object only when where is no other question using this object (this happens as long as page objects are not copied completely when a question is duplicated)
00936                         $page = new ilPageObject("qpl", $question_id);
00937                         $page->delete();
00938                 //}
00939                 
00940                 $query = sprintf("DELETE FROM qpl_questions WHERE question_id = %s",
00941                         $this->ilias->db->quote($question_id)
00942                         );
00943                 $result = $this->ilias->db->query($query);
00944                 $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
00945                         $this->ilias->db->quote($question_id)
00946                         );
00947                 $result = $this->ilias->db->query($query);
00948 
00949                 // delete the question in the tst_test_question table (list of test questions)
00950                 $querydelete = sprintf("DELETE FROM tst_test_question WHERE question_fi = %s", $this->ilias->db->quote($question_id));
00951                 $deleteresult = $this->ilias->db->query($querydelete);
00952 
00953                 // delete suggested solutions contained in the question
00954                 $querydelete = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s", $this->ilias->db->quote($question_id));
00955                 $deleteresult = $this->ilias->db->query($querydelete);
00956                                 
00957                 $directory = CLIENT_WEB_DIR . "/assessment/" . $obj_id . "/$question_id";
00958                 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
00959                 {
00960                         $directory = escapeshellarg($directory);
00961                         exec("rm -rf $directory");
00962                 }
00963         }
00964 
00968         function getTotalAnswers()
00969         {
00970                 return $this->_getTotalAnswers($this->id);
00971         }
00972 
00979         function _getTotalAnswers($a_q_id)
00980         {
00981                 global $ilDB;
00982 
00983                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
00984                         $ilDB->quote($a_q_id),
00985                         $ilDB->quote($a_q_id)
00986                 );
00987                 $result = $ilDB->query($query);
00988 
00989                 if ($result->numRows() == 0)
00990                 {
00991                         return 0;
00992                 }
00993                 $found_id = array();
00994                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00995                 {
00996                         array_push($found_id, $row->question_id);
00997                 }
00998 
00999                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi IN (%s) GROUP BY CONCAT(user_fi,test_fi)",
01000                         join($found_id, ","));
01001 
01002                 $result = $ilDB->query($query);
01003 
01004                 return $result->numRows();
01005         }
01006 
01007 
01014         function _getTotalRightAnswers($a_q_id)
01015         {
01016                 global $ilDB;
01017                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
01018                         $ilDB->quote($a_q_id),
01019                         $ilDB->quote($a_q_id)
01020                 );
01021                 $result = $ilDB->query($query);
01022                 if ($result->numRows() == 0)
01023                 {
01024                         return 0;
01025                 }
01026                 $found_id = array();
01027                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01028                 {
01029                         array_push($found_id, $row->question_id);
01030                 }
01031                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi IN (%s) GROUP BY CONCAT(user_fi,test_fi)",
01032                         join($found_id, ",")
01033                 );
01034                 $result = $ilDB->query($query);
01035                 $answers = array();
01036                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01037                 {
01038                         $question =& ASS_Question::_instanciateQuestion($row->question_fi);
01039                         $reached = $question->getReachedPoints($row->user_fi, $row->test_fi);
01040                         $max = $question->getMaximumPoints();
01041                         array_push($answers, array("reached" => $reached, "max" => $max));
01042                 }
01043                 $max = 0.0;
01044                 $reached = 0.0;
01045                 foreach ($answers as $key => $value)
01046                 {
01047                         $max += $value["max"];
01048                         $reached += $value["reached"];
01049                 }
01050                 if ($max > 0)
01051                 {
01052                         return $reached / $max;
01053                 }
01054                 else
01055                 {
01056                         return 0;
01057                 }
01058         }
01059 
01060         function copyPageOfQuestion($a_q_id)
01061         {
01062                 if ($a_q_id > 0)
01063                 {
01064                         $page = new ilPageObject("qpl", $a_q_id);
01065 
01066                         $xml = str_replace("il__qst_".$a_q_id, "il__qst_".$this->id,
01067                                 $page->getXMLContent());
01068                         $this->page->setXMLContent($xml);
01069                         $this->page->saveMobUsage($xml);
01070                         $this->page->updateFromXML();
01071                 }
01072         }
01073 
01074         function getPageOfQuestion()
01075         {
01076                 $page = new ilPageObject("qpl", $this->id);
01077                 return $page->getXMLContent();
01078         }
01079 
01089   function _getQuestionType($question_id) {
01090                 global $ilDB;
01091 
01092     if ($question_id < 1)
01093       return "";
01094 
01095     $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",
01096       $ilDB->quote($question_id)
01097     );
01098     $result = $ilDB->query($query);
01099     if ($result->numRows() == 1) {
01100       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01101       return $data->type_tag;
01102     } else {
01103       return "";
01104     }
01105   }
01106 
01116   function _getQuestionTitle($question_id) {
01117                 global $ilDB;
01118 
01119     if ($question_id < 1)
01120       return "";
01121 
01122     $query = sprintf("SELECT title FROM qpl_questions WHERE qpl_questions.question_id = %s",
01123       $ilDB->quote($question_id)
01124     );
01125     $result = $ilDB->query($query);
01126     if ($result->numRows() == 1) {
01127       $data = $result->fetchRow(DB_FETCHMODE_ASSOC);
01128       return $data["title"];
01129     } else {
01130       return "";
01131     }
01132   }
01133 
01142         function loadFromDb($question_id)
01143         {
01144                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01145                         $this->ilias->db->quote($this->getId() . "")
01146                 );
01147                 $result = $this->ilias->db->query($query);
01148                 $this->suggested_solutions = array();
01149                 if ($result->numRows())
01150                 {
01151                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01152                         {
01153                                 $this->suggested_solutions[$row["subquestion_index"]] = array(
01154                                         "internal_link" => $row["internal_link"],
01155                                         "import_id" => $row["import_id"]
01156                                 );
01157                         }
01158                 }
01159         }
01160 
01169         function saveToDb($original_id = "")
01170         {
01171                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01172                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01173                         $this->ilias->db->quote($this->getId() . "")
01174                 );
01175                 $result = $this->ilias->db->query($query);
01176                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->getId());
01177                 foreach ($this->suggested_solutions as $index => $solution)
01178                 {
01179                         $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)",
01180                                 $this->ilias->db->quote($this->getId() . ""),
01181                                 $this->ilias->db->quote($solution["internal_link"] . ""),
01182                                 $this->ilias->db->quote($solution["import_id"] . ""),
01183                                 $this->ilias->db->quote($index . "")
01184                         );
01185                         $this->ilias->db->query($query);
01186                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
01187                         {
01188                                 ilInternalLink::_saveLink("qst", $this->getId(), $matches[2], $matches[3], $matches[1]);
01189                         }
01190                 }
01191         }
01192         
01200         function deleteSuggestedSolutions()
01201         {
01202                 // delete the links in the qpl_suggested_solutions table
01203                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01204                         $this->ilias->db->quote($this->getId() . "")
01205                 );
01206                 $result = $this->ilias->db->query($query);
01207                 // delete the links in the int_link table
01208                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01209                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->getId());
01210         }
01211         
01221         function getSuggestedSolution($subquestion_index = 0)
01222         {
01223                 if (array_key_exists($subquestion_index, $this->suggested_solutions))
01224                 {
01225                         return $this->suggested_solutions[$subquestion_index];
01226                 }
01227                 else
01228                 {
01229                         return array();
01230                 }
01231         }
01232 
01243         function getSuggestedSolutionTitle($subquestion_index = 0)
01244         {
01245                 if (array_key_exists($subquestion_index, $this->suggested_solutions))
01246                 {
01247                         $title = $this->suggested_solutions[$subquestion_index]["internal_link"];
01248                         // TO DO: resolve internal link an get link type and title
01249                 }
01250                 else
01251                 {
01252                         $title = "";
01253                 }
01254                 return $title;
01255         }
01256 
01268         function setSuggestedSolution($solution_id = "", $subquestion_index = 0, $is_import = false)
01269         {
01270                 if (strcmp($solution_id, "") != 0)
01271                 {
01272                         $import_id = "";
01273                         if ($is_import)
01274                         {
01275                                 $import_id = $solution_id;
01276                                 $solution_id = $this->_resolveInternalLink($import_id);
01277                         }
01278                         $this->suggested_solutions[$subquestion_index] = array(
01279                                 "internal_link" => $solution_id,
01280                                 "import_id" => $import_id
01281                         );
01282                 }
01283         }
01284         
01285         function _resolveInternalLink($internal_link)
01286         {
01287                 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01288                 {
01289                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01290                         require_once "./content/classes/class.ilLMObject.php";
01291                         require_once "./content/classes/class.ilGlossaryTerm.php";
01292                         switch ($matches[2])
01293                         {
01294                                 case "lm":
01295                                         $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01296                                         break;
01297                                 case "pg":
01298                                         $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01299                                         break;
01300                                 case "st":
01301                                         $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01302                                         break;
01303                                 case "git":
01304                                         $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01305                                         break;
01306                                 case "mob":
01307                                         $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01308                                         break;
01309                         }
01310                         if (strcmp($resolved_link, "") == 0)
01311                         {
01312                                 $resolved_link = $internal_link;
01313                         }
01314                 }
01315                 else
01316                 {
01317                         $resolved_link = $internal_link;
01318                 }
01319                 return $resolved_link;
01320         }
01321         
01322         function _resolveIntLinks($question_id)
01323         {
01324                 global $ilDB;
01325                 $resolvedlinks = 0;
01326                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01327                         $ilDB->quote($question_id . "")
01328                 );
01329                 $result = $ilDB->query($query);
01330                 if ($result->numRows())
01331                 {
01332                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01333                         {
01334                                 $internal_link = $row["internal_link"];
01335                                 $resolved_link = ASS_Question::_resolveInternalLink($internal_link);
01336                                 if (strcmp($internal_link, $resolved_link) != 0)
01337                                 {
01338                                         // internal link was resolved successfully
01339                                         $queryupdate = sprintf("UPDATE qpl_suggested_solutions SET internal_link = %s WHERE suggested_solution_id = %s",
01340                                                 $ilDB->quote($resolved_link),
01341                                                 $ilDB->quote($row["suggested_solution_id"] . "")
01342                                         );
01343                                         $updateresult = $ilDB->query($queryupdate);
01344                                         $resolvedlinks++;
01345                                 }
01346                         }
01347                 }
01348                 if ($resolvedlinks)
01349                 {
01350                         // there are resolved links -> reenter theses links to the database
01351 
01352                         // delete all internal links from the database
01353                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01354                         ilInternalLink::_deleteAllLinksOfSource("qst", $question_id);
01355 
01356                         $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01357                                 $ilDB->quote($question_id . "")
01358                         );
01359                         $result = $ilDB->query($query);
01360                         if ($result->numRows())
01361                         {
01362                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01363                                 {
01364                                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01365                                         {
01366                                                 ilInternalLink::_saveLink("qst", $question_id, $matches[2], $matches[3], $matches[1]);
01367                                         }
01368                                 }
01369                         }
01370                 }
01371         }
01372         
01373         function _getInternalLinkHref($target = "")
01374         {
01375                 global $ilDB;
01376                 $linktypes = array(
01377                         "lm" => "LearningModule",
01378                         "pg" => "PageObject",
01379                         "st" => "StructureObject",
01380                         "git" => "GlossaryItem",
01381                         "mob" => "MediaObject"
01382                 );
01383                 $href = "";
01384                 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01385                 {
01386                         $type = $matches[1];
01387                         $target_id = $matches[2];
01388                         switch($linktypes[$matches[1]])
01389                         {
01390                                 case "LearningModule":
01391                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01392                                         break;
01393                                 case "PageObject":
01394                                 case "StructureObject":
01395                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01396                                         break;
01397                                 case "GlossaryItem":
01398                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01399                                         break;
01400                                 case "MediaObject":
01401                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/content/lm_presentation.php?obj_type=" . $linktypes[$type] . "&cmd=media&ref_id=".$_GET["ref_id"]."&mob_id=".$target_id;
01402                                         break;
01403                         }
01404                 }
01405                 return $href;
01406         }
01407         
01417         function _getOriginalId($question_id)
01418         {
01419                 global $ilDB;
01420                 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
01421                         $ilDB->quote($question_id . "")
01422                 );
01423                 $result = $ilDB->query($query);
01424                 if ($result->numRows() > 0)
01425                 {
01426                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01427                         if ($row["original_id"] > 0)
01428                         {
01429                                 return $row["original_id"];
01430                         }
01431                         else
01432                         {
01433                                 return $row["question_id"];
01434                         }
01435                 }
01436                 else
01437                 {
01438                         return "";
01439                 }
01440         }
01441 
01442         function syncWithOriginal()
01443         {
01444                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01445                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01446                         $this->ilias->db->quote($this->original_id . "")
01447                 );
01448                 $result = $this->ilias->db->query($query);
01449                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->original_id);
01450                 foreach ($this->suggested_solutions as $index => $solution)
01451                 {
01452                         $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)",
01453                                 $this->ilias->db->quote($this->original_id . ""),
01454                                 $this->ilias->db->quote($solution["internal_link"] . ""),
01455                                 $this->ilias->db->quote($solution["import_id"] . ""),
01456                                 $this->ilias->db->quote($index . "")
01457                         );
01458                         $this->ilias->db->query($query);
01459                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
01460                         {
01461                                 ilInternalLink::_saveLink("qst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01462                         }
01463                 }
01464         }
01465 
01466         function createRandomSolution($test_id, $user_id)
01467         {
01468         }
01469 
01479         function _questionExists($question_id)
01480         {
01481                 global $ilDB;
01482 
01483                 if ($question_id < 1)
01484                 {
01485                         return false;
01486                 }
01487                 
01488                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE question_id = %s",
01489                         $ilDB->quote($question_id)
01490                 );
01491     $result = $ilDB->query($query);
01492                 if ($result->numRows() == 1)
01493                 {
01494                         return true;
01495                 }
01496                 else
01497                 {
01498                         return false;
01499                 }
01500         }
01501 
01511   function &_instanciateQuestion($question_id) 
01512         {
01513                 if (strcmp($question_id, "") != 0)
01514                 {
01515                         $question_type = ASS_Question::_getQuestionType($question_id);
01516                         switch ($question_type) {
01517                                 case "qt_cloze":
01518                                         $question = new ASS_ClozeTest();
01519                                         break;
01520                                 case "qt_matching":
01521                                         $question = new ASS_MatchingQuestion();
01522                                         break;
01523                                 case "qt_ordering":
01524                                         $question = new ASS_OrderingQuestion();
01525                                         break;
01526                                 case "qt_imagemap":
01527                                         $question = new ASS_ImagemapQuestion();
01528                                         break;
01529                                 case "qt_multiple_choice_sr":
01530                                 case "qt_multiple_choice_mr":
01531                                         $question = new ASS_MultipleChoice();
01532                                         break;
01533                                 case "qt_javaapplet":
01534                                         $question = new ASS_JavaApplet();
01535                                         break;
01536                                 case "qt_text":
01537                                         $question = new ASS_TextQuestion();
01538                                         break;
01539                         }
01540                         $question->loadFromDb($question_id);
01541                         return $question;
01542                 }
01543   }
01544 
01545 }
01546 
01547 ?>

Generated on Fri Dec 13 2013 09:06:32 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1