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
00036 class assTextQuestion extends assQuestion
00037 {
00045 var $question;
00046
00054 var $maxNumOfChars;
00055
00064 var $keywords;
00065
00073 var $text_rating;
00074
00088 function assTextQuestion(
00089 $title = "",
00090 $comment = "",
00091 $author = "",
00092 $owner = -1,
00093 $question = ""
00094 )
00095 {
00096 $this->assQuestion($title, $comment, $author, $owner);
00097 $this->question = $question;
00098 $this->maxNumOfChars = 0;
00099 $this->points = 0;
00100 $this->keywords = "";
00101 }
00102
00111 function isComplete()
00112 {
00113 if (($this->title) and ($this->author) and ($this->question) and ($this->getMaximumPoints() > 0))
00114 {
00115 return true;
00116 }
00117 else
00118 {
00119 return false;
00120 }
00121 }
00122
00136 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
00137 {
00138 global $ilUser;
00139
00140
00141 unset($_SESSION["import_mob_xhtml"]);
00142 $presentation = $item->getPresentation();
00143 $duration = $item->getDuration();
00144 $now = getdate();
00145 $maxchars = 0;
00146 $maxpoints = 0;
00147 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00148 foreach ($presentation->order as $entry)
00149 {
00150 switch ($entry["type"])
00151 {
00152 case "response":
00153 $response = $presentation->response[$entry["index"]];
00154 $rendertype = $response->getRenderType();
00155 switch (strtolower(get_class($rendertype)))
00156 {
00157 case "ilqtirenderfib":
00158 $maxchars = $rendertype->getMaxchars();
00159 break;
00160 }
00161 break;
00162 }
00163 }
00164
00165 foreach ($item->resprocessing as $resprocessing)
00166 {
00167 $outcomes = $resprocessing->getOutcomes();
00168 foreach ($outcomes->decvar as $decvar)
00169 {
00170 $maxpoints = $decvar->getMaxvalue();
00171 }
00172 }
00173
00174 $this->setTitle($item->getTitle());
00175 $this->setComment($item->getComment());
00176 $this->setAuthor($item->getAuthor());
00177 $this->setOwner($ilUser->getId());
00178 $this->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
00179 $this->setObjId($questionpool_id);
00180 $this->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
00181 $this->setPoints($maxpoints);
00182 $this->setMaxNumOfChars($maxchars);
00183 $textrating = $item->getMetadataEntry("textrating");
00184 if (strlen($textrating))
00185 {
00186 $this->setTextRating($textrating);
00187 }
00188 $keywords = $item->getMetadataEntry("keywords");
00189 if (strlen($keywords))
00190 {
00191 $this->setKeywords($keywords);
00192 }
00193 $this->saveToDb();
00194 if (count($item->suggested_solutions))
00195 {
00196 foreach ($item->suggested_solutions as $suggested_solution)
00197 {
00198 $this->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
00199 }
00200 $this->saveToDb();
00201 }
00202
00203 if (is_array($_SESSION["import_mob_xhtml"]))
00204 {
00205 include_once "./content/classes/Media/class.ilObjMediaObject.php";
00206 include_once "./Services/RTE/classes/class.ilRTE.php";
00207 foreach ($_SESSION["import_mob_xhtml"] as $mob)
00208 {
00209 if ($tst_id > 0)
00210 {
00211 include_once "./assessment/classes/class.ilObjTest.php";
00212 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
00213 }
00214 else
00215 {
00216 include_once "./assessment/classes/class.ilObjQuestionPool.php";
00217 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
00218 }
00219 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
00220 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->getId());
00221 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getQuestion()), 1));
00222 }
00223 $this->saveToDb();
00224 }
00225 if ($tst_id > 0)
00226 {
00227 $q_1_id = $this->getId();
00228 $question_id = $this->duplicate(true);
00229 $tst_object->questions[$question_counter++] = $question_id;
00230 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
00231 }
00232 else
00233 {
00234 $import_mapping[$item->getIdent()] = array("pool" => $this->getId(), "test" => 0);
00235 }
00236
00237 }
00238
00248 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00249 {
00250 include_once("./classes/class.ilXmlWriter.php");
00251 $a_xml_writer = new ilXmlWriter;
00252
00253 $a_xml_writer->xmlHeader();
00254 $a_xml_writer->xmlStartTag("questestinterop");
00255 $attrs = array(
00256 "ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
00257 "title" => $this->getTitle()
00258 );
00259 $a_xml_writer->xmlStartTag("item", $attrs);
00260
00261 $a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
00262
00263 $workingtime = $this->getEstimatedWorkingTime();
00264 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
00265 $a_xml_writer->xmlElement("duration", NULL, $duration);
00266
00267 $a_xml_writer->xmlStartTag("itemmetadata");
00268 $a_xml_writer->xmlStartTag("qtimetadata");
00269 $a_xml_writer->xmlStartTag("qtimetadatafield");
00270 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
00271 $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
00272 $a_xml_writer->xmlEndTag("qtimetadatafield");
00273 $a_xml_writer->xmlStartTag("qtimetadatafield");
00274 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
00275 $a_xml_writer->xmlElement("fieldentry", NULL, TEXT_QUESTION_IDENTIFIER);
00276 $a_xml_writer->xmlEndTag("qtimetadatafield");
00277 $a_xml_writer->xmlStartTag("qtimetadatafield");
00278 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
00279 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
00280 $a_xml_writer->xmlEndTag("qtimetadatafield");
00281 $a_xml_writer->xmlStartTag("qtimetadatafield");
00282 $a_xml_writer->xmlElement("fieldlabel", NULL, "textrating");
00283 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getTextRating());
00284 $a_xml_writer->xmlEndTag("qtimetadatafield");
00285 $a_xml_writer->xmlStartTag("qtimetadatafield");
00286 $a_xml_writer->xmlElement("fieldlabel", NULL, "keywords");
00287 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getKeywords());
00288 $a_xml_writer->xmlEndTag("qtimetadatafield");
00289 $a_xml_writer->xmlEndTag("qtimetadata");
00290 $a_xml_writer->xmlEndTag("itemmetadata");
00291
00292
00293 $attrs = array(
00294 "label" => $this->getTitle()
00295 );
00296 $a_xml_writer->xmlStartTag("presentation", $attrs);
00297
00298 $a_xml_writer->xmlStartTag("flow");
00299
00300 $this->addQTIMaterial($a_xml_writer, $this->getQuestion());
00301
00302 $attrs = array(
00303 "ident" => "TEXT",
00304 "rcardinality" => "Ordered"
00305 );
00306 $a_xml_writer->xmlStartTag("response_str", $attrs);
00307 $attrs = array(
00308 "fibtype" => "String",
00309 "prompt" => "Box"
00310 );
00311 if ($this->getMaxNumOfChars() > 0)
00312 {
00313 $attrs["maxchars"] = $this->getMaxNumOfChars();
00314 }
00315 $a_xml_writer->xmlStartTag("render_fib", $attrs);
00316 $attrs = array(
00317 "ident" => "A"
00318 );
00319 $a_xml_writer->xmlStartTag("response_label", $attrs);
00320 $a_xml_writer->xmlEndTag("response_label");
00321 $a_xml_writer->xmlEndTag("render_fib");
00322
00323 $solution = $this->getSuggestedSolution(0);
00324 if (count($solution))
00325 {
00326 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00327 {
00328 $a_xml_writer->xmlStartTag("material");
00329 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00330 if (strcmp($matches[1], "") != 0)
00331 {
00332 $intlink = $solution["internal_link"];
00333 }
00334 $attrs = array(
00335 "label" => "suggested_solution"
00336 );
00337 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
00338 $a_xml_writer->xmlEndTag("material");
00339 }
00340 }
00341 $a_xml_writer->xmlEndTag("response_str");
00342 $a_xml_writer->xmlEndTag("flow");
00343 $a_xml_writer->xmlEndTag("presentation");
00344
00345
00346 $attrs = array(
00347 "scoremodel" => "HumanRater"
00348 );
00349 $a_xml_writer->xmlStartTag("resprocessing", $attrs);
00350 $a_xml_writer->xmlStartTag("outcomes");
00351 $attrs = array(
00352 "varname" => "WritingScore",
00353 "vartype" => "Integer",
00354 "minvalue" => "0",
00355 "maxvalue" => $this->getPoints()
00356 );
00357 $a_xml_writer->xmlStartTag("decvar", $attrs);
00358 $a_xml_writer->xmlEndTag("decvar");
00359 $a_xml_writer->xmlEndTag("outcomes");
00360
00361 $a_xml_writer->xmlStartTag("respcondition");
00362 $a_xml_writer->xmlStartTag("conditionvar");
00363 $a_xml_writer->xmlElement("other", NULL, "tutor_rated");
00364 $a_xml_writer->xmlEndTag("conditionvar");
00365 $a_xml_writer->xmlEndTag("respcondition");
00366 $a_xml_writer->xmlEndTag("resprocessing");
00367
00368 $a_xml_writer->xmlEndTag("item");
00369 $a_xml_writer->xmlEndTag("questestinterop");
00370
00371 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00372 if (!$a_include_header)
00373 {
00374 $pos = strpos($xml, "?>");
00375 $xml = substr($xml, $pos + 2);
00376 }
00377 return $xml;
00378 }
00379
00388 function saveToDb($original_id = "")
00389 {
00390 global $ilDB;
00391
00392 $complete = 0;
00393 if ($this->isComplete())
00394 {
00395 $complete = 1;
00396 }
00397 $estw_time = $this->getEstimatedWorkingTime();
00398 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00399
00400 if ($original_id)
00401 {
00402 $original_id = $ilDB->quote($original_id);
00403 }
00404 else
00405 {
00406 $original_id = "NULL";
00407 }
00408
00409
00410 include_once("./Services/RTE/classes/class.ilRTE.php");
00411 ilRTE::_cleanupMediaObjectUsage($this->question, "qpl:html",
00412 $this->getId());
00413
00414 if ($this->id == -1)
00415 {
00416
00417 $now = getdate();
00418 $question_type = $this->getQuestionType();
00419 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00420 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, points, question_text, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00421 $ilDB->quote($question_type),
00422 $ilDB->quote($this->obj_id),
00423 $ilDB->quote($this->title),
00424 $ilDB->quote($this->comment),
00425 $ilDB->quote($this->author),
00426 $ilDB->quote($this->owner),
00427 $ilDB->quote($this->getPoints() . ""),
00428 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00429 $ilDB->quote($estw_time),
00430 $ilDB->quote("$complete"),
00431 $ilDB->quote($created),
00432 $original_id
00433 );
00434 $result = $ilDB->query($query);
00435
00436 if ($result == DB_OK)
00437 {
00438 $this->id = $ilDB->getLastInsertId();
00439 $query = sprintf("INSERT INTO qpl_question_essay (question_fi, maxNumOfChars, keywords, textgap_rating) VALUES (%s, %s, %s, %s)",
00440 $ilDB->quote($this->id . ""),
00441 $ilDB->quote($this->getMaxNumOfChars()),
00442 $ilDB->quote($this->getKeywords() . ""),
00443 $ilDB->quote($this->getTextRating() . "")
00444 );
00445 $ilDB->query($query);
00446
00447
00448 $this->createPageObject();
00449
00450 if ($this->getTestId() > 0)
00451 {
00452 $this->insertIntoTest($this->getTestId());
00453 }
00454 }
00455 }
00456 else
00457 {
00458
00459 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, points = %s, question_text = %s, working_time=%s, complete = %s WHERE question_id = %s",
00460 $ilDB->quote($this->obj_id. ""),
00461 $ilDB->quote($this->title),
00462 $ilDB->quote($this->comment),
00463 $ilDB->quote($this->author),
00464 $ilDB->quote($this->getPoints() . ""),
00465 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00466 $ilDB->quote($estw_time),
00467 $ilDB->quote("$complete"),
00468 $ilDB->quote($this->id)
00469 );
00470 $result = $ilDB->query($query);
00471 $query = sprintf("UPDATE qpl_question_essay SET maxNumOfChars = %s, keywords = %s, textgap_rating = %s WHERE question_fi = %s",
00472 $ilDB->quote($this->getMaxNumOfChars()),
00473 $ilDB->quote($this->getKeywords() . ""),
00474 $ilDB->quote($this->getTextRating() . ""),
00475 $ilDB->quote($this->id . "")
00476 );
00477 $result = $ilDB->query($query);
00478 }
00479 parent::saveToDb($original_id);
00480 }
00481
00491 function loadFromDb($question_id)
00492 {
00493 global $ilDB;
00494
00495 $query = sprintf("SELECT qpl_questions.*, qpl_question_essay.* FROM qpl_questions, qpl_question_essay WHERE question_id = %s AND qpl_questions.question_id = qpl_question_essay.question_fi",
00496 $ilDB->quote($question_id)
00497 );
00498 $result = $ilDB->query($query);
00499 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00500 {
00501 if ($result->numRows() == 1)
00502 {
00503 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00504 $this->id = $question_id;
00505 $this->title = $data->title;
00506 $this->comment = $data->comment;
00507 $this->solution_hint = $data->solution_hint;
00508 $this->original_id = $data->original_id;
00509 $this->obj_id = $data->obj_fi;
00510 $this->author = $data->author;
00511 $this->owner = $data->owner;
00512 include_once("./Services/RTE/classes/class.ilRTE.php");
00513 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00514 $this->maxNumOfChars = $data->maxNumOfChars;
00515 $this->keywords = $data->keywords;
00516 $this->text_rating = $data->textgap_rating;
00517 $this->points = $data->points;
00518 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00519 }
00520 }
00521 parent::loadFromDb($question_id);
00522 }
00523
00531 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00532 {
00533 if ($this->id <= 0)
00534 {
00535
00536 return;
00537 }
00538
00539 $this_id = $this->getId();
00540 $clone = $this;
00541 include_once ("./assessment/classes/class.assQuestion.php");
00542 $original_id = assQuestion::_getOriginalId($this->id);
00543 $clone->id = -1;
00544 if ($title)
00545 {
00546 $clone->setTitle($title);
00547 }
00548
00549 if ($author)
00550 {
00551 $clone->setAuthor($author);
00552 }
00553 if ($owner)
00554 {
00555 $clone->setOwner($owner);
00556 }
00557
00558 if ($for_test)
00559 {
00560 $clone->saveToDb($original_id);
00561 }
00562 else
00563 {
00564 $clone->saveToDb();
00565 }
00566
00567
00568 $clone->copyPageOfQuestion($this_id);
00569
00570 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00571
00572 return $clone->id;
00573 }
00574
00582 function copyObject($target_questionpool, $title = "")
00583 {
00584 if ($this->id <= 0)
00585 {
00586
00587 return;
00588 }
00589
00590 $clone = $this;
00591 include_once ("./assessment/classes/class.assQuestion.php");
00592 $original_id = assQuestion::_getOriginalId($this->id);
00593 $clone->id = -1;
00594 $source_questionpool = $this->getObjId();
00595 $clone->setObjId($target_questionpool);
00596 if ($title)
00597 {
00598 $clone->setTitle($title);
00599 }
00600 $clone->saveToDb();
00601
00602
00603 $clone->copyPageOfQuestion($original_id);
00604
00605 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00606
00607 return $clone->id;
00608 }
00609
00619 function getQuestion()
00620 {
00621 return $this->question;
00622 }
00623
00633 function setQuestion($question = "")
00634 {
00635 $this->question = $question;
00636 }
00637
00647 function getMaxNumOfChars()
00648 {
00649 if (strcmp($this->maxNumOfChars, "") == 0)
00650 {
00651 return 0;
00652 }
00653 else
00654 {
00655 return $this->maxNumOfChars;
00656 }
00657 }
00658
00668 function setMaxNumOfChars($maxchars = 0)
00669 {
00670 $this->maxNumOfChars = $maxchars;
00671 }
00672
00681 function getMaximumPoints()
00682 {
00683 return $this->points;
00684 }
00685
00697 function setReachedPoints($active_id, $points, $pass = NULL)
00698 {
00699 global $ilDB;
00700
00701 if (($points > 0) && ($points <= $this->getPoints()))
00702 {
00703 if (is_null($pass))
00704 {
00705 $pass = $this->getSolutionMaxPass($active_id);
00706 }
00707 $query = sprintf("UPDATE tst_test_result SET points = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00708 $ilDB->quote($points . ""),
00709 $ilDB->quote($active_id . ""),
00710 $ilDB->quote($this->getId() . ""),
00711 $ilDB->quote($pass . "")
00712 );
00713 $result = $ilDB->query($query);
00714 return true;
00715 }
00716 else
00717 {
00718 return false;
00719 }
00720 }
00721
00734 function _setReachedPoints($active_id, $question_id, $points, $maxpoints, $pass = NULL)
00735 {
00736 global $ilDB;
00737
00738 if ($points <= $maxpoints)
00739 {
00740 if (is_null($pass))
00741 {
00742 include_once "./assessment/classes/class.assQuestion.php";
00743 $pass = assQuestion::_getSolutionMaxPass($question_id, $active_id);
00744 }
00745 $query = sprintf("UPDATE tst_test_result SET points = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00746 $ilDB->quote($points . ""),
00747 $ilDB->quote($active_id . ""),
00748 $ilDB->quote($question_id . ""),
00749 $ilDB->quote($pass . "")
00750 );
00751 $result = $ilDB->query($query);
00752
00753
00754 include_once "./assessment/classes/class.ilObjTest.php";
00755 include_once './course/classes/class.ilCourseObjectiveResult.php';
00756 ilCourseObjectiveResult::_updateObjectiveResult(ilObjTest::_getUserIdFromActiveId($active_id),$question_id,$points);
00757
00758 return true;
00759 }
00760 else
00761 {
00762 return false;
00763 }
00764 }
00765
00776 function isKeywordMatching($answertext, $a_keyword)
00777 {
00778 $result = FALSE;
00779 $textrating = $this->getTextRating();
00780 include_once "./classes/class.ilStr.php";
00781 switch ($textrating)
00782 {
00783 case TEXTGAP_RATING_CASEINSENSITIVE:
00784 if (ilStr::strPos(ilStr::strToLower($answertext), ilStr::strToLower($a_keyword)) !== false) return TRUE;
00785 break;
00786 case TEXTGAP_RATING_CASESENSITIVE:
00787 if (ilStr::strPos(utf8_decode($answertext), $a_keyword) !== false) return TRUE;
00788 break;
00789 }
00790 $answerwords = array();
00791 if (preg_match_all("/([^\s.]+)/", $answertext, $matches))
00792 {
00793 foreach ($matches[1] as $answerword)
00794 {
00795 array_push($answerwords, trim($answerword));
00796 }
00797 }
00798 foreach ($answerwords as $a_original)
00799 {
00800 switch ($textrating)
00801 {
00802 case TEXTGAP_RATING_LEVENSHTEIN1:
00803 if (levenshtein(utf8_decode($a_original), utf8_decode($a_keyword)) <= 1) return TRUE;
00804 break;
00805 case TEXTGAP_RATING_LEVENSHTEIN2:
00806 if (levenshtein(utf8_decode($a_original), utf8_decode($a_keyword)) <= 2) return TRUE;
00807 break;
00808 case TEXTGAP_RATING_LEVENSHTEIN3:
00809 if (levenshtein(utf8_decode($a_original), utf8_decode($a_keyword)) <= 3) return TRUE;
00810 break;
00811 case TEXTGAP_RATING_LEVENSHTEIN4:
00812 if (levenshtein(utf8_decode($a_original), utf8_decode($a_keyword)) <= 4) return TRUE;
00813 break;
00814 case TEXTGAP_RATING_LEVENSHTEIN5:
00815 if (levenshtein(utf8_decode($a_original), utf8_decode($a_keyword)) <= 5) return TRUE;
00816 break;
00817 }
00818 }
00819 return $result;
00820 }
00821
00833 function calculateReachedPoints($active_id, $pass = NULL)
00834 {
00835 global $ilDB;
00836
00837 $points = 0;
00838 if (is_null($pass))
00839 {
00840 $pass = $this->getSolutionMaxPass($active_id);
00841 }
00842 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00843 $ilDB->quote($active_id . ""),
00844 $ilDB->quote($this->getId() . ""),
00845 $ilDB->quote($pass . "")
00846 );
00847 $result = $ilDB->query($query);
00848 if ($result->numRows() == 1)
00849 {
00850 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00851 if ($row["points"])
00852 {
00853 $points = $row["points"];
00854 }
00855 else
00856 {
00857 $keywords =& $this->getKeywordList();
00858 if (count($keywords))
00859 {
00860 $foundkeyword = false;
00861 foreach ($keywords as $keyword)
00862 {
00863 if (!$foundkeyword)
00864 {
00865 if ($this->isKeywordMatching($row["value1"], $keyword))
00866 {
00867 $foundkeyword = true;
00868 }
00869 }
00870 }
00871 if ($foundkeyword) $points = $this->getMaximumPoints();
00872 }
00873 }
00874 }
00875
00876 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
00877 return $points;
00878 }
00879
00890 function saveWorkingData($active_id, $pass = NULL)
00891 {
00892 global $ilDB;
00893 global $ilUser;
00894
00895 include_once "./assessment/classes/class.ilObjTest.php";
00896 $activepass = ilObjTest::_getPass($active_id);
00897
00898 $query = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
00899 $ilDB->quote($active_id . ""),
00900 $ilDB->quote($this->getId() . ""),
00901 $ilDB->quote($activepass . "")
00902 );
00903 $result = $ilDB->query($query);
00904
00905 $text = ilUtil::stripSlashes($_POST["TEXT"], FALSE);
00906 if ($this->getMaxNumOfChars())
00907 {
00908 include_once "./classes/class.ilStr.php";
00909 $text = ilStr::subStr($text, 0, $this->getMaxNumOfChars());
00910 }
00911 $entered_values = 0;
00912 if (strlen($text))
00913 {
00914 $query = sprintf("INSERT INTO tst_solutions (solution_id, active_fi, question_fi, value1, value2, pass, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, %s, NULL)",
00915 $ilDB->quote($active_id . ""),
00916 $ilDB->quote($this->getId() . ""),
00917 $ilDB->quote(trim($text) . ""),
00918 $ilDB->quote($activepass . "")
00919 );
00920 $result = $ilDB->query($query);
00921 $entered_values++;
00922 }
00923 if ($entered_values)
00924 {
00925 include_once ("./classes/class.ilObjAssessmentFolder.php");
00926 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00927 {
00928 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00929 }
00930 }
00931 else
00932 {
00933 include_once ("./classes/class.ilObjAssessmentFolder.php");
00934 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00935 {
00936 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
00937 }
00938 }
00939 parent::saveWorkingData($active_id, $pass);
00940 return true;
00941 }
00942
00943 function syncWithOriginal()
00944 {
00945 global $ilDB;
00946
00947 if ($this->original_id)
00948 {
00949 $complete = 0;
00950 if ($this->isComplete())
00951 {
00952 $complete = 1;
00953 }
00954 $estw_time = $this->getEstimatedWorkingTime();
00955 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00956
00957 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time=%s, complete = %s WHERE question_id = %s",
00958 $ilDB->quote($this->obj_id. ""),
00959 $ilDB->quote($this->title. ""),
00960 $ilDB->quote($this->comment. ""),
00961 $ilDB->quote($this->author. ""),
00962 $ilDB->quote($this->question. ""),
00963 $ilDB->quote($estw_time. ""),
00964 $ilDB->quote($complete. ""),
00965 $ilDB->quote($this->original_id. "")
00966 );
00967 $result = $ilDB->query($query);
00968 $query = sprintf("UPDATE qpl_question_essay SET maxNumOfChars = %s, keywords = %s, textgap_rating = %s WHERE question_fi = %s",
00969 $ilDB->quote($this->maxNumOfChars. ""),
00970 $ilDB->quote($this->getKeywords() . ""),
00971 $ilDB->quote($this->getTextRating() . ""),
00972 $ilDB->quote($this->original_id . "")
00973 );
00974 $result = $ilDB->query($query);
00975
00976 parent::syncWithOriginal();
00977 }
00978 }
00979
00980 function createRandomSolution($test_id, $user_id)
00981 {
00982 }
00983
00992 function getQuestionType()
00993 {
00994 return 8;
00995 }
00996
01005 function getKeywords()
01006 {
01007 return $this->keywords;
01008 }
01009
01018 function setKeywords($a_keywords)
01019 {
01020 $this->keywords = $a_keywords;
01021 }
01022
01031 function &getKeywordList()
01032 {
01033 $keywords = array();
01034 if (preg_match_all("/([^\s]+)/", $this->keywords, $matches))
01035 {
01036 foreach ($matches[1] as $keyword)
01037 {
01038 array_push($keywords, trim($keyword));
01039 }
01040 }
01041 return $keywords;
01042 }
01043
01053 function getTextRating()
01054 {
01055 return $this->text_rating;
01056 }
01057
01067 function setTextRating($a_text_rating)
01068 {
01069 switch ($a_text_rating)
01070 {
01071 case TEXTGAP_RATING_CASEINSENSITIVE:
01072 case TEXTGAP_RATING_CASESENSITIVE:
01073 case TEXTGAP_RATING_LEVENSHTEIN1:
01074 case TEXTGAP_RATING_LEVENSHTEIN2:
01075 case TEXTGAP_RATING_LEVENSHTEIN3:
01076 case TEXTGAP_RATING_LEVENSHTEIN4:
01077 case TEXTGAP_RATING_LEVENSHTEIN5:
01078 $this->text_rating = $a_text_rating;
01079 break;
01080 default:
01081 $this->text_rating = TEXTGAP_RATING_CASEINSENSITIVE;
01082 break;
01083 }
01084 }
01085
01094 function getAdditionalTableName()
01095 {
01096 return "qpl_question_essay";
01097 }
01098
01099 }
01100
01101 ?>