• 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()
00823         {
00824                 $query = sprintf("SELECT COUNT(question_id) AS question_count FROM qpl_questions WHERE original_id = %s",
00825                         $this->ilias->db->quote("$this->id")
00826                         );
00827                 $result = $this->ilias->db->query($query);
00828                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00829                 return $row->question_count;
00830         }
00831 
00843         function removeAllQuestionReferences($question_id = "")
00844         {
00845         /*
00846                 if (!$question_id)
00847                 {
00848                         $question_id = $this->getId();
00849                 }
00850                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi = %s", $this->ilias->db->quote("$question_id"));
00851                 $result = $this->ilias->db->query($query);
00852                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
00853                 {
00854                         // Mark all tests containing this question as "not started"
00855                         $querychange = sprintf("DELETE FROM tst_active WHERE user_fi = %s AND test_fi = %s",
00856                                 $this->ilias->db->quote("$result->user_fi"),
00857                                 $this->ilias->db->quote("$result->test_fi")
00858                                 );
00859                         $changeresult = $this->ilias->db->query($querychange);
00860                 }
00861                 // delete all resultsets for this question
00862                 $querydelete = sprintf("DELETE FROM tst_solutions WHERE question_fi = %s", $this->ilias->db->quote("$question_id"));
00863                 $deleteresult = $this->ilias->db->query($querydelete);
00864                 */
00865         }
00866 
00875         function pcArrayShuffle($array)
00876         {
00877                 mt_srand((double)microtime()*1000000);
00878                 $i = count($array);
00879                 if ($i > 0)
00880                 {
00881                         while(--$i)
00882                         {
00883                                 $j = mt_rand(0, $i);
00884                                 if ($i != $j)
00885                                 {
00886                                         // swap elements
00887                                         $tmp = $array[$j];
00888                                         $array[$j] = $array[$i];
00889                                         $array[$i] = $tmp;
00890                                 }
00891                         }
00892                 }
00893                 return $array;
00894         }
00895 
00901         function getQuestionTypeFromDb($question_id)
00902         {
00903                 global $ilDB;
00904 
00905                 $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",
00906                         $ilDB->quote($question_id));
00907 
00908                 $result = $ilDB->query($query);
00909                 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00910 
00911                 return $data->type_tag;
00912         }
00913 
00922         function delete($question_id)
00923         {
00924                 if ($question_id < 1)
00925                 return;
00926 
00927                 $query = sprintf("SELECT obj_fi FROM qpl_questions WHERE question_id = %s",
00928                         $this->ilias->db->quote($question_id)
00929                         );
00930         $result = $this->ilias->db->query($query);
00931                 if ($result->numRows() == 1)
00932                 {
00933                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00934                         $obj_id = $row["obj_fi"];
00935                 }
00936                 else
00937                 {
00938                         return;
00939                 }
00940 
00941                 $query = sprintf("DELETE FROM qpl_questions WHERE question_id = %s",
00942                         $this->ilias->db->quote($question_id)
00943                         );
00944                 $result = $this->ilias->db->query($query);
00945                 $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
00946                         $this->ilias->db->quote($question_id)
00947                         );
00948                 $result = $this->ilias->db->query($query);
00949 
00950                 $this->removeAllQuestionReferences($question_id);
00951 
00952                 // delete page object
00953                 $page = new ilPageObject("qpl", $question_id);
00954                 $page->delete();
00955 
00956                 // delete the question in the tst_test_question table (list of test questions)
00957                 $querydelete = sprintf("DELETE FROM tst_test_question WHERE question_fi = %s", $this->ilias->db->quote($question_id));
00958                 $deleteresult = $this->ilias->db->query($querydelete);
00959 
00960                 // delete suggested solutions contained in the question
00961                 $querydelete = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s", $this->ilias->db->quote($question_id));
00962                 $deleteresult = $this->ilias->db->query($querydelete);
00963                                 
00964                 $directory = CLIENT_WEB_DIR . "/assessment/" . $obj_id . "/$question_id";
00965                 if (preg_match("/\d+/", $obj_id) and preg_match("/\d+/", $question_id) and is_dir($directory))
00966                 {
00967                         $directory = escapeshellarg($directory);
00968                         exec("rm -rf $directory");
00969                 }
00970         }
00971 
00975         function getTotalAnswers()
00976         {
00977                 return $this->_getTotalAnswers($this->id);
00978         }
00979 
00986         function _getTotalAnswers($a_q_id)
00987         {
00988                 global $ilDB;
00989 
00990                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s",
00991                         $ilDB->quote($a_q_id));
00992 
00993                 $result = $ilDB->query($query);
00994 
00995                 if ($result->numRows() == 0)
00996                 {
00997                         return 0;
00998                 }
00999                 $found_id = array();
01000                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01001                 {
01002                         array_push($found_id, $row->question_id);
01003                 }
01004 
01005                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi IN (%s) GROUP BY CONCAT(user_fi,test_fi)",
01006                         join($found_id, ","));
01007 
01008                 $result = $ilDB->query($query);
01009 
01010                 return $result->numRows();
01011         }
01012 
01013 
01020         function _getTotalRightAnswers($a_q_id)
01021         {
01022                 global $ilDB;
01023                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE original_id = %s",
01024                         $ilDB->quote($a_q_id)
01025                 );
01026                 $result = $ilDB->query($query);
01027                 if ($result->numRows() == 0)
01028                 {
01029                         return 0;
01030                 }
01031                 $found_id = array();
01032                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01033                 {
01034                         array_push($found_id, $row->question_id);
01035                 }
01036                 $query = sprintf("SELECT * FROM tst_solutions WHERE question_fi IN (%s) GROUP BY CONCAT(user_fi,test_fi)",
01037                         join($found_id, ",")
01038                 );
01039                 $result = $ilDB->query($query);
01040                 $answers = array();
01041                 while ($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
01042                 {
01043                         $question =& ASS_Question::_instanciateQuestion($row->question_fi);
01044                         $reached = $question->getReachedPoints($row->user_fi, $row->test_fi);
01045                         $max = $question->getMaximumPoints();
01046                         array_push($answers, array("reached" => $reached, "max" => $max));
01047                 }
01048                 $max = 0.0;
01049                 $reached = 0.0;
01050                 foreach ($answers as $key => $value)
01051                 {
01052                         $max += $value["max"];
01053                         $reached += $value["reached"];
01054                 }
01055                 if ($max > 0)
01056                 {
01057                         return $reached / $max;
01058                 }
01059                 else
01060                 {
01061                         return 0;
01062                 }
01063         }
01064 
01065         function copyPageOfQuestion($a_q_id)
01066         {
01067                 if ($a_q_id > 0)
01068                 {
01069                         $page = new ilPageObject("qpl", $a_q_id);
01070 
01071                         $xml = str_replace("il__qst_".$a_q_id, "il__qst_".$this->id,
01072                                 $page->getXMLContent());
01073 
01074                         $this->page->setXMLContent($xml);
01075                         $this->page->updateFromXML();
01076                 }
01077         }
01078 
01079         function getPageOfQuestion()
01080         {
01081                 $page = new ilPageObject("qpl", $this->id);
01082                 return $page->getXMLContent();
01083         }
01084 
01094   function _getQuestionType($question_id) {
01095                 global $ilDB;
01096 
01097     if ($question_id < 1)
01098       return "";
01099 
01100     $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",
01101       $ilDB->quote($question_id)
01102     );
01103     $result = $ilDB->query($query);
01104     if ($result->numRows() == 1) {
01105       $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
01106       return $data->type_tag;
01107     } else {
01108       return "";
01109     }
01110   }
01111 
01121   function _getQuestionTitle($question_id) {
01122                 global $ilDB;
01123 
01124     if ($question_id < 1)
01125       return "";
01126 
01127     $query = sprintf("SELECT title FROM qpl_questions WHERE qpl_questions.question_id = %s",
01128       $ilDB->quote($question_id)
01129     );
01130     $result = $ilDB->query($query);
01131     if ($result->numRows() == 1) {
01132       $data = $result->fetchRow(DB_FETCHMODE_ASSOC);
01133       return $data["title"];
01134     } else {
01135       return "";
01136     }
01137   }
01138 
01147         function loadFromDb($question_id)
01148         {
01149                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01150                         $this->ilias->db->quote($this->getId() . "")
01151                 );
01152                 $result = $this->ilias->db->query($query);
01153                 $this->suggested_solutions = array();
01154                 if ($result->numRows())
01155                 {
01156                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01157                         {
01158                                 $this->suggested_solutions[$row["subquestion_index"]] = array(
01159                                         "internal_link" => $row["internal_link"],
01160                                         "import_id" => $row["import_id"]
01161                                 );
01162                         }
01163                 }
01164         }
01165 
01174         function saveToDb($original_id = "")
01175         {
01176                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01177                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01178                         $this->ilias->db->quote($this->getId() . "")
01179                 );
01180                 $result = $this->ilias->db->query($query);
01181                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->getId());
01182                 foreach ($this->suggested_solutions as $index => $solution)
01183                 {
01184                         $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)",
01185                                 $this->ilias->db->quote($this->getId() . ""),
01186                                 $this->ilias->db->quote($solution["internal_link"] . ""),
01187                                 $this->ilias->db->quote($solution["import_id"] . ""),
01188                                 $this->ilias->db->quote($index . "")
01189                         );
01190                         $this->ilias->db->query($query);
01191                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
01192                         {
01193                                 ilInternalLink::_saveLink("qst", $this->getId(), $matches[2], $matches[3], $matches[1]);
01194                         }
01195                 }
01196         }
01197         
01205         function deleteSuggestedSolutions()
01206         {
01207                 // delete the links in the qpl_suggested_solutions table
01208                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01209                         $this->ilias->db->quote($this->getId() . "")
01210                 );
01211                 $result = $this->ilias->db->query($query);
01212                 // delete the links in the int_link table
01213                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01214                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->getId());
01215         }
01216         
01226         function getSuggestedSolution($subquestion_index = 0)
01227         {
01228                 if (array_key_exists($subquestion_index, $this->suggested_solutions))
01229                 {
01230                         return $this->suggested_solutions[$subquestion_index];
01231                 }
01232                 else
01233                 {
01234                         return array();
01235                 }
01236         }
01237 
01248         function getSuggestedSolutionTitle($subquestion_index = 0)
01249         {
01250                 if (array_key_exists($subquestion_index, $this->suggested_solutions))
01251                 {
01252                         $title = $this->suggested_solutions[$subquestion_index]["internal_link"];
01253                         // TO DO: resolve internal link an get link type and title
01254                 }
01255                 else
01256                 {
01257                         $title = "";
01258                 }
01259                 return $title;
01260         }
01261 
01273         function setSuggestedSolution($solution_id = "", $subquestion_index = 0, $is_import = false)
01274         {
01275                 if (strcmp($solution_id, "") != 0)
01276                 {
01277                         $import_id = "";
01278                         if ($is_import)
01279                         {
01280                                 $import_id = $solution_id;
01281                                 $solution_id = $this->_resolveInternalLink($import_id);
01282                         }
01283                         $this->suggested_solutions[$subquestion_index] = array(
01284                                 "internal_link" => $solution_id,
01285                                 "import_id" => $import_id
01286                         );
01287                 }
01288         }
01289         
01290         function _resolveInternalLink($internal_link)
01291         {
01292                 if (preg_match("/il_(\d+)_(\w+)_(\d+)/", $internal_link, $matches))
01293                 {
01294                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01295                         require_once "./content/classes/class.ilLMObject.php";
01296                         require_once "./content/classes/class.ilGlossaryTerm.php";
01297                         switch ($matches[2])
01298                         {
01299                                 case "lm":
01300                                         $resolved_link = ilLMObject::_getIdForImportId($internal_link);
01301                                         break;
01302                                 case "pg":
01303                                         $resolved_link = ilInternalLink::_getIdForImportId("PageObject", $internal_link);
01304                                         break;
01305                                 case "st":
01306                                         $resolved_link = ilInternalLink::_getIdForImportId("StructureObject", $internal_link);
01307                                         break;
01308                                 case "git":
01309                                         $resolved_link = ilInternalLink::_getIdForImportId("GlossaryItem", $internal_link);
01310                                         break;
01311                                 case "mob":
01312                                         $resolved_link = ilInternalLink::_getIdForImportId("MediaObject", $internal_link);
01313                                         break;
01314                         }
01315                         if (strcmp($resolved_link, "") == 0)
01316                         {
01317                                 $resolved_link = $internal_link;
01318                         }
01319                 }
01320                 else
01321                 {
01322                         $resolved_link = $internal_link;
01323                 }
01324                 return $resolved_link;
01325         }
01326         
01327         function _resolveIntLinks($question_id)
01328         {
01329                 global $ilDB;
01330                 $resolvedlinks = 0;
01331                 $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01332                         $ilDB->quote($question_id . "")
01333                 );
01334                 $result = $ilDB->query($query);
01335                 if ($result->numRows())
01336                 {
01337                         while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01338                         {
01339                                 $internal_link = $row["internal_link"];
01340                                 $resolved_link = ASS_Question::_resolveInternalLink($internal_link);
01341                                 if (strcmp($internal_link, $resolved_link) != 0)
01342                                 {
01343                                         // internal link was resolved successfully
01344                                         $queryupdate = sprintf("UPDATE qpl_suggested_solutions SET internal_link = %s WHERE suggested_solution_id = %s",
01345                                                 $ilDB->quote($resolved_link),
01346                                                 $ilDB->quote($row["suggested_solution_id"] . "")
01347                                         );
01348                                         $updateresult = $ilDB->query($queryupdate);
01349                                         $resolvedlinks++;
01350                                 }
01351                         }
01352                 }
01353                 if ($resolvedlinks)
01354                 {
01355                         // there are resolved links -> reenter theses links to the database
01356 
01357                         // delete all internal links from the database
01358                         require_once "./content/classes/Pages/class.ilInternalLink.php";
01359                         ilInternalLink::_deleteAllLinksOfSource("qst", $question_id);
01360 
01361                         $query = sprintf("SELECT * FROM qpl_suggested_solutions WHERE question_fi = %s",
01362                                 $ilDB->quote($question_id . "")
01363                         );
01364                         $result = $ilDB->query($query);
01365                         if ($result->numRows())
01366                         {
01367                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
01368                                 {
01369                                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $row["internal_link"], $matches))
01370                                         {
01371                                                 ilInternalLink::_saveLink("qst", $question_id, $matches[2], $matches[3], $matches[1]);
01372                                         }
01373                                 }
01374                         }
01375                 }
01376         }
01377         
01378         function _getInternalLinkHref($target = "")
01379         {
01380                 global $ilDB;
01381                 $linktypes = array(
01382                         "lm" => "LearningModule",
01383                         "pg" => "PageObject",
01384                         "st" => "StructureObject",
01385                         "git" => "GlossaryItem",
01386                         "mob" => "MediaObject"
01387                 );
01388                 $href = "";
01389                 if (preg_match("/il__(\w+)_(\d+)/", $target, $matches))
01390                 {
01391                         $type = $matches[1];
01392                         $target_id = $matches[2];
01393                         switch($linktypes[$matches[1]])
01394                         {
01395                                 case "LearningModule":
01396                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01397                                         break;
01398                                 case "PageObject":
01399                                 case "StructureObject":
01400                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01401                                         break;
01402                                 case "GlossaryItem":
01403                                         $href = ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) ."/goto.php?target=" . $type . "_" . $target_id;
01404                                         break;
01405                                 case "MediaObject":
01406                                         $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;
01407                                         break;
01408                         }
01409                 }
01410                 return $href;
01411         }
01412         
01422         function _getOriginalId($question_id)
01423         {
01424                 global $ilDB;
01425                 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
01426                         $ilDB->quote($question_id . "")
01427                 );
01428                 $result = $ilDB->query($query);
01429                 if ($result->numRows() > 0)
01430                 {
01431                         $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01432                         if ($row["original_id"] > 0)
01433                         {
01434                                 return $row["original_id"];
01435                         }
01436                         else
01437                         {
01438                                 return $row["question_id"];
01439                         }
01440                 }
01441                 else
01442                 {
01443                         return "";
01444                 }
01445         }
01446 
01447         function syncWithOriginal()
01448         {
01449                 require_once "./content/classes/Pages/class.ilInternalLink.php";
01450                 $query = sprintf("DELETE FROM qpl_suggested_solutions WHERE question_fi = %s",
01451                         $this->ilias->db->quote($this->original_id . "")
01452                 );
01453                 $result = $this->ilias->db->query($query);
01454                 ilInternalLink::_deleteAllLinksOfSource("qst", $this->original_id);
01455                 foreach ($this->suggested_solutions as $index => $solution)
01456                 {
01457                         $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)",
01458                                 $this->ilias->db->quote($this->original_id . ""),
01459                                 $this->ilias->db->quote($solution["internal_link"] . ""),
01460                                 $this->ilias->db->quote($solution["import_id"] . ""),
01461                                 $this->ilias->db->quote($index . "")
01462                         );
01463                         $this->ilias->db->query($query);
01464                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
01465                         {
01466                                 ilInternalLink::_saveLink("qst", $this->original_id, $matches[2], $matches[3], $matches[1]);
01467                         }
01468                 }
01469         }
01470 
01471         function createRandomSolution($test_id, $user_id)
01472         {
01473         }
01474 
01484         function _questionExists($question_id)
01485         {
01486                 global $ilDB;
01487 
01488                 if ($question_id < 1)
01489                 {
01490                         return false;
01491                 }
01492                 
01493                 $query = sprintf("SELECT question_id FROM qpl_questions WHERE question_id = %s",
01494                         $ilDB->quote($question_id)
01495                 );
01496     $result = $ilDB->query($query);
01497                 if ($result->numRows() == 1)
01498                 {
01499                         return true;
01500                 }
01501                 else
01502                 {
01503                         return false;
01504                 }
01505         }
01506 
01516   function &_instanciateQuestion($question_id) 
01517         {
01518                 if (strcmp($question_id, "") != 0)
01519                 {
01520                         $question_type = ASS_Question::_getQuestionType($question_id);
01521                         switch ($question_type) {
01522                                 case "qt_cloze":
01523                                         $question = new ASS_ClozeTest();
01524                                         break;
01525                                 case "qt_matching":
01526                                         $question = new ASS_MatchingQuestion();
01527                                         break;
01528                                 case "qt_ordering":
01529                                         $question = new ASS_OrderingQuestion();
01530                                         break;
01531                                 case "qt_imagemap":
01532                                         $question = new ASS_ImagemapQuestion();
01533                                         break;
01534                                 case "qt_multiple_choice_sr":
01535                                 case "qt_multiple_choice_mr":
01536                                         $question = new ASS_MultipleChoice();
01537                                         break;
01538                                 case "qt_javaapplet":
01539                                         $question = new ASS_JavaApplet();
01540                                         break;
01541                                 case "qt_text":
01542                                         $question = new ASS_TextQuestion();
01543                                         break;
01544                         }
01545                         $question->loadFromDb($question_id);
01546                         return $question;
01547                 }
01548   }
01549 
01550 }
01551 
01552 ?>

Generated on Fri Dec 13 2013 08:00:13 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1