ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $this->pairs[$index] = $this->pairs[$index]->withPoints($value);
44 }
45 }
46
47 public function checkInput(): bool
48 {
49 $data = $this->raw($this->getPostVar());
50 $result = $this->forms_helper->checkPointsInput($data, $this->getRequired());
51
52 if (!is_array($result)) {
53 $this->setAlert($this->lng->txt($result));
54 return false;
55 }
56
57 if (max($result) <= 0) {
58 $this->setAlert($this->lng->txt('enter_enough_positive_points'));
59 return false;
60 }
61
62 return $this->checkSubItemsInput();
63 }
64
65 public function insert(ilTemplate $a_tpl): void
66 {
67 $tpl = new ilTemplate('tpl.prop_matchingpaircorrection_input.html', true, true, 'components/ILIAS/TestQuestionPool');
68 $i = 0;
69 $term_ids = [];
70 $definition_ids = [];
71 foreach ($this->pairs as $pair) {
72 $tpl->setCurrentBlock('row');
73
74 foreach ($this->terms as $term) {
75 if ($pair->getTerm()->getIdentifier() !== $term->getIdentifier()) {
76 continue;
77 }
78 $term_ids[] = $term->getIdentifier();
79 if ($term->getText() !== '') {
80 $tpl->setVariable('TERM', ilLegacyFormElementsUtil::prepareTextareaOutput($term->getText(), true, true));
81 }
82 if ($term->getPicture() !== '') {
83 $tpl->setCurrentBlock('term_image');
84 $tpl->setVariable('THUMBNAIL_HREF', $this->path_including_prefix . $term->getPicture());
85 $tpl->setVariable('THUMB_ALT', $this->lng->txt('image'));
86 $tpl->setVariable('THUMB_TITLE', $this->lng->txt('image'));
87 $tpl->parseCurrentBlock();
88 $tpl->setCurrentBlock('row');
89 }
90 break;
91 }
92 foreach ($this->definitions as $definition) {
93 if ($pair->getDefinition()->getIdentifier() !== $definition->getIdentifier()) {
94 continue;
95 }
96 $definition_ids[] = $definition->getIdentifier();
97 if ($definition->getText() !== '') {
98 $tpl->setVariable('DEFINITION', ilLegacyFormElementsUtil::prepareTextareaOutput($definition->getText(), true, true));
99 }
100 if ($definition->getPicture() !== '') {
101 $tpl->setCurrentBlock('definition_image');
102 $tpl->setVariable('THUMBNAIL_HREF', $this->path_including_prefix . $definition->getPicture());
103 $tpl->setVariable('THUMB_ALT', $this->lng->txt('image'));
104 $tpl->setVariable('THUMB_TITLE', $this->lng->txt('image'));
105 $tpl->parseCurrentBlock();
106 $tpl->setCurrentBlock('row');
107 }
108 break;
109 }
110
111 $tpl->setVariable('POINTS_VALUE', $pair->getPoints());
112 $tpl->setVariable('ROW_NUMBER', $i);
113
114 $tpl->setVariable('ID', $this->getPostVar() . "[$i]");
115 $tpl->setVariable('POST_VAR', $this->getPostVar());
116
117 $tpl->parseCurrentBlock();
118
119 $i++;
120 }
121
122 $tpl->setCurrentBlock('term_ids');
123 $tpl->setVariable('POST_VAR', $this->getPostVar());
124 $tpl->setVariable('TERM_IDS', join(',', $term_ids));
125 $tpl->parseCurrentBlock();
126
127 $tpl->setCurrentBlock('definition_ids');
128 $tpl->setVariable('POST_VAR', $this->getPostVar());
129 $tpl->setVariable('DEFINITION_IDS', join(',', $definition_ids));
130 $tpl->parseCurrentBlock();
131
132 $tpl->setVariable('ELEMENT_ID', $this->getPostVar());
133 $tpl->setVariable('TEXT_POINTS', $this->lng->txt('points'));
134 $tpl->setVariable('TEXT_DEFINITION', $this->lng->txt('definition'));
135 $tpl->setVariable('TEXT_TERM', $this->lng->txt('term'));
136 $tpl->setVariable('TEXT_ACTIONS', $this->lng->txt('actions'));
137
138 $a_tpl->setCurrentBlock('prop_generic');
139 $a_tpl->setVariable('PROP_GENERIC', $tpl->get());
140 $a_tpl->parseCurrentBlock();
141 }
142}
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)