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 ASS_TextQuestion extends ASS_Question
00037 {
00045 var $question;
00046
00054 var $maxNumOfChars;
00055
00069 function ASS_TextQuestion(
00070 $title = "",
00071 $comment = "",
00072 $author = "",
00073 $owner = -1,
00074 $question = ""
00075 )
00076 {
00077 $this->ASS_Question($title, $comment, $author, $owner);
00078 $this->question = $question;
00079 $this->maxNumOfChars = 0;
00080 $this->points = 0;
00081 }
00082
00091 function isComplete()
00092 {
00093 if (($this->title) and ($this->author) and ($this->question) and ($this->getMaximumPoints() > 0))
00094 {
00095 return true;
00096 }
00097 else
00098 {
00099 return false;
00100 }
00101 }
00102
00112 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00113 {
00114 include_once("./classes/class.ilXmlWriter.php");
00115 $a_xml_writer = new ilXmlWriter;
00116
00117 $a_xml_writer->xmlHeader();
00118 $a_xml_writer->xmlStartTag("questestinterop");
00119 $attrs = array(
00120 "ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
00121 "title" => $this->getTitle()
00122 );
00123 $a_xml_writer->xmlStartTag("item", $attrs);
00124
00125 $a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
00126
00127 $workingtime = $this->getEstimatedWorkingTime();
00128 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
00129 $a_xml_writer->xmlElement("duration", NULL, $duration);
00130
00131 $a_xml_writer->xmlStartTag("itemmetadata");
00132 $a_xml_writer->xmlStartTag("qtimetadata");
00133 $a_xml_writer->xmlStartTag("qtimetadatafield");
00134 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
00135 $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
00136 $a_xml_writer->xmlEndTag("qtimetadatafield");
00137 $a_xml_writer->xmlStartTag("qtimetadatafield");
00138 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
00139 $a_xml_writer->xmlElement("fieldentry", NULL, TEXT_QUESTION_IDENTIFIER);
00140 $a_xml_writer->xmlEndTag("qtimetadatafield");
00141 $a_xml_writer->xmlStartTag("qtimetadatafield");
00142 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
00143 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
00144 $a_xml_writer->xmlEndTag("qtimetadatafield");
00145 $a_xml_writer->xmlEndTag("qtimetadata");
00146 $a_xml_writer->xmlEndTag("itemmetadata");
00147
00148
00149 $attrs = array(
00150 "label" => $this->getTitle()
00151 );
00152 $a_xml_writer->xmlStartTag("presentation", $attrs);
00153
00154 $a_xml_writer->xmlStartTag("flow");
00155
00156 $a_xml_writer->xmlStartTag("material");
00157 $a_xml_writer->xmlElement("mattext", NULL, $this->get_question());
00158 $a_xml_writer->xmlEndTag("material");
00159
00160 $attrs = array(
00161 "ident" => "TEXT",
00162 "rcardinality" => "Ordered"
00163 );
00164 $a_xml_writer->xmlStartTag("response_str", $attrs);
00165 $attrs = array(
00166 "fibtype" => "String",
00167 "prompt" => "Box"
00168 );
00169 if ($this->getMaxNumOfChars() > 0)
00170 {
00171 $attrs["maxchars"] = $this->getMaxNumOfChars();
00172 }
00173 $a_xml_writer->xmlStartTag("render_fib", $attrs);
00174 $attrs = array(
00175 "ident" => "A"
00176 );
00177 $a_xml_writer->xmlStartTag("response_label", $attrs);
00178 $a_xml_writer->xmlEndTag("response_label");
00179 $a_xml_writer->xmlEndTag("render_fib");
00180
00181 $solution = $this->getSuggestedSolution(0);
00182 if (count($solution))
00183 {
00184 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00185 {
00186 $a_xml_writer->xmlStartTag("material");
00187 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00188 if (strcmp($matches[1], "") != 0)
00189 {
00190 $intlink = $solution["internal_link"];
00191 }
00192 $attrs = array(
00193 "label" => "suggested_solution"
00194 );
00195 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
00196 $a_xml_writer->xmlEndTag("material");
00197 }
00198 }
00199 $a_xml_writer->xmlEndTag("response_str");
00200 $a_xml_writer->xmlEndTag("flow");
00201 $a_xml_writer->xmlEndTag("presentation");
00202
00203
00204 $attrs = array(
00205 "scoremodel" => "HumanRater"
00206 );
00207 $a_xml_writer->xmlStartTag("resprocessing", $attrs);
00208 $a_xml_writer->xmlStartTag("outcomes");
00209 $attrs = array(
00210 "varname" => "WritingScore",
00211 "vartype" => "Integer",
00212 "minvalue" => "0",
00213 "maxvalue" => $this->getPoints()
00214 );
00215 $a_xml_writer->xmlStartTag("decvar", $attrs);
00216 $a_xml_writer->xmlEndTag("decvar");
00217 $a_xml_writer->xmlEndTag("outcomes");
00218
00219 $a_xml_writer->xmlStartTag("respcondition");
00220 $a_xml_writer->xmlStartTag("conditionvar");
00221 $a_xml_writer->xmlElement("other", NULL, "tutor_rated");
00222 $a_xml_writer->xmlEndTag("conditionvar");
00223 $a_xml_writer->xmlEndTag("respcondition");
00224 $a_xml_writer->xmlEndTag("resprocessing");
00225
00226 $a_xml_writer->xmlEndTag("item");
00227 $a_xml_writer->xmlEndTag("questestinterop");
00228
00229 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00230 if (!$a_include_header)
00231 {
00232 $pos = strpos($xml, "?>");
00233 $xml = substr($xml, $pos + 2);
00234 }
00235 return $xml;
00236 }
00237
00246 function saveToDb($original_id = "")
00247 {
00248 global $ilias;
00249
00250 $complete = 0;
00251 if ($this->isComplete())
00252 {
00253 $complete = 1;
00254 }
00255 $db = & $ilias->db;
00256
00257 $estw_time = $this->getEstimatedWorkingTime();
00258 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00259
00260 if ($original_id)
00261 {
00262 $original_id = $db->quote($original_id);
00263 }
00264 else
00265 {
00266 $original_id = "NULL";
00267 }
00268
00269 if ($this->id == -1)
00270 {
00271
00272 $now = getdate();
00273 $question_type = $this->getQuestionType();
00274 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00275 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, points, question_text, working_time, maxNumOfChars, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00276 $db->quote($question_type),
00277 $db->quote($this->obj_id),
00278 $db->quote($this->title),
00279 $db->quote($this->comment),
00280 $db->quote($this->author),
00281 $db->quote($this->owner),
00282 $db->quote($this->getPoints() . ""),
00283 $db->quote($this->question),
00284 $db->quote($estw_time),
00285 $db->quote($this->getMaxNumOfChars()),
00286 $db->quote("$complete"),
00287 $db->quote($created),
00288 $original_id
00289 );
00290 $result = $db->query($query);
00291
00292 if ($result == DB_OK)
00293 {
00294 $this->id = $this->ilias->db->getLastInsertId();
00295
00296
00297 $this->createPageObject();
00298
00299
00300 if ($this->getTestId() > 0)
00301 {
00302 $this->insertIntoTest($this->getTestId());
00303 }
00304 }
00305 }
00306 else
00307 {
00308
00309 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, points = %s, question_text = %s, working_time=%s, maxNumOfChars = %s, complete = %s WHERE question_id = %s",
00310 $db->quote($this->obj_id. ""),
00311 $db->quote($this->title),
00312 $db->quote($this->comment),
00313 $db->quote($this->author),
00314 $db->quote($this->getPoints() . ""),
00315 $db->quote($this->question),
00316 $db->quote($estw_time),
00317 $db->quote($this->getMaxNumOfChars()),
00318 $db->quote("$complete"),
00319 $db->quote($this->id)
00320 );
00321 $result = $db->query($query);
00322 }
00323 parent::saveToDb($original_id);
00324 }
00325
00335 function loadFromDb($question_id)
00336 {
00337 global $ilias;
00338
00339 $db = & $ilias->db;
00340 $query = sprintf("SELECT * FROM qpl_questions WHERE question_id = %s",
00341 $db->quote($question_id));
00342 $result = $db->query($query);
00343 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00344 {
00345 if ($result->numRows() == 1)
00346 {
00347 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00348 $this->id = $question_id;
00349 $this->title = $data->title;
00350 $this->comment = $data->comment;
00351 $this->solution_hint = $data->solution_hint;
00352 $this->original_id = $data->original_id;
00353 $this->obj_id = $data->obj_fi;
00354 $this->author = $data->author;
00355 $this->owner = $data->owner;
00356 $this->question = $data->question_text;
00357 $this->maxNumOfChars = $data->maxNumOfChars;
00358 $this->points = $data->points;
00359 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00360 }
00361 }
00362 parent::loadFromDb($question_id);
00363 }
00364
00372 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00373 {
00374 if ($this->id <= 0)
00375 {
00376
00377 return;
00378 }
00379
00380 $this_id = $this->getId();
00381 $clone = $this;
00382 include_once ("./assessment/classes/class.assQuestion.php");
00383 $original_id = ASS_Question::_getOriginalId($this->id);
00384 $clone->id = -1;
00385 if ($title)
00386 {
00387 $clone->setTitle($title);
00388 }
00389
00390 if ($author)
00391 {
00392 $clone->setAuthor($author);
00393 }
00394 if ($owner)
00395 {
00396 $clone->setOwner($owner);
00397 }
00398
00399 if ($for_test)
00400 {
00401 $clone->saveToDb($original_id);
00402 }
00403 else
00404 {
00405 $clone->saveToDb();
00406 }
00407
00408
00409 $clone->copyPageOfQuestion($this_id);
00410
00411 return $clone->id;
00412 }
00413
00421 function copyObject($target_questionpool, $title = "")
00422 {
00423 if ($this->id <= 0)
00424 {
00425
00426 return;
00427 }
00428
00429 $clone = $this;
00430 include_once ("./assessment/classes/class.assQuestion.php");
00431 $original_id = ASS_Question::_getOriginalId($this->id);
00432 $clone->id = -1;
00433 $source_questionpool = $this->getObjId();
00434 $clone->setObjId($target_questionpool);
00435 if ($title)
00436 {
00437 $clone->setTitle($title);
00438 }
00439 $clone->saveToDb();
00440
00441
00442 $clone->copyPageOfQuestion($original_id);
00443
00444 return $clone->id;
00445 }
00446
00456 function get_question()
00457 {
00458 return $this->question;
00459 }
00460
00470 function set_question($question = "")
00471 {
00472 $this->question = $question;
00473 }
00474
00484 function getMaxNumOfChars()
00485 {
00486 if (strcmp($this->maxNumOfChars, "") == 0)
00487 {
00488 return 0;
00489 }
00490 else
00491 {
00492 return $this->maxNumOfChars;
00493 }
00494 }
00495
00505 function setMaxNumOfChars($maxchars = 0)
00506 {
00507 $this->maxNumOfChars = $maxchars;
00508 }
00509
00518 function getMaximumPoints()
00519 {
00520 return $this->points;
00521 }
00522
00534 function setReachedPoints($user_id, $test_id, $points, $pass = NULL)
00535 {
00536 if (($points > 0) && ($points <= $this->getPoints()))
00537 {
00538 if (is_null($pass))
00539 {
00540 $pass = $this->getSolutionMaxPass($user_id, $test_id);
00541 }
00542 $query = sprintf("UPDATE tst_test_result SET points = %s WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
00543 $this->ilias->db->quote($points . ""),
00544 $this->ilias->db->quote($user_id . ""),
00545 $this->ilias->db->quote($test_id . ""),
00546 $this->ilias->db->quote($this->getId() . ""),
00547 $this->ilias->db->quote($pass . "")
00548 );
00549 $result = $this->ilias->db->query($query);
00550 return true;
00551 }
00552 else
00553 {
00554 return false;
00555 }
00556 }
00557
00570 function _setReachedPoints($user_id, $test_id, $question_id, $points, $maxpoints, $pass = NULL)
00571 {
00572 global $ilDB;
00573
00574 if ($points <= $maxpoints)
00575 {
00576 if (is_null($pass))
00577 {
00578 include_once "./assessment/classes/class.assQuestion.php";
00579 $pass = ASS_Question::_getSolutionMaxPass($question_id, $user_id, $test_id);
00580 }
00581 $query = sprintf("UPDATE tst_test_result SET points = %s WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
00582 $ilDB->quote($points . ""),
00583 $ilDB->quote($user_id . ""),
00584 $ilDB->quote($test_id . ""),
00585 $ilDB->quote($question_id . ""),
00586 $ilDB->quote($pass . "")
00587 );
00588 $result = $this->ilias->db->query($query);
00589
00590
00591 include_once 'course/classes/class.ilCourseObjectiveResult.php';
00592 ilCourseObjectiveResult::_updateUserResult($user_id,$question_id,$points);
00593
00594 return true;
00595 }
00596 else
00597 {
00598 return false;
00599 }
00600 }
00601
00613 function calculateReachedPoints($user_id, $test_id, $pass = NULL)
00614 {
00615 global $ilDB;
00616
00617 $points = 0;
00618 if (is_null($pass))
00619 {
00620 $pass = $this->getSolutionMaxPass($user_id, $test_id);
00621 }
00622 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
00623 $this->ilias->db->quote($user_id . ""),
00624 $this->ilias->db->quote($test_id . ""),
00625 $this->ilias->db->quote($this->getId() . ""),
00626 $this->ilias->db->quote($pass . "")
00627 );
00628 $result = $this->ilias->db->query($query);
00629 if ($result->numRows() == 1)
00630 {
00631 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00632 if ($row["points"])
00633 {
00634 $points = $row["points"];
00635 }
00636 }
00637
00638
00639 $query = sprintf("SELECT * FROM tst_tests WHERE test_id = %s",
00640 $ilDB->quote($test_id)
00641 );
00642 $result = $ilDB->query($query);
00643 if ($result->numRows() == 1)
00644 {
00645 $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
00646 if ($row["count_system"] == 1)
00647 {
00648 if ($points != $this->getMaximumPoints())
00649 {
00650 $points = 0;
00651 }
00652 }
00653 }
00654 else
00655 {
00656 $points = 0;
00657 }
00658 return $points;
00659 }
00660
00670 function getReachedInformation($user_id, $test_id, $pass = NULL)
00671 {
00672 $found_values = array();
00673 $query = sprintf("SELECT * FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
00674 $this->ilias->db->quote($user_id . ""),
00675 $this->ilias->db->quote($test_id . ""),
00676 $this->ilias->db->quote($this->getId() . ""),
00677 $this->ilias->db->quote($pass . "")
00678 );
00679 $result = $this->ilias->db->query($query);
00680 $user_result = array();
00681 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
00682 {
00683 $user_result = array(
00684 "value" => $data->value1
00685 );
00686 }
00687 return $user_result;
00688 }
00689
00700 function saveWorkingData($test_id, $pass = NULL)
00701 {
00702 global $ilDB;
00703 global $ilUser;
00704
00705 $db =& $ilDB->db;
00706
00707 include_once "./assessment/classes/class.ilObjTest.php";
00708 $activepass = ilObjTest::_getPass($ilUser->id, $test_id);
00709
00710 $query = sprintf("DELETE FROM tst_solutions WHERE user_fi = %s AND test_fi = %s AND question_fi = %s AND pass = %s",
00711 $db->quote($ilUser->id . ""),
00712 $db->quote($test_id . ""),
00713 $db->quote($this->getId() . ""),
00714 $db->quote($activepass . "")
00715 );
00716 $result = $db->query($query);
00717
00718 $text = ilUtil::stripSlashes($_POST["TEXT"]);
00719 if ($this->getMaxNumOfChars())
00720 {
00721 $text = substr($text, 0, $this->getMaxNumOfChars());
00722 }
00723 $entered_values = 0;
00724 if (strlen($text))
00725 {
00726 $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)",
00727 $db->quote($ilUser->id . ""),
00728 $db->quote($test_id . ""),
00729 $db->quote($this->getId() . ""),
00730 $db->quote($text . ""),
00731 $db->quote($activepass . "")
00732 );
00733 $result = $db->query($query);
00734 $entered_values++;
00735 }
00736 if ($entered_values)
00737 {
00738 include_once ("./classes/class.ilObjAssessmentFolder.php");
00739 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00740 {
00741 $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $test_id, $this->getId());
00742 }
00743 }
00744 else
00745 {
00746 include_once ("./classes/class.ilObjAssessmentFolder.php");
00747 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00748 {
00749 $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $test_id, $this->getId());
00750 }
00751 }
00752 parent::saveWorkingData($test_id, $pass);
00753 return true;
00754 }
00755
00756 function syncWithOriginal()
00757 {
00758 global $ilias;
00759 if ($this->original_id)
00760 {
00761 $complete = 0;
00762 if ($this->isComplete())
00763 {
00764 $complete = 1;
00765 }
00766 $db = & $ilias->db;
00767
00768 $estw_time = $this->getEstimatedWorkingTime();
00769 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00770
00771 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, working_time=%s, maxNumOfChars = %s, complete = %s WHERE question_id = %s",
00772 $db->quote($this->obj_id. ""),
00773 $db->quote($this->title. ""),
00774 $db->quote($this->comment. ""),
00775 $db->quote($this->author. ""),
00776 $db->quote($this->question. ""),
00777 $db->quote($estw_time. ""),
00778 $db->quote($this->maxNumOfChars. ""),
00779 $db->quote($complete. ""),
00780 $db->quote($this->original_id. "")
00781 );
00782 $result = $db->query($query);
00783
00784 parent::syncWithOriginal();
00785 }
00786 }
00787
00788 function createRandomSolution($test_id, $user_id)
00789 {
00790 }
00791
00800 function getQuestionType()
00801 {
00802 return 8;
00803 }
00804 }
00805
00806 ?>