00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./assessment/classes/class.assQuestion.php";
00025 include_once "./assessment/classes/inc.AssessmentConstants.php";
00026
00037 class assImagemapQuestion extends assQuestion
00038 {
00039
00047 var $question;
00048
00056 var $answers;
00057
00065 var $imagemap_filename;
00066
00074 var $image_filename;
00075
00083 var $imagemap_contents;
00084 var $coords;
00085
00100 function assImagemapQuestion(
00101 $title = "",
00102 $comment = "",
00103 $author = "",
00104 $owner = -1,
00105 $question = "",
00106 $imagemap_filename = "",
00107 $image_filename = ""
00108
00109 )
00110 {
00111 $this->assQuestion($title, $comment, $author, $owner);
00112 $this->question = $question;
00113 $this->imagemap_filename = $imagemap_filename;
00114 $this->image_filename = $image_filename;
00115 $this->answers = array();
00116 $this->coords = array();
00117 }
00118
00127 function isComplete()
00128 {
00129 if (($this->title) and ($this->author) and ($this->question) and ($this->image_filename) and (count($this->answers)) and ($this->getMaximumPoints() > 0))
00130 {
00131 return true;
00132 }
00133 else
00134 {
00135 return false;
00136 }
00137 }
00138
00147 function saveToDb($original_id = "")
00148 {
00149 global $ilDB;
00150
00151 $complete = 0;
00152 if ($this->isComplete())
00153 {
00154 $complete = 1;
00155 }
00156
00157 $estw_time = $this->getEstimatedWorkingTime();
00158 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00159 if ($original_id)
00160 {
00161 $original_id = $ilDB->quote($original_id);
00162 }
00163 else
00164 {
00165 $original_id = "NULL";
00166 }
00167
00168
00169 include_once("./Services/RTE/classes/class.ilRTE.php");
00170 ilRTE::_cleanupMediaObjectUsage($this->question, "qpl:html",
00171 $this->getId());
00172
00173 if ($this->id == -1)
00174 {
00175
00176 $now = getdate();
00177 $question_type = $this->getQuestionType();
00178 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00179 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, working_time, points, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00180 $ilDB->quote($question_type),
00181 $ilDB->quote($this->obj_id),
00182 $ilDB->quote($this->title),
00183 $ilDB->quote($this->comment),
00184 $ilDB->quote($this->author),
00185 $ilDB->quote($this->owner),
00186 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00187 $ilDB->quote($estw_time),
00188 $ilDB->quote($this->getMaximumPoints() . ""),
00189 $ilDB->quote("$complete"),
00190 $ilDB->quote($created),
00191 $original_id
00192 );
00193 $result = $ilDB->query($query);
00194 if ($result == DB_OK)
00195 {
00196 $this->id = $ilDB->getLastInsertId();
00197 $insertquery = sprintf("INSERT INTO qpl_question_imagemap (question_fi, image_file) VALUES (%s, %s)",
00198 $ilDB->quote($this->id . ""),
00199 $ilDB->quote($this->image_filename)
00200 );
00201 $ilDB->query($insertquery);
00202
00203 $this->createPageObject();
00204
00205 if ($this->getTestId() > 0)
00206 {
00207 $this->insertIntoTest($this->getTestId());
00208 }
00209 }
00210 }
00211 else
00212 {
00213
00214 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time = %s, points = %s, complete = %s WHERE question_id = %s",
00215 $ilDB->quote($this->obj_id. ""),
00216 $ilDB->quote($this->title),
00217 $ilDB->quote($this->comment),
00218 $ilDB->quote($this->author),
00219 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00220 $ilDB->quote($estw_time),
00221 $ilDB->quote($this->getMaximumPoints() . ""),
00222 $ilDB->quote("$complete"),
00223 $ilDB->quote($this->id)
00224 );
00225 $result = $ilDB->query($query);
00226 $query = sprintf("UPDATE qpl_question_imagemap SET image_file = %s WHERE question_fi = %s",
00227 $ilDB->quote($this->image_filename),
00228 $ilDB->quote($this->id)
00229 );
00230 $result = $ilDB->query($query);
00231
00232 }
00233
00234 if ($result == DB_OK)
00235 {
00236 $query = sprintf("DELETE FROM qpl_answer_imagemap WHERE question_fi = %s",
00237 $ilDB->quote($this->id)
00238 );
00239 $result = $ilDB->query($query);
00240
00241 foreach ($this->answers as $key => $value)
00242 {
00243 $answer_obj = $this->answers[$key];
00244
00245 $query = sprintf("INSERT INTO qpl_answer_imagemap (answer_id, question_fi, answertext, points, aorder, correctness, coords, area) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s)",
00246 $ilDB->quote($this->id),
00247 $ilDB->quote($answer_obj->getAnswertext() . ""),
00248 $ilDB->quote($answer_obj->getPoints() . ""),
00249 $ilDB->quote($answer_obj->getOrder() . ""),
00250 $ilDB->quote($answer_obj->getState() . ""),
00251 $ilDB->quote($answer_obj->getCoords() . ""),
00252 $ilDB->quote($answer_obj->getArea() . "")
00253 );
00254 $answer_result = $ilDB->query($query);
00255 }
00256 }
00257 parent::saveToDb($original_id);
00258 }
00259
00267 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00268 {
00269 if ($this->id <= 0)
00270 {
00271
00272 return;
00273 }
00274
00275 $this_id = $this->getId();
00276 $clone = $this;
00277 include_once ("./assessment/classes/class.assQuestion.php");
00278 $original_id = assQuestion::_getOriginalId($this->id);
00279 $clone->id = -1;
00280 if ($title)
00281 {
00282 $clone->setTitle($title);
00283 }
00284 if ($author)
00285 {
00286 $clone->setAuthor($author);
00287 }
00288 if ($owner)
00289 {
00290 $clone->setOwner($owner);
00291 }
00292 if ($for_test)
00293 {
00294 $clone->saveToDb($original_id);
00295 }
00296 else
00297 {
00298 $clone->saveToDb();
00299 }
00300
00301
00302 $clone->copyPageOfQuestion($this_id);
00303
00304 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00305
00306
00307 $clone->duplicateImage($this_id);
00308 return $clone->id;
00309 }
00310
00318 function copyObject($target_questionpool, $title = "")
00319 {
00320 if ($this->id <= 0)
00321 {
00322
00323 return;
00324 }
00325
00326 $clone = $this;
00327 include_once ("./assessment/classes/class.assQuestion.php");
00328 $original_id = assQuestion::_getOriginalId($this->id);
00329 $clone->id = -1;
00330 $source_questionpool = $this->getObjId();
00331 $clone->setObjId($target_questionpool);
00332 if ($title)
00333 {
00334 $clone->setTitle($title);
00335 }
00336 $clone->saveToDb();
00337
00338
00339 $clone->copyPageOfQuestion($original_id);
00340
00341 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00342
00343
00344 $clone->copyImage($original_id, $source_questionpool);
00345 return $clone->id;
00346 }
00347
00348 function duplicateImage($question_id)
00349 {
00350 $imagepath = $this->getImagePath();
00351 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00352 if (!file_exists($imagepath)) {
00353 ilUtil::makeDirParents($imagepath);
00354 }
00355 $filename = $this->get_image_filename();
00356 if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
00357 print "image could not be duplicated!!!! ";
00358 }
00359 }
00360
00361 function copyImage($question_id, $source_questionpool)
00362 {
00363 $imagepath = $this->getImagePath();
00364 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00365 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
00366 if (!file_exists($imagepath))
00367 {
00368 ilUtil::makeDirParents($imagepath);
00369 }
00370 $filename = $this->get_image_filename();
00371 if (!copy($imagepath_original . $filename, $imagepath . $filename))
00372 {
00373 print "image could not be copied!!!! ";
00374 }
00375 }
00376
00386 function loadFromDb($question_id)
00387 {
00388 global $ilDB;
00389
00390 $query = sprintf("SELECT qpl_questions.*, qpl_question_imagemap.* FROM qpl_questions, qpl_question_imagemap WHERE question_id = %s AND qpl_questions.question_id = qpl_question_imagemap.question_fi",
00391 $ilDB->quote($question_id)
00392 );
00393 $result = $ilDB->query($query);
00394 if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00395 if ($result->numRows() == 1) {
00396 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00397 $this->id = $question_id;
00398 $this->obj_id = $data->obj_fi;
00399 $this->title = $data->title;
00400 $this->comment = $data->comment;
00401 $this->author = $data->author;
00402 $this->original_id = $data->original_id;
00403 $this->solution_hint = $data->solution_hint;
00404 $this->owner = $data->owner;
00405 include_once("./Services/RTE/classes/class.ilRTE.php");
00406 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00407 $this->image_filename = $data->image_file;
00408 $this->points = $data->points;
00409 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00410 }
00411 $query = sprintf("SELECT * FROM qpl_answer_imagemap WHERE question_fi = %s ORDER BY aorder ASC",
00412 $ilDB->quote($question_id)
00413 );
00414 $result = $ilDB->query($query);
00415 include_once "./assessment/classes/class.assAnswerImagemap.php";
00416 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00417 {
00418 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00419 {
00420 array_push($this->answers, new ASS_AnswerImagemap($data->answertext, $data->points, $data->aorder, $data->coords, $data->area));
00421 }
00422 }
00423 }
00424 parent::loadFromDb($question_id);
00425 }
00426
00440 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
00441 {
00442 global $ilUser;
00443
00444
00445 unset($_SESSION["import_mob_xhtml"]);
00446 $presentation = $item->getPresentation();
00447 $duration = $item->getDuration();
00448 $now = getdate();
00449 $questionimage = array();
00450 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00451 $answers = array();
00452 foreach ($presentation->order as $entry)
00453 {
00454 switch ($entry["type"])
00455 {
00456 case "response":
00457 $response = $presentation->response[$entry["index"]];
00458 $rendertype = $response->getRenderType();
00459 switch (strtolower(get_class($rendertype)))
00460 {
00461 case "ilqtirenderhotspot":
00462 foreach ($rendertype->material as $mat)
00463 {
00464 for ($i = 0; $i < $mat->getMaterialCount(); $i++)
00465 {
00466 $m = $mat->getMaterial($i);
00467 if (strcmp($m["type"], "matimage") == 0)
00468 {
00469 $questionimage = array(
00470 "imagetype" => $m["material"]->getImageType(),
00471 "label" => $m["material"]->getLabel(),
00472 "content" => $m["material"]->getContent()
00473 );
00474 }
00475 }
00476 }
00477 foreach ($rendertype->response_labels as $response_label)
00478 {
00479 $ident = $response_label->getIdent();
00480 $answerhint = "";
00481 foreach ($response_label->material as $mat)
00482 {
00483 $answerhint .= $this->QTIMaterialToString($mat);
00484 }
00485 $answers[$ident] = array(
00486 "answerhint" => $answerhint,
00487 "areatype" => $response_label->getRarea(),
00488 "coordinates" => $response_label->getContent(),
00489 "points" => 0,
00490 "answerorder" => $response_label->getIdent(),
00491 "correctness" => "1",
00492 "action" => ""
00493 );
00494 }
00495 break;
00496 }
00497 break;
00498 }
00499 }
00500 $responses = array();
00501 foreach ($item->resprocessing as $resprocessing)
00502 {
00503 foreach ($resprocessing->respcondition as $respcondition)
00504 {
00505 $coordinates = "";
00506 $conditionvar = $respcondition->getConditionvar();
00507 foreach ($conditionvar->order as $order)
00508 {
00509 switch ($order["field"])
00510 {
00511 case "varinside":
00512 $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
00513 break;
00514 }
00515 }
00516 foreach ($respcondition->setvar as $setvar)
00517 {
00518 foreach ($answers as $ident => $answer)
00519 {
00520 if (strcmp($answer["coordinates"], $coordinates) == 0)
00521 {
00522 $answers[$ident]["action"] = $setvar->getAction();
00523 $answers[$ident]["points"] = $setvar->getContent();
00524 }
00525 }
00526 }
00527 }
00528 }
00529
00530 $this->setTitle($item->getTitle());
00531 $this->setComment($item->getComment());
00532 $this->setAuthor($item->getAuthor());
00533 $this->setOwner($ilUser->getId());
00534 $this->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
00535 $this->setObjId($questionpool_id);
00536 $this->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
00537 $areas = array("2" => "rect", "1" => "circle", "3" => "poly");
00538 $this->image_filename = $questionimage["label"];
00539 foreach ($answers as $answer)
00540 {
00541 $this->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]]);
00542 }
00543 $this->saveToDb();
00544 if (count($item->suggested_solutions))
00545 {
00546 foreach ($item->suggested_solutions as $suggested_solution)
00547 {
00548 $this->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
00549 }
00550 $this->saveToDb();
00551 }
00552 $image =& base64_decode($questionimage["content"]);
00553 $imagepath = $this->getImagePath();
00554 if (!file_exists($imagepath))
00555 {
00556 include_once "./classes/class.ilUtil.php";
00557 ilUtil::makeDirParents($imagepath);
00558 }
00559 $imagepath .= $questionimage["label"];
00560 $fh = fopen($imagepath, "wb");
00561 if ($fh == false)
00562 {
00563
00564
00565
00566 }
00567 else
00568 {
00569 $imagefile = fwrite($fh, $image);
00570 fclose($fh);
00571 }
00572
00573 if (is_array($_SESSION["import_mob_xhtml"]))
00574 {
00575 include_once "./content/classes/Media/class.ilObjMediaObject.php";
00576 include_once "./Services/RTE/classes/class.ilRTE.php";
00577 foreach ($_SESSION["import_mob_xhtml"] as $mob)
00578 {
00579 if ($tst_id > 0)
00580 {
00581 include_once "./assessment/classes/class.ilObjTest.php";
00582 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
00583 }
00584 else
00585 {
00586 include_once "./assessment/classes/class.ilObjQuestionPool.php";
00587 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
00588 }
00589 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
00590 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->getId());
00591 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getQuestion()), 1));
00592 }
00593 $this->saveToDb();
00594 }
00595 if ($tst_id > 0)
00596 {
00597 $q_1_id = $this->getId();
00598 $question_id = $this->duplicate(true);
00599 $tst_object->questions[$question_counter++] = $question_id;
00600 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
00601 }
00602 else
00603 {
00604 $import_mapping[$item->getIdent()] = array("pool" => $this->getId(), "test" => 0);
00605 }
00606
00607 }
00608
00618 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00619 {
00620 include_once("./classes/class.ilXmlWriter.php");
00621 $a_xml_writer = new ilXmlWriter;
00622
00623 $a_xml_writer->xmlHeader();
00624 $a_xml_writer->xmlStartTag("questestinterop");
00625 $attrs = array(
00626 "ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
00627 "title" => $this->getTitle()
00628 );
00629 $a_xml_writer->xmlStartTag("item", $attrs);
00630
00631 $a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
00632
00633 $workingtime = $this->getEstimatedWorkingTime();
00634 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
00635 $a_xml_writer->xmlElement("duration", NULL, $duration);
00636
00637 $a_xml_writer->xmlStartTag("itemmetadata");
00638 $a_xml_writer->xmlStartTag("qtimetadata");
00639 $a_xml_writer->xmlStartTag("qtimetadatafield");
00640 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
00641 $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
00642 $a_xml_writer->xmlEndTag("qtimetadatafield");
00643 $a_xml_writer->xmlStartTag("qtimetadatafield");
00644 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
00645 $a_xml_writer->xmlElement("fieldentry", NULL, IMAGEMAP_QUESTION_IDENTIFIER);
00646 $a_xml_writer->xmlEndTag("qtimetadatafield");
00647 $a_xml_writer->xmlStartTag("qtimetadatafield");
00648 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
00649 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
00650 $a_xml_writer->xmlEndTag("qtimetadatafield");
00651 $a_xml_writer->xmlEndTag("qtimetadata");
00652 $a_xml_writer->xmlEndTag("itemmetadata");
00653
00654
00655 $attrs = array(
00656 "label" => $this->getTitle()
00657 );
00658 $a_xml_writer->xmlStartTag("presentation", $attrs);
00659
00660 $a_xml_writer->xmlStartTag("flow");
00661
00662 $this->addQTIMaterial($a_xml_writer, $this->getQuestion());
00663
00664 $attrs = array(
00665 "ident" => "IM",
00666 "rcardinality" => "Single"
00667 );
00668 $a_xml_writer->xmlStartTag("response_xy", $attrs);
00669 $solution = $this->getSuggestedSolution(0);
00670 if (count($solution))
00671 {
00672 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00673 {
00674 $a_xml_writer->xmlStartTag("material");
00675 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00676 if (strcmp($matches[1], "") != 0)
00677 {
00678 $intlink = $solution["internal_link"];
00679 }
00680 $attrs = array(
00681 "label" => "suggested_solution"
00682 );
00683 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
00684 $a_xml_writer->xmlEndTag("material");
00685 }
00686 }
00687 $a_xml_writer->xmlStartTag("render_hotspot");
00688 $a_xml_writer->xmlStartTag("material");
00689 $imagetype = "image/jpeg";
00690 if (preg_match("/.*\.(png|gif)$/", $this->get_image_filename(), $matches))
00691 {
00692 $imagetype = "image/" . $matches[1];
00693 }
00694 $attrs = array(
00695 "imagtype" => $imagetype,
00696 "label" => $this->get_image_filename()
00697 );
00698 if ($a_include_binary)
00699 {
00700 if ($force_image_references)
00701 {
00702 $attrs["uri"] = $this->getImagePathWeb() . $this->get_image_filename();
00703 $a_xml_writer->xmlElement("matimage", $attrs);
00704 }
00705 else
00706 {
00707 $attrs["embedded"] = "base64";
00708 $imagepath = $this->getImagePath() . $this->get_image_filename();
00709 $fh = fopen($imagepath, "rb");
00710 if ($fh == false)
00711 {
00712 global $ilErr;
00713 $ilErr->raiseError($this->lng->txt("error_open_image_file"), $ilErr->MESSAGE);
00714 return;
00715 }
00716 $imagefile = fread($fh, filesize($imagepath));
00717 fclose($fh);
00718 $base64 = base64_encode($imagefile);
00719 $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
00720 }
00721 }
00722 else
00723 {
00724 $a_xml_writer->xmlElement("matimage", $attrs);
00725 }
00726 $a_xml_writer->xmlEndTag("material");
00727
00728
00729 foreach ($this->answers as $index => $answer)
00730 {
00731 $rared = "";
00732 switch ($answer->getArea())
00733 {
00734 case "rect":
00735 $rarea = "Rectangle";
00736 break;
00737 case "circle":
00738 $rarea = "Ellipse";
00739 break;
00740 case "poly":
00741 $rarea = "Bounded";
00742 break;
00743 }
00744 $attrs = array(
00745 "ident" => $index,
00746 "rarea" => $rarea
00747 );
00748 $a_xml_writer->xmlStartTag("response_label", $attrs);
00749 $a_xml_writer->xmlData($answer->getCoords());
00750 $a_xml_writer->xmlStartTag("material");
00751 $a_xml_writer->xmlElement("mattext", NULL, $answer->getAnswertext());
00752 $a_xml_writer->xmlEndTag("material");
00753 $a_xml_writer->xmlEndTag("response_label");
00754 }
00755 $a_xml_writer->xmlEndTag("render_hotspot");
00756 $a_xml_writer->xmlEndTag("response_xy");
00757 $a_xml_writer->xmlEndTag("flow");
00758 $a_xml_writer->xmlEndTag("presentation");
00759
00760
00761 $a_xml_writer->xmlStartTag("resprocessing");
00762 $a_xml_writer->xmlStartTag("outcomes");
00763 $a_xml_writer->xmlStartTag("decvar");
00764 $a_xml_writer->xmlEndTag("decvar");
00765 $a_xml_writer->xmlEndTag("outcomes");
00766
00767 foreach ($this->answers as $index => $answer)
00768 {
00769 $attrs = array(
00770 "continue" => "Yes"
00771 );
00772 $a_xml_writer->xmlStartTag("respcondition", $attrs);
00773
00774 $a_xml_writer->xmlStartTag("conditionvar");
00775 if (!$answer->isStateSet())
00776 {
00777 $a_xml_writer->xmlStartTag("not");
00778 }
00779 $areatype = "";
00780 switch ($answer->getArea())
00781 {
00782 case "rect":
00783 $areatype = "Rectangle";
00784 break;
00785 case "circle":
00786 $areatype = "Ellipse";
00787 break;
00788 case "poly":
00789 $areatype = "Bounded";
00790 break;
00791 }
00792 $attrs = array(
00793 "respident" => "IM",
00794 "areatype" => $areatype
00795 );
00796 $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
00797 if (!$answer->isStateSet())
00798 {
00799 $a_xml_writer->xmlEndTag("not");
00800 }
00801 $a_xml_writer->xmlEndTag("conditionvar");
00802
00803 $attrs = array(
00804 "action" => "Add"
00805 );
00806 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
00807 $linkrefid = "response_$index";
00808 $attrs = array(
00809 "feedbacktype" => "Response",
00810 "linkrefid" => $linkrefid
00811 );
00812 $a_xml_writer->xmlElement("displayfeedback", $attrs);
00813 $a_xml_writer->xmlEndTag("respcondition");
00814 }
00815 $a_xml_writer->xmlEndTag("resprocessing");
00816
00817
00818 foreach ($this->answers as $index => $answer)
00819 {
00820 $linkrefid = "";
00821 $linkrefid = "response_$index";
00822 $attrs = array(
00823 "ident" => $linkrefid,
00824 "view" => "All"
00825 );
00826 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
00827
00828 $a_xml_writer->xmlStartTag("flow_mat");
00829 $a_xml_writer->xmlStartTag("material");
00830 $a_xml_writer->xmlElement("mattext");
00831 $a_xml_writer->xmlEndTag("material");
00832 $a_xml_writer->xmlEndTag("flow_mat");
00833 $a_xml_writer->xmlEndTag("itemfeedback");
00834 }
00835
00836 $a_xml_writer->xmlEndTag("item");
00837 $a_xml_writer->xmlEndTag("questestinterop");
00838
00839 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00840 if (!$a_include_header)
00841 {
00842 $pos = strpos($xml, "?>");
00843 $xml = substr($xml, $pos + 2);
00844 }
00845 return $xml;
00846 }
00847
00857 function getQuestion() {
00858 return $this->question;
00859 }
00860
00870 function setQuestion($question = "") {
00871 $this->question = $question;
00872 }
00873
00883 function get_imagemap_filename() {
00884 return $this->imagemap_filename;
00885 }
00886
00896 function setImagemapFilename($imagemap_filename, $imagemap_tempfilename = "") {
00897 if (!empty($imagemap_filename)) {
00898 $this->imagemap_filename = $imagemap_filename;
00899 }
00900 if (!empty($imagemap_tempfilename)) {
00901 $fp = fopen($imagemap_tempfilename, "r");
00902 $contents = fread($fp, filesize($imagemap_tempfilename));
00903 fclose($fp);
00904 if (preg_match_all("/<area(.+)>/siU", $contents, $matches)) {
00905 for ($i=0; $i< count($matches[1]); $i++) {
00906 preg_match("/alt\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $alt);
00907 preg_match("/coords\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $coords);
00908 preg_match("/shape\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $shape);
00909 $this->addAnswer($alt[1], 0.0, count($this->answers), $coords[1], $shape[1]);
00910 }
00911 }
00912 }
00913 }
00914
00924 function get_image_filename() {
00925 return $this->image_filename;
00926 }
00927
00937 function setImageFilename($image_filename, $image_tempfilename = "") {
00938
00939 if (!empty($image_filename))
00940 {
00941 $image_filename = str_replace(" ", "_", $image_filename);
00942 $this->image_filename = $image_filename;
00943 }
00944 if (!empty($image_tempfilename)) {
00945 $imagepath = $this->getImagePath();
00946 if (!file_exists($imagepath)) {
00947 ilUtil::makeDirParents($imagepath);
00948 }
00949
00950 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
00951 {
00952 $this->ilias->raiseError("The image could not be uploaded!", $this->ilias->error_obj->MESSAGE);
00953 }
00954 }
00955 }
00956
00966 function get_imagemap_contents($href = "#") {
00967 $imagemap_contents = "<map name=\"".$this->title."\"> ";
00968 for ($i = 0; $i < count($this->answers); $i++) {
00969 $imagemap_contents .= "<area alt=\"".$this->answers[$i]->getAnswertext()."\" ";
00970 $imagemap_contents .= "shape=\"".$this->answers[$i]->getArea()."\" ";
00971 $imagemap_contents .= "coords=\"".$this->answers[$i]->getCoords()."\" ";
00972 $imagemap_contents .= "href=\"$href&selimage=" . $this->answers[$i]->getOrder() . "\" /> ";
00973 }
00974 $imagemap_contents .= "</map>";
00975 return $imagemap_contents;
00976 }
00977
00992 function addAnswer(
00993 $answertext = "",
00994 $points = 0.0,
00995 $order = 0,
00996 $coords="",
00997 $area=""
00998 )
00999 {
01000 include_once "./assessment/classes/class.assAnswerImagemap.php";
01001 if (array_key_exists($order, $this->answers))
01002 {
01003
01004 $answer = new ASS_AnswerImagemap($answertext, $points, $order, $coords, $area);
01005 for ($i = count($this->answers) - 1; $i >= $order; $i--)
01006 {
01007 $this->answers[$i+1] = $this->answers[$i];
01008 $this->answers[$i+1]->setOrder($i+1);
01009 }
01010 $this->answers[$order] = $answer;
01011 }
01012 else
01013 {
01014
01015 $answer = new ASS_AnswerImagemap($answertext, $points, count($this->answers), $coords, $area);
01016 array_push($this->answers, $answer);
01017 }
01018 }
01019
01029 function getAnswerCount() {
01030 return count($this->answers);
01031 }
01032
01044 function getAnswer($index = 0) {
01045 if ($index < 0) return NULL;
01046 if (count($this->answers) < 1) return NULL;
01047 if ($index >= count($this->answers)) return NULL;
01048 return $this->answers[$index];
01049 }
01050
01061 function deleteArea($index = 0) {
01062 if ($index < 0) return;
01063 if (count($this->answers) < 1) return;
01064 if ($index >= count($this->answers)) return;
01065 unset($this->answers[$index]);
01066 $this->answers = array_values($this->answers);
01067 for ($i = 0; $i < count($this->answers); $i++) {
01068 if ($this->answers[$i]->getOrder() > $index) {
01069 $this->answers[$i]->setOrder($i);
01070 }
01071 }
01072 }
01073
01082 function flushAnswers() {
01083 $this->answers = array();
01084 }
01085
01094 function getMaximumPoints() {
01095 $points = 0;
01096 foreach ($this->answers as $key => $value) {
01097 if ($value->getPoints() > $points)
01098 {
01099 $points = $value->getPoints();
01100 }
01101 }
01102 return $points;
01103 }
01104
01116 function calculateReachedPoints($active_id, $pass = NULL)
01117 {
01118 global $ilDB;
01119
01120 $found_values = array();
01121 if (is_null($pass))
01122 {
01123 $pass = $this->getSolutionMaxPass($active_id);
01124 }
01125 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
01126 $ilDB->quote($active_id . ""),
01127 $ilDB->quote($this->getId() . ""),
01128 $ilDB->quote($pass . "")
01129 );
01130 $result = $ilDB->query($query);
01131 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01132 {
01133 if (strcmp($data->value1, "") != 0)
01134 {
01135 array_push($found_values, $data->value1);
01136 }
01137 }
01138 $points = 0;
01139 if (count($found_values) > 0)
01140 {
01141 foreach ($this->answers as $key => $answer)
01142 {
01143 if (in_array($key, $found_values))
01144 {
01145 $points += $answer->getPoints();
01146 }
01147 }
01148 }
01149
01150 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
01151 return $points;
01152 }
01153
01164 function saveWorkingData($active_id, $pass = NULL)
01165 {
01166 global $ilDB;
01167 global $ilUser;
01168
01169 include_once "./assessment/classes/class.ilObjTest.php";
01170 $activepass = ilObjTest::_getPass($active_id);
01171
01172 $query = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
01173 $ilDB->quote($active_id . ""),
01174 $ilDB->quote($this->getId() . ""),
01175 $ilDB->quote($activepass . "")
01176 );
01177 $result = $ilDB->query($query);
01178
01179 if (strlen($_GET["selImage"]))
01180 {
01181 $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
01182 $ilDB->quote($active_id),
01183 $ilDB->quote($this->getId()),
01184 $ilDB->quote($_GET["selImage"]),
01185 $ilDB->quote($activepass . "")
01186 );
01187
01188 $result = $ilDB->query($query);
01189 include_once ("./classes/class.ilObjAssessmentFolder.php");
01190 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
01191 {
01192 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
01193 }
01194 }
01195 else
01196 {
01197 include_once ("./classes/class.ilObjAssessmentFolder.php");
01198 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
01199 {
01200 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
01201 }
01202 }
01203
01204 parent::saveWorkingData($active_id, $pass);
01205 return true;
01206 }
01207
01208 function syncWithOriginal()
01209 {
01210 global $ilDB;
01211
01212 if ($this->original_id)
01213 {
01214 $complete = 0;
01215 if ($this->isComplete())
01216 {
01217 $complete = 1;
01218 }
01219
01220 $estw_time = $this->getEstimatedWorkingTime();
01221 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
01222
01223 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time = %s, points = %s, complete = %s WHERE question_id = %s",
01224 $ilDB->quote($this->obj_id. ""),
01225 $ilDB->quote($this->title . ""),
01226 $ilDB->quote($this->comment . ""),
01227 $ilDB->quote($this->author . ""),
01228 $ilDB->quote($this->question . ""),
01229 $ilDB->quote($estw_time . ""),
01230 $ilDB->quote($this->getMaximumPoints() . ""),
01231 $ilDB->quote($complete . ""),
01232 $ilDB->quote($this->original_id . "")
01233 );
01234 $result = $ilDB->query($query);
01235 $query = sprintf("UPDATE qpl_question_imagemap SET image_file = %s WHERE question_fi = %s",
01236 $ilDB->quote($this->image_filename . ""),
01237 $ilDB->quote($this->original_id . "")
01238 );
01239 $result = $ilDB->query($query);
01240
01241 if ($result == DB_OK)
01242 {
01243
01244
01245 $query = sprintf("DELETE FROM qpl_answer_imagemap WHERE question_fi = %s",
01246 $ilDB->quote($this->original_id)
01247 );
01248 $result = $ilDB->query($query);
01249
01250 foreach ($this->answers as $key => $value)
01251 {
01252 $answer_obj = $this->answers[$key];
01253 $query = sprintf("INSERT INTO qpl_answer_imagemap (answer_id, question_fi, answertext, points, aorder, correctness, coords, area) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s)",
01254 $ilDB->quote($this->original_id . ""),
01255 $ilDB->quote($answer_obj->getAnswertext() . ""),
01256 $ilDB->quote($answer_obj->getPoints() . ""),
01257 $ilDB->quote($answer_obj->getOrder() . ""),
01258 $ilDB->quote($answer_obj->getState() . ""),
01259 $ilDB->quote($answer_obj->getCoords() . ""),
01260 $ilDB->quote($answer_obj->getArea() . "")
01261 );
01262 $answer_result = $ilDB->query($query);
01263 }
01264 }
01265 parent::syncWithOriginal();
01266 }
01267 }
01268
01277 function getQuestionType()
01278 {
01279 return 6;
01280 }
01281
01290 function getAdditionalTableName()
01291 {
01292 return "qpl_question_imagemap";
01293 }
01294
01303 function getAnswerTableName()
01304 {
01305 return "qpl_answer_imagemap";
01306 }
01307 }
01308
01309 ?>