00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 include_once "./assessment/classes/class.assQuestion.php";
00024 include_once "./assessment/classes/inc.AssessmentConstants.php";
00025
00038 class assNumeric extends assQuestion
00039 {
00047 var $question;
00048
00056 var $ranges;
00057
00065 var $maxchars;
00066
00080 function assNumeric(
00081 $title = "",
00082 $comment = "",
00083 $author = "",
00084 $owner = -1,
00085 $question = ""
00086 )
00087 {
00088 $this->assQuestion($title, $comment, $author, $owner);
00089 $this->question = $question;
00090 $this->ranges = array();
00091 $this->maxchars = 6;
00092 }
00093
00102 function isComplete()
00103 {
00104 if (($this->title) and ($this->author) and ($this->question) and (count($this->ranges)) and ($this->getMaximumPoints() > 0))
00105 {
00106 return true;
00107 }
00108 else
00109 {
00110 return false;
00111 }
00112 }
00113
00127 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
00128 {
00129 global $ilUser;
00130
00131
00132 unset($_SESSION["import_mob_xhtml"]);
00133 $presentation = $item->getPresentation();
00134 $duration = $item->getDuration();
00135 $now = getdate();
00136 $maxchars = 0;
00137 $points = 0;
00138 $upperlimit = 0;
00139 $lowerlimit = 0;
00140 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00141 foreach ($presentation->order as $entry)
00142 {
00143 switch ($entry["type"])
00144 {
00145 case "response":
00146 $response = $presentation->response[$entry["index"]];
00147 $rendertype = $response->getRenderType();
00148 switch (strtolower(get_class($rendertype)))
00149 {
00150 case "ilqtirenderfib":
00151 $maxchars = $rendertype->getMaxchars();
00152 break;
00153 }
00154 break;
00155 }
00156 }
00157
00158 foreach ($item->resprocessing as $resprocessing)
00159 {
00160 foreach ($resprocessing->respcondition as $respcondition)
00161 {
00162 $conditionvar = $respcondition->getConditionvar();
00163 foreach ($conditionvar->order as $order)
00164 {
00165 switch ($order["field"])
00166 {
00167 case "varlte":
00168 $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
00169 break;
00170 case "vargte":
00171 $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
00172 break;
00173 }
00174 }
00175 foreach ($respcondition->setvar as $setvar)
00176 {
00177 $points = $setvar->getContent();
00178 }
00179 }
00180 }
00181
00182 $this->setTitle($item->getTitle());
00183 $this->setComment($item->getComment());
00184 $this->setAuthor($item->getAuthor());
00185 $this->setOwner($ilUser->getId());
00186 $this->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
00187 $this->setObjId($questionpool_id);
00188 $this->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
00189 $this->setMaxChars($maxchars);
00190 $this->addRange($lowerlimit, $upperlimit, $points);
00191 $this->saveToDb();
00192 if (count($item->suggested_solutions))
00193 {
00194 foreach ($item->suggested_solutions as $suggested_solution)
00195 {
00196 $this->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
00197 }
00198 $this->saveToDb();
00199 }
00200
00201 if (is_array($_SESSION["import_mob_xhtml"]))
00202 {
00203 include_once "./content/classes/Media/class.ilObjMediaObject.php";
00204 include_once "./Services/RTE/classes/class.ilRTE.php";
00205 foreach ($_SESSION["import_mob_xhtml"] as $mob)
00206 {
00207 if ($tst_id > 0)
00208 {
00209 include_once "./assessment/classes/class.ilObjTest.php";
00210 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
00211 }
00212 else
00213 {
00214 include_once "./assessment/classes/class.ilObjQuestionPool.php";
00215 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
00216 }
00217 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
00218 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->getId());
00219 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getQuestion()), 1));
00220 }
00221 $this->saveToDb();
00222 }
00223 if ($tst_id > 0)
00224 {
00225 $q_1_id = $this->getId();
00226 $question_id = $this->duplicate(true);
00227 $tst_object->questions[$question_counter++] = $question_id;
00228 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
00229 }
00230 else
00231 {
00232 $import_mapping[$item->getIdent()] = array("pool" => $this->getId(), "test" => 0);
00233 }
00234
00235 }
00236
00246 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00247 {
00248 include_once("./classes/class.ilXmlWriter.php");
00249 $a_xml_writer = new ilXmlWriter;
00250
00251 $a_xml_writer->xmlHeader();
00252 $a_xml_writer->xmlStartTag("questestinterop");
00253 $attrs = array(
00254 "ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
00255 "title" => $this->getTitle()
00256 );
00257 $a_xml_writer->xmlStartTag("item", $attrs);
00258
00259 $a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
00260
00261 $workingtime = $this->getEstimatedWorkingTime();
00262 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
00263 $a_xml_writer->xmlElement("duration", NULL, $duration);
00264
00265 $a_xml_writer->xmlStartTag("itemmetadata");
00266 $a_xml_writer->xmlStartTag("qtimetadata");
00267 $a_xml_writer->xmlStartTag("qtimetadatafield");
00268 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
00269 $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
00270 $a_xml_writer->xmlEndTag("qtimetadatafield");
00271 $a_xml_writer->xmlStartTag("qtimetadatafield");
00272 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
00273 $a_xml_writer->xmlElement("fieldentry", NULL, NUMERIC_QUESTION_IDENTIFIER);
00274 $a_xml_writer->xmlEndTag("qtimetadatafield");
00275 $a_xml_writer->xmlStartTag("qtimetadatafield");
00276 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
00277 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
00278 $a_xml_writer->xmlEndTag("qtimetadatafield");
00279 $a_xml_writer->xmlEndTag("qtimetadata");
00280 $a_xml_writer->xmlEndTag("itemmetadata");
00281
00282
00283 $attrs = array(
00284 "label" => $this->getTitle()
00285 );
00286 $a_xml_writer->xmlStartTag("presentation", $attrs);
00287
00288 $a_xml_writer->xmlStartTag("flow");
00289
00290 $this->addQTIMaterial($a_xml_writer, $this->getQuestion());
00291
00292 $attrs = array(
00293 "ident" => "NUM",
00294 "rcardinality" => "Single",
00295 "numtype" => "Decimal"
00296 );
00297 $a_xml_writer->xmlStartTag("response_num", $attrs);
00298 $solution = $this->getSuggestedSolution(0);
00299 if (count($solution))
00300 {
00301 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00302 {
00303 $a_xml_writer->xmlStartTag("material");
00304 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00305 if (strcmp($matches[1], "") != 0)
00306 {
00307 $intlink = $solution["internal_link"];
00308 }
00309 $attrs = array(
00310 "label" => "suggested_solution"
00311 );
00312 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
00313 $a_xml_writer->xmlEndTag("material");
00314 }
00315 }
00316
00317 $attrs = array(
00318 "fibtype" => "Decimal",
00319 "maxchars" => $this->getMaxChars()
00320 );
00321 $a_xml_writer->xmlStartTag("render_fib", $attrs);
00322 $a_xml_writer->xmlEndTag("render_fib");
00323 $a_xml_writer->xmlEndTag("response_num");
00324 $a_xml_writer->xmlEndTag("flow");
00325 $a_xml_writer->xmlEndTag("presentation");
00326
00327
00328 $a_xml_writer->xmlStartTag("resprocessing");
00329 $a_xml_writer->xmlStartTag("outcomes");
00330 $a_xml_writer->xmlStartTag("decvar");
00331 $a_xml_writer->xmlEndTag("decvar");
00332 $a_xml_writer->xmlEndTag("outcomes");
00333
00334 foreach ($this->ranges as $index => $range)
00335 {
00336 $a_xml_writer->xmlStartTag("respcondition");
00337
00338 $a_xml_writer->xmlStartTag("conditionvar");
00339 $attrs = array(
00340 "respident" => "NUM"
00341 );
00342 $a_xml_writer->xmlElement("vargte", $attrs, $range->getLowerLimit());
00343 $a_xml_writer->xmlElement("varlte", $attrs, $range->getUpperLimit());
00344 $a_xml_writer->xmlEndTag("conditionvar");
00345
00346 $attrs = array(
00347 "action" => "Add"
00348 );
00349 $a_xml_writer->xmlElement("setvar", $attrs, $range->getPoints());
00350
00351 $attrs = array(
00352 "feedbacktype" => "Response",
00353 "linkrefid" => "Correct"
00354 );
00355 $a_xml_writer->xmlElement("displayfeedback", $attrs);
00356 $a_xml_writer->xmlEndTag("respcondition");
00357 }
00358 $a_xml_writer->xmlEndTag("resprocessing");
00359
00360
00361 foreach ($this->ranges as $index => $range)
00362 {
00363 $attrs = array(
00364 "ident" => "Correct",
00365 "view" => "All"
00366 );
00367 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
00368
00369 $a_xml_writer->xmlStartTag("flow_mat");
00370 $a_xml_writer->xmlStartTag("material");
00371 $a_xml_writer->xmlElement("mattext");
00372 $a_xml_writer->xmlEndTag("material");
00373 $a_xml_writer->xmlEndTag("flow_mat");
00374 $a_xml_writer->xmlEndTag("itemfeedback");
00375 }
00376
00377 $a_xml_writer->xmlEndTag("item");
00378 $a_xml_writer->xmlEndTag("questestinterop");
00379
00380 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00381 if (!$a_include_header)
00382 {
00383 $pos = strpos($xml, "?>");
00384 $xml = substr($xml, $pos + 2);
00385 }
00386 return $xml;
00387 }
00388
00397 function saveToDb($original_id = "")
00398 {
00399 global $ilDB;
00400
00401 $complete = 0;
00402 if ($this->isComplete())
00403 {
00404 $complete = 1;
00405 }
00406 $estw_time = $this->getEstimatedWorkingTime();
00407 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00408
00409 if ($original_id)
00410 {
00411 $original_id = $ilDB->quote($original_id);
00412 }
00413 else
00414 {
00415 $original_id = "NULL";
00416 }
00417
00418
00419 include_once("./Services/RTE/classes/class.ilRTE.php");
00420 ilRTE::_cleanupMediaObjectUsage($this->question, "qpl:html",
00421 $this->getId());
00422
00423 if ($this->id == -1)
00424 {
00425
00426 $now = getdate();
00427 $question_type = $this->getQuestionType();
00428 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00429 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00430 $ilDB->quote($question_type),
00431 $ilDB->quote($this->obj_id),
00432 $ilDB->quote($this->title),
00433 $ilDB->quote($this->comment),
00434 $ilDB->quote($this->author),
00435 $ilDB->quote($this->owner),
00436 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00437 $ilDB->quote($this->getMaximumPoints() . ""),
00438 $ilDB->quote($estw_time),
00439 $ilDB->quote("$complete"),
00440 $ilDB->quote($created),
00441 $original_id
00442 );
00443 $result = $ilDB->query($query);
00444
00445 if ($result == DB_OK)
00446 {
00447 $this->id = $ilDB->getLastInsertId();
00448 $query = sprintf("INSERT INTO qpl_question_numeric (question_fi, maxNumOfChars) VALUES (%s, %s)",
00449 $ilDB->quote($this->id . ""),
00450 $ilDB->quote($this->getMaxChars() . "")
00451 );
00452 $ilDB->query($query);
00453
00454
00455 $this->createPageObject();
00456
00457 if ($this->getTestId() > 0)
00458 {
00459 $this->insertIntoTest($this->getTestId());
00460 }
00461 }
00462 }
00463 else
00464 {
00465
00466 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
00467 $ilDB->quote($this->obj_id. ""),
00468 $ilDB->quote($this->title),
00469 $ilDB->quote($this->comment),
00470 $ilDB->quote($this->author),
00471 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00472 $ilDB->quote($this->getMaximumPoints() . ""),
00473 $ilDB->quote($estw_time),
00474 $ilDB->quote("$complete"),
00475 $ilDB->quote($this->id)
00476 );
00477 $result = $ilDB->query($query);
00478 $query = sprintf("UPDATE qpl_question_numeric SET maxNumOfChars = %s WHERE question_fi = %s",
00479 $ilDB->quote($this->getMaxChars() . ""),
00480 $ilDB->quote($this->id . "")
00481 );
00482 $result = $ilDB->query($query);
00483 }
00484 if ($result == DB_OK)
00485 {
00486
00487
00488
00489 $query = sprintf("DELETE FROM qpl_numeric_range WHERE question_fi = %s",
00490 $ilDB->quote($this->id)
00491 );
00492 $result = $ilDB->query($query);
00493
00494
00495 foreach ($this->ranges as $key => $range)
00496 {
00497 $query = sprintf("INSERT INTO qpl_numeric_range (range_id, question_fi, lowerlimit, upperlimit, points, aorder, lastchange) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00498 $ilDB->quote($this->id),
00499 $ilDB->quote($range->getLowerLimit()),
00500 $ilDB->quote($range->getUpperLimit() . ""),
00501 $ilDB->quote($range->getPoints() . ""),
00502 $ilDB->quote($range->getOrder() . "")
00503 );
00504 $answer_result = $ilDB->query($query);
00505 }
00506 }
00507 parent::saveToDb($original_id);
00508 }
00509
00519 function loadFromDb($question_id)
00520 {
00521 global $ilDB;
00522
00523 $query = sprintf("SELECT qpl_questions.*, qpl_question_numeric.* FROM qpl_questions, qpl_question_numeric WHERE question_id = %s AND qpl_questions.question_id = qpl_question_numeric.question_fi",
00524 $ilDB->quote($question_id)
00525 );
00526 $result = $ilDB->query($query);
00527 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00528 {
00529 if ($result->numRows() == 1)
00530 {
00531 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00532 $this->id = $question_id;
00533 $this->title = $data->title;
00534 $this->comment = $data->comment;
00535 $this->solution_hint = $data->solution_hint;
00536 $this->original_id = $data->original_id;
00537 $this->obj_id = $data->obj_fi;
00538 $this->author = $data->author;
00539 $this->owner = $data->owner;
00540 $this->points = $data->points;
00541 include_once("./Services/RTE/classes/class.ilRTE.php");
00542 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00543 $this->maxchars = $data->maxNumOfChars;
00544 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00545 }
00546
00547 $query = sprintf("SELECT * FROM qpl_numeric_range WHERE question_fi = %s ORDER BY aorder ASC",
00548 $ilDB->quote($question_id)
00549 );
00550
00551 $result = $ilDB->query($query);
00552
00553 include_once "./assessment/classes/class.assNumericRange.php";
00554 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00555 {
00556 while ($data = $result->fetchRow(DB_FETCHMODE_ASSOC))
00557 {
00558 array_push($this->ranges, new assNumericRange($data["lowerlimit"], $data["upperlimit"], $data["points"], $data["aorder"]));
00559 }
00560 }
00561 }
00562 parent::loadFromDb($question_id);
00563 }
00564
00565
00575 function setQuestion($question = "")
00576 {
00577 $this->question = $question;
00578 }
00579
00594 function addRange(
00595 $lowerlimit = 0.0,
00596 $upperlimit = 0.0,
00597 $points = 0.0,
00598 $order = 0
00599 )
00600 {
00601 $found = -1;
00602 foreach ($this->ranges as $key => $range)
00603 {
00604 if ($range->getOrder() == $order)
00605 {
00606 $found = $order;
00607 }
00608 }
00609 include_once "./assessment/classes/class.assNumericRange.php";
00610 if ($found >= 0)
00611 {
00612
00613 $range = new assNumericRange($lowerlimit, $upperlimit, $points, $found);
00614 array_push($this->ranges, $range);
00615 for ($i = $found + 1; $i < count($this->ranges); $i++)
00616 {
00617 $this->ranges[$i] = $this->ranges[$i-1];
00618 }
00619 $this->ranges[$found] = $range;
00620 }
00621 else
00622 {
00623
00624 $range = new assNumericRange($lowerlimit, $upperlimit, $points, count($this->ranges));
00625 array_push($this->ranges, $range);
00626 }
00627 }
00628
00636 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00637 {
00638 if ($this->id <= 0)
00639 {
00640
00641 return;
00642 }
00643
00644 $this_id = $this->getId();
00645 $clone = $this;
00646 include_once ("./assessment/classes/class.assQuestion.php");
00647 $original_id = assQuestion::_getOriginalId($this->id);
00648 $clone->id = -1;
00649 if ($title)
00650 {
00651 $clone->setTitle($title);
00652 }
00653
00654 if ($author)
00655 {
00656 $clone->setAuthor($author);
00657 }
00658 if ($owner)
00659 {
00660 $clone->setOwner($owner);
00661 }
00662
00663 if ($for_test)
00664 {
00665 $clone->saveToDb($original_id);
00666 }
00667 else
00668 {
00669 $clone->saveToDb();
00670 }
00671
00672
00673 $clone->copyPageOfQuestion($this_id);
00674
00675 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00676
00677 return $clone->id;
00678 }
00679
00687 function copyObject($target_questionpool, $title = "")
00688 {
00689 if ($this->id <= 0)
00690 {
00691
00692 return;
00693 }
00694
00695 $clone = $this;
00696 include_once ("./assessment/classes/class.assQuestion.php");
00697 $original_id = assQuestion::_getOriginalId($this->id);
00698 $clone->id = -1;
00699 $source_questionpool = $this->getObjId();
00700 $clone->setObjId($target_questionpool);
00701 if ($title)
00702 {
00703 $clone->setTitle($title);
00704 }
00705 $clone->saveToDb();
00706
00707
00708 $clone->copyPageOfQuestion($original_id);
00709
00710 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00711
00712 return $clone->id;
00713 }
00714
00724 function getQuestion()
00725 {
00726 return $this->question;
00727 }
00728
00738 function getRangeCount()
00739 {
00740 return count($this->ranges);
00741 }
00742
00754 function getRange($index = 0)
00755 {
00756 if ($index < 0) return NULL;
00757 if (count($this->ranges) < 1) return NULL;
00758 if ($index >= count($this->ranges)) return NULL;
00759
00760 return $this->ranges[$index];
00761 }
00762
00773 function deleteRange($index = 0)
00774 {
00775 if ($index < 0) return;
00776 if (count($this->ranges) < 1) return;
00777 if ($index >= count($this->ranges)) return;
00778 unset($this->ranges[$index]);
00779 $this->ranges = array_values($this->ranges);
00780 for ($i = 0; $i < count($this->ranges); $i++)
00781 {
00782 if ($this->ranges[$i]->getOrder() > $index)
00783 {
00784 $this->ranges[$i]->setOrder($i);
00785 }
00786 }
00787 }
00788
00797 function flushRanges()
00798 {
00799 $this->ranges = array();
00800 }
00801
00810 function getMaximumPoints()
00811 {
00812 $max = 0;
00813 foreach ($this->ranges as $key => $range)
00814 {
00815 if ($range->getPoints() > $max)
00816 {
00817 $max = $range->getPoints();
00818 }
00819 }
00820 return $max;
00821 }
00822
00831 function getBestRange()
00832 {
00833 $max = 0;
00834 $bestrange = NULL;
00835 foreach ($this->ranges as $key => $range)
00836 {
00837 if ($range->getPoints() > $max)
00838 {
00839 $max = $range->getPoints();
00840 $bestrange = $range;
00841 }
00842 }
00843 return $bestrange;
00844 }
00845
00857 function calculateReachedPoints($active_id, $pass = NULL)
00858 {
00859 global $ilDB;
00860
00861 $found_values = array();
00862 if (is_null($pass))
00863 {
00864 $pass = $this->getSolutionMaxPass($active_id);
00865 }
00866 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00867 $ilDB->quote($active_id . ""),
00868 $ilDB->quote($this->getId() . ""),
00869 $ilDB->quote($pass . "")
00870 );
00871 $result = $ilDB->query($query);
00872 $data = $result->fetchRow(DB_FETCHMODE_ASSOC);
00873
00874 $enteredvalue = $data["value1"];
00875 if (!is_numeric($enteredvalue)) return 0;
00876 $points = 0;
00877 foreach ($this->ranges as $key => $range)
00878 {
00879 if ($points == 0)
00880 {
00881 if ($range->contains($enteredvalue))
00882 {
00883 $points = $range->getPoints();
00884 }
00885 }
00886 }
00887
00888 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00889 return $points;
00890 }
00891
00902 function saveWorkingData($active_id, $pass = NULL)
00903 {
00904 global $ilDB;
00905 global $ilUser;
00906
00907 include_once "./assessment/classes/class.ilObjTest.php";
00908 $actualpass = ilObjTest::_getPass($active_id);
00909 $entered_values = 0;
00910 $numeric_result = str_replace(",",".",$_POST["numeric_result"]);
00911 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00912 $ilDB->quote($active_id . ""),
00913 $ilDB->quote($this->getId() . ""),
00914 $ilDB->quote($actualpass . "")
00915 );
00916 $result = $ilDB->query($query);
00917 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00918 $update = $row->solution_id;
00919 if ($update)
00920 {
00921 if (strlen($numeric_result))
00922 {
00923 $query = sprintf("UPDATE tst_solutions SET value1 = %s WHERE solution_id = %s",
00924 $ilDB->quote(trim($numeric_result)),
00925 $ilDB->quote($update)
00926 );
00927 $result = $ilDB->query($query);
00928 $entered_values++;
00929 }
00930 else
00931 {
00932 $query = sprintf("DELETE FROM tst_solutions WHERE solution_id = %s",
00933 $ilDB->quote($update)
00934 );
00935 $result = $ilDB->query($query);
00936 }
00937 }
00938 else
00939 {
00940 if (strlen($numeric_result))
00941 {
00942 $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
00943 $ilDB->quote($active_id),
00944 $ilDB->quote($this->getId()),
00945 $ilDB->quote(trim($numeric_result)),
00946 $ilDB->quote($actualpass . "")
00947 );
00948 $result = $ilDB->query($query);
00949 $entered_values++;
00950 }
00951 }
00952 if ($entered_values)
00953 {
00954 include_once ("./classes/class.ilObjAssessmentFolder.php");
00955 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00956 {
00957 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00958 }
00959 }
00960 else
00961 {
00962 include_once ("./classes/class.ilObjAssessmentFolder.php");
00963 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00964 {
00965 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00966 }
00967 }
00968 parent::saveWorkingData($active_id, $pass);
00969 return true;
00970 }
00971
00972 function syncWithOriginal()
00973 {
00974 global $ilDB;
00975
00976 if ($this->original_id)
00977 {
00978 $complete = 0;
00979 if ($this->isComplete())
00980 {
00981 $complete = 1;
00982 }
00983
00984 $estw_time = $this->getEstimatedWorkingTime();
00985 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00986
00987 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
00988 $ilDB->quote($this->obj_id. ""),
00989 $ilDB->quote($this->title. ""),
00990 $ilDB->quote($this->comment. ""),
00991 $ilDB->quote($this->author. ""),
00992 $ilDB->quote($this->question. ""),
00993 $ilDB->quote($this->getMaximumPoints() . ""),
00994 $ilDB->quote($estw_time. ""),
00995 $ilDB->quote($complete. ""),
00996 $ilDB->quote($this->original_id. "")
00997 );
00998 $result = $ilDB->query($query);
00999 $query = sprintf("UPDATE qpl_question_numeric SET maxNumOfChars = %s WHERE question_fi = %s",
01000 $ilDB->quote($this->getMaxChars() . ""),
01001 $ilDB->quote($this->original_id . "")
01002 );
01003 $result = $ilDB->query($query);
01004
01005 if ($result == DB_OK)
01006 {
01007
01008
01009
01010 $query = sprintf("DELETE FROM qpl_numeric_range WHERE question_fi = %s",
01011 $ilDB->quote($this->original_id)
01012 );
01013 $result = $ilDB->query($query);
01014
01015
01016 foreach ($this->ranges as $key => $range)
01017 {
01018 $query = sprintf("INSERT INTO qpl_numeric_range (range_id, question_fi, lowerlimit, upperlimit, points, aorder, lastchange) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
01019 $ilDB->quote($this->original_id),
01020 $ilDB->quote($range->getLowerLimit()),
01021 $ilDB->quote($range->getUpperLimit() . ""),
01022 $ilDB->quote($range->getPoints() . ""),
01023 $ilDB->quote($range->getOrder() . "")
01024 );
01025 $answer_result = $ilDB->query($query);
01026 }
01027 }
01028 parent::syncWithOriginal();
01029 }
01030 }
01031
01040 function getQuestionType()
01041 {
01042 return 9;
01043 }
01044
01053 function getMaxChars()
01054 {
01055 return $this->maxchars;
01056 }
01057
01066 function setMaxChars($maxchars)
01067 {
01068 $this->maxchars = $maxchars;
01069 }
01070
01079 function getAdditionalTableName()
01080 {
01081 return "qpl_question_numeric";
01082 }
01083 }
01084
01085 ?>