ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilEssayKeywordWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
20{
21 public function setValue($a_value): void
22 {
23 $answers = $this->forms_helper->transformArray($a_value, 'answer', $this->refinery->kindlyTo()->string());
24 $points = $this->forms_helper->transformPoints($a_value, 'points');
25 $points_unchecked = $this->forms_helper->transformPoints($a_value, 'points_unchecked');
26
27 $this->values = [];
28 foreach ($answers as $index => $value) {
30 $value,
31 $points[$index] ?? 0.0,
32 $index,
33 $points_unchecked[$index] ?? 0.0
34 );
35 $this->values[] = $answer;
36 }
37 }
38
43 public function checkInput(): bool
44 {
45 $data = $this->raw($this->getPostVar());
46
47 if (!is_array($data)) {
48 $this->setAlert($this->lng->txt('msg_input_is_required'));
49 return false;
50 }
51
52 // check answers
53 $answers = $this->checkAnswersInput($data);
54 if (!is_array($answers)) {
55 $this->setAlert($this->lng->txt($answers));
56 return false;
57 }
58
59 // check points
60 $result = $this->forms_helper->checkPointsInputEnoughPositive($data, true);
61 if (!is_array($result)) {
62 $this->setAlert($this->lng->txt($result));
63 return false;
64 }
65
66 return $this->checkSubItemsInput();
67 }
68
73 public function insert(ilTemplate $a_tpl): void
74 {
75 global $DIC;
76 $lng = $DIC['lng'];
77
78 $tpl = new ilTemplate("tpl.prop_essaykeywordswizardinput.html", true, true, "components/ILIAS/TestQuestionPool");
79 $i = 0;
80 foreach ($this->values as $value) {
81 if ($this->getSingleline()) {
82 if (is_object($value)) {
83 $tpl->setCurrentBlock("prop_text_propval");
84 $tpl->setVariable(
85 "PROPERTY_VALUE",
87 );
88 $tpl->parseCurrentBlock();
89 $tpl->setCurrentBlock("prop_points_propval");
90 $tpl->setVariable(
91 "PROPERTY_VALUE",
93 );
94 $tpl->parseCurrentBlock();
95 }
96 $tpl->setCurrentBlock('singleline');
97 $tpl->setVariable("SIZE", $this->getSize());
98 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
99 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
100 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
101 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
102 if ($this->getDisabled()) {
103 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
104 }
105 $tpl->parseCurrentBlock();
106 } else {
107 if (!$this->getSingleline()) {
108 if (is_object($value)) {
109 $tpl->setCurrentBlock("prop_points_propval");
110 $tpl->setVariable(
111 "PROPERTY_VALUE",
113 );
114 $tpl->parseCurrentBlock();
115 }
116 }
117 }
118
119 $tpl->setCurrentBlock("row");
120 $tpl->setVariable("POST_VAR", $this->getPostVar());
121 $tpl->setVariable("ROW_NUMBER", $i);
122 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
123 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
124 if ($this->getDisabled()) {
125 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
126 }
127 $tpl->setVariable("ADD_BUTTON", $this->renderer->render(
128 $this->glyph_factory->add()->withAction('#')
129 ));
130 $tpl->setVariable("REMOVE_BUTTON", $this->renderer->render(
131 $this->glyph_factory->remove()->withAction('#')
132 ));
133 $tpl->parseCurrentBlock();
134 $i++;
135 }
136
137 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
138 $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
139 $tpl->setVariable("TEXT_NO", $lng->txt('no'));
140 $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
141 $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
142 $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
143 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
144 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
145 $tpl->setVariable("POINTS_CHECKED_TEXT", $lng->txt('checkbox_checked'));
146
147 $a_tpl->setCurrentBlock("prop_generic");
148 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
149 $a_tpl->parseCurrentBlock();
150
151 global $DIC;
152 $tpl = $DIC['tpl'];
153 $tpl->addJavascript("assets/js/answerwizardinput.js");
154 $tpl->addJavascript("assets/js/essaykeywordwizard.js");
155 }
156}
renderer()
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked,...
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
insert(ilTemplate $a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
This class represents a single choice wizard property in a property form.
checkAnswersInput(array $data)
Checks the input of the answers and returns the answers as an array if the input is valid or a string...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
global $DIC
Definition: shib_login.php:26