ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
36  public function setThumbsWebPathWithPrefix(string $path_including_prefix): void
37  {
38  $this->path_including_prefix = $path_including_prefix;
39  }
40 
41  public function setValue($a_value): void
42  {
43  if (is_array($a_value)) {
44  if (is_array($a_value['points'])) {
45  foreach ($a_value['points'] as $idx => $term) {
46  $this->pairs[$idx]->withPoints($a_value['points'][$idx]);
47  }
48  }
49  }
50  }
51 
52  public function checkInput(): bool
53  {
54  $foundvalues = $_POST[$this->getPostVar()];
55  if (is_array($foundvalues)) {
56  $max = 0;
57  foreach ($foundvalues['points'] as $val) {
58  if ($val > 0) {
59  $max += $val;
60  }
61  if ($this->getRequired() && (strlen($val)) == 0) {
62  $this->setAlert($this->lng->txt("msg_input_is_required"));
63  return false;
64  }
65  }
66  if ($max <= 0) {
67  $this->setAlert($this->lng->txt("enter_enough_positive_points"));
68  return false;
69  }
70  } else {
71  if ($this->getRequired()) {
72  $this->setAlert($this->lng->txt("msg_input_is_required"));
73  return false;
74  }
75  }
76 
77  return $this->checkSubItemsInput();
78  }
79 
80  public function insert(ilTemplate $a_tpl): void
81  {
82  $tpl = new ilTemplate("tpl.prop_matchingpaircorrection_input.html", true, true, "Modules/TestQuestionPool");
83  $i = 0;
84 
85  $term_ids = [];
86  $definition_ids = [];
87  foreach ($this->pairs as $pair) {
88  $tpl->setCurrentBlock('row');
89 
90  foreach ($this->terms as $term) {
91  if ($pair->getTerm()->getIdentifier() !== $term->getIdentifier()) {
92  continue;
93  }
94  $term_ids[] = $term->getIdentifier();
95  if ($term->getText() !== '') {
96  $tpl->setVariable('TERM', ilLegacyFormElementsUtil::prepareTextareaOutput($term->getText(), true, true));
97  }
98  if ($term->getPicture() !== '') {
99  $tpl->setCurrentBlock('term_image');
100  $tpl->setVariable('THUMBNAIL_HREF', $this->path_including_prefix . $term->getPicture());
101  $tpl->setVariable('THUMB_ALT', $this->lng->txt('image'));
102  $tpl->setVariable('THUMB_TITLE', $this->lng->txt('image'));
103  $tpl->parseCurrentBlock();
104  $tpl->setCurrentBlock('row');
105  }
106  break;
107  }
108  foreach ($this->definitions as $definition) {
109  if ($pair->getDefinition()->getIdentifier() !== $definition->getIdentifier()) {
110  continue;
111  }
112  $definition_ids[] = $definition->getIdentifier();
113  if ($definition->getText() !== '') {
114  $tpl->setVariable('DEFINITION', ilLegacyFormElementsUtil::prepareTextareaOutput($definition->getText(), true, true));
115  }
116  if ($definition->getPicture() !== '') {
117  $tpl->setCurrentBlock('definition_image');
118  $tpl->setVariable('THUMBNAIL_HREF', $this->path_including_prefix . $definition->getPicture());
119  $tpl->setVariable('THUMB_ALT', $this->lng->txt('image'));
120  $tpl->setVariable('THUMB_TITLE', $this->lng->txt('image'));
121  $tpl->parseCurrentBlock();
122  $tpl->setCurrentBlock('row');
123  }
124  break;
125  }
126 
127  $tpl->setVariable('POINTS_VALUE', $pair->getPoints());
128  $tpl->setVariable('ROW_NUMBER', $i);
129 
130  $tpl->setVariable('ID', $this->getPostVar() . "[$i]");
131  $tpl->setVariable('POST_VAR', $this->getPostVar());
132 
133  $tpl->parseCurrentBlock();
134 
135  $i++;
136  }
137 
138  $tpl->setCurrentBlock('term_ids');
139  $tpl->setVariable('POST_VAR', $this->getPostVar());
140  $tpl->setVariable('TERM_IDS', join(',', $term_ids));
141  $tpl->parseCurrentBlock();
142 
143  $tpl->setCurrentBlock('definition_ids');
144  $tpl->setVariable('POST_VAR', $this->getPostVar());
145  $tpl->setVariable('DEFINITION_IDS', join(',', $definition_ids));
146  $tpl->parseCurrentBlock();
147 
148  $tpl->setVariable('ELEMENT_ID', $this->getPostVar());
149  $tpl->setVariable('TEXT_POINTS', $this->lng->txt('points'));
150  $tpl->setVariable('TEXT_DEFINITION', $this->lng->txt('definition'));
151  $tpl->setVariable('TEXT_TERM', $this->lng->txt('term'));
152  $tpl->setVariable('TEXT_ACTIONS', $this->lng->txt('actions'));
153 
154  $a_tpl->setCurrentBlock('prop_generic');
155  $a_tpl->setVariable('PROP_GENERIC', $tpl->get());
156  $a_tpl->parseCurrentBlock();
157  }
158 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
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...
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...