ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMatchingPairWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
23
32{
33 protected $pairs = [];
34 protected $allowMove = false;
35 protected $terms = [];
36 protected $definitions = [];
37
39 protected GlyphFactory $glyph_factory;
41
48 public function __construct($a_title = "", $a_postvar = "")
49 {
50 parent::__construct($a_title, $a_postvar);
51
52 global $DIC;
53
54 $this->forms_helper = new ilTestLegacyFormsHelper();
55 $this->glyph_factory = $DIC->ui()->factory()->symbol()->glyph();
56 $this->renderer = $DIC->ui()->renderer();
57 }
58
59 public function setValue($a_value): void
60 {
61 $this->pairs = [];
62 $this->terms = [];
63 $this->definitions = [];
64
65 $to_int = $this->refinery->kindlyTo()->int();
66 $points = $this->forms_helper->transformPoints($a_value);
67 $terms = $this->forms_helper->transformArray($a_value, 'term', $to_int);
68 $definitions = $this->forms_helper->transformArray($a_value, 'definition', $to_int);
69
70 foreach ($terms as $index => $term) {
71 $this->pairs[] = new assAnswerMatchingPair(
72 new assAnswerMatchingTerm('', '', $term),
73 new assAnswerMatchingDefinition('', '', $definitions[$index] ?? 0),
74 $points[$index]
75 );
76 }
77
78 $term_ids = explode(',', $a_value['term_id']);
79 foreach ($term_ids as $id) {
80 $this->terms[] = new assAnswerMatchingTerm('', '', (int) $id);
81 }
82
83 $definition_ids = explode(',', $a_value['definition_id']);
84 foreach ($definition_ids as $id) {
85 $this->definitions[] = new assAnswerMatchingDefinition('', '', (int) $id);
86 }
87 }
88
94 public function setTerms($a_terms): void
95 {
96 $this->terms = $a_terms;
97 }
98
104 public function setDefinitions($a_definitions): void
105 {
106 $this->definitions = $a_definitions;
107 }
108
114 public function setPairs($a_pairs): void
115 {
116 $this->pairs = $a_pairs;
117 }
118
124 public function setAllowMove($a_allow_move): void
125 {
126 $this->allowMove = $a_allow_move;
127 }
128
134 public function getAllowMove(): bool
135 {
136 return $this->allowMove;
137 }
138
143 public function checkInput(): bool
144 {
145 $to_int = $this->refinery->kindlyTo()->int();
146 $data = $this->raw($this->getPostVar());
147
148 if (!is_array($data)) {
149 $this->setAlert($this->lng->txt('msg_input_is_required'));
150 return false;
151 }
152
153 // check points
154 $result_points = $this->forms_helper->checkPointsInputEnoughPositive($data, true);
155 if (!is_array($result_points)) {
156 $this->setAlert($this->lng->txt($result_points));
157 return false;
158 }
159
160 // check answers
161 $terms = $this->forms_helper->transformArray($data, 'term', $to_int);
162 $definitions = $this->forms_helper->transformArray($data, 'definition', $to_int);
163 foreach ([$terms, $definitions] as $value) {
164 if ($value < 1 && $this->getRequired()) {
165 $this->setAlert($this->lng->txt('msg_input_is_required'));
166 return false;
167 }
168 }
169
170 return $this->checkSubItemsInput();
171 }
172
177 public function insert(ilTemplate $a_tpl): void
178 {
179 global $DIC;
180 $lng = $DIC['lng'];
181 $global_tpl = $DIC['tpl'];
182 $global_tpl->addJavascript("assets/js/answerwizardinput.js");
183 $global_tpl->addJavascript("assets/js/matchingpairwizard.js");
184
185 $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "components/ILIAS/TestQuestionPool");
186 $i = 0;
187
188 foreach ($this->pairs as $pair) {
189 $counter = 1;
190 $tpl->setCurrentBlock("option_term");
191 $tpl->setVariable("TEXT_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($lng->txt('please_select')));
192 $tpl->setVariable("VALUE_OPTION", 0);
193 $tpl->parseCurrentBlock();
194 foreach ($this->terms as $term) {
195 $tpl->setCurrentBlock("option_term");
196 $tpl->setVariable("VALUE_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($term->getIdentifier()));
197 $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
198 if ($pair->getTerm()->getIdentifier() == $term->getIdentifier()) {
199 $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
200 }
201 $tpl->parseCurrentBlock();
202 $counter++;
203 }
204 $counter = 1;
205 $tpl->setCurrentBlock("option_definition");
206 $tpl->setVariable("TEXT_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($lng->txt('please_select')));
207 $tpl->setVariable("VALUE_OPTION", 0);
208 $tpl->parseCurrentBlock();
209 foreach ($this->definitions as $definition) {
210 $tpl->setCurrentBlock("option_definition");
211 $tpl->setVariable("VALUE_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($definition->getIdentifier()));
212 $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
213 if ($pair->getDefinition()->getIdentifier() == $definition->getIdentifier()) {
214 $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
215 }
216 $tpl->parseCurrentBlock();
217 $counter++;
218 }
219
220
221 $tpl->setCurrentBlock('points_value');
222 $tpl->setVariable('POINTS_VALUE', $pair->getPoints());
223 $tpl->parseCurrentBlock();
224
225 if ($this->getAllowMove()) {
226 $tpl->setCurrentBlock("move");
227 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
228 $tpl->setVariable("UP_BUTTON", $this->renderer->render(
229 $this->glyph_factory->up()->withAction('#')
230 ));
231 $tpl->setVariable("DOWN_BUTTON", $this->renderer->render(
232 $this->glyph_factory->down()->withAction('#')
233 ));
234 $tpl->parseCurrentBlock();
235 }
236
237 $tpl->setCurrentBlock("row");
238 $tpl->setVariable("ROW_NUMBER", $i);
239
240 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
241 $tpl->setVariable("ADD_BUTTON", $this->renderer->render(
242 $this->glyph_factory->add()->withAction('#')
243 ));
244 $tpl->setVariable("REMOVE_BUTTON", $this->renderer->render(
245 $this->glyph_factory->remove()->withAction('#')
246 ));
247
248 $tpl->setVariable("POST_VAR", $this->getPostVar());
249
250 $tpl->parseCurrentBlock();
251
252 $i++;
253 }
254
255 $tpl->setCurrentBlock('term_ids');
256 $ids = [];
257 foreach ($this->terms as $term) {
258 array_push($ids, $term->getIdentifier());
259 }
260 $tpl->setVariable("POST_VAR", $this->getPostVar());
261 $tpl->setVariable("TERM_IDS", join(",", $ids));
262 $tpl->parseCurrentBlock();
263
264 $tpl->setCurrentBlock('definition_ids');
265 $ids = [];
266 foreach ($this->definitions as $definition) {
267 array_push($ids, $definition->getIdentifier());
268 }
269 $tpl->setVariable("POST_VAR", $this->getPostVar());
270 $tpl->setVariable("DEFINITION_IDS", join(",", $ids));
271 $tpl->parseCurrentBlock();
272
273 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
274 $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
275 $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
276 $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
277 $tpl->setVariable("TEXT_ACTIONS", $lng->txt('actions'));
278
279 $a_tpl->setCurrentBlock("prop_generic");
280 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
281 $a_tpl->parseCurrentBlock();
282 }
283}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderer()
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Class for matching question definitions.
Class for matching question pairs.
Class for matching question terms.
ilGlobalTemplateInterface $global_tpl
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 key value pair wizard property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setDefinitions($a_definitions)
Set definitions.
checkInput()
Check input, strip slashes etc.
insert(ilTemplate $a_tpl)
Insert property html.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a text property in a property form.
This is how a factory for glyphs looks like.
Definition: Factory.php:27
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$counter