ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilImagemapCorrectionsInputGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 public function setValueByArray(array $a_values): void
30 {
31 $this->setAreasByArray($a_values[$this->getPostVar()]['coords']);
32 }
33
34 public function setAreasByArray($a_areas): void
35 {
36 $points = $this->forms_helper->transformPoints($a_areas, 'points');
37 $points_unchecked = $this->forms_helper->transformPoints($a_areas, 'points_unchecked');
38
39 foreach (array_keys($this->areas) as $index) {
40 $points_unchecked[$index] = $this->getPointsUncheckedFieldEnabled() && isset($points_unchecked[$index])
41 ? $points_unchecked[$index] : 0.0;
42
43 $this->areas[$index]->setPointsUnchecked($points_unchecked[$index]);
44 $this->areas[$index]->setPoints($points[$index]);
45 }
46 }
47
48 public function checkInput(): bool
49 {
50 $data = $this->raw($this->getPostVar());
51 if (!is_array($data) || !is_array($data['coords'])) {
52 $this->setAlert($this->lng->txt('form_msg_input_is_required'));
53 return false;
54 }
55
56 $result = $this->forms_helper->checkPointsInputEnoughPositive($data['coords'], $this->getRequired());
57 if (!is_array($result)) {
58 if ($result === 'msg_input_is_required') {
59 $this->setAlert($this->lng->txt('form_msg_area_missing_points'));
60 } else {
61 $this->setAlert($this->lng->txt($result));
62 }
63 return false;
64 }
65
66 return true;
67 }
68
69 public function insert(ilTemplate $a_tpl): void
70 {
71 global $DIC;
72 $lng = $DIC['lng'];
73
74 $template = new ilTemplate('tpl.prop_imagemapquestioncorrection_input.html', true, true, 'components/ILIAS/TestQuestionPool');
75
76 if ($this->getImage() !== '') {
77 $template->setCurrentBlock('image');
78 if (count($this->getAreas())) {
79 $preview = new ilImagemapPreview($this->getImagePath() . $this->getValue());
80 foreach ($this->getAreas() as $index => $area) {
81 $preview->addArea($index, $area->getArea(), $area->getCoords(), $area->getAnswertext(), '', '', true, $this->getLineColor());
82 }
83 $preview->createPreview();
84 $imagepath = $this->getImagePathWeb() . $preview->getPreviewFilename($this->getImagePath(), $this->getValue()) . '?img=' . time();
85 $template->setVariable('SRC_IMAGE', $imagepath);
86 } else {
87 $template->setVariable('SRC_IMAGE', $this->getImage());
88 }
89 $template->setVariable('ALT_IMAGE', $this->getAlt());
90 $template->setVariable('POST_VAR_D', $this->getPostVar());
91 $template->parseCurrentBlock();
92 }
93
94 if (is_array($this->getAreas()) && $this->getAreas()) {
95 $counter = 0;
96 foreach ($this->getAreas() as $area) {
97 if ($area->getPoints() !== '') {
98 $template->setCurrentBlock('area_points_value');
99 $template->setVariable('VALUE_POINTS', $area->getPoints());
100 $template->parseCurrentBlock();
101 }
102 if ($this->getPointsUncheckedFieldEnabled()) {
103 if ($area->getPointsUnchecked() !== '') {
104 $template->setCurrentBlock('area_points_unchecked_value');
105 $template->setVariable('VALUE_POINTS_UNCHECKED', $area->getPointsUnchecked());
106 $template->parseCurrentBlock();
107 }
108
109 $template->setCurrentBlock('area_points_unchecked_field');
110 $template->parseCurrentBlock();
111 }
112 $template->setCurrentBlock('row');
113 if ($area->getAnswertext() !== '') {
114 $template->setVariable('ANSWER_AREA', $area->getAnswertext());
115 }
116 $template->setVariable('POST_VAR_R', $this->getPostVar());
117 $template->setVariable('TEXT_SHAPE', strtoupper($area->getArea()));
118 $template->setVariable('VALUE_SHAPE', $area->getArea());
119 $coords = preg_replace("/(\d+,\d+,)/", "\$1 ", $area->getCoords());
120 $template->setVariable('VALUE_COORDINATES', $area->getCoords());
121 $template->setVariable('TEXT_COORDINATES', $coords);
122 $template->setVariable('COUNTER', $counter);
123 $template->parseCurrentBlock();
124 $counter++;
125 }
126 $template->setCurrentBlock('areas');
127 $template->setVariable('TEXT_NAME', $lng->txt('ass_imap_hint'));
128 if ($this->getPointsUncheckedFieldEnabled()) {
129 $template->setVariable('TEXT_POINTS', $lng->txt('points_checked'));
130
131 $template->setCurrentBlock('area_points_unchecked_head');
132 $template->setVariable('TEXT_POINTS_UNCHECKED', $lng->txt('points_unchecked'));
133 $template->parseCurrentBlock();
134 } else {
135 $template->setVariable('TEXT_POINTS', $lng->txt('points'));
136 }
137 $template->setVariable('TEXT_SHAPE', $lng->txt('shape'));
138 $template->setVariable('TEXT_COORDINATES', $lng->txt('coordinates'));
139 $template->setVariable('TEXT_COMMANDS', $lng->txt('actions'));
140 $template->parseCurrentBlock();
141 }
142
143 $template->setVariable('POST_VAR', $this->getPostVar());
144 $template->setVariable('ID', $this->getFieldId());
145 $template->setVariable('TXT_BROWSE', $lng->txt('select_file'));
146 $template->setVariable('TXT_MAX_SIZE', $lng->txt('file_notice') . ' ' .
147 $this->getMaxFileSizeString());
148
149 $a_tpl->setCurrentBlock('prop_generic');
150 $a_tpl->setVariable('PROP_GENERIC', $template->get());
151 $a_tpl->parseCurrentBlock();
152 }
153}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
insert(ilTemplate $a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
setValueByArray(array $a_values)
Set value by array.
This class represents an image map file property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
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
$counter