Cloze test question GUI representation. More...
Public Member Functions | |
assClozeTestGUI ($id=-1) | |
assClozeTestGUI constructor | |
getQuestionType () | |
Returns the question type string. | |
getCommand ($cmd) | |
editQuestion () | |
Creates an output of the edit form for the question. | |
writePostData () | |
Evaluates a posted edit form and writes the form data in the question object. | |
delete () | |
delete | |
addSelectGap () | |
addTextGap () | |
setGapValues ($a_apply_text=true) | |
setShuffleState () | |
createGaps () | |
create gaps | |
outQuestionForTest ($formaction, $active_id, $pass=NULL, $is_postponed=FALSE, $use_post_solutions=FALSE) | |
getSolutionOutput ($active_id, $pass=NULL, $graphicalOutput=FALSE, $result_output=FALSE, $show_question_only=TRUE) | |
getPreview () | |
getTestOutput ($active_id, $pass=NULL, $is_postponed=FALSE, $use_post_solutions=FALSE) | |
checkInput () | |
check input fields | |
addSuggestedSolution () | |
Handler for cmd[addSuggestedSolution] to add a suggested solution for the question. | |
removeSuggestedSolution () |
Cloze test question GUI representation.
The assClozeTestGUI class encapsulates the GUI representation for cloze test questions.
class.assClozeTestGUI.php Assessment
Definition at line 37 of file class.assClozeTestGUI.php.
assClozeTestGUI::addSelectGap | ( | ) |
Definition at line 432 of file class.assClozeTestGUI.php.
References editQuestion(), ilUtil::stripSlashes(), and writePostData().
{ $this->writePostData(); $len = strlen("addSelectGap_"); $i = substr($this->ctrl->getCmd(), $len); $this->object->setAnswertext( ilUtil::stripSlashes($i), ilUtil::stripSlashes($this->object->getGapTextCount($i)), "", 1 ); $this->editQuestion(); }
assClozeTestGUI::addSuggestedSolution | ( | ) |
Handler for cmd[addSuggestedSolution] to add a suggested solution for the question.
Handler for cmd[addSuggestedSolution] to add a suggested solution for the question
public
Reimplemented from assQuestionGUI.
Definition at line 919 of file class.assClozeTestGUI.php.
References $_GET, $_POST, $_SESSION, $key, checkInput(), editQuestion(), assQuestionGUI::getErrorMessage(), assQuestionGUI::getQuestionTemplate(), sendInfo(), and writePostData().
{ $addForGap = -1; if (array_key_exists("cmd", $_POST)) { foreach ($_POST["cmd"] as $key => $value) { if (preg_match("/addSuggestedSolution_(\d+)/", $key, $matches)) { $addForGap = $matches[1]; } } } if ($addForGap > -1) { if ($this->writePostData()) { sendInfo($this->getErrorMessage()); $this->editQuestion(); return; } if (!$this->checkInput()) { sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer")); $this->editQuestion(); return; } $_POST["internalLinkType"] = $_POST["internalLinkType_$addForGap"]; $_SESSION["subquestion_index"] = $addForGap; } $this->object->saveToDb(); $_GET["q_id"] = $this->object->getId(); $this->tpl->setVariable("HEADER", $this->object->getTitle()); $this->getQuestionTemplate(); parent::addSuggestedSolution(); }
assClozeTestGUI::addTextGap | ( | ) |
Definition at line 448 of file class.assClozeTestGUI.php.
References editQuestion(), ilUtil::stripSlashes(), and writePostData().
{ $this->writePostData(); $len = strlen("addTextGap_"); $i = substr($this->ctrl->getCmd(), $len); $this->object->setAnswertext( ilUtil::stripSlashes($i), ilUtil::stripSlashes($this->object->getGapTextCount($i)), "", 1 ); $this->editQuestion(); }
assClozeTestGUI::assClozeTestGUI | ( | $ | id = -1 |
) |
assClozeTestGUI constructor
The constructor takes possible arguments an creates an instance of the assClozeTestGUI object.
integer | $id The database id of a image map question object public |
Definition at line 47 of file class.assClozeTestGUI.php.
References $id, and assQuestionGUI::assQuestionGUI().
{ $this->assQuestionGUI(); include_once "./assessment/classes/class.assClozeTest.php"; $this->object = new assClozeTest(); if ($id >= 0) { $this->object->loadFromDb($id); } }
assClozeTestGUI::checkInput | ( | ) |
check input fields
Definition at line 909 of file class.assClozeTestGUI.php.
References $_POST.
Referenced by addSuggestedSolution(), and writePostData().
{ if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["clozetext"])) { return false; } return true; }
assClozeTestGUI::createGaps | ( | ) |
create gaps
Definition at line 558 of file class.assClozeTestGUI.php.
References editQuestion(), setGapValues(), setShuffleState(), and writePostData().
{ $this->writePostData(); $this->setGapValues(false); $this->setShuffleState(); $this->object->updateAllGapParams(); $this->editQuestion(); }
assClozeTestGUI::delete | ( | ) |
delete
Definition at line 417 of file class.assClozeTestGUI.php.
References $_POST, $key, editQuestion(), and writePostData().
{ $this->writePostData(); foreach ($_POST["cmd"] as $key => $value) { // Check, if one of the gap values was deleted if (preg_match("/delete_(\d+)_(\d+)/", $key, $matches)) { $selectgap = "selectgap_" . $matches[1] . "_" . $matches[2]; $this->object->deleteAnswertextByIndex($matches[1], $matches[2]); } } $this->editQuestion(); }
assClozeTestGUI::editQuestion | ( | ) |
Creates an output of the edit form for the question.
Creates an output of the edit form for the question
public
Definition at line 108 of file class.assClozeTestGUI.php.
References $_GET, $key, $obj_id, assQuestion::_getInternalLinkHref(), ilRTE::_getRTEClassname(), ilObject::_lookupType(), assQuestionGUI::getQuestionTemplate(), assQuestionGUI::outOtherQuestionData(), and ilUtil::prepareFormOutput().
Referenced by addSelectGap(), addSuggestedSolution(), addTextGap(), createGaps(), delete(), and removeSuggestedSolution().
{ include_once "./assessment/classes/class.assQuestion.php"; $internallinks = array( "lm" => $this->lng->txt("obj_lm"), "st" => $this->lng->txt("obj_st"), "pg" => $this->lng->txt("obj_pg"), "glo" => $this->lng->txt("glossary_term") ); //$this->tpl->setVariable("HEADER", $this->object->getTitle()); $this->getQuestionTemplate(); $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_cloze_question.html", true); for ($i = 0; $i < $this->object->getGapCount(); $i++) { $gap = $this->object->getGap($i); if ($gap[0]->getClozeType() == CLOZE_TEXT) { $this->tpl->setCurrentBlock("textgap_value"); foreach ($gap as $key => $value) { $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value")); $this->tpl->setVariable("VALUE_TEXT_GAP", ilUtil::prepareFormOutput($value->getAnswertext())); $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key"); $this->tpl->setVariable("VALUE_GAP", $i); $this->tpl->setVariable("VALUE_INDEX", $key); $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key); $this->tpl->setVariable("VALUE_GAP", $i); $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points")); $this->tpl->setVariable("VALUE_TEXT_GAP_POINTS", $value->getPoints()); $this->tpl->setVariable("DELETE", $this->lng->txt("delete")); $this->tpl->parseCurrentBlock(); } foreach ($internallinks as $key => $value) { $this->tpl->setCurrentBlock("textgap_internallink"); $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key); $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("textgap_suggested_solution"); $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint")); if (array_key_exists($i, $this->object->suggested_solutions)) { $solution_array = $this->object->getSuggestedSolution($i); $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]); $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> "); $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove")); $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i); $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change")); $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]); } else { $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add")); } $this->tpl->setVariable("VALUE_GAP_COUNTER", $i); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("textgap"); $this->tpl->setVariable("ADD_TEXT_GAP", $this->lng->txt("add_gap")); $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i"); $this->tpl->parseCurrentBlock(); } elseif ($gap[0]->getClozeType() == CLOZE_SELECT) { $this->tpl->setCurrentBlock("selectgap_value"); foreach ($gap as $key => $value) { $this->tpl->setVariable("TEXT_VALUE", $this->lng->txt("value")); $this->tpl->setVariable("VALUE_SELECT_GAP", ilUtil::prepareFormOutput($value->getAnswertext())); $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i" . "_" . "$key"); $this->tpl->setVariable("VALUE_GAP", $i); $this->tpl->setVariable("VALUE_INDEX", $key); $this->tpl->setVariable("VALUE_STATUS_COUNTER", $key); $this->tpl->setVariable("VALUE_GAP", $i); $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points")); $this->tpl->setVariable("VALUE_SELECT_GAP_POINTS", $value->getPoints()); $this->tpl->setVariable("DELETE", $this->lng->txt("delete")); $this->tpl->parseCurrentBlock(); } foreach ($internallinks as $key => $value) { $this->tpl->setCurrentBlock("selectgap_internallink"); $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key); $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("selectgap_suggested_solution"); $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint")); if (array_key_exists($i, $this->object->suggested_solutions)) { $solution_array = $this->object->getSuggestedSolution($i); $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]); $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> "); $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove")); $this->tpl->setVariable("VALUE_GAP_COUNTER_REMOVE", $i); $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change")); $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]); } else { $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add")); } $this->tpl->setVariable("VALUE_GAP_COUNTER", $i); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock("selectgap"); $this->tpl->setVariable("ADD_SELECT_GAP", $this->lng->txt("add_gap")); $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers")); $this->tpl->setVariable("VALUE_GAP_COUNTER", "$i"); if ($gap[0]->getShuffle()) { $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\""); } else { $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\""); } $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes")); $this->tpl->setVariable("TXT_NO", $this->lng->txt("no")); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("answer_row"); $name = $gap[0]->getName(); if (!$name) { $name = $this->lng->txt("gap") . " " . ($i+1); } $this->tpl->setVariable("TEXT_GAP_NAME", $name); $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type")); if ($gap[0]->getClozeType() == CLOZE_SELECT) { $this->tpl->setVariable("SELECTED_SELECT_GAP", " selected=\"selected\""); } else { $this->tpl->setVariable("SELECTED_TEXT_GAP", " selected=\"selected\""); } $this->tpl->setVariable("TEXT_TEXT_GAP", $this->lng->txt("text_gap")); $this->tpl->setVariable("TEXT_SELECT_GAP", $this->lng->txt("select_gap")); $this->tpl->setVariable("VALUE_GAP_COUNTER", $i); $this->tpl->parseCurrentBlock(); } // call to other question data i.e. estimated working time block $this->outOtherQuestionData(); $this->tpl->setCurrentBlock("HeadContent"); $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>"; if (preg_match("/addTextGap_(\d+)/", $this->ctrl->getCmd(), $matches)) { $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\");")); } else if (preg_match("/addSelectGap_(\d+)/", $this->ctrl->getCmd(), $matches)) { $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\");")); } else { $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_cloze_test.title.focus();")); } $this->tpl->parseCurrentBlock(); // Add textgap rating options $textgap_options = array( array("ci", $this->lng->txt("cloze_textgap_case_insensitive")), array("cs", $this->lng->txt("cloze_textgap_case_sensitive")), array("l1", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1")), array("l2", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2")), array("l3", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3")), array("l4", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4")), array("l5", sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5")) ); $textgap_rating = $this->object->getTextgapRating(); foreach ($textgap_options as $textgap_option) { $this->tpl->setCurrentBlock("textgap_rating"); $this->tpl->setVariable("TEXTGAP_VALUE", $textgap_option[0]); $this->tpl->setVariable("TEXTGAP_TEXT", $textgap_option[1]); if (strcmp($textgap_rating, $textgap_option[0]) == 0) { $this->tpl->setVariable("SELECTED_TEXTGAP_VALUE", " selected=\"selected\""); } $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("question_data"); $this->tpl->setVariable("VALUE_CLOZE_TITLE", ilUtil::prepareFormOutput($this->object->getTitle())); $this->tpl->setVariable("VALUE_CLOZE_COMMENT", ilUtil::prepareFormOutput($this->object->getComment())); $this->tpl->setVariable("VALUE_CLOZE_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor())); $cloze_text = $this->object->getClozeText(); $this->tpl->setVariable("VALUE_CLOZE_TEXT", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($cloze_text))); $this->tpl->setVariable("TEXT_CREATE_GAPS", $this->lng->txt("create_gaps")); $this->tpl->setVariable("CLOZE_ID", $this->object->getId()); $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title")); $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author")); $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description")); $this->tpl->setVariable("TEXT_CLOZE_TEXT", $this->lng->txt("cloze_text")); $this->tpl->setVariable("TEXT_CLOSE_HINT", ilUtil::prepareFormOutput($this->lng->txt("close_text_hint"))); $this->tpl->setVariable("TEXTGAP_RATING", $this->lng->txt("cloze_textgap_rating")); $this->tpl->setVariable("TEXT_GAP_DEFINITION", $this->lng->txt("gap_definition")); $this->tpl->setVariable("SAVE",$this->lng->txt("save")); $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit")); $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel")); $this->ctrl->setParameter($this, "sel_question_types", "assClozeTest"); $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assClozeTest")); $this->tpl->setVariable("ACTION_CLOZE_TEST", $this->ctrl->getFormAction($this)); $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field")); $this->tpl->parseCurrentBlock(); include_once "./Services/RTE/classes/class.ilRTE.php"; $rtestring = ilRTE::_getRTEClassname(); include_once "./Services/RTE/classes/class.$rtestring.php"; $rte = new $rtestring(); $rte->addPlugin("latex"); $rte->addButton("latex"); include_once "./classes/class.ilObject.php"; $obj_id = $_GET["q_id"]; $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE); $rte->addRTESupport($obj_id, $obj_type, "assessment"); $this->tpl->setCurrentBlock("adm_content"); $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); $this->tpl->parseCurrentBlock(); }
assClozeTestGUI::getCommand | ( | $ | cmd | ) |
Reimplemented from assQuestionGUI.
Definition at line 74 of file class.assClozeTestGUI.php.
References $cmd.
{ if (substr($cmd, 0, 6) == "delete") { $cmd = "delete"; } if (substr($cmd, 0, 10) == "addTextGap") { $cmd = "addTextGap"; } if (substr($cmd, 0, 12) == "addSelectGap") { $cmd = "addSelectGap"; } if (substr($cmd, 0, 20) == "addSuggestedSolution") { $cmd = "addSuggestedSolution"; } if (substr($cmd, 0, 23) == "removeSuggestedSolution") { $cmd = "removeSuggestedSolution"; } return $cmd; }
assClozeTestGUI::getPreview | ( | ) |
Definition at line 758 of file class.assClozeTestGUI.php.
References $counter.
{ // generate the question output include_once "./classes/class.ilTemplate.php"; $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, TRUE); $cloze =& $this->object->createCloseTextArray(); $cloze_text = $cloze["delimiters"]; $counter = 0; foreach ($cloze_text as $delimiter) { $template->setCurrentBlock("cloze_text"); $template->setVariable("CLOZE_TEXT", $this->object->prepareTextareaOutput($delimiter[0], TRUE)); $template->parseCurrentBlock(); $gap = $this->object->getGap($counter); if ($gap) { if ($gap[0]->getClozeType() == CLOZE_SELECT) { // shuffle output $gkeys = array_keys($gap); if ($gap[0]->getShuffle()) { $gkeys = $this->object->pcArrayShuffle($gkeys); } // add answers foreach ($gkeys as $index) { $answer = $gap[$index]; $template->setCurrentBlock("select_gap_option"); $template->setVariable("SELECT_GAP_VALUE", $index); $template->setVariable("SELECT_GAP_TEXT", $answer->getAnswertext()); $template->parseCurrentBlock(); } $template->setCurrentBlock("select_gap"); $template->setVariable("GAP_COUNTER", $counter); $template->setVariable("PLEASE_SELECT", $this->lng->txt("please_select")); $template->parseCurrentBlock(); } else { $template->setCurrentBlock("text_gap"); $template->setVariable("GAP_COUNTER", $counter); $template->setVariable("TEXT_GAP_SIZE", $this->object->getColumnSize($gap)); $template->parseCurrentBlock(); } } $template->touchBlock("cloze_part"); $counter++; } $questionoutput = $template->get(); $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput); return $questionoutput; }
assClozeTestGUI::getQuestionType | ( | ) |
Returns the question type string.
Returns the question type string
Reimplemented from assQuestionGUI.
Definition at line 68 of file class.assClozeTestGUI.php.
{ return "assClozeTest"; }
assClozeTestGUI::getSolutionOutput | ( | $ | active_id, | |
$ | pass = NULL , |
|||
$ | graphicalOutput = FALSE , |
|||
$ | result_output = FALSE , |
|||
$ | show_question_only = TRUE | |||
) |
Definition at line 575 of file class.assClozeTestGUI.php.
References $counter, assQuestionGUI::getILIASPage(), and ilUtil::getImagePath().
{ // get the solution of the user for the active pass or from the last pass if allowed $user_solution = array(); if ($active_id) { $user_solution =& $this->object->getSolutionValues($active_id, $pass); if (!is_array($user_solution)) { $user_solution = array(); } } else { for ($i = 0; $i < $this->object->getGapCount(); $i++) { $gap = $this->object->getGap($i); if ($gap[0]->getClozeType() == CLOZE_SELECT) { $maxpoints = 0; $foundindex = -1; foreach ($gap as $index => $answer) { if ($answer->getPoints() > $maxpoints) { $maxpoints = $answer->getPoints(); $foundindex = $index; } } array_push($user_solution, array("value1" => $i, "value2" => $foundindex)); } else { $best_solutions = array(); foreach ($gap as $index => $answer) { if (is_array($best_solutions[$answer->getPoints()])) { array_push($best_solutions[$answer->getPoints()], """.$answer->getAnswertext()."""); } else { $best_solutions[$answer->getPoints()] = array(); array_push($best_solutions[$answer->getPoints()], """.$answer->getAnswertext()."""); } } krsort($best_solutions, SORT_NUMERIC); reset($best_solutions); $found = current($best_solutions); array_push($user_solution, array("value1" => $i, "value2" => join(" " . $this->lng->txt("or") . " ", $found))); } } } // generate the question output include_once "./classes/class.ilTemplate.php"; $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", TRUE, TRUE, TRUE); $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", TRUE, TRUE, TRUE); $cloze =& $this->object->createCloseTextArray(); //print_r($cloze); $cloze_text = $cloze["delimiters"]; //print_r($cloze); $counter = 0; foreach ($cloze_text as $delimiter) { $template->setCurrentBlock("cloze_text"); $template->setVariable("CLOZE_TEXT", $this->object->prepareTextareaOutput($delimiter[0], TRUE)); $template->parseCurrentBlock(); $ssc = $this->object->_getSuggestedSolutionCount($this->object->getId()); $gap = $this->object->getGap($counter); $filledgap = FALSE; foreach ($user_solution as $solution) { if (strcmp($solution["value1"], $counter) == 0) { $filledgap = TRUE; if ($active_id) { if ($graphicalOutput) { // output of ok/not ok icons for user entered solutions $check = $this->object->testGapSolution($solution["value2"], $gap); if ($check["best"]) { $template->setCurrentBlock("icon_ok"); $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif")); $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right")); $template->parseCurrentBlock(); } else { $template->setCurrentBlock("icon_not_ok"); if ($check["positive"]) { $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif")); $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive")); } else { $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif")); $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong")); } $template->parseCurrentBlock(); } } if ($ssc > 0) { $ss = $this->object->_getSuggestedSolution($this->object->getId(), $gap_index); if (count($ss)) { $template->setCurrentBlock("solution_hint"); $template->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint")); $template->setVariable("URL_SOLUTION_HINT", $this->object->_getInternalLinkHref($ss["internal_link"])); $template->parseCurrentBlock(); } } } if ($result_output) { $points = $this->object->getMaximumGapPoints($solution["value1"]); $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")"; $template->setCurrentBlock("result_output"); $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points)); $template->parseCurrentBlock(); } $template->setCurrentBlock("solution"); if ((strlen($solution["value2"])) && ($gap[0]->getClozeType() == CLOZE_SELECT)) { if (array_key_exists($solution["value2"], $gap)) { $template->setVariable("SOLUTION", $gap[$solution["value2"]]->getAnswertext()); } } else { $template->setVariable("SOLUTION", $solution["value2"]); } $template->parseCurrentBlock(); } } if (count($gap) && !$filledgap) { if ($graphicalOutput) { $template->setCurrentBlock("icon_not_ok"); $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif")); $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong")); $template->parseCurrentBlock(); } if ($result_output) { $points = 0; $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")"; $template->setCurrentBlock("result_output"); $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points)); $template->parseCurrentBlock(); } $template->setCurrentBlock("solution"); $fillspace = ""; for ($chars = 0; $chars < $this->object->getColumnSize($gap); $chars++) { $fillspace .= " "; } $template->setVariable("SOLUTION", $fillspace); $template->parseCurrentBlock(); } $template->parseCurrentBlock(); $template->touchBlock("cloze_part"); $counter++; } $questionoutput = $template->get(); $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput); $solutionoutput = $solutiontemplate->get(); if (!$show_question_only) { // get page object output $pageoutput = $this->getILIASPage(); $solutionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $solutionoutput, $pageoutput); } return $solutionoutput; }
assClozeTestGUI::getTestOutput | ( | $ | active_id, | |
$ | pass = NULL , |
|||
$ | is_postponed = FALSE , |
|||
$ | use_post_solutions = FALSE | |||
) |
Definition at line 813 of file class.assClozeTestGUI.php.
References $counter, ilObjTest::_getHidePreviousResults(), ilObjTest::_getPass(), assQuestionGUI::outQuestionPage(), and ilUtil::prepareFormOutput().
Referenced by outQuestionForTest().
{ // get page object output $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id); // get the solution of the user for the active pass or from the last pass if allowed $user_solution = array(); if ($active_id) { include_once "./assessment/classes/class.ilObjTest.php"; if (ilObjTest::_getHidePreviousResults($active_id, true)) { if (is_null($pass)) $pass = ilObjTest::_getPass($active_id); } $user_solution =& $this->object->getSolutionValues($active_id, $pass); if (!is_array($user_solution)) { $user_solution = array(); } } // generate the question output include_once "./classes/class.ilTemplate.php"; $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, TRUE); $cloze =& $this->object->createCloseTextArray(); //print_r($cloze); $cloze_text = $cloze["delimiters"]; //print_r($cloze); $counter = 0; foreach ($cloze_text as $delimiter) { $template->setCurrentBlock("cloze_text"); $template->setVariable("CLOZE_TEXT", $this->object->prepareTextareaOutput($delimiter[0], TRUE)); $template->parseCurrentBlock(); $gap = $this->object->getGap($counter); if ($gap) { if ($gap[0]->getClozeType() == CLOZE_SELECT) { // shuffle output $gkeys = array_keys($gap); if ($gap[0]->getShuffle()) { $gkeys = $this->object->pcArrayShuffle($gkeys); } // add answers foreach ($gkeys as $index) { $answer = $gap[$index]; $template->setCurrentBlock("select_gap_option"); $template->setVariable("SELECT_GAP_VALUE", $index); $template->setVariable("SELECT_GAP_TEXT", $answer->getAnswertext()); foreach ($user_solution as $solution) { if (strcmp($solution["value1"], $counter) == 0) { if (strcmp($solution["value2"], $index) == 0) { $template->setVariable("SELECT_GAP_SELECTED", " selected=\"selected\""); } } } $template->parseCurrentBlock(); } $template->setCurrentBlock("select_gap"); $template->setVariable("GAP_COUNTER", $counter); $template->setVariable("PLEASE_SELECT", $this->lng->txt("please_select")); $template->parseCurrentBlock(); } else { $template->setCurrentBlock("text_gap"); $template->setVariable("GAP_COUNTER", $counter); foreach ($user_solution as $solution) { if (strcmp($solution["value1"], $counter) == 0) { $template->setVariable("VALUE_GAP", " value=\"" . ilUtil::prepareFormOutput($solution["value2"]) . "\""); } } $template->setVariable("TEXT_GAP_SIZE", $this->object->getColumnSize($gap)); $template->parseCurrentBlock(); } } $template->touchBlock("cloze_part"); $counter++; } $questionoutput = $template->get(); $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput); return $questionoutput; }
assClozeTestGUI::outQuestionForTest | ( | $ | formaction, | |
$ | active_id, | |||
$ | pass = NULL , |
|||
$ | is_postponed = FALSE , |
|||
$ | use_post_solutions = FALSE | |||
) |
Definition at line 568 of file class.assClozeTestGUI.php.
References getTestOutput().
{ $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions); $this->tpl->setVariable("QUESTION_OUTPUT", $test_output); $this->tpl->setVariable("FORMACTION", $formaction); }
assClozeTestGUI::removeSuggestedSolution | ( | ) |
Reimplemented from assQuestionGUI.
Definition at line 956 of file class.assClozeTestGUI.php.
References $_POST, $key, and editQuestion().
{ $removeFromGap = -1; foreach ($_POST["cmd"] as $key => $value) { if (preg_match("/removeSuggestedSolution_(\d+)/", $key, $matches)) { $removeFromGap = $matches[1]; } } if ($removeFromGap > -1) { unset($this->object->suggested_solutions[$removeFromGap]); } $this->object->saveToDb(); $this->editQuestion(); }
assClozeTestGUI::setGapValues | ( | $ | a_apply_text = true |
) |
Definition at line 464 of file class.assClozeTestGUI.php.
References $_POST, $key, $result, and ilUtil::stripSlashes().
Referenced by createGaps(), and writePostData().
{ //echo "<br>SETGapValues:$a_apply_text:"; $result = 0; foreach ($_POST as $key => $value) { // Set gap values if (preg_match("/textgap_(\d+)_(\d+)/", $key, $matches)) { $answer_array = $this->object->getGap($matches[1]); if (strlen($value) > 0) { // Only change gap values <> empty string if (array_key_exists($matches[2], $answer_array)) { if ($a_apply_text) { if (strcmp($value, $answer_array[$matches[2]]->getAnswertext()) != 0) { $this->object->setAnswertext( ilUtil::stripSlashes($matches[1]), ilUtil::stripSlashes($matches[2]), ilUtil::stripSlashes($value) ); } $points = $_POST["points_$matches[1]_$matches[2]"]; $this->object->setSingleAnswerPoints($matches[1], $matches[2], $points); $this->object->setSingleAnswerState($matches[1], $matches[2], 1); } else { if (strcmp($value, $answer_array[$matches[2]]->getAnswertext()) == 0) { $points = $_POST["points_$matches[1]_$matches[2]"]; $this->object->setSingleAnswerPoints($matches[1], $matches[2], $points); $this->object->setSingleAnswerState($matches[1], $matches[2], 1); } } } } else { // Display errormessage: You've tried to set an gap value to an empty string! } } if (preg_match("/selectgap_(\d+)_(\d+)/", $key, $matches)) { $answer_array = $this->object->getGap($matches[1]); if (strlen($value) > 0) { // Only change gap values <> empty string if (array_key_exists($matches[2], $answer_array)) { if (strcmp($value, $answer_array[$matches[2]]->getAnswertext()) != 0) { if ($a_apply_text) { $this->object->setAnswertext( ilUtil::stripSlashes($matches[1]), ilUtil::stripSlashes($matches[2]), ilUtil::stripSlashes($value) ); } } $points = $_POST["points_$matches[1]_$matches[2]"]; $this->object->setSingleAnswerPoints($matches[1], $matches[2], $points); $this->object->setSingleAnswerState($matches[1], $matches[2], 1); } } else { // Display errormessage: You've tried to set an gap value to an empty string! } } } return $result; }
assClozeTestGUI::setShuffleState | ( | ) |
Definition at line 543 of file class.assClozeTestGUI.php.
Referenced by createGaps(), and writePostData().
{ foreach ($_POST as $key => $value) { // Set select gap shuffle state if (preg_match("/^shuffle_(\d+)$/", $key, $matches)) { $this->object->setGapShuffle($matches[1], $value); } } }
assClozeTestGUI::writePostData | ( | ) |
Evaluates a posted edit form and writes the form data in the question object.
Evaluates a posted edit form and writes the form data in the question object
Reimplemented from assQuestionGUI.
Definition at line 345 of file class.assClozeTestGUI.php.
References $_GET, $_POST, $key, $result, ilObjAdvancedEditing::_getUsedHTMLTagsAsString(), checkInput(), sendInfo(), setGapValues(), setShuffleState(), ilUtil::stripSlashes(), and assQuestionGUI::writeOtherPostData().
Referenced by addSelectGap(), addSuggestedSolution(), addTextGap(), createGaps(), and delete().
{ $result = 0; $saved = false; // Delete all existing gaps and create new gaps from the form data $this->object->flushGaps(); if (!$this->checkInput()) { $result = 1; } if (($result) and ($_POST["cmd"]["add"])) { // You cannot create gaps before you enter the required data sendInfo($this->lng->txt("fill_out_all_required_fields_create_gaps")); $_POST["cmd"]["add"] = ""; } $this->object->setTitle(ilUtil::stripSlashes($_POST["title"])); $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"])); $this->object->setComment(ilUtil::stripSlashes($_POST["comment"])); $this->object->setTextgapRating($_POST["textgap_rating"]); include_once "./classes/class.ilObjAdvancedEditing.php"; $cloze_text = ilUtil::stripSlashes($_POST["clozetext"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")); $this->object->setClozeText($cloze_text); // adding estimated working time $saved = $saved | $this->writeOtherPostData($result); $this->object->suggested_solutions = array(); foreach ($_POST as $key => $value) { if (preg_match("/^solution_hint_(\d+)/", $key, $matches)) { if ($value) { $this->object->setSuggestedSolution($value, $matches[1]); } } } if ($this->ctrl->getCmd() != "createGaps") { $result = $this->setGapValues(); $this->setShuffleState(); foreach ($_POST as $key => $value) { // Set the cloze type of the gap if (preg_match("/clozetype_(\d+)/", $key, $matches)) { $this->object->setClozeType($matches[1], $value); } } } $this->object->updateAllGapParams(); if ($saved) { // If the question was saved automatically before an upload, we have to make // sure, that the state after the upload is saved. Otherwise the user could be // irritated, if he presses cancel, because he only has the question state before // the upload process. $this->object->saveToDb(); $_GET["q_id"] = $this->object->getId(); } return $result; }