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 ASS_ImagemapQuestion extends ASS_Question
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 ASS_ImagemapQuestion(
00101 $title = "",
00102 $comment = "",
00103 $author = "",
00104 $owner = -1,
00105 $question = "",
00106 $imagemap_filename = "",
00107 $image_filename = ""
00108
00109 )
00110 {
00111 $this->ASS_Question($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 $ilias;
00150
00151 $complete = 0;
00152 if ($this->isComplete())
00153 {
00154 $complete = 1;
00155 }
00156
00157 $db = & $ilias->db;
00158
00159 $estw_time = $this->getEstimatedWorkingTime();
00160 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00161 if ($original_id)
00162 {
00163 $original_id = $db->quote($original_id);
00164 }
00165 else
00166 {
00167 $original_id = "NULL";
00168 }
00169
00170 if ($this->id == -1)
00171 {
00172
00173 $now = getdate();
00174 $question_type = $this->getQuestionType();
00175 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00176 $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)",
00177 $db->quote($question_type),
00178 $db->quote($this->obj_id),
00179 $db->quote($this->title),
00180 $db->quote($this->comment),
00181 $db->quote($this->author),
00182 $db->quote($this->owner),
00183 $db->quote($this->question),
00184 $db->quote($estw_time),
00185 $db->quote($this->getMaximumPoints() . ""),
00186 $db->quote($this->image_filename),
00187 $db->quote("$complete"),
00188 $db->quote($created),
00189 $original_id
00190 );
00191 $result = $db->query($query);
00192 if ($result == DB_OK)
00193 {
00194 $this->id = $db->getLastInsertId();
00195
00196
00197 $this->createPageObject();
00198
00199
00200 if ($this->getTestId() > 0)
00201 {
00202 $this->insertIntoTest($this->getTestId());
00203 }
00204 }
00205 }
00206 else
00207 {
00208
00209 $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",
00210 $db->quote($this->obj_id. ""),
00211 $db->quote($this->title),
00212 $db->quote($this->comment),
00213 $db->quote($this->author),
00214 $db->quote($this->question),
00215 $db->quote($estw_time),
00216 $db->quote($this->getMaximumPoints() . ""),
00217 $db->quote($this->image_filename),
00218 $db->quote("$complete"),
00219 $db->quote($this->id)
00220 );
00221 $result = $db->query($query);
00222 }
00223
00224 if ($result == DB_OK)
00225 {
00226 $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
00227 $db->quote($this->id)
00228 );
00229 $result = $db->query($query);
00230
00231 foreach ($this->answers as $key => $value)
00232 {
00233 $answer_obj = $this->answers[$key];
00234
00235 $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)",
00236 $db->quote($this->id),
00237 $db->quote($answer_obj->get_answertext() . ""),
00238 $db->quote($answer_obj->get_points() . ""),
00239 $db->quote($answer_obj->get_order() . ""),
00240 $db->quote($answer_obj->getState() . ""),
00241 $db->quote($answer_obj->get_coords() . ""),
00242 $db->quote($answer_obj->get_area() . "")
00243 );
00244 $answer_result = $db->query($query);
00245 }
00246 }
00247 parent::saveToDb($original_id);
00248 }
00249
00257 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00258 {
00259 if ($this->id <= 0)
00260 {
00261
00262 return;
00263 }
00264
00265 $this_id = $this->getId();
00266 $clone = $this;
00267 include_once ("./assessment/classes/class.assQuestion.php");
00268 $original_id = ASS_Question::_getOriginalId($this->id);
00269 $clone->id = -1;
00270 if ($title)
00271 {
00272 $clone->setTitle($title);
00273 }
00274 if ($author)
00275 {
00276 $clone->setAuthor($author);
00277 }
00278 if ($owner)
00279 {
00280 $clone->setOwner($owner);
00281 }
00282 if ($for_test)
00283 {
00284 $clone->saveToDb($original_id);
00285 }
00286 else
00287 {
00288 $clone->saveToDb();
00289 }
00290
00291
00292 $clone->copyPageOfQuestion($this_id);
00293
00294
00295 $clone->duplicateImage($this_id);
00296 return $clone->id;
00297 }
00298
00306 function copyObject($target_questionpool, $title = "")
00307 {
00308 if ($this->id <= 0)
00309 {
00310
00311 return;
00312 }
00313
00314 $clone = $this;
00315 include_once ("./assessment/classes/class.assQuestion.php");
00316 $original_id = ASS_Question::_getOriginalId($this->id);
00317 $clone->id = -1;
00318 $source_questionpool = $this->getObjId();
00319 $clone->setObjId($target_questionpool);
00320 if ($title)
00321 {
00322 $clone->setTitle($title);
00323 }
00324 $clone->saveToDb();
00325
00326
00327 $clone->copyPageOfQuestion($original_id);
00328
00329
00330 $clone->copyImage($original_id, $source_questionpool);
00331 return $clone->id;
00332 }
00333
00334 function duplicateImage($question_id)
00335 {
00336 $imagepath = $this->getImagePath();
00337 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00338 if (!file_exists($imagepath)) {
00339 ilUtil::makeDirParents($imagepath);
00340 }
00341 $filename = $this->get_image_filename();
00342 if (!copy($imagepath_original . $filename, $imagepath . $filename)) {
00343 print "image could not be duplicated!!!! ";
00344 }
00345 }
00346
00347 function copyImage($question_id, $source_questionpool)
00348 {
00349 $imagepath = $this->getImagePath();
00350 $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath);
00351 $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original);
00352 if (!file_exists($imagepath))
00353 {
00354 ilUtil::makeDirParents($imagepath);
00355 }
00356 $filename = $this->get_image_filename();
00357 if (!copy($imagepath_original . $filename, $imagepath . $filename))
00358 {
00359 print "image could not be copied!!!! ";
00360 }
00361 }
00362
00372 function loadFromDb($question_id)
00373 {
00374 global $ilias;
00375
00376 $db = & $ilias->db;
00377 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
00378 $db->quote($question_id)
00379 );
00380 $result = $db->query($query);
00381 if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00382 if ($result->numRows() == 1) {
00383 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00384 $this->id = $question_id;
00385 $this->obj_id = $data->obj_fi;
00386 $this->title = $data->title;
00387 $this->comment = $data->comment;
00388 $this->author = $data->author;
00389 $this->original_id = $data->original_id;
00390 $this->solution_hint = $data->solution_hint;
00391 $this->owner = $data->owner;
00392 $this->question = $data->question_text;
00393 $this->image_filename = $data->image_file;
00394 $this->points = $data->points;
00395 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00396 }
00397 $query = sprintf("SELECT * FROM qpl_answers WHERE question_fi = %s ORDER BY aorder ASC",
00398 $db->quote($question_id)
00399 );
00400 $result = $db->query($query);
00401 include_once "./assessment/classes/class.assAnswerImagemap.php";
00402 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00403 {
00404 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00405 {
00406 if ($data->correctness == 0)
00407 {
00408
00409 $data->correctness = 1;
00410 $data->points = 0;
00411 }
00412 array_push($this->answers, new ASS_AnswerImagemap($data->answertext, $data->points, $data->aorder, $data->correctness, $data->coords, $data->area));
00413 }
00414 }
00415 }
00416 parent::loadFromDb($question_id);
00417 }
00418
00426 function addAnswer($answertext, $points, $answerorder, $correctness, $coords, $area)
00427 {
00428 include_once "./assessment/classes/class.assAnswerImagemap.php";
00429 array_push($this->answers, new ASS_AnswerImagemap($answertext, $points, $answerorder, $correctness, $coords, $area));
00430 }
00431
00441 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00442 {
00443 include_once("./classes/class.ilXmlWriter.php");
00444 $a_xml_writer = new ilXmlWriter;
00445
00446 $a_xml_writer->xmlHeader();
00447 $a_xml_writer->xmlStartTag("questestinterop");
00448 $attrs = array(
00449 "ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
00450 "title" => $this->getTitle()
00451 );
00452 $a_xml_writer->xmlStartTag("item", $attrs);
00453
00454 $a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
00455
00456 $workingtime = $this->getEstimatedWorkingTime();
00457 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
00458 $a_xml_writer->xmlElement("duration", NULL, $duration);
00459
00460 $a_xml_writer->xmlStartTag("itemmetadata");
00461 $a_xml_writer->xmlStartTag("qtimetadata");
00462 $a_xml_writer->xmlStartTag("qtimetadatafield");
00463 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
00464 $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
00465 $a_xml_writer->xmlEndTag("qtimetadatafield");
00466 $a_xml_writer->xmlStartTag("qtimetadatafield");
00467 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
00468 $a_xml_writer->xmlElement("fieldentry", NULL, IMAGEMAP_QUESTION_IDENTIFIER);
00469 $a_xml_writer->xmlEndTag("qtimetadatafield");
00470 $a_xml_writer->xmlStartTag("qtimetadatafield");
00471 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
00472 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
00473 $a_xml_writer->xmlEndTag("qtimetadatafield");
00474 $a_xml_writer->xmlEndTag("qtimetadata");
00475 $a_xml_writer->xmlEndTag("itemmetadata");
00476
00477
00478 $attrs = array(
00479 "label" => $this->getTitle()
00480 );
00481 $a_xml_writer->xmlStartTag("presentation", $attrs);
00482
00483 $a_xml_writer->xmlStartTag("flow");
00484
00485 $a_xml_writer->xmlStartTag("material");
00486 $a_xml_writer->xmlElement("mattext", NULL, $this->get_question());
00487 $a_xml_writer->xmlEndTag("material");
00488
00489 $attrs = array(
00490 "ident" => "IM",
00491 "rcardinality" => "Single"
00492 );
00493 $a_xml_writer->xmlStartTag("response_xy", $attrs);
00494 $solution = $this->getSuggestedSolution(0);
00495 if (count($solution))
00496 {
00497 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00498 {
00499 $a_xml_writer->xmlStartTag("material");
00500 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00501 if (strcmp($matches[1], "") != 0)
00502 {
00503 $intlink = $solution["internal_link"];
00504 }
00505 $attrs = array(
00506 "label" => "suggested_solution"
00507 );
00508 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
00509 $a_xml_writer->xmlEndTag("material");
00510 }
00511 }
00512 $a_xml_writer->xmlStartTag("render_hotspot");
00513 $a_xml_writer->xmlStartTag("material");
00514 $imagetype = "image/jpeg";
00515 if (preg_match("/.*\.(png|gif)$/", $this->get_image_filename(), $matches))
00516 {
00517 $imagetype = "image/" . $matches[1];
00518 }
00519 $attrs = array(
00520 "imagtype" => $imagetype,
00521 "label" => $this->get_image_filename()
00522 );
00523 if ($a_include_binary)
00524 {
00525 if ($force_image_references)
00526 {
00527 $attrs["uri"] = $this->getImagePathWeb() . $this->get_image_filename();
00528 $a_xml_writer->xmlElement("matimage", $attrs);
00529 }
00530 else
00531 {
00532 $attrs["embedded"] = "base64";
00533 $imagepath = $this->getImagePath() . $this->get_image_filename();
00534 $fh = fopen($imagepath, "rb");
00535 if ($fh == false)
00536 {
00537 global $ilErr;
00538 $ilErr->raiseError($this->lng->txt("error_open_image_file"), $ilErr->MESSAGE);
00539 return;
00540 }
00541 $imagefile = fread($fh, filesize($imagepath));
00542 fclose($fh);
00543 $base64 = base64_encode($imagefile);
00544 $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
00545 }
00546 }
00547 else
00548 {
00549 $a_xml_writer->xmlElement("matimage", $attrs);
00550 }
00551 $a_xml_writer->xmlEndTag("material");
00552
00553
00554 foreach ($this->answers as $index => $answer)
00555 {
00556 $rared = "";
00557 switch ($answer->get_area())
00558 {
00559 case "rect":
00560 $rarea = "Rectangle";
00561 break;
00562 case "circle":
00563 $rarea = "Ellipse";
00564 break;
00565 case "poly":
00566 $rarea = "Bounded";
00567 break;
00568 }
00569 $attrs = array(
00570 "ident" => $index,
00571 "rarea" => $rarea
00572 );
00573 $a_xml_writer->xmlStartTag("response_label", $attrs);
00574 $a_xml_writer->xmlData($answer->get_coords());
00575 $a_xml_writer->xmlStartTag("material");
00576 $a_xml_writer->xmlElement("mattext", NULL, $answer->get_answertext());
00577 $a_xml_writer->xmlEndTag("material");
00578 $a_xml_writer->xmlEndTag("response_label");
00579 }
00580 $a_xml_writer->xmlEndTag("render_hotspot");
00581 $a_xml_writer->xmlEndTag("response_xy");
00582 $a_xml_writer->xmlEndTag("flow");
00583 $a_xml_writer->xmlEndTag("presentation");
00584
00585
00586 $a_xml_writer->xmlStartTag("resprocessing");
00587 $a_xml_writer->xmlStartTag("outcomes");
00588 $a_xml_writer->xmlStartTag("decvar");
00589 $a_xml_writer->xmlEndTag("decvar");
00590 $a_xml_writer->xmlEndTag("outcomes");
00591
00592 foreach ($this->answers as $index => $answer)
00593 {
00594 $attrs = array(
00595 "continue" => "Yes"
00596 );
00597 $a_xml_writer->xmlStartTag("respcondition", $attrs);
00598
00599 $a_xml_writer->xmlStartTag("conditionvar");
00600 if (!$answer->isStateSet())
00601 {
00602 $a_xml_writer->xmlStartTag("not");
00603 }
00604 $areatype = "";
00605 switch ($answer->get_area())
00606 {
00607 case "rect":
00608 $areatype = "Rectangle";
00609 break;
00610 case "circle":
00611 $areatype = "Ellipse";
00612 break;
00613 case "poly":
00614 $areatype = "Bounded";
00615 break;
00616 }
00617 $attrs = array(
00618 "respident" => "IM",
00619 "areatype" => $areatype
00620 );
00621 $a_xml_writer->xmlElement("varinside", $attrs, $answer->get_coords());
00622 if (!$answer->isStateSet())
00623 {
00624 $a_xml_writer->xmlEndTag("not");
00625 }
00626 $a_xml_writer->xmlEndTag("conditionvar");
00627
00628 $attrs = array(
00629 "action" => "Add"
00630 );
00631 $a_xml_writer->xmlElement("setvar", $attrs, $answer->get_points());
00632
00633 if ($answer->isStateChecked())
00634 {
00635 $linkrefid = "True";
00636 }
00637 else
00638 {
00639 $linkrefid = "False_$index";
00640 }
00641 $attrs = array(
00642 "feedbacktype" => "Response",
00643 "linkrefid" => $linkrefid
00644 );
00645 $a_xml_writer->xmlElement("displayfeedback", $attrs);
00646 $a_xml_writer->xmlEndTag("respcondition");
00647 }
00648 $a_xml_writer->xmlEndTag("resprocessing");
00649
00650
00651 foreach ($this->answers as $index => $answer)
00652 {
00653 $linkrefid = "";
00654 if ($answer->isStateChecked())
00655 {
00656 $linkrefid = "True";
00657 }
00658 else
00659 {
00660 $linkrefid = "False_$index";
00661 }
00662 $attrs = array(
00663 "ident" => $linkrefid,
00664 "view" => "All"
00665 );
00666 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
00667
00668 $a_xml_writer->xmlStartTag("flow_mat");
00669 $a_xml_writer->xmlStartTag("material");
00670 $a_xml_writer->xmlElement("mattext");
00671 $a_xml_writer->xmlEndTag("material");
00672 $a_xml_writer->xmlEndTag("flow_mat");
00673 $a_xml_writer->xmlEndTag("itemfeedback");
00674 }
00675
00676 $a_xml_writer->xmlEndTag("item");
00677 $a_xml_writer->xmlEndTag("questestinterop");
00678
00679 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00680 if (!$a_include_header)
00681 {
00682 $pos = strpos($xml, "?>");
00683 $xml = substr($xml, $pos + 2);
00684 }
00685 return $xml;
00686 }
00687
00697 function get_question() {
00698 return $this->question;
00699 }
00700
00710 function set_question($question = "") {
00711 $this->question = $question;
00712 }
00713
00723 function get_imagemap_filename() {
00724 return $this->imagemap_filename;
00725 }
00726
00736 function set_imagemap_filename($imagemap_filename, $imagemap_tempfilename = "") {
00737 if (!empty($imagemap_filename)) {
00738 $this->imagemap_filename = $imagemap_filename;
00739 }
00740 if (!empty($imagemap_tempfilename)) {
00741 $fp = fopen($imagemap_tempfilename, "r");
00742 $contents = fread($fp, filesize($imagemap_tempfilename));
00743 fclose($fp);
00744 if (preg_match_all("/<area(.+)>/siU", $contents, $matches)) {
00745 for ($i=0; $i< count($matches[1]); $i++) {
00746 preg_match("/alt\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $alt);
00747 preg_match("/coords\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $coords);
00748 preg_match("/shape\s*=\s*\"(.+)\"\s*/siU", $matches[1][$i], $shape);
00749 $this->add_answer($alt[1], 0.0, FALSE, count($this->answers), $coords[1], $shape[1]);
00750 }
00751 }
00752 }
00753 }
00754
00764 function get_image_filename() {
00765 return $this->image_filename;
00766 }
00767
00777 function set_image_filename($image_filename, $image_tempfilename = "") {
00778
00779 if (!empty($image_filename))
00780 {
00781 $image_filename = str_replace(" ", "_", $image_filename);
00782 $this->image_filename = $image_filename;
00783 }
00784 if (!empty($image_tempfilename)) {
00785 $imagepath = $this->getImagePath();
00786 if (!file_exists($imagepath)) {
00787 ilUtil::makeDirParents($imagepath);
00788 }
00789
00790 if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $imagepath.$image_filename))
00791 {
00792 $this->ilias->raiseError("The image could not be uploaded!", $this->ilias->error_obj->MESSAGE);
00793 }
00794 }
00795 }
00796
00806 function get_imagemap_contents($href = "#") {
00807 $imagemap_contents = "<map name=\"".$this->title."\"> ";
00808 for ($i = 0; $i < count($this->answers); $i++) {
00809 $imagemap_contents .= "<area alt=\"".$this->answers[$i]->get_answertext()."\" ";
00810 $imagemap_contents .= "shape=\"".$this->answers[$i]->get_area()."\" ";
00811 $imagemap_contents .= "coords=\"".$this->answers[$i]->get_coords()."\" ";
00812 $imagemap_contents .= "href=\"$href&selimage=" . $this->answers[$i]->get_order() . "\" /> ";
00813 }
00814 $imagemap_contents .= "</map>";
00815 return $imagemap_contents;
00816 }
00817
00832 function add_answer(
00833 $answertext = "",
00834 $points = 0.0,
00835 $status = 0,
00836 $order = 0,
00837 $coords="",
00838 $area=""
00839 )
00840 {
00841 include_once "./assessment/classes/class.assAnswerImagemap.php";
00842 if (array_key_exists($order, $this->answers))
00843 {
00844
00845 $answer = new ASS_AnswerImagemap($answertext, $points, $order, $status, $coords, $area);
00846 for ($i = count($this->answers) - 1; $i >= $order; $i--)
00847 {
00848 $this->answers[$i+1] = $this->answers[$i];
00849 $this->answers[$i+1]->set_order($i+1);
00850 }
00851 $this->answers[$order] = $answer;
00852 }
00853 else
00854 {
00855
00856 $answer = new ASS_AnswerImagemap($answertext, $points, count($this->answers), $status, $coords, $area);
00857 array_push($this->answers, $answer);
00858 }
00859 }
00860
00870 function get_answer_count() {
00871 return count($this->answers);
00872 }
00873
00885 function get_answer($index = 0) {
00886 if ($index < 0) return NULL;
00887 if (count($this->answers) < 1) return NULL;
00888 if ($index >= count($this->answers)) return NULL;
00889 return $this->answers[$index];
00890 }
00891
00902 function deleteArea($index = 0) {
00903 if ($index < 0) return;
00904 if (count($this->answers) < 1) return;
00905 if ($index >= count($this->answers)) return;
00906 unset($this->answers[$index]);
00907 $this->answers = array_values($this->answers);
00908 for ($i = 0; $i < count($this->answers); $i++) {
00909 if ($this->answers[$i]->get_order() > $index) {
00910 $this->answers[$i]->set_order($i);
00911 }
00912 }
00913 }
00914
00923 function flush_answers() {
00924 $this->answers = array();
00925 }
00926
00935 function getMaximumPoints() {
00936 $points = array("set" => 0, "unset" => 0);
00937 foreach ($this->answers as $key => $value) {
00938 if ($value->get_points() > $points["set"])
00939 {
00940 $points["set"] = $value->get_points();
00941 }
00942 }
00943 return $points["set"];
00944 }
00945
00957 function calculateReachedPoints($user_id, $test_id, $pass = NULL)
00958 {
00959 global $ilDB;
00960
00961 $found_values = array();
00962 if (is_null($pass))
00963 {
00964 $pass = $this->getSolutionMaxPass($user_id, $test_id);
00965 }
00966 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
00967 $ilDB->quote($user_id . ""),
00968 $ilDB->quote($test_id . ""),
00969 $ilDB->quote($this->getId() . ""),
00970 $ilDB->quote($pass . "")
00971 );
00972 $result = $ilDB->query($query);
00973 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00974 {
00975 if (strcmp($data->value1, "") != 0)
00976 {
00977 array_push($found_values, $data->value1);
00978 }
00979 }
00980 $points = 0;
00981 if (count($found_values) > 0)
00982 {
00983 foreach ($this->answers as $key => $answer)
00984 {
00985 if ($answer->isStateChecked())
00986 {
00987 if (in_array($key, $found_values))
00988 {
00989 $points += $answer->get_points();
00990 }
00991 }
00992 }
00993 }
00994
00995
00996 $query = sprintf("SELECT * FROM tst_tests WHERE test_id = %s",
00997 $ilDB->quote($test_id)
00998 );
00999 $result = $ilDB->query($query);
01000 if ($result->numRows() == 1)
01001 {
01002 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
01003 if ($row["count_system"] == 1)
01004 {
01005 if ($points != $this->getMaximumPoints())
01006 {
01007 $points = 0;
01008 }
01009 }
01010 }
01011 else
01012 {
01013 $points = 0;
01014 }
01015 return $points;
01016 }
01017
01027 function getReachedInformation($user_id, $test_id, $pass = NULL)
01028 {
01029 $found_values = array();
01030 if (is_null($pass))
01031 {
01032 $pass = $this->getSolutionMaxPass($user_id, $test_id);
01033 }
01034 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
01035 $this->ilias->db->quote($user_id . ""),
01036 $this->ilias->db->quote($test_id . ""),
01037 $this->ilias->db->quote($this->getId() . ""),
01038 $this->ilias->db->quote($pass . "")
01039 );
01040 $result = $this->ilias->db->query($query);
01041 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01042 {
01043 array_push($found_values, $data->value1);
01044 }
01045 $counter = 1;
01046 $user_result = array();
01047 foreach ($found_values as $key => $value)
01048 {
01049 $solution = array(
01050 "order" => "$counter",
01051 "points" => 0,
01052 "true" => 0,
01053 "value" => "",
01054 );
01055 if (strlen($value) > 0)
01056 {
01057 $solution["value"] = $value;
01058 $solution["points"] = $this->answers[$value]->get_points();
01059 if ($this->answers[$value]->isStateChecked())
01060 {
01061 $solution["true"] = 1;
01062 }
01063 }
01064 $counter++;
01065 array_push($user_result, $solution);
01066 }
01067 return $user_result;
01068 }
01069
01080 function saveWorkingData($test_id, $pass = NULL)
01081 {
01082 global $ilDB;
01083 global $ilUser;
01084 $db =& $ilDB->db;
01085
01086 include_once "./assessment/classes/class.ilObjTest.php";
01087 $activepass = ilObjTest::_getPass($ilUser->id, $test_id);
01088
01089 $query = sprintf("DELETE FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
01090 $db->quote($ilUser->id . ""),
01091 $db->quote($test_id . ""),
01092 $db->quote($this->getId() . ""),
01093 $db->quote($activepass . "")
01094 );
01095 $result = $db->query($query);
01096
01097 if (strlen($_GET["selImage"]))
01098 {
01099 $query = sprintf("INSERT INTO tst_solutions (solution_id, user_fi, test_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL, %s, NULL)",
01100 $db->quote($ilUser->id),
01101 $db->quote($test_id),
01102 $db->quote($this->getId()),
01103 $db->quote($_GET["selImage"]),
01104 $db->quote($activepass . "")
01105 );
01106 $result = $db->query($query);
01107
01108 include_once ("./classes/class.ilObjAssessmentFolder.php");
01109 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
01110 {
01111 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $test_id, $this->getId());
01112 }
01113 }
01114 else
01115 {
01116 include_once ("./classes/class.ilObjAssessmentFolder.php");
01117 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
01118 {
01119 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $test_id, $this->getId());
01120 }
01121 }
01122 parent::saveWorkingData($test_id, $pass);
01123 return true;
01124 }
01125
01126 function syncWithOriginal()
01127 {
01128 global $ilias;
01129 if ($this->original_id)
01130 {
01131 $complete = 0;
01132 if ($this->isComplete())
01133 {
01134 $complete = 1;
01135 }
01136 $db = & $ilias->db;
01137
01138 $estw_time = $this->getEstimatedWorkingTime();
01139 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
01140
01141 $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",
01142 $db->quote($this->obj_id. ""),
01143 $db->quote($this->title . ""),
01144 $db->quote($this->comment . ""),
01145 $db->quote($this->author . ""),
01146 $db->quote($this->question . ""),
01147 $db->quote($estw_time . ""),
01148 $db->quote($this->getMaximumPoints() . ""),
01149 $db->quote($this->image_filename . ""),
01150 $db->quote($complete . ""),
01151 $db->quote($this->original_id . "")
01152 );
01153 $result = $db->query($query);
01154
01155 if ($result == DB_OK)
01156 {
01157
01158
01159 $query = sprintf("DELETE FROM qpl_answers WHERE question_fi = %s",
01160 $db->quote($this->original_id)
01161 );
01162 $result = $db->query($query);
01163
01164 foreach ($this->answers as $key => $value)
01165 {
01166 $answer_obj = $this->answers[$key];
01167 $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)",
01168 $db->quote($this->original_id . ""),
01169 $db->quote($answer_obj->get_answertext() . ""),
01170 $db->quote($answer_obj->get_points() . ""),
01171 $db->quote($answer_obj->get_order() . ""),
01172 $db->quote($answer_obj->getState() . ""),
01173 $db->quote($answer_obj->get_coords() . ""),
01174 $db->quote($answer_obj->get_area() . "")
01175 );
01176 $answer_result = $db->query($query);
01177 }
01178 }
01179 parent::syncWithOriginal();
01180 }
01181 }
01182
01191 function getQuestionType()
01192 {
01193 return 6;
01194 }
01195 }
01196
01197 ?>