ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilAssMatchingPairCorrectionsInputGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 private string $path_including_prefix;
30
31 public function getPairs(): array
32 {
33 return $this->pairs;
34 }
35
37 {
38 $this->path_including_prefix = $path_including_prefix;
39 }
40 public function setValue($a_value): void
41 {
42 foreach ($this->forms_helper->transformPoints($a_value) as $index => $value) {
43 if ($value === null) {
44 return;
45 }
46
47 $this->pairs[$index] = $this->pairs[$index]->withPoints($value);
48 }
49 }
50
51 public function checkInput(): bool
52 {
53 $data = $this->raw($this->getPostVar());
54 $result = $this->forms_helper->checkPointsInput($data, $this->getRequired());
55
56 if (!is_array($result)) {
57 $this->setAlert($this->lng->txt($result));
58 return false;
59 }
60
61 if (max($result) <= 0) {
62 $this->setAlert($this->lng->txt('enter_enough_positive_points'));
63 return false;
64 }
65
66 return $this->checkSubItemsInput();
67 }
68
69 public function insert(ilTemplate $a_tpl): void
70 {
71 $tpl = new ilTemplate('tpl.prop_matchingpaircorrection_input.html', true, true, 'components/ILIAS/TestQuestionPool');
72 $i = 0;
73 $term_ids = [];
74 $definition_ids = [];
75 foreach ($this->pairs as $pair) {
76 $tpl->setCurrentBlock('row');
77
78 foreach ($this->terms as $term) {
79 if ($pair->getTerm()->getIdentifier() !== $term->getIdentifier()) {
80 continue;
81 }
82 $term_ids[] = $term->getIdentifier();
83 if ($term->getText() !== '') {
84 $tpl->setVariable('TERM', ilLegacyFormElementsUtil::prepareTextareaOutput($term->getText(), true, true));
85 }
86 if ($term->getPicture() !== '') {
87 $tpl->setCurrentBlock('term_image');
88 $tpl->setVariable('THUMBNAIL_HREF', $this->path_including_prefix . $term->getPicture());
89 $tpl->setVariable('THUMB_ALT', $this->lng->txt('image'));
90 $tpl->setVariable('THUMB_TITLE', $this->lng->txt('image'));
91 $tpl->parseCurrentBlock();
92 $tpl->setCurrentBlock('row');
93 }
94 break;
95 }
96 foreach ($this->definitions as $definition) {
97 if ($pair->getDefinition()->getIdentifier() !== $definition->getIdentifier()) {
98 continue;
99 }
100 $definition_ids[] = $definition->getIdentifier();
101 if ($definition->getText() !== '') {
102 $tpl->setVariable('DEFINITION', ilLegacyFormElementsUtil::prepareTextareaOutput($definition->getText(), true, true));
103 }
104 if ($definition->getPicture() !== '') {
105 $tpl->setCurrentBlock('definition_image');
106 $tpl->setVariable('THUMBNAIL_HREF', $this->path_including_prefix . $definition->getPicture());
107 $tpl->setVariable('THUMB_ALT', $this->lng->txt('image'));
108 $tpl->setVariable('THUMB_TITLE', $this->lng->txt('image'));
109 $tpl->parseCurrentBlock();
110 $tpl->setCurrentBlock('row');
111 }
112 break;
113 }
114
115 $tpl->setVariable('POINTS_VALUE', $pair->getPoints());
116 $tpl->setVariable('ROW_NUMBER', $i);
117
118 $tpl->setVariable('ID', $this->getPostVar() . "[$i]");
119 $tpl->setVariable('POST_VAR', $this->getPostVar());
120
121 $tpl->parseCurrentBlock();
122
123 $i++;
124 }
125
126 $tpl->setCurrentBlock('term_ids');
127 $tpl->setVariable('POST_VAR', $this->getPostVar());
128 $tpl->setVariable('TERM_IDS', join(',', $term_ids));
129 $tpl->parseCurrentBlock();
130
131 $tpl->setCurrentBlock('definition_ids');
132 $tpl->setVariable('POST_VAR', $this->getPostVar());
133 $tpl->setVariable('DEFINITION_IDS', join(',', $definition_ids));
134 $tpl->parseCurrentBlock();
135
136 $tpl->setVariable('ELEMENT_ID', $this->getPostVar());
137 $tpl->setVariable('TEXT_POINTS', $this->lng->txt('points'));
138 $tpl->setVariable('TEXT_DEFINITION', $this->lng->txt('definition'));
139 $tpl->setVariable('TEXT_TERM', $this->lng->txt('term'));
140 $tpl->setVariable('TEXT_ACTIONS', $this->lng->txt('actions'));
141
142 $a_tpl->setCurrentBlock('prop_generic');
143 $a_tpl->setVariable('PROP_GENERIC', $tpl->get());
144 $a_tpl->parseCurrentBlock();
145 }
146}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
static prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free,...
This class represents a key value pair wizard property in a property form.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)