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

assessment/classes/class.assImagemapQuestion.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.assQuestion.php";
00025 require_once "./assessment/classes/class.assAnswerImagemap.php";
00026 
00027 define ("IMAGEMAP_QUESTION_IDENTIFIER", "IMAGE MAP QUESTION");
00028 
00039 class ASS_ImagemapQuestion extends ASS_Question {
00040 
00048   var $question;
00049 
00057   var $answers;
00058 
00068   var $points;
00069 
00077   var $imagemap_filename;
00078 
00086   var $image_filename;
00087 
00095   var $imagemap_contents;
00096         var $coords;
00097 
00112   function ASS_ImagemapQuestion(
00113     $title = "",
00114     $comment = "",
00115     $author = "",
00116     $owner = -1,
00117     $question = "",
00118     $imagemap_filename = "",
00119     $image_filename = ""
00120 
00121   )
00122   {
00123     $this->ASS_Question($title, $comment, $author, $owner);
00124     $this->question = $question;
00125     $this->imagemap_filename = $imagemap_filename;
00126     $this->image_filename = $image_filename;
00127     $this->answers = array();
00128                 $this->points = $points;
00129                 $this->coords = array();
00130   }
00131 
00140         function isComplete()
00141         {
00142                 if (($this->title) and ($this->author) and ($this->question) and ($this->image_filename) and (count($this->answers)))
00143                 {
00144                         return true;
00145                 }
00146                         else
00147                 {
00148                         return false;
00149                 }
00150         }
00151 
00160         function saveToDb($original_id = "")
00161         {
00162                 global $ilias;
00163 
00164                 $complete = 0;
00165                 if ($this->isComplete())
00166                 {
00167                         $complete = 1;
00168                 }
00169 
00170                 $db = & $ilias->db;
00171 
00172                 $estw_time = $this->getEstimatedWorkingTime();
00173                 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00174                 if ($original_id)
00175                 {
00176                         $original_id = $db->quote($original_id);
00177                 }
00178                 else
00179                 {
00180                         $original_id = "NULL";
00181                 }
00182 
00183                 if ($this->id == -1)
00184                 {
00185                         // Neuen Datensatz schreiben
00186                         $now = getdate();
00187                         $question_type = $this->getQuestionType();
00188                         $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00189                         $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, working_time, points, image_file, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00190                                 $db->quote($question_type),
00191                                 $db->quote($this->obj_id),
00192                                 $db->quote($this->title),
00193                                 $db->quote($this->comment),
00194                                 $db->quote($this->author),
00195                                 $db->quote($this->owner),
00196                                 $db->quote($this->question),
00197                                 $db->quote($estw_time),
00198                                 $db->quote($this->points),
00199                                 $db->quote($this->image_filename),
00200                                 $db->quote("$complete"),
00201                                 $db->quote($created),
00202                                 $original_id
00203                         );
00204                         $result = $db->query($query);
00205                         if ($result == DB_OK)
00206                         {
00207                                 $this->id = $db->getLastInsertId();
00208 
00209                                 // create page object of question
00210                                 $this->createPageObject();
00211 
00212                                 // Falls die Frage in einen Test eingef�gt werden soll, auch diese Verbindung erstellen
00213                                 if ($this->getTestId() > 0)
00214                                 {
00215                                         $this->insertIntoTest($this->getTestId());
00216                                 }
00217                         }
00218                 }
00219                 else
00220                 {
00221                         // Vorhandenen Datensatz aktualisieren
00222                         $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time = %s, points = %s, image_file = %s, complete = %s WHERE question_id = %s",
00223                                 $db->quote($this->obj_id. ""),
00224                                 $db->quote($this->title),
00225                                 $db->quote($this->comment),
00226                                 $db->quote($this->author),
00227                                 $db->quote($this->question),
00228                                 $db->quote($estw_time),
00229                                 $db->quote($this->points),
00230                                 $db->quote($this->image_filename),
00231                                 $db->quote("$complete"),
00232                                 $db->quote($this->id)
00233                         );
00234                         $result = $db->query($query);
00235                 }
00236 
00237                 if ($result == DB_OK)
00238                 {
00239                         $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
00240                                 $db->quote($this->id)
00241                         );
00242                         $result = $db->query($query);
00243                         // Anworten wegschreiben
00244                         foreach ($this->answers as $key => $value)
00245                         {
00246                                 $answer_obj = $this->answers[$key];
00247                                 //print "id:".$this->id." answer tex:".$answer_obj->get_answertext()." answer_obj->get_order():".$answer_obj->get_order()." answer_obj->get_coords():".$answer_obj->get_coords()." answer_obj->get_area():".$answer_obj->get_area();
00248                                 $query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, answertext, points, aorder, correctness, coords, area, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, NULL)",
00249                                         $db->quote($this->id),
00250                                         $db->quote($answer_obj->get_answertext() . ""),
00251                                         $db->quote($answer_obj->get_points() . ""),
00252                                         $db->quote($answer_obj->get_order() . ""),
00253                                         $db->quote($answer_obj->getState() . ""),
00254                                         $db->quote($answer_obj->get_coords() . ""),
00255                                         $db->quote($answer_obj->get_area() . "")
00256                                         );
00257                                 $answer_result = $db->query($query);
00258                                 }
00259                 }
00260                 parent::saveToDb($original_id);
00261         }
00262 
00270         function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00271         {
00272                 if ($this->id <= 0)
00273                 {
00274                         // The question has not been saved. It cannot be duplicated
00275                         return;
00276                 }
00277                 // duplicate the question in database
00278                 $clone = $this;
00279                 $original_id = $this->id;
00280                 if ($original_id <= 0)
00281                 {
00282                         $original_id = "";
00283                 }
00284                 $clone->id = -1;
00285                 if ($title)
00286                 {
00287                         $clone->setTitle($title);
00288                 }
00289                 if ($author)
00290                 {
00291                         $clone->setAuthor($author);
00292                 }
00293                 if ($owner)
00294                 {
00295                         $clone->setOwner($owner);
00296                 }
00297                 if ($for_test)
00298                 {
00299                         $clone->saveToDb($original_id);
00300                 }
00301                 else
00302                 {
00303                         $clone->saveToDb();
00304                 }
00305 
00306                 // copy question page content
00307                 $clone->copyPageOfQuestion($original_id);
00308 
00309                 // duplicate the image
00310                 $clone->duplicateImage($original_id);
00311                 return $clone->id;
00312         }
00313 
00314         function duplicateImage($question_id)
00315         {
00316                 $imagepath = $this->getImagePath();
00317                 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00318                 if (!file_exists($imagepath)) {
00319                         ilUtil::makeDirParents($imagepath);
00320                 }
00321                 $filename = $this->get_image_filename();
00322                 if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
00323                         print "image could not be duplicated!!!! ";
00324                 }
00325         }
00326 
00336   function loadFromDb($question_id)
00337   {
00338     global $ilias;
00339 
00340     $db = & $ilias->db;
00341     $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
00342       $db->quote($question_id)
00343     );
00344     $result = $db->query($query);
00345     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00346       if ($result->numRows() == 1) {
00347         $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00348         $this->id = $question_id;
00349                                 $this->obj_id = $data->obj_fi;
00350         $this->title = $data->title;
00351         $this->comment = $data->comment;
00352         $this->author = $data->author;
00353                                 $this->original_id = $data->original_id;
00354                                 $this->solution_hint = $data->solution_hint;
00355         $this->owner = $data->owner;
00356         $this->question = $data->question_text;
00357         $this->image_filename = $data->image_file;
00358         $this->points = $data->points;
00359         $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00360       }
00361       $query = sprintf("SELECT * FROM qpl_answers WHERE question_fi = %s ORDER BY aorder ASC",
00362         $db->quote($question_id)
00363       );
00364       $result = $db->query($query);
00365       if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00366         while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
00367                                         if ($data->correctness == 0)
00368                                         {
00369                                                 // fix for older single response answers where points could be given for unchecked answers
00370                                                 $data->correctness = 1;
00371                                                 $data->points = 0;
00372                                         }
00373           array_push($this->answers, new ASS_AnswerImagemap($data->answertext, $data->points, $data->aorder, $data->correctness, $data->coords, $data->area));
00374         }
00375       }
00376     }
00377                 parent::loadFromDb($question_id);
00378   }
00379 
00389         function from_xml($xml_text)
00390         {
00391                 $result = false;
00392                 if (!empty($this->domxml))
00393                 {
00394                         $this->domxml->free();
00395                 }
00396                 $xml_text = preg_replace("/>\s*?</", "><", $xml_text);
00397                 $this->domxml = domxml_open_mem($xml_text);
00398                 if (!empty($this->domxml))
00399                 {
00400                         $root = $this->domxml->document_element();
00401                         $item = $root->first_child();
00402                         $this->setTitle($item->get_attribute("title"));
00403                         $this->gaps = array();
00404                         $itemnodes = $item->child_nodes();
00405                         $materials = array();
00406                         $filename = "";
00407                         $image = "";
00408                         $shuffle = "";
00409                         foreach ($itemnodes as $index => $node)
00410                         {
00411                                 switch ($node->node_name())
00412                                 {
00413                                         case "qticomment":
00414                                                 $comment = $node->get_content();
00415                                                 if (strpos($comment, "ILIAS Version=") !== false)
00416                                                 {
00417                                                 }
00418                                                 elseif (strpos($comment, "Questiontype=") !== false)
00419                                                 {
00420                                                 }
00421                                                 elseif (strpos($comment, "Author=") !== false)
00422                                                 {
00423                                                         $comment = str_replace("Author=", "", $comment);
00424                                                         $this->setAuthor($comment);
00425                                                 }
00426                                                 else
00427                                                 {
00428                                                         $this->setComment($comment);
00429                                                 }
00430                                                 break;
00431                                         case "duration":
00432                                                 $iso8601period = $node->get_content();
00433                                                 if (preg_match("/P(\d+)Y(\d+)M(\d+)DT(\d+)H(\d+)M(\d+)S/", $iso8601period, $matches))
00434                                                 {
00435                                                         $this->setEstimatedWorkingTime($matches[4], $matches[5], $matches[6]);
00436                                                 }
00437                                                 break;
00438                                         case "presentation":
00439                                                 $flow = $node->first_child();
00440                                                 $flownodes = $flow->child_nodes();
00441                                                 foreach ($flownodes as $idx => $flownode)
00442                                                 {
00443                                                         if (strcmp($flownode->node_name(), "material") == 0)
00444                                                         {
00445                                                                 $mattext = $flownode->first_child();
00446                                                                 $this->set_question($mattext->get_content());
00447                                                         }
00448                                                         elseif (strcmp($flownode->node_name(), "response_xy") == 0)
00449                                                         {
00450                                                                 $ident = $flownode->get_attribute("ident");
00451                                                                 $subnodes = $flownode->child_nodes();
00452                                                                 foreach ($subnodes as $node_type)
00453                                                                 {
00454                                                                         switch ($node_type->node_name())
00455                                                                         {
00456                                                                                 case "material":
00457                                                                                         $matlabel = $node_type->get_attribute("label");
00458                                                                                         if (strcmp($matlabel, "suggested_solution") == 0)
00459                                                                                         {
00460                                                                                                 $mattype = $node_type->first_child();
00461                                                                                                 if (strcmp($mattype->node_name(), "mattext") == 0)
00462                                                                                                 {
00463                                                                                                         $suggested_solution = $mattype->get_content();
00464                                                                                                         if ($suggested_solution)
00465                                                                                                         {
00466                                                                                                                 if ($this->getId() < 1)
00467                                                                                                                 {
00468                                                                                                                         $this->saveToDb();
00469                                                                                                                 }
00470                                                                                                                 $this->setSuggestedSolution($suggested_solution, 0, true);
00471                                                                                                         }
00472                                                                                                 }
00473                                                                                         }
00474                                                                                         break;
00475                                                                                 case "render_hotspot":
00476                                                                                         $render_hotspot = $node_type;
00477                                                                                         $labels = $render_hotspot->child_nodes();
00478                                                                                         foreach ($labels as $lidx => $response_label)
00479                                                                                         {
00480                                                                                                 if (strcmp($response_label->node_name(), "material") == 0)
00481                                                                                                 {
00482                                                                                                         // image map image
00483                                                                                                         $mattype = $response_label->first_child();
00484                                                                                                         if (strcmp($mattype->node_name(), "matimage") == 0)
00485                                                                                                         {
00486                                                                                                                 $filename = $mattype->get_attribute("label");
00487                                                                                                                 $image = base64_decode($mattype->get_content());
00488                                                                                                         }
00489                                                                                                 }
00490                                                                                                 else
00491                                                                                                 {
00492                                                                                                         $material_children = $response_label->child_nodes();
00493                                                                                                         switch ($response_label->get_attribute("rarea"))
00494                                                                                                         {
00495                                                                                                                 case "Ellipse":
00496                                                                                                                         $materials[$response_label->get_attribute("ident")]["area"] = "circle";
00497                                                                                                                         break;
00498                                                                                                                 case "Bounded":
00499                                                                                                                         $materials[$response_label->get_attribute("ident")]["area"] = "poly";
00500                                                                                                                         break;
00501                                                                                                                 case "Rectangle":
00502                                                                                                                         $materials[$response_label->get_attribute("ident")]["area"] = "rect";
00503                                                                                                                         break;
00504                                                                                                         }
00505                                                                                                         foreach ($material_children as $midx => $childnode)
00506                                                                                                         {
00507                                                                                                                 if (strcmp($childnode->node_name(), "#text") == 0)
00508                                                                                                                 {
00509                                                                                                                         $materials[$response_label->get_attribute("ident")]["coords"] = $childnode->get_content();
00510                                                                                                                 }
00511                                                                                                                 elseif (strcmp($childnode->node_name(), "material") == 0)
00512                                                                                                                 {
00513                                                                                                                         $materials[$response_label->get_attribute("ident")]["answertext"] = $childnode->get_content();
00514                                                                                                                 }
00515                                                                                                         }
00516                                                                                                 }
00517                                                                                         }
00518                                                                                         break;
00519                                                                         }
00520                                                                 }
00521                                                         }
00522                                                 }
00523                                                 break;
00524                                         case "resprocessing":
00525                                                 $resproc_nodes = $node->child_nodes();
00526                                                 foreach ($resproc_nodes as $index => $respcondition)
00527                                                 {
00528                                                         if (strcmp($respcondition->node_name(), "respcondition") == 0)
00529                                                         {
00530                                                                 $respcondition_array =& ilQTIUtils::_getRespcondition($respcondition);
00531                                                                 foreach ($materials as $index => $material)
00532                                                                 {
00533                                                                         if (strcmp($material["coords"], $respcondition_array["conditionvar"]["value"]) == 0)
00534                                                                         {
00535                                                                                 $this->add_answer(
00536                                                                                         $material["answertext"], 
00537                                                                                         $respcondition_array["setvar"]["points"],
00538                                                                                         $respcondition_array["conditionvar"]["selected"],
00539                                                                                         $index,
00540                                                                                         $material["coords"],
00541                                                                                         $material["area"]
00542                                                                                 );
00543                                                                         }
00544                                                                 }
00545                                                         }
00546                                                 }
00547                                                 break;
00548                                 }
00549                         }
00550                         if ($filename)
00551                         {
00552                                 $this->saveToDb();
00553                                 $imagepath = $this->getImagePath();
00554                                 if (!file_exists($imagepath))
00555                                 {
00556                                         ilUtil::makeDirParents($imagepath);
00557                                 }
00558                                 $imagepath .=  $filename;
00559                                 $fh = fopen($imagepath, "wb");
00560                                 if ($fh == false)
00561                                 {
00562                                         global $ilErr;
00563                                         $ilErr->raiseError($this->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->WARNING);
00564                                         return;
00565                                 }
00566                                 $imagefile = fwrite($fh, $image);
00567                                 fclose($fh);
00568                                 $this->image_filename = $filename;
00569                         }
00570                         $result = true;
00571                 }
00572                 return $result;
00573         }
00574 
00584         function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false)
00585         {
00586                 if (!empty($this->domxml))
00587                 {
00588                         $this->domxml->free();
00589                 }
00590                 $xml_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<questestinterop></questestinterop>\n";
00591                 $this->domxml = domxml_open_mem($xml_header);
00592                 $root = $this->domxml->document_element();
00593                 // qti ident
00594                 $qtiIdent = $this->domxml->create_element("item");
00595                 $qtiIdent->set_attribute("ident", "il_".IL_INST_ID."_qst_".$this->getId());
00596                 $qtiIdent->set_attribute("title", $this->getTitle());
00597                 $root->append_child($qtiIdent);
00598                 // add qti comment
00599                 $qtiComment = $this->domxml->create_element("qticomment");
00600                 $qtiCommentText = $this->domxml->create_text_node($this->getComment());
00601                 $qtiComment->append_child($qtiCommentText);
00602                 $qtiIdent->append_child($qtiComment);
00603                 $qtiComment = $this->domxml->create_element("qticomment");
00604                 $qtiCommentText = $this->domxml->create_text_node("ILIAS Version=".$this->ilias->getSetting("ilias_version"));
00605                 $qtiComment->append_child($qtiCommentText);
00606                 $qtiIdent->append_child($qtiComment);
00607                 $qtiComment = $this->domxml->create_element("qticomment");
00608                 $qtiCommentText = $this->domxml->create_text_node("Questiontype=".IMAGEMAP_QUESTION_IDENTIFIER);
00609                 $qtiComment->append_child($qtiCommentText);
00610                 $qtiIdent->append_child($qtiComment);
00611                 $qtiComment = $this->domxml->create_element("qticomment");
00612                 $qtiCommentText = $this->domxml->create_text_node("Author=".$this->getAuthor());
00613                 $qtiComment->append_child($qtiCommentText);
00614                 $qtiIdent->append_child($qtiComment);
00615         // add estimated working time
00616                 $qtiDuration = $this->domxml->create_element("duration");
00617                 $workingtime = $this->getEstimatedWorkingTime();
00618                 $qtiDurationText = $this->domxml->create_text_node(sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]));
00619                 $qtiDuration->append_child($qtiDurationText);
00620                 $qtiIdent->append_child($qtiDuration);
00621                 // PART I: qti presentation
00622                 $qtiPresentation = $this->domxml->create_element("presentation");
00623                 $qtiPresentation->set_attribute("label", $this->getTitle());
00624                 // add flow to presentation
00625                 $qtiFlow = $this->domxml->create_element("flow");
00626                 // add material with question text to presentation
00627                 $qtiMaterial = $this->domxml->create_element("material");
00628                 $qtiMatText = $this->domxml->create_element("mattext");
00629                 $qtiMatTextText = $this->domxml->create_text_node($this->get_question());
00630                 $qtiMatText->append_child($qtiMatTextText);
00631                 $qtiMaterial->append_child($qtiMatText);
00632                 $qtiFlow->append_child($qtiMaterial);
00633                 // add answers to presentation
00634                 $qtiResponseXy = $this->domxml->create_element("response_xy");
00635                 $qtiResponseXy->set_attribute("ident", "IM");
00636                 $qtiResponseXy->set_attribute("rcardinality", "Single");
00637                 $solution = $this->getSuggestedSolution(0);
00638                 if (count($solution))
00639                 {
00640                         if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00641                         {
00642                                 $qtiMaterial = $this->domxml->create_element("material");
00643                                 $qtiMaterial->set_attribute("label", "suggested_solution");
00644                                 $qtiMatText = $this->domxml->create_element("mattext");
00645                                 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00646                                 if (strcmp($matches[1], "") != 0)
00647                                 {
00648                                         $intlink = $solution["internal_link"];
00649                                 }
00650                                 $qtiMatTextText = $this->domxml->create_text_node($intlink);
00651                                 $qtiMatText->append_child($qtiMatTextText);
00652                                 $qtiMaterial->append_child($qtiMatText);
00653                                 $qtiResponseXy->append_child($qtiMaterial);
00654                         }
00655                 }
00656                 $qtiRenderHotspot = $this->domxml->create_element("render_hotspot");
00657                 $qtiMaterial = $this->domxml->create_element("material");
00658                 $qtiMatImage = $this->domxml->create_element("matimage");
00659                 $qtiMatImage->set_attribute("imagtype", "image/jpeg");
00660                 $qtiMatImage->set_attribute("label", $this->get_image_filename());
00661                 if ($a_include_binary)
00662                 {
00663                         $qtiMatImage->set_attribute("embedded", "base64");
00664                         $imagepath = $this->getImagePath() . $this->get_image_filename();
00665                         $fh = fopen($imagepath, "rb");
00666                         if ($fh == false)
00667                         {
00668                                 global $ilErr;
00669                                 $ilErr->raiseError($this->lng->txt("error_open_image_file"), $ilErr->WARNING);
00670                                 return;
00671                         }
00672                         $imagefile = fread($fh, filesize($imagepath));
00673                         fclose($fh);
00674                         $base64 = base64_encode($imagefile);
00675                         $qtiBase64Data = $this->domxml->create_text_node($base64);
00676                         $qtiMatImage->append_child($qtiBase64Data);
00677                 }
00678                 $qtiMaterial->append_child($qtiMatImage);
00679                 $qtiRenderHotspot->append_child($qtiMaterial);
00680                 // add answers
00681                 foreach ($this->answers as $index => $answer)
00682                 {
00683                         $qtiResponseLabel = $this->domxml->create_element("response_label");
00684                         $qtiResponseLabel->set_attribute("ident", $index);
00685                         switch ($answer->get_area())
00686                         {
00687                                 case "rect":
00688                                         $qtiResponseLabel->set_attribute("rarea", "Rectangle");
00689                                         break;
00690                                 case "circle":
00691                                         $qtiResponseLabel->set_attribute("rarea", "Ellipse");
00692                                         break;
00693                                 case "poly":
00694                                         $qtiResponseLabel->set_attribute("rarea", "Bounded");
00695                                         break;
00696                         }
00697                         $qtiResponseLabelCoords = $this->domxml->create_text_node($answer->get_coords());
00698                         $qtiMaterial = $this->domxml->create_element("material");
00699                         $qtiMatText = $this->domxml->create_element("mattext");
00700                         $qtiMatTextText = $this->domxml->create_text_node($answer->get_answertext());
00701                         $qtiMatText->append_child($qtiMatTextText);
00702                         $qtiMaterial->append_child($qtiMatText);
00703                         $qtiResponseLabel->append_child($qtiResponseLabelCoords);
00704                         $qtiResponseLabel->append_child($qtiMaterial);
00705                         $qtiRenderHotspot->append_child($qtiResponseLabel);
00706                 }
00707                 $qtiResponseXy->append_child($qtiRenderHotspot);
00708                 $qtiFlow->append_child($qtiResponseXy);
00709                 $qtiPresentation->append_child($qtiFlow);
00710                 $qtiIdent->append_child($qtiPresentation);
00711 
00712                 // PART II: qti resprocessing
00713                 $qtiResprocessing = $this->domxml->create_element("resprocessing");
00714                 $qtiOutcomes = $this->domxml->create_element("outcomes");
00715                 $qtiDecvar = $this->domxml->create_element("decvar");
00716                 $qtiOutcomes->append_child($qtiDecvar);
00717                 $qtiResprocessing->append_child($qtiOutcomes);
00718                 // add response conditions
00719                 foreach ($this->answers as $index => $answer)
00720                 {
00721                         $qtiRespcondition = $this->domxml->create_element("respcondition");
00722                         $qtiRespcondition->set_attribute("continue", "Yes");
00723                         // qti conditionvar
00724                         $qtiConditionvar = $this->domxml->create_element("conditionvar");
00725                         if (!$answer->isStateSet())
00726                         {
00727                                 $qtinot = $this->domxml->create_element("not");
00728                         }
00729                         $qtiVarinside = $this->domxml->create_element("varinside");
00730                         $qtiVarinside->set_attribute("respident", "IM");
00731                         switch ($answer->get_area())
00732                         {
00733                                 case "rect":
00734                                         $qtiVarinside->set_attribute("areatype", "Rectangle");
00735                                         break;
00736                                 case "circle":
00737                                         $qtiVarinside->set_attribute("areatype", "Ellipse");
00738                                         break;
00739                                 case "poly":
00740                                         $qtiVarinside->set_attribute("areatype", "Bounded");
00741                                         break;
00742                         }
00743                         $qtiVarinsideText = $this->domxml->create_text_node($answer->get_coords());
00744                         $qtiVarinside->append_child($qtiVarinsideText);
00745                         if (!$answer->isStateSet())
00746                         {
00747                                 $qtiConditionvar->append_child($qtinot);
00748                                 $qtinot->append_child($qtiVarinside);
00749                         }
00750                         else
00751                         {
00752                                 $qtiConditionvar->append_child($qtiVarinside);
00753                         }
00754                         // qti setvar
00755                         $qtiSetvar = $this->domxml->create_element("setvar");
00756                         $qtiSetvar->set_attribute("action", "Add");
00757                         $qtiSetvarText = $this->domxml->create_text_node($answer->get_points());
00758                         $qtiSetvar->append_child($qtiSetvarText);
00759                         // qti displayfeedback
00760                         $qtiDisplayfeedback = $this->domxml->create_element("displayfeedback");
00761                         $qtiDisplayfeedback->set_attribute("feedbacktype", "Response");
00762                         $linkrefid = "";
00763                         if ($answer->isStateSet())
00764                         {
00765                                 $linkrefid = "True";
00766                         }
00767                           else
00768                         {
00769                                 $linkrefid = "False_$index";
00770                         }
00771                         $qtiDisplayfeedback->set_attribute("linkrefid", $linkrefid);
00772                         $qtiRespcondition->append_child($qtiConditionvar);
00773                         $qtiRespcondition->append_child($qtiSetvar);
00774                         $qtiRespcondition->append_child($qtiDisplayfeedback);
00775                         $qtiResprocessing->append_child($qtiRespcondition);
00776                 }
00777                 $qtiIdent->append_child($qtiResprocessing);
00778 
00779                 // PART III: qti itemfeedback
00780                 foreach ($this->answers as $index => $answer)
00781                 {
00782                         $qtiItemfeedback = $this->domxml->create_element("itemfeedback");
00783                         $linkrefid = "";
00784                         if ($answer->isStateSet())
00785                         {
00786                                 $linkrefid = "True";
00787                         }
00788                           else
00789                         {
00790                                 $linkrefid = "False_$index";
00791                         }
00792                         $qtiItemfeedback->set_attribute("ident", $linkrefid);
00793                         $qtiItemfeedback->set_attribute("view", "All");
00794                         // qti flow_mat
00795                         $qtiFlowmat = $this->domxml->create_element("flow_mat");
00796                         $qtiMaterial = $this->domxml->create_element("material");
00797                         $qtiMattext = $this->domxml->create_element("mattext");
00798                         // Insert response text for right/wrong answers here!!!
00799                         $qtiMattextText = $this->domxml->create_text_node("");
00800                         $qtiMattext->append_child($qtiMattextText);
00801                         $qtiMaterial->append_child($qtiMattext);
00802                         $qtiFlowmat->append_child($qtiMaterial);
00803                         $qtiItemfeedback->append_child($qtiFlowmat);
00804                         $qtiIdent->append_child($qtiItemfeedback);
00805                 }
00806 
00807                 $xml = $this->domxml->dump_mem(true);
00808                 if (!$a_include_header)
00809                 {
00810                         $pos = strpos($xml, "?>");
00811                         $xml = substr($xml, $pos + 2);
00812                 }
00813 //echo htmlentities($xml);
00814                 return $xml;
00815 
00816         }
00817 
00827   function get_question() {
00828     return $this->question;
00829   }
00830 
00840   function set_question($question = "") {
00841     $this->question = $question;
00842   }
00843 
00853   function get_imagemap_filename() {
00854     return $this->imagemap_filename;
00855   }
00856 
00866   function set_imagemap_filename($imagemap_filename, $imagemap_tempfilename = "") {
00867     if (!empty($imagemap_filename)) {
00868       $this->imagemap_filename = $imagemap_filename;
00869     }
00870     if (!empty($imagemap_tempfilename)) {
00871             $fp = fopen($imagemap_tempfilename, "r");
00872             $contents = fread($fp, filesize($imagemap_tempfilename));
00873       fclose($fp);
00874                         if (preg_match_all("/<area(.+)>/siU", $contents, $matches)) {
00875                         for ($i=0; $i< count($matches[1]); $i++) {
00876                         preg_match("/alt\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $alt);
00877                         preg_match("/coords\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $coords);
00878                         preg_match("/shape\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $shape);
00879                                         $this->add_answer($alt[1], 0.0, FALSE, count($this->answers), $coords[1], $shape[1]);
00880                         }
00881                         }
00882     }
00883         }
00884 
00894   function get_image_filename() {
00895     return $this->image_filename;
00896   }
00897 
00907   function set_image_filename($image_filename, $image_tempfilename = "") {
00908 
00909     if (!empty($image_filename)) {
00910       $this->image_filename = $image_filename;
00911     }
00912                 if (!empty($image_tempfilename)) {
00913                         $imagepath = $this->getImagePath();
00914                         if (!file_exists($imagepath)) {
00915                                 ilUtil::makeDirParents($imagepath);
00916                         }
00917                         
00918                         //if (!move_uploaded_file($image_tempfilename, $imagepath . $image_filename))
00919                         if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
00920                         {
00921                                 print "image not uploaded!!!! ";
00922                         } else {
00923                                 // create thumbnail file
00924                                 $size = 100;
00925                                 $thumbpath = $imagepath . $image_filename . "." . "thumb.jpg";
00926                                 $convert_cmd = ilUtil::getConvertCmd() . " $imagepath$image_filename -resize $sizex$size $thumbpath";
00927                                 system($convert_cmd);
00928                         }
00929                 }
00930   }
00931 
00941   function get_imagemap_contents($href = "#") {
00942                 $imagemap_contents = "<map name=\"".$this->title."\"> ";
00943                 for ($i = 0; $i < count($this->answers); $i++) {
00944                         $imagemap_contents .= "<area alt=\"".$this->answers[$i]->get_answertext()."\" ";
00945                         $imagemap_contents .= "shape=\"".$this->answers[$i]->get_area()."\" ";
00946                         $imagemap_contents .= "coords=\"".$this->answers[$i]->get_coords()."\" ";
00947                         $imagemap_contents .= "href=\"$href&selimage=" . $this->answers[$i]->get_order() . "\" /> ";
00948                 }
00949                 $imagemap_contents .= "</map>";
00950     return $imagemap_contents;
00951   }
00952 
00962   function get_points() {
00963     return $this->points;
00964   }
00965 
00975   function set_points($points = 0.0) {
00976     $this->points = $points;
00977   }
00978 
00993   function add_answer(
00994     $answertext = "",
00995     $points = 0.0,
00996     $status = 0,
00997     $order = 0,
00998     $coords="",
00999     $area=""
01000   )
01001   {
01002     if (array_key_exists($order, $this->answers)) {
01003       // Antwort einf�gen
01004       $answer = new ASS_AnswerImagemap($answertext, $points, $found, $status, $coords, $area);
01005                         for ($i = count($this->answers) - 1; $i >= $order; $i--) {
01006                                 $this->answers[$i+1] = $this->answers[$i];
01007                                 $this->answers[$i+1]->set_order($i+1);
01008                         }
01009                         $this->answers[$order] = $answer;
01010     } else {
01011       // Anwort anh�ngen
01012       $answer = new ASS_AnswerImagemap($answertext, $points, count($this->answers), $status, $coords, $area);
01013       array_push($this->answers, $answer);
01014     }
01015   }
01016 
01026   function get_answer_count() {
01027     return count($this->answers);
01028   }
01029 
01041   function get_answer($index = 0) {
01042     if ($index < 0) return NULL;
01043     if (count($this->answers) < 1) return NULL;
01044     if ($index >= count($this->answers)) return NULL;
01045     return $this->answers[$index];
01046   }
01047 
01058   function deleteArea($index = 0) {
01059     if ($index < 0) return;
01060     if (count($this->answers) < 1) return;
01061     if ($index >= count($this->answers)) return;
01062     unset($this->answers[$index]);
01063     $this->answers = array_values($this->answers);
01064     for ($i = 0; $i < count($this->answers); $i++) {
01065       if ($this->answers[$i]->get_order() > $index) {
01066         $this->answers[$i]->set_order($i);
01067       }
01068     }
01069   }
01070 
01079   function flush_answers() {
01080     $this->answers = array();
01081   }
01082 
01091   function getMaximumPoints() {
01092                 $points = array("set" => 0, "unset" => 0);
01093                 foreach ($this->answers as $key => $value) {
01094                         if ($value->get_points() > $points["set"])
01095                         {
01096                                 $points["set"] = $value->get_points();
01097                         }
01098                 }
01099                 return $points["set"];
01100   }
01101 
01111   function getReachedPoints($user_id, $test_id) {
01112     $found_values = array();
01113     $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
01114       $this->ilias->db->quote($user_id),
01115       $this->ilias->db->quote($test_id),
01116       $this->ilias->db->quote($this->getId())
01117     );
01118     $result = $this->ilias->db->query($query);
01119                 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01120                 {
01121                         if (strcmp($data->value1, "") != 0)
01122                         {
01123                                 array_push($found_values, $data->value1);
01124                         }
01125                 }
01126                 $points = 0;
01127                 if (count($found_values) > 0)
01128                 {
01129                         foreach ($this->answers as $key => $answer)
01130                         {
01131                                 if ($answer->isStateChecked())
01132                                 {
01133                                         if (in_array($key, $found_values))
01134                                         {
01135                                                 $points += $answer->get_points();
01136                                         }
01137                                 }
01138                         }
01139                 }
01140                 return $points;
01141   }
01142 
01154         function _getReachedPoints($user_id, $test_id)
01155         {
01156                 return 0;
01157         }
01158 
01168   function getReachedInformation($user_id, $test_id) {
01169     $found_values = array();
01170     $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
01171       $this->ilias->db->quote($user_id),
01172       $this->ilias->db->quote($test_id),
01173       $this->ilias->db->quote($this->getId())
01174     );
01175     $result = $this->ilias->db->query($query);
01176                 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01177                 {
01178                         array_push($found_values, $data->value1);
01179                 }
01180                 $counter = 1;
01181                 $user_result = array();
01182                 foreach ($found_values as $key => $value)
01183                 {
01184                         $solution = array(
01185                                 "order" => "$counter",
01186                                 "points" => 0,
01187                                 "true" => 0,
01188                                 "value" => "",
01189                                 );
01190                         if (strlen($value) > 0)
01191                         {
01192                                 $solution["value"] = $value;
01193                                 $solution["points"] = $this->answers[$value]->get_points();
01194                                 if ($this->answers[$value]->isStateChecked())
01195                                 {
01196                                         $solution["true"] = 1;
01197                                 }
01198                         }
01199                         $counter++;
01200                         array_push($user_result, $solution);
01201                 }
01202                 return $user_result;
01203   }
01204 
01215   function saveWorkingData($test_id, $limit_to = LIMIT_NO_LIMIT) {
01216     global $ilDB;
01217                 global $ilUser;
01218     $db =& $ilDB->db;
01219 
01220     $query = sprintf("DELETE FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s",
01221       $db->quote($ilUser->id),
01222       $db->quote($test_id),
01223       $db->quote($this->getId())
01224     );
01225     $result = $db->query($query);
01226 
01227                 $query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL, NULL)",
01228                         $db->quote($ilUser->id),
01229                         $db->quote($test_id),
01230                         $db->quote($this->getId()),
01231                         $db->quote($_GET["selImage"])
01232                 );
01233                 $result = $db->query($query);
01234 //    parent::saveWorkingData($limit_to);
01235                 return true;
01236   }
01237 
01238         function syncWithOriginal()
01239         {
01240                 global $ilias;
01241                 if ($this->original_id)
01242                 {
01243                         $complete = 0;
01244                         if ($this->isComplete())
01245                         {
01246                                 $complete = 1;
01247                         }
01248                         $db = & $ilias->db;
01249         
01250                         $estw_time = $this->getEstimatedWorkingTime();
01251                         $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
01252         
01253                         $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time = %s, points = %s, image_file = %s, complete = %s WHERE question_id = %s",
01254                                 $db->quote($this->obj_id. ""),
01255                                 $db->quote($this->title . ""),
01256                                 $db->quote($this->comment . ""),
01257                                 $db->quote($this->author . ""),
01258                                 $db->quote($this->question . ""),
01259                                 $db->quote($estw_time . ""),
01260                                 $db->quote($this->points . ""),
01261                                 $db->quote($this->image_filename . ""),
01262                                 $db->quote($complete . ""),
01263                                 $db->quote($this->original_id . "")
01264                         );
01265                         $result = $db->query($query);
01266 
01267                         if ($result == DB_OK)
01268                         {
01269                                 // write answers
01270                                 // delete old answers
01271                                 $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
01272                                         $db->quote($this->original_id)
01273                                 );
01274                                 $result = $db->query($query);
01275         
01276                                 foreach ($this->answers as $key => $value)
01277                                 {
01278                                         $answer_obj = $this->answers[$key];
01279                                         $query = sprintf("INSERT INTO qpl_answers (answer_id, question_fi, answertext, points, aorder, correctness, coords, area, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, NULL)",
01280                                                 $db->quote($this->original_id . ""),
01281                                                 $db->quote($answer_obj->get_answertext() . ""),
01282                                                 $db->quote($answer_obj->get_points() . ""),
01283                                                 $db->quote($answer_obj->get_order() . ""),
01284                                                 $db->quote($answer_obj->getState() . ""),
01285                                                 $db->quote($answer_obj->get_coords() . ""),
01286                                                 $db->quote($answer_obj->get_area() . "")
01287                                                 );
01288                                         $answer_result = $db->query($query);
01289                                 }
01290                         }
01291                         parent::syncWithOriginal();
01292                 }
01293         }
01294 
01303         function getQuestionType()
01304         {
01305                 return 6;
01306         }
01307 }
01308 
01309 ?>

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