ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
LongMenu.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30use ILIAS\Data\UUID\Factory as UuidFactory;
36use ILIAS\Refinery\Factory as Refinery;
39use ILIAS\UI\Factory as UIFactory;
41
42class LongMenu extends Type
43{
44 private const int DEFAULT_MIN_AUTOCOMPLETE = 3;
46
47 public function __construct(
50 private readonly GlobalTemplate $global_tpl
51 ) {
53 }
54
55 #[\Override]
56 public function getIdentifier(): string
57 {
58 return 'long_menu';
59 }
60
61 #[\Override]
63 Gap $gap,
64 ?AdditionalAttemptData $additional_attempt_data,
65 ?Response $response_data
66 ): string {
67 $gap_name = $gap->getAnswerInputId()->toString();
68
69 $gaptemplate = new \ilTemplate(
70 'tpl.cloze_gap_longmenu.html',
71 true,
72 true,
73 'components/ILIAS/Questions'
74 );
75
76 $gaptemplate->setVariable(
77 'GAP_NAME',
78 $gap_name
79 );
80
81 $response = $response_data?->getResponseForInput($gap->getAnswerInputId());
82 if ($response !== null) {
83 $gaptemplate->setVariable(
84 'VALUE',
85 htmlentities(
86 $response instanceof Uuid
87 ? $gap->getAnswerOptions()
88 ->getAnswerOptionById($response)
89 ->getTextValue()
90 : $response
91 )
92 );
93 }
94
95 $this->global_tpl->addOnLoadCode('il.questions.cloze.initLongmenuGap('
96 . "document.querySelector('input[name=\"{$gap_name}\"]'), "
97 . "{$gap->getMinAutocomplete()}, "
98 . json_encode(
99 array_values(
100 $gap->getAnswerOptions()->buildArrayForSelectInput(
101 $this->refinery->random()->dontShuffle()
102 )
103 )
104 ) . ')');
105 return $gaptemplate->get();
106 }
107
108 #[\Override]
110 FileUpload $file_upload,
111 Environment $environment,
112 Gap $gap
113 ): array {
114 $ff = $environment->getUIFactory()->input()->field();
115 $inputs = [
116 'answer_options' => $ff->tag(
117 $environment->getLanguage()->txt('answer_options'),
118 []
119 )->withValue($gap->getAnswerOptions()->getTagsArrayFromAnswerOptions()),
120 'upload_answer_options' => $ff->file(
121 new Upload(
122 $file_upload,
123 $environment
124 ),
125 $environment->getLanguage()->txt('upload_answer_options'),
126 $environment->getLanguage()->txt('upload_answer_options_info')
127 )->withAcceptedMimeTypes(self::ACCEPTED_MIME_TYPES),
128 'min_autocomplete' => $ff->numeric(
129 $environment->getLanguage()->txt('min_auto_complete')
130 )->withRequired(true)
131 ->withValue($gap->getMinAutocomplete() ?? self::DEFAULT_MIN_AUTOCOMPLETE)
132 ];
133
134 if ($environment->isMarkingRequired()) {
135 $inputs['options_awarding_points'] = $ff->tag(
136 $environment->getLanguage()->txt('answer_options_awarding_points'),
137 $gap->getAnswerOptions()->getTagsArrayFromAnswerOptions()
138 )->withRequired(true)
139 ->withValue(
140 array_values(
141 array_map(
142 fn(AnswerOption $v): string => $v->getTextValue(),
143 $gap->getAnswerOptions()->getAnswerOptionsAwardingPoints()
144 )
145 )
146 );
147 }
148
149 return $inputs;
150 }
151
152 #[\Override]
154 {
155 return $this->refinery->custom()->constraint(
156 function (array $vs): bool {
157 $values = [
158 ...$vs['answer_options'],
159 ...$this->retrieveAnswerOptionsArrayFromUpload(
160 $vs['upload_answer_options']
161 )
162 ];
163
164 return $values !== [] && array_filter(
165 $vs['options_awarding_points'],
166 fn(string $v): bool => !in_array($v, $values)
167 ) === [];
168 },
169 $this->lng->txt('error')
170 );
171 }
172 #[\Override]
173 public function getEditPointsInputs(
174 UIFactory $ui_factory,
175 AnswerOptions $answer_options,
176 bool $input_required
177 ): array {
178 return $answer_options->getEditPointsInputs(
179 $ui_factory->input()->field(),
180 fn(AnswerOption $v): string => $v->getTextValue(),
181 $answer_options->getAnswerOptionsAwardingPoints()
182 );
183 }
184
185 #[\Override]
187 bool $input_required
188 ): ?Constraint {
189 if (!$input_required) {
190 return null;
191 }
192
193 return $this->refinery->custom()->constraint(
194 function (array $vs): bool {
195 foreach ($vs as $v) {
196 if ($v > 0.0) {
197 return true;
198 }
199 }
200 return false;
201 },
202 $this->lng->txt('at_least_one_gap_positiv_points')
203 );
204 }
205
206 #[\Override]
208 Gap $gap
209 ): Transformation {
210 return $this->refinery->custom()->transformation(
211 fn(array $vs): Gap => $gap
212 ->withMinAutocomplete($vs['min_autocomplete'])
213 ->withAnswerOptions(
214 $gap->getAnswerOptions()->withAnswerOptionsFromTags(
215 [
216 ...$vs['answer_options'],
217 ...$this->retrieveAnswerOptionsArrayFromUpload(
218 $vs['upload_answer_options']
219 )
220 ]
221 )->withAnswerOptionsAwardingPoints($vs['options_awarding_points'])
222 )
223 );
224 }
225
226 #[\Override]
228 RequestWrapper $post_wrapper,
229 UuidFactory $uuid_factory,
230 Gap $gap
231 ): AnswerInputResponse {
232 $response_value = $this->retrieveResponseValueFromPost(
233 $post_wrapper,
234 $uuid_factory,
235 $gap
236 );
237
238 $response_is_uuid = $response_value instanceof Uuid;
239
240 return new AnswerInputResponse(
241 $gap,
242 $response_is_uuid
243 ? $response_value
244 : null,
245 $response_is_uuid
246 ? ''
247 : $response_value
248 );
249 }
250
252 ?array $upload_value
253 ): array {
254 if ($upload_value === null
255 || ($decoded_value = base64_decode($upload_value[0] ?? '')) === '') {
256 return [];
257 }
258
259 return array_filter(
260 mb_split('\R', $decoded_value)
261 );
262 }
263
265 RequestWrapper $post_wrapper,
266 UuidFactory $uuid_factory,
267 Gap $gap
268 ): Uuid|string {
269 return $post_wrapper->retrieve(
270 $gap->getAnswerInputId()->toString(),
271 $this->refinery->byTrying([
272 $this->refinery->custom()->transformation(
273 function (?string $v) use ($gap): Uuid|string {
274 if ($v === null) {
275 return '';
276 }
277
278 $answer_option = $gap->getAnswerOptions()
279 ->getAnswerOptionByTextValue($v);
280
281 if ($answer_option === null) {
282 return $v;
283 }
284
285 return $answer_option?->getAnswerOptionId();
286 }
287 ),
288 $this->refinery->always('')
289 ])
290 );
291 }
292}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Mime type determination.
Definition: MimeType.php:30
getEditAnswerOptionsInputs(FileUpload $file_upload, Environment $environment, Gap $gap)
Definition: LongMenu.php:109
getParticipantViewLegacyInput(Gap $gap, ?AdditionalAttemptData $additional_attempt_data, ?Response $response_data)
Definition: LongMenu.php:62
getEditPointsInputs(UIFactory $ui_factory, AnswerOptions $answer_options, bool $input_required)
Definition: LongMenu.php:173
retrieveResponseValueFromPost(RequestWrapper $post_wrapper, UuidFactory $uuid_factory, Gap $gap)
Definition: LongMenu.php:264
retrieveResponseFromPost(RequestWrapper $post_wrapper, UuidFactory $uuid_factory, Gap $gap)
Definition: LongMenu.php:227
__construct(Language $lng, Refinery $refinery, private readonly GlobalTemplate $global_tpl)
Definition: LongMenu.php:47
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface RequestWrapper.
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
A transformation is a function from one datatype to another.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))
$response
Definition: xapitoken.php:92