19 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
52 $this->
object->loadFromDb(
$id);
65 $this->answers_from_post = $_POST[
'answers'][
'answer'];
66 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
86 $this->editForm = $form;
88 $form->setFormAction($this->
ctrl->getFormAction($this));
90 $form->setMultipart(
false);
91 $form->setTableWidth(
"100%");
92 $form->setId(
"asstextsubset");
102 $form->setValuesByPost();
103 $points = $form->getItemByPostVar(
'points');
104 $points->setValue($this->
object->getMaximumPoints());
105 $errors = !$form->checkInput();
106 $form->setValuesByPost();
113 $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
124 $position = key($_POST[
'cmd'][
'addanswers']);
125 $this->
object->addAnswer(
"", 0, $position + 1);
135 $position = key($_POST[
'cmd'][
'removeanswers']);
136 $this->
object->deleteAnswer($position);
155 $graphicalOutput =
false,
156 $result_output =
false,
157 $show_question_only =
true,
158 $show_feedback =
false,
159 $show_correct_solution =
false,
160 $show_manual_scoring =
false,
161 $show_question_text =
true 164 $solutions = array();
165 if (($active_id > 0) && (!$show_correct_solution)) {
166 $solutions = $this->
object->getSolutionValues($active_id, $pass);
169 foreach ($this->
object->answers as $answer) {
170 $points_string_for_key = (string) $answer->getPoints();
171 if ($answer->getPoints() > 0) {
172 if (!array_key_exists($points_string_for_key, $rank)) {
173 $rank[$points_string_for_key] = array();
175 array_push($rank[$points_string_for_key], $answer->getAnswertext());
178 krsort($rank, SORT_NUMERIC);
179 foreach ($rank as
$index => $bestsolutions) {
180 array_push($solutions, array(
"value1" => join(
",", $bestsolutions),
"points" =>
$index));
184 $template =
new ilTemplate(
"tpl.il_as_qpl_textsubset_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
185 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
186 $available_answers = &$this->
object->getAvailableAnswers();
187 for (
$i = 0;
$i < $this->
object->getCorrectAnswers();
$i++) {
188 if (!array_key_exists(
$i, $solutions) || (strcmp($solutions[
$i][
"value1"],
"") == 0)) {
190 if (($active_id > 0) && (!$show_correct_solution)) {
191 if ($graphicalOutput) {
193 $index = $this->
object->isAnswerCorrect($available_answers, $solutions[$i][
"value1"]);
196 unset($available_answers[
$index]);
204 $template->setCurrentBlock(
"icon_ok");
205 $template->setVariable(
"ICON_OK", $correctness_icon);
206 $template->parseCurrentBlock();
209 $template->setCurrentBlock(
"textsubset_row");
211 $template->setVariable(
"COUNTER", $i + 1);
212 if ($result_output) {
213 $points = $solutions[
$i][
"points"];
214 $resulttext = ($points == 1) ?
"(%s " . $this->
lng->txt(
"point") .
")" :
"(%s " . $this->
lng->txt(
"points") .
")";
215 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
217 $template->parseCurrentBlock();
220 if ($show_question_text ==
true) {
221 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
223 $questionoutput = $template->get();
225 if (strlen($feedback)) {
231 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
232 $solutiontemplate->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($feedback,
true));
234 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
236 $solutionoutput = $solutiontemplate->get();
237 if (!$show_question_only) {
241 return $solutionoutput;
244 public function getPreview($show_question_only =
false, $showInlineFeedback =
false): string
247 $template =
new ilTemplate(
"tpl.il_as_qpl_textsubset_output.html",
true,
true,
"Modules/TestQuestionPool");
248 $width = $this->
object->getMaxTextboxWidth();
249 for (
$i = 0;
$i < $this->
object->getCorrectAnswers();
$i++) {
250 $template->setCurrentBlock(
"textsubset_row");
251 foreach ($solutions as $idx => $solution_value) {
253 $template->setVariable(
"TEXTFIELD_VALUE",
" value=\"" 258 $template->setVariable(
"COUNTER",
$i + 1);
259 $template->setVariable(
"TEXTFIELD_ID",
$i);
260 $template->setVariable(
"TEXTFIELD_SIZE", $width);
261 $template->parseCurrentBlock();
263 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
264 $questionoutput = $template->get();
265 if (!$show_question_only) {
269 return $questionoutput;
272 public function getTestOutput($active_id, $pass = null, $is_postponed =
false, $use_post_solutions =
false, $inlineFeedback =
false): string
277 $solutions = $this->
object->getUserSolutionPreferingIntermediate($active_id, $pass);
280 $template =
new ilTemplate(
"tpl.il_as_qpl_textsubset_output.html",
true,
true,
"Modules/TestQuestionPool");
281 $width = $this->
object->getMaxTextboxWidth();
282 for (
$i = 0;
$i < $this->
object->getCorrectAnswers();
$i++) {
283 $template->setCurrentBlock(
"textsubset_row");
284 foreach ($solutions as $idx => $solution_value) {
286 $template->setVariable(
"TEXTFIELD_VALUE",
" value=\"" 291 $template->setVariable(
"COUNTER",
$i + 1);
292 $template->setVariable(
"TEXTFIELD_ID",
$i);
293 $template->setVariable(
"TEXTFIELD_SIZE", $width);
294 $template->parseCurrentBlock();
296 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
297 $questionoutput = $template->get();
298 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
305 return $this->
object->prepareTextareaOutput($output,
true);
310 $this->
object->setCorrectAnswers($_POST[
"correctanswers"]);
311 $this->
object->setTextRating($_POST[
"text_rating"]);
317 $this->
object->flushAnswers();
318 foreach ($this->answers_from_post as
$index => $answertext) {
320 $this->
object->addAnswer(htmlentities($answertext), $_POST[
'answers'][
'points'][
$index], $index);
327 $correctanswers =
new ilNumberInputGUI($this->
lng->txt(
"nr_of_correct_answers"),
"correctanswers");
329 $correctanswers->setDecimals(0);
330 $correctanswers->setSize(3);
331 $correctanswers->setValue($this->
object->getCorrectAnswers());
332 $correctanswers->setRequired(
true);
333 $form->
addItem($correctanswers);
338 $points->setMinvalueShouldBeGreater(
true);
340 $points->setDisabled(
true);
341 $points->allowDecimals(
true);
342 $points->setValue($this->
object->getMaximumPoints());
343 $points->setRequired(
false);
348 $text_options = array(
349 "ci" => $this->
lng->txt(
"cloze_textgap_case_insensitive"),
350 "cs" => $this->
lng->txt(
"cloze_textgap_case_sensitive")
352 if (!$this->
object->getSelfAssessmentEditingMode()) {
353 $text_options[
"l1"] = sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"1");
354 $text_options[
"l2"] = sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"2");
355 $text_options[
"l3"] = sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"3");
356 $text_options[
"l4"] = sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"4");
357 $text_options[
"l5"] = sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"5");
360 $textrating->setValue($this->
object->getTextRating());
369 $choices->setQuestionObject($this->
object);
370 $choices->setSingleline(
true);
371 $choices->setAllowMove(
false);
372 $choices->setMinValue(0.0);
373 if ($this->
object->getAnswerCount() == 0) {
374 $this->
object->addAnswer(
"", 0, 0);
376 $choices->setValues(array_map(
378 $value->setAnswerText(html_entity_decode($value->getAnswerText()));
381 $this->
object->getAnswers()
431 $aggregate = array();
433 foreach ($relevant_answers_chosen as $relevant_answer) {
434 if (array_key_exists($relevant_answer[
'value1'], $aggregate)) {
435 $aggregate[$relevant_answer[
'value1']]++;
437 $aggregate[$relevant_answer[
'value1']] = 1;
450 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
452 foreach ($aggregate as
$key => $value) {
465 foreach ($relevantAnswers as $ans) {
466 if (!isset($answers[$ans[
'value1']])) {
467 $answers[$ans[
'value1']] = array(
468 'answer' => $ans[
'value1'],
'frequency' => 0
472 $answers[$ans[
'value1']][
'frequency']++;
480 foreach ($answers as
$key => $ans) {
483 foreach ($this->
object->getAnswers() as $item) {
484 if ($ans[
'answer'] !== $item->getAnswerText()) {
493 $answers[
$key][
'addable'] =
true;
504 $choices->setQuestionObject($this->
object);
505 $choices->setValues($this->
object->getAnswers());
515 $values = $input->getValues();
517 foreach ($this->
object->getAnswers() as
$index => $answer) {
518 $points = (float) str_replace(
',',
'.', $values[$index]->getPoints());
519 $answer->setPoints($points);
isTestPresentationContext()
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
hasCorrectSolution($activeId, $passIndex)
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
generateCorrectnessIconsForCorrectness(int $correctness)
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
getPreview($show_question_only=false, $showInlineFeedback=false)
getSolutionOutput( $active_id, $pass=null, $graphicalOutput=false, $result_output=false, $show_question_only=true, $show_feedback=false, $show_correct_solution=false, $show_manual_scoring=false, $show_question_text=true)
Get the question solution output.
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getSpecificFeedbackOutput(array $userSolution)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
escapeTemplatePlaceholders(string $text)
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CSS_CLASS_FEEDBACK_CORRECT
ilGlobalPageTemplate $tpl
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
removeanswers()
Remove an answer.
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
getAnswersFrequency($relevantAnswers, $questionIndex)
writeQuestionGenericPostData()
renderAggregateView($aggregate)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
const CSS_CLASS_FEEDBACK_WRONG
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
getTestOutput($active_id, $pass=null, $is_postponed=false, $use_post_solutions=false, $inlineFeedback=false)
saveTaxonomyAssignments()
static extendedTrim(string $value)
Trim non-printable characters from the beginning and end of a string.
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
getAggregatedAnswersView(array $relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
completeAddAnswerAction($answers, $questionIndex)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct($id=-1)
assTextSubsetGUI constructor
aggregateAnswers($relevant_answers_chosen)
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
addanswers()
Add a new answer.
writePostData(bool $always=false)
{}
getGenericFeedbackOutput(int $active_id, ?int $pass)