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.assQuestionGUI.php";
00025
00037 class assClozeTestGUI extends assQuestionGUI
00038 {
00047 function assClozeTestGUI(
00048 $id = -1
00049 )
00050 {
00051 $this->assQuestionGUI();
00052 include_once "./assessment/classes/class.assClozeTest.php";
00053 $this->object = new assClozeTest();
00054 if ($id >= 0)
00055 {
00056 $this->object->loadFromDb($id);
00057 }
00058 }
00059
00068 function getQuestionType()
00069 {
00070 return "assClozeTest";
00071 }
00072
00073
00074 function getCommand($cmd)
00075 {
00076 if (substr($cmd, 0, 6) == "delete")
00077 {
00078 $cmd = "delete";
00079 }
00080 if (substr($cmd, 0, 10) == "addTextGap")
00081 {
00082 $cmd = "addTextGap";
00083 }
00084 if (substr($cmd, 0, 12) == "addSelectGap")
00085 {
00086 $cmd = "addSelectGap";
00087 }
00088 if (substr($cmd, 0, 20) == "addSuggestedSolution")
00089 {
00090 $cmd = "addSuggestedSolution";
00091 }
00092 if (substr($cmd, 0, 23) == "removeSuggestedSolution")
00093 {
00094 $cmd = "removeSuggestedSolution";
00095 }
00096
00097 return $cmd;
00098 }
00099
00100
00108 function editQuestion()
00109 {
00110 include_once "./assessment/classes/class.assQuestion.php";
00111 $internallinks = array(
00112 "lm" => $this->lng->txt("obj_lm"),
00113 "st" => $this->lng->txt("obj_st"),
00114 "pg" => $this->lng->txt("obj_pg"),
00115 "glo" => $this->lng->txt("glossary_term")
00116 );
00117
00118 $this->getQuestionTemplate();
00119 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_cloze_question.html", true);
00120 for ($i = 0; $i < $this->object->getGapCount(); $i++)
00121 {
00122 $gap = $this->object->getGap($i);
00123 if ($gap[0]->getClozeType() == CLOZE_TEXT)
00124 {
00125 $this->tpl->setCurrentBlock("textgap_value");
00126 foreach ($gap as $key => $value)
00127 {
00128 $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value"));
00129 $this->tpl->setVariable("VALUE_TEXT_GAP", ilUtil::prepareFormOutput($value->getAnswertext()));
00130 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key");
00131 $this->tpl->setVariable("VALUE_GAP", $i);
00132 $this->tpl->setVariable("VALUE_INDEX", $key);
00133 $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key);
00134 $this->tpl->setVariable("VALUE_GAP", $i);
00135 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00136 $this->tpl->setVariable("VALUE_TEXT_GAP_POINTS", $value->getPoints());
00137 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00138 $this->tpl->parseCurrentBlock();
00139 }
00140
00141 foreach ($internallinks as $key => $value)
00142 {
00143 $this->tpl->setCurrentBlock("textgap_internallink");
00144 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00145 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00146 $this->tpl->parseCurrentBlock();
00147 }
00148
00149 $this->tpl->setCurrentBlock("textgap_suggested_solution");
00150 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00151 if (array_key_exists($i, $this->object->suggested_solutions))
00152 {
00153 $solution_array = $this->object->getSuggestedSolution($i);
00154 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00155 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00156 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00157 $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i);
00158 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00159 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00160 }
00161 else
00162 {
00163 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00164 }
00165 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00166 $this->tpl->parseCurrentBlock();
00167 $this->tpl->setCurrentBlock("textgap");
00168 $this->tpl->setVariable("ADD_TEXT_GAP", $this->lng->txt("add_gap"));
00169 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i");
00170 $this->tpl->parseCurrentBlock();
00171 }
00172 elseif ($gap[0]->getClozeType() == CLOZE_SELECT)
00173 {
00174 $this->tpl->setCurrentBlock("selectgap_value");
00175 foreach ($gap as $key => $value)
00176 {
00177 $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value"));
00178 $this->tpl->setVariable("VALUE_SELECT_GAP", ilUtil::prepareFormOutput($value->getAnswertext()));
00179 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key");
00180 $this->tpl->setVariable("VALUE_GAP", $i);
00181 $this->tpl->setVariable("VALUE_INDEX", $key);
00182 $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key);
00183 $this->tpl->setVariable("VALUE_GAP", $i);
00184 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00185 $this->tpl->setVariable("VALUE_SELECT_GAP_POINTS", $value->getPoints());
00186 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00187 $this->tpl->parseCurrentBlock();
00188 }
00189
00190 foreach ($internallinks as $key => $value)
00191 {
00192 $this->tpl->setCurrentBlock("selectgap_internallink");
00193 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00194 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00195 $this->tpl->parseCurrentBlock();
00196 }
00197
00198 $this->tpl->setCurrentBlock("selectgap_suggested_solution");
00199 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00200 if (array_key_exists($i, $this->object->suggested_solutions))
00201 {
00202 $solution_array = $this->object->getSuggestedSolution($i);
00203 $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00204 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00205 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00206 $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i);
00207 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00208 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00209 }
00210 else
00211 {
00212 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00213 }
00214 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00215 $this->tpl->parseCurrentBlock();
00216 $this->tpl->setCurrentBlock("selectgap");
00217 $this->tpl->setVariable("ADD_SELECT_GAP", $this->lng->txt("add_gap"));
00218 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00219 $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i");
00220 if ($gap[0]->getShuffle())
00221 {
00222 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00223 }
00224 else
00225 {
00226 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00227 }
00228 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00229 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00230 $this->tpl->parseCurrentBlock();
00231 }
00232 $this->tpl->setCurrentBlock("answer_row");
00233 $name = $gap[0]->getName();
00234 if (!$name)
00235 {
00236 $name = $this->lng->txt("gap") . " " . ($i+1);
00237 }
00238 $this->tpl->setVariable("TEXT_GAP_NAME", $name);
00239 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00240 if ($gap[0]->getClozeType() == CLOZE_SELECT)
00241 {
00242 $this->tpl->setVariable("SELECTED_SELECT_GAP", " selected=\"selected\"");
00243 }
00244 else
00245 {
00246 $this->tpl->setVariable("SELECTED_TEXT_GAP", " selected=\"selected\"");
00247 }
00248 $this->tpl->setVariable("TEXT_TEXT_GAP", $this->lng->txt("text_gap"));
00249 $this->tpl->setVariable("TEXT_SELECT_GAP", $this->lng->txt("select_gap"));
00250 $this->tpl->setVariable("VALUE_GAP_COUNTER", $i);
00251 $this->tpl->parseCurrentBlock();
00252 }
00253
00254
00255 $this->outOtherQuestionData();
00256
00257 $this->tpl->setCurrentBlock("HeadContent");
00258 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00259 if (preg_match("/addTextGap_(\d+)/", $this->ctrl->getCmd(), $matches))
00260 {
00261 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.textgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".focus(); document.frm_cloze_test.textgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".scrollIntoView(\"true\");"));
00262 }
00263 else if (preg_match("/addSelectGap_(\d+)/", $this->ctrl->getCmd(), $matches))
00264 {
00265 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.selectgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".focus(); document.frm_cloze_test.selectgap_" . $matches[1] . "_" .(count($this->object->gaps[$matches[1]]) - 1).".scrollIntoView(\"true\");"));
00266 }
00267 else
00268 {
00269 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.title.focus();"));
00270 }
00271 $this->tpl->parseCurrentBlock();
00272
00273
00274 $textgap_options = array(
00275 array("ci", $this->lng->txt("cloze_textgap_case_insensitive")),
00276 array("cs", $this->lng->txt("cloze_textgap_case_sensitive")),
00277 array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")),
00278 array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")),
00279 array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")),
00280 array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")),
00281 array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5"))
00282 );
00283 $textgap_rating = $this->object->getTextgapRating();
00284 foreach ($textgap_options as $textgap_option)
00285 {
00286 $this->tpl->setCurrentBlock("textgap_rating");
00287 $this->tpl->setVariable("TEXTGAP_VALUE", $textgap_option[0]);
00288 $this->tpl->setVariable("TEXTGAP_TEXT", $textgap_option[1]);
00289 if (strcmp($textgap_rating, $textgap_option[0]) == 0)
00290 {
00291 $this->tpl->setVariable("SELECTED_TEXTGAP_VALUE", " selected=\"selected\"");
00292 }
00293 $this->tpl->parseCurrentBlock();
00294 }
00295
00296 $this->tpl->setCurrentBlock("question_data");
00297 $this->tpl->setVariable("VALUE_CLOZE_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00298 $this->tpl->setVariable("VALUE_CLOZE_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00299 $this->tpl->setVariable("VALUE_CLOZE_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00300 $cloze_text = $this->object->getClozeText();
00301 $this->tpl->setVariable("VALUE_CLOZE_TEXT", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($cloze_text)));
00302 $this->tpl->setVariable("TEXT_CREATE_GAPS", $this->lng->txt("create_gaps"));
00303 $this->tpl->setVariable("CLOZE_ID", $this->object->getId());
00304
00305 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00306 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00307 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00308 $this->tpl->setVariable("TEXT_CLOZE_TEXT", $this->lng->txt("cloze_text"));
00309 $this->tpl->setVariable("TEXT_CLOSE_HINT", ilUtil::prepareFormOutput($this->lng->txt("close_text_hint")));
00310 $this->tpl->setVariable("TEXTGAP_RATING", $this->lng->txt("cloze_textgap_rating"));
00311 $this->tpl->setVariable("TEXT_GAP_DEFINITION", $this->lng->txt("gap_definition"));
00312 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00313 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00314 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00315 $this->ctrl->setParameter($this, "sel_question_types", "assClozeTest");
00316 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assClozeTest"));
00317 $this->tpl->setVariable("ACTION_CLOZE_TEST", $this->ctrl->getFormAction($this));
00318 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00319 $this->tpl->parseCurrentBlock();
00320
00321 include_once "./Services/RTE/classes/class.ilRTE.php";
00322 $rtestring = ilRTE::_getRTEClassname();
00323 include_once "./Services/RTE/classes/class.$rtestring.php";
00324 $rte = new $rtestring();
00325 $rte->addPlugin("latex");
00326 $rte->addButton("latex");
00327 include_once "./classes/class.ilObject.php";
00328 $obj_id = $_GET["q_id"];
00329 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00330 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00331
00332 $this->tpl->setCurrentBlock("adm_content");
00333 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\"");
00334 $this->tpl->parseCurrentBlock();
00335 }
00336
00345 function writePostData()
00346 {
00347 $result = 0;
00348 $saved = false;
00349
00350
00351 $this->object->flushGaps();
00352
00353 if (!$this->checkInput())
00354 {
00355 $result = 1;
00356 }
00357
00358 if (($result) and ($_POST["cmd"]["add"]))
00359 {
00360
00361 sendInfo($this->lng->txt("fill_out_all_required_fields_create_gaps"));
00362 $_POST["cmd"]["add"] = "";
00363 }
00364
00365 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00366 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00367 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00368 $this->object->setTextgapRating($_POST["textgap_rating"]);
00369 include_once "./classes/class.ilObjAdvancedEditing.php";
00370 $cloze_text = ilUtil::stripSlashes($_POST["clozetext"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00371 $this->object->setClozeText($cloze_text);
00372
00373 $saved = $saved | $this->writeOtherPostData($result);
00374 $this->object->suggested_solutions = array();
00375 foreach ($_POST as $key => $value)
00376 {
00377 if (preg_match("/^solution_hint_(\d+)/", $key, $matches))
00378 {
00379 if ($value)
00380 {
00381 $this->object->setSuggestedSolution($value, $matches[1]);
00382 }
00383 }
00384 }
00385
00386 if ($this->ctrl->getCmd() != "createGaps")
00387 {
00388 $result = $this->setGapValues();
00389 $this->setShuffleState();
00390
00391 foreach ($_POST as $key => $value)
00392 {
00393
00394 if (preg_match("/clozetype_(\d+)/", $key, $matches))
00395 {
00396 $this->object->setClozeType($matches[1], $value);
00397 }
00398 }
00399 }
00400
00401 $this->object->updateAllGapParams();
00402 if ($saved)
00403 {
00404
00405
00406
00407
00408 $this->object->saveToDb();
00409 $_GET["q_id"] = $this->object->getId();
00410 }
00411 return $result;
00412 }
00413
00417 function delete()
00418 {
00419 $this->writePostData();
00420 foreach ($_POST["cmd"] as $key => $value)
00421 {
00422
00423 if (preg_match("/delete_(\d+)_(\d+)/", $key, $matches))
00424 {
00425 $selectgap = "selectgap_" . $matches[1] . "_" . $matches[2];
00426 $this->object->deleteAnswertextByIndex($matches[1], $matches[2]);
00427 }
00428 }
00429 $this->editQuestion();
00430 }
00431
00432 function addSelectGap()
00433 {
00434 $this->writePostData();
00435
00436 $len = strlen("addSelectGap_");
00437 $i = substr($this->ctrl->getCmd(), $len);
00438 $this->object->setAnswertext(
00439 ilUtil::stripSlashes($i),
00440 ilUtil::stripSlashes($this->object->getGapTextCount($i)),
00441 "",
00442 1
00443 );
00444
00445 $this->editQuestion();
00446 }
00447
00448 function addTextGap()
00449 {
00450 $this->writePostData();
00451
00452 $len = strlen("addTextGap_");
00453 $i = substr($this->ctrl->getCmd(), $len);
00454 $this->object->setAnswertext(
00455 ilUtil::stripSlashes($i),
00456 ilUtil::stripSlashes($this->object->getGapTextCount($i)),
00457 "",
00458 1
00459 );
00460
00461 $this->editQuestion();
00462 }
00463
00464 function setGapValues($a_apply_text = true)
00465 {
00466
00467 $result = 0;
00468 foreach ($_POST as $key => $value)
00469 {
00470
00471 if (preg_match("/textgap_(\d+)_(\d+)/", $key, $matches))
00472 {
00473 $answer_array = $this->object->getGap($matches[1]);
00474 if (strlen($value) > 0)
00475 {
00476
00477 if (array_key_exists($matches[2], $answer_array))
00478 {
00479 if ($a_apply_text)
00480 {
00481 if (strcmp($value, $answer_array[$matches[2]]->getAnswertext()) != 0)
00482 {
00483 $this->object->setAnswertext(
00484 ilUtil::stripSlashes($matches[1]),
00485 ilUtil::stripSlashes($matches[2]),
00486 ilUtil::stripSlashes($value)
00487 );
00488 }
00489 $points = $_POST["points_$matches[1]_$matches[2]"];
00490 $this->object->setSingleAnswerPoints($matches[1], $matches[2], $points);
00491 $this->object->setSingleAnswerState($matches[1], $matches[2], 1);
00492 }
00493 else
00494 {
00495 if (strcmp($value, $answer_array[$matches[2]]->getAnswertext()) == 0)
00496 {
00497 $points = $_POST["points_$matches[1]_$matches[2]"];
00498 $this->object->setSingleAnswerPoints($matches[1], $matches[2], $points);
00499 $this->object->setSingleAnswerState($matches[1], $matches[2], 1);
00500 }
00501 }
00502 }
00503 }
00504 else
00505 {
00506
00507 }
00508 }
00509
00510 if (preg_match("/selectgap_(\d+)_(\d+)/", $key, $matches))
00511 {
00512 $answer_array = $this->object->getGap($matches[1]);
00513 if (strlen($value) > 0)
00514 {
00515
00516 if (array_key_exists($matches[2], $answer_array))
00517 {
00518 if (strcmp($value, $answer_array[$matches[2]]->getAnswertext()) != 0)
00519 {
00520 if ($a_apply_text)
00521 {
00522 $this->object->setAnswertext(
00523 ilUtil::stripSlashes($matches[1]),
00524 ilUtil::stripSlashes($matches[2]),
00525 ilUtil::stripSlashes($value)
00526 );
00527 }
00528 }
00529 $points = $_POST["points_$matches[1]_$matches[2]"];
00530 $this->object->setSingleAnswerPoints($matches[1], $matches[2], $points);
00531 $this->object->setSingleAnswerState($matches[1], $matches[2], 1);
00532 }
00533 }
00534 else
00535 {
00536
00537 }
00538 }
00539 }
00540 return $result;
00541 }
00542
00543 function setShuffleState()
00544 {
00545 foreach ($_POST as $key => $value)
00546 {
00547
00548 if (preg_match("/^shuffle_(\d+)$/", $key, $matches))
00549 {
00550 $this->object->setGapShuffle($matches[1], $value);
00551 }
00552 }
00553 }
00554
00558 function createGaps()
00559 {
00560 $this->writePostData();
00561
00562 $this->setGapValues(false);
00563 $this->setShuffleState();
00564 $this->object->updateAllGapParams();
00565 $this->editQuestion();
00566 }
00567
00568 function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00569 {
00570 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
00571 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00572 $this->tpl->setVariable("FORMACTION", $formaction);
00573 }
00574
00575 function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE)
00576 {
00577
00578 $user_solution = array();
00579 if ($active_id)
00580 {
00581 $user_solution =& $this->object->getSolutionValues($active_id, $pass);
00582 if (!is_array($user_solution))
00583 {
00584 $user_solution = array();
00585 }
00586 }
00587 else
00588 {
00589 for ($i = 0; $i < $this->object->getGapCount(); $i++)
00590 {
00591 $gap = $this->object->getGap($i);
00592 if ($gap[0]->getClozeType() == CLOZE_SELECT)
00593 {
00594 $maxpoints = 0;
00595 $foundindex = -1;
00596 foreach ($gap as $index => $answer)
00597 {
00598 if ($answer->getPoints() > $maxpoints)
00599 {
00600 $maxpoints = $answer->getPoints();
00601 $foundindex = $index;
00602 }
00603 }
00604 array_push($user_solution, array("value1" => $i, "value2" => $foundindex));
00605 }
00606 else
00607 {
00608 $best_solutions = array();
00609 foreach ($gap as $index => $answer)
00610 {
00611 if (is_array($best_solutions[$answer->getPoints()]))
00612 {
00613 array_push($best_solutions[$answer->getPoints()], """.$answer->getAnswertext().""");
00614 }
00615 else
00616 {
00617 $best_solutions[$answer->getPoints()] = array();
00618 array_push($best_solutions[$answer->getPoints()], """.$answer->getAnswertext().""");
00619 }
00620 }
00621 krsort($best_solutions, SORT_NUMERIC);
00622 reset($best_solutions);
00623 $found = current($best_solutions);
00624 array_push($user_solution, array("value1" => $i, "value2" => join(" " . $this->lng->txt("or") . " ", $found)));
00625 }
00626 }
00627 }
00628
00629
00630 include_once "./classes/class.ilTemplate.php";
00631 $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", TRUE, TRUE, TRUE);
00632 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, TRUE);
00633 $cloze =& $this->object->createCloseTextArray();
00634
00635 $cloze_text = $cloze["delimiters"];
00636
00637 $counter = 0;
00638 foreach ($cloze_text as $delimiter)
00639 {
00640 $template->setCurrentBlock("cloze_text");
00641 $template->setVariable("CLOZE_TEXT", $this->object->prepareTextareaOutput($delimiter[0], TRUE));
00642 $template->parseCurrentBlock();
00643 $ssc = $this->object->_getSuggestedSolutionCount($this->object->getId());
00644 $gap = $this->object->getGap($counter);
00645 $filledgap = FALSE;
00646 foreach ($user_solution as $solution)
00647 {
00648 if (strcmp($solution["value1"], $counter) == 0)
00649 {
00650 $filledgap = TRUE;
00651 if ($active_id)
00652 {
00653 if ($graphicalOutput)
00654 {
00655
00656 $check = $this->object->testGapSolution($solution["value2"], $gap);
00657 if ($check["best"])
00658 {
00659 $template->setCurrentBlock("icon_ok");
00660 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00661 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00662 $template->parseCurrentBlock();
00663 }
00664 else
00665 {
00666 $template->setCurrentBlock("icon_not_ok");
00667 if ($check["positive"])
00668 {
00669 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
00670 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
00671 }
00672 else
00673 {
00674 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00675 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00676 }
00677 $template->parseCurrentBlock();
00678 }
00679 }
00680 if ($ssc > 0)
00681 {
00682 $ss = $this->object->_getSuggestedSolution($this->object->getId(), $gap_index);
00683 if (count($ss))
00684 {
00685 $template->setCurrentBlock("solution_hint");
00686 $template->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00687 $template->setVariable("URL_SOLUTION_HINT", $this->object->_getInternalLinkHref($ss["internal_link"]));
00688 $template->parseCurrentBlock();
00689 }
00690 }
00691 }
00692 if ($result_output)
00693 {
00694 $points = $this->object->getMaximumGapPoints($solution["value1"]);
00695 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
00696 $template->setCurrentBlock("result_output");
00697 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
00698 $template->parseCurrentBlock();
00699 }
00700 $template->setCurrentBlock("solution");
00701 if ((strlen($solution["value2"])) && ($gap[0]->getClozeType() == CLOZE_SELECT))
00702 {
00703 if (array_key_exists($solution["value2"], $gap))
00704 {
00705 $template->setVariable("SOLUTION", $gap[$solution["value2"]]->getAnswertext());
00706 }
00707 }
00708 else
00709 {
00710 $template->setVariable("SOLUTION", $solution["value2"]);
00711 }
00712 $template->parseCurrentBlock();
00713 }
00714 }
00715 if (count($gap) && !$filledgap)
00716 {
00717 if ($graphicalOutput)
00718 {
00719 $template->setCurrentBlock("icon_not_ok");
00720 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00721 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00722 $template->parseCurrentBlock();
00723 }
00724 if ($result_output)
00725 {
00726 $points = 0;
00727 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
00728 $template->setCurrentBlock("result_output");
00729 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
00730 $template->parseCurrentBlock();
00731 }
00732 $template->setCurrentBlock("solution");
00733 $fillspace = "";
00734 for ($chars = 0; $chars < $this->object->getColumnSize($gap); $chars++)
00735 {
00736 $fillspace .= " ";
00737 }
00738 $template->setVariable("SOLUTION", $fillspace);
00739 $template->parseCurrentBlock();
00740 }
00741 $template->parseCurrentBlock();
00742 $template->touchBlock("cloze_part");
00743 $counter++;
00744 }
00745 $questionoutput = $template->get();
00746 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00747
00748 $solutionoutput = $solutiontemplate->get();
00749 if (!$show_question_only)
00750 {
00751
00752 $pageoutput = $this->getILIASPage();
00753 $solutionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $solutionoutput, $pageoutput);
00754 }
00755 return $solutionoutput;
00756 }
00757
00758 function getPreview()
00759 {
00760
00761 include_once "./classes/class.ilTemplate.php";
00762 $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, TRUE);
00763 $cloze =& $this->object->createCloseTextArray();
00764 $cloze_text = $cloze["delimiters"];
00765 $counter = 0;
00766 foreach ($cloze_text as $delimiter)
00767 {
00768 $template->setCurrentBlock("cloze_text");
00769 $template->setVariable("CLOZE_TEXT", $this->object->prepareTextareaOutput($delimiter[0], TRUE));
00770 $template->parseCurrentBlock();
00771 $gap = $this->object->getGap($counter);
00772 if ($gap)
00773 {
00774 if ($gap[0]->getClozeType() == CLOZE_SELECT)
00775 {
00776
00777 $gkeys = array_keys($gap);
00778 if ($gap[0]->getShuffle())
00779 {
00780 $gkeys = $this->object->pcArrayShuffle($gkeys);
00781 }
00782
00783
00784 foreach ($gkeys as $index)
00785 {
00786 $answer = $gap[$index];
00787 $template->setCurrentBlock("select_gap_option");
00788 $template->setVariable("SELECT_GAP_VALUE", $index);
00789 $template->setVariable("SELECT_GAP_TEXT", $answer->getAnswertext());
00790 $template->parseCurrentBlock();
00791 }
00792 $template->setCurrentBlock("select_gap");
00793 $template->setVariable("GAP_COUNTER", $counter);
00794 $template->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
00795 $template->parseCurrentBlock();
00796 }
00797 else
00798 {
00799 $template->setCurrentBlock("text_gap");
00800 $template->setVariable("GAP_COUNTER", $counter);
00801 $template->setVariable("TEXT_GAP_SIZE", $this->object->getColumnSize($gap));
00802 $template->parseCurrentBlock();
00803 }
00804 }
00805 $template->touchBlock("cloze_part");
00806 $counter++;
00807 }
00808 $questionoutput = $template->get();
00809 $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00810 return $questionoutput;
00811 }
00812
00813 function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00814 {
00815
00816 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00817
00818
00819 $user_solution = array();
00820 if ($active_id)
00821 {
00822 include_once "./assessment/classes/class.ilObjTest.php";
00823 if (ilObjTest::_getHidePreviousResults($active_id, true))
00824 {
00825 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00826 }
00827 $user_solution =& $this->object->getSolutionValues($active_id, $pass);
00828 if (!is_array($user_solution))
00829 {
00830 $user_solution = array();
00831 }
00832 }
00833
00834
00835 include_once "./classes/class.ilTemplate.php";
00836 $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, TRUE);
00837 $cloze =& $this->object->createCloseTextArray();
00838
00839 $cloze_text = $cloze["delimiters"];
00840
00841 $counter = 0;
00842 foreach ($cloze_text as $delimiter)
00843 {
00844 $template->setCurrentBlock("cloze_text");
00845 $template->setVariable("CLOZE_TEXT", $this->object->prepareTextareaOutput($delimiter[0], TRUE));
00846 $template->parseCurrentBlock();
00847 $gap = $this->object->getGap($counter);
00848 if ($gap)
00849 {
00850 if ($gap[0]->getClozeType() == CLOZE_SELECT)
00851 {
00852
00853 $gkeys = array_keys($gap);
00854 if ($gap[0]->getShuffle())
00855 {
00856 $gkeys = $this->object->pcArrayShuffle($gkeys);
00857 }
00858
00859
00860 foreach ($gkeys as $index)
00861 {
00862 $answer = $gap[$index];
00863 $template->setCurrentBlock("select_gap_option");
00864 $template->setVariable("SELECT_GAP_VALUE", $index);
00865 $template->setVariable("SELECT_GAP_TEXT", $answer->getAnswertext());
00866 foreach ($user_solution as $solution)
00867 {
00868 if (strcmp($solution["value1"], $counter) == 0)
00869 {
00870 if (strcmp($solution["value2"], $index) == 0)
00871 {
00872 $template->setVariable("SELECT_GAP_SELECTED", " selected=\"selected\"");
00873 }
00874 }
00875 }
00876 $template->parseCurrentBlock();
00877 }
00878 $template->setCurrentBlock("select_gap");
00879 $template->setVariable("GAP_COUNTER", $counter);
00880 $template->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
00881 $template->parseCurrentBlock();
00882 }
00883 else
00884 {
00885 $template->setCurrentBlock("text_gap");
00886 $template->setVariable("GAP_COUNTER", $counter);
00887 foreach ($user_solution as $solution)
00888 {
00889 if (strcmp($solution["value1"], $counter) == 0)
00890 {
00891 $template->setVariable("VALUE_GAP", " value=\"" . ilUtil::prepareFormOutput($solution["value2"]) . "\"");
00892 }
00893 }
00894 $template->setVariable("TEXT_GAP_SIZE", $this->object->getColumnSize($gap));
00895 $template->parseCurrentBlock();
00896 }
00897 }
00898 $template->touchBlock("cloze_part");
00899 $counter++;
00900 }
00901 $questionoutput = $template->get();
00902 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00903 return $questionoutput;
00904 }
00905
00909 function checkInput()
00910 {
00911 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["clozetext"]))
00912 {
00913 return false;
00914 }
00915 return true;
00916 }
00917
00918
00919 function addSuggestedSolution()
00920 {
00921 $addForGap = -1;
00922 if (array_key_exists("cmd", $_POST))
00923 {
00924 foreach ($_POST["cmd"] as $key => $value)
00925 {
00926 if (preg_match("/addSuggestedSolution_(\d+)/", $key, $matches))
00927 {
00928 $addForGap = $matches[1];
00929 }
00930 }
00931 }
00932 if ($addForGap > -1)
00933 {
00934 if ($this->writePostData())
00935 {
00936 sendInfo($this->getErrorMessage());
00937 $this->editQuestion();
00938 return;
00939 }
00940 if (!$this->checkInput())
00941 {
00942 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00943 $this->editQuestion();
00944 return;
00945 }
00946 $_POST["internalLinkType"] = $_POST["internalLinkType_$addForGap"];
00947 $_SESSION["subquestion_index"] = $addForGap;
00948 }
00949 $this->object->saveToDb();
00950 $_GET["q_id"] = $this->object->getId();
00951 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00952 $this->getQuestionTemplate();
00953 parent::addSuggestedSolution();
00954 }
00955
00956 function removeSuggestedSolution()
00957 {
00958 $removeFromGap = -1;
00959 foreach ($_POST["cmd"] as $key => $value)
00960 {
00961 if (preg_match("/removeSuggestedSolution_(\d+)/", $key, $matches))
00962 {
00963 $removeFromGap = $matches[1];
00964 }
00965 }
00966 if ($removeFromGap > -1)
00967 {
00968 unset($this->object->suggested_solutions[$removeFromGap]);
00969 }
00970 $this->object->saveToDb();
00971 $this->editQuestion();
00972 }
00973
00974 }
00975 ?>