ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.assFileUploadGUI.php
Go to the documentation of this file.
1<?php
2
34{
35 public const REUSE_FILES_LANGVAR = 'ass_file_upload_reuse_btn';
36 public const REUSE_FILES_ACTION = 'reuse';
37 public const DELETE_FILES_LANGVAR = 'delete';
38 public const DELETE_FILES_ACTION = 'delete';
39 private const HANDLE_FILE_UPLOAD = 'handleFileUpload';
40
49 public function __construct(int $id = -1)
50 {
52
53 $this->object = new assFileUpload();
54 $this->setErrorMessage($this->lng->txt('msg_form_save_error'));
55 if ($id >= 0) {
56 $this->object->loadFromDb($id);
57 }
58 }
59
63 protected function writePostData(bool $always = false): int
64 {
65 if (!$always && $this->editQuestion(true)) {
66 return 1;
67 }
68
72 return 0;
73 }
74
76 {
77 $this->object->setPoints($this->request_data_collector->float('points'));
78 $this->object->setMaxSize($this->request_data_collector->int('maxsize') ?? null);
79
80 $this->object->setAllowedExtensions($this->request_data_collector->string('allowedextensions'));
81 $completion_by_submission = $this->request_data_collector->int('completion_by_submission');
82 $this->object->setCompletionBySubmission($completion_by_submission === 1);
83 }
84
85 public function editQuestion(
86 bool $checkonly = false,
87 ?bool $is_save_cmd = null
88 ): bool {
89 $save = $is_save_cmd ?? $this->isSaveCommand();
90
91 $form = new ilPropertyFormGUI();
92 $this->editForm = $form;
93
94 $form->setFormAction($this->ctrl->getFormAction($this));
95 $form->setTitle($this->outQuestionType());
96 $form->setMultipart(false);
97 $form->setTableWidth("100%");
98 $form->setId("assfileupload");
99
100 $this->addBasicQuestionFormProperties($form);
102
103 $this->populateTaxonomyFormSection($form);
104 $this->addQuestionFormCommandButtons($form);
105
106 $errors = false;
107
108 if ($save) {
109 $form->setValuesByPost();
110 $errors = !$form->checkInput();
111 $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and
112 // we need this if we don't want to have duplication of backslashes
113 if ($errors) {
114 $checkonly = false;
115 }
116 }
117
118 if (!$checkonly) {
119 $this->renderEditForm($form);
120 }
121 return $errors;
122 }
123
125 {
126 $maxsize = new ilNumberInputGUI($this->lng->txt("maxsize"), "maxsize");
127 $maxsize->allowDecimals(false);
128 $maxsize->setValue($this->object->getMaxSize() > 0 ? (string) $this->object->getMaxSize() : null);
129 $maxsize->setInfo($this->lng->txt("maxsize_info"));
130 $maxsize->setSize(10);
131 $maxsize->setMinValue(0);
132 $maxsize->setMaxValue((float) $this->object->determineMaxFilesize());
133 $maxsize->setRequired(false);
134 $form->addItem($maxsize);
135
136 $allowedextensions = new ilTextInputGUI($this->lng->txt("allowedextensions"), "allowedextensions");
137 $allowedextensions->setInfo($this->lng->txt("allowedextensions_info"));
138 $allowedextensions->setValue($this->object->getAllowedExtensions());
139 $allowedextensions->setRequired(false);
140 $form->addItem($allowedextensions);
141
142 $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
143 $points->allowDecimals(true);
144 $points->setValue(
145 is_numeric($this->object->getPoints()) && $this->object->getPoints(
146 ) >= 0 ? $this->object->getPoints() : ''
147 );
148 $points->setRequired(true);
149 $points->setSize(3);
150 $points->setMinValue(0.0);
151 $points->setMinvalueShouldBeGreater(true);
152 $form->addItem($points);
153
154 $subcompl = new ilCheckboxInputGUI($this->lng->txt(
155 'ass_completion_by_submission'
156 ), 'completion_by_submission');
157 $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
158 $subcompl->setValue('1');
159 $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
160 $form->addItem($subcompl);
161 return $form;
162 }
163
164 public function getSolutionOutput(
165 int $active_id,
166 ?int $pass = null,
167 bool $graphical_output = false,
168 bool $result_output = false,
169 bool $show_question_only = true,
170 bool $show_feedback = false,
171 bool $show_correct_solution = false,
172 bool $show_manual_scoring = false,
173 bool $show_question_text = true,
174 bool $show_inline_feedback = true
175 ): string {
176 // get the solution of the user for the active pass or from the last pass if allowed
177 $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", true, true, "components/ILIAS/TestQuestionPool");
178
179 $solutionvalue = "";
180 if (($active_id > 0) && (!$show_correct_solution)) {
181 $solutions = $this->object->getSolutionValues($active_id, $pass);
182
183 $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
184 $table_gui = new assFileUploadFileTableGUI($this, 'gotoquestion');
185 $table_gui->setTitle(
186 $this->lng->txt('already_delivered_files'),
187 'standard/icon_file.svg',
188 $this->lng->txt('already_delivered_files')
189 );
190 $table_gui->setData($files);
191 $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "components/ILIAS/TestQuestionPool");
192 $table_gui->setSelectAllCheckbox("");
193 $table_gui->disable('numinfo');
194 $template->setCurrentBlock("files");
195 $template->setVariable('FILES', $table_gui->getHTML());
196 $template->parseCurrentBlock();
197 }
198
199 if ($this->object->getAllowedExtensions() === '') {
200 $template->setCurrentBlock("allowed_extensions");
201 $template->setVariable("TXT_ALLOWED_EXTENSIONS", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
202 $template->parseCurrentBlock();
203 }
204 $template->setVariable("CMD_UPLOAD", self::HANDLE_FILE_UPLOAD);
205 $template->setVariable("TEXT_UPLOAD", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('upload')));
206 $template->setVariable("TXT_UPLOAD_FILE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_add')));
207 $template->setVariable("TXT_MAX_SIZE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
208
209 if (($active_id > 0) && (!$show_correct_solution)) {
210 $reached_points = $this->object->getReachedPoints($active_id, $pass);
211 if ($graphical_output) {
212 $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_NOT_OK);
213 if ($reached_points == $this->object->getMaximumPoints()) {
214 $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_OK);
215 } elseif ($reached_points > 0) {
216 $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_MOSTLY_OK);
217 }
218 $template->setCurrentBlock("icon_ok");
219 $template->setVariable("ICON_OK", $correctness_icon);
220 $template->parseCurrentBlock();
221 }
222 } else {
223 $reached_points = $this->object->getPoints();
224 }
225
226 if ($result_output) {
227 $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
228 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
229 }
230 if ($show_question_text == true) {
231 $template->setVariable("QUESTIONTEXT", $this->renderLatex($this->object->getQuestionForHTMLOutput()));
232 }
233 $questionoutput = $template->get();
234 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "components/ILIAS/TestQuestionPool");
235 $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getGenericFeedbackOutput((int) $active_id, $pass) : "";
236 if (strlen($feedback)) {
237 $cssClass = (
238 $this->hasCorrectSolution($active_id, $pass) ?
240 );
241
242 $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
243 $solutiontemplate->setVariable("FEEDBACK", ilLegacyFormElementsUtil::prepareTextareaOutput($feedback, true));
244 }
245 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
246 $solutionoutput = $solutiontemplate->get();
247 if (!$show_question_only) {
248 // get page object output
249 $solutionoutput = $this->getILIASPage($solutionoutput);
250 }
251 return $solutionoutput;
252 }
253
254 public function getPreview(
255 bool $show_question_only = false,
256 bool $show_inline_feedback = false
257 ): string {
258 $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "components/ILIAS/TestQuestionPool");
259
260 if (is_object($this->getPreviewSession())) {
261 $files = $this->object->getPreviewFileUploads($this->getPreviewSession());
262 $table_gui = new assFileUploadFileTableGUI(null, $this->getQuestionActionCmd(), 'ilAssQuestionPreview');
263 $table_gui->setTitle(
264 $this->lng->txt('already_delivered_files'),
265 'standard/icon_file.svg',
266 $this->lng->txt('already_delivered_files')
267 );
268 $table_gui->setData($files);
269 // hey: prevPassSolutions - support file reuse with table
270
271 list($lang_var, $cmd) = $this->getCommandButtonLangVarAndAction();
272 $table_gui->initCommand(
273 $lang_var,
274 $cmd,
276 );
277 // hey.
278 $template->setCurrentBlock("files");
279 $template->setVariable('FILES', $table_gui->getHTML());
280 $template->parseCurrentBlock();
281 }
282
283 if ($this->object->getAllowedExtensions() !== '') {
284 $template->setCurrentBlock("allowed_extensions");
285 $template->setVariable("TXT_ALLOWED_EXTENSIONS", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
286 $template->parseCurrentBlock();
287 }
288 $template->setVariable("QUESTIONTEXT", $this->renderLatex($this->object->getQuestionForHTMLOutput()));
289 $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
290 $template->setVariable("TEXT_UPLOAD", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('upload')));
291 $template->setVariable("TXT_UPLOAD_FILE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_add')));
292 $template->setVariable("TXT_MAX_SIZE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
293
294 $questionoutput = $template->get();
295 if (!$show_question_only) {
296 // get page object output
297 $questionoutput = $this->getILIASPage($questionoutput);
298 }
299 return $questionoutput;
300 }
301
302 public function getTestOutput(
303 int $active_id,
304 int $pass,
305 bool $is_question_postponed = false,
306 array|bool $user_post_solutions = false,
307 bool $show_specific_inline_feedback = false
308 ): string {
309 // generate the question output
310 $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "components/ILIAS/TestQuestionPool");
311
312 if ($active_id) {
313 $files = $this->object->getTestOutputSolutions($active_id, $pass);
314 // hey.
315 $table_gui = new assFileUploadFileTableGUI(null, $this->getQuestionActionCmd());
316 $table_gui->setTitle(
317 $this->lng->txt('already_delivered_files'),
318 'standard/icon_file.svg',
319 $this->lng->txt('already_delivered_files')
320 );
321 $table_gui->setData($files);
322
323 list($lang_var, $cmd) = $this->getCommandButtonLangVarAndAction();
324 $table_gui->initCommand(
325 $lang_var,
326 $cmd,
327 $this->getTestPresentationFileTablePostVar()
328 );
329 // hey.
330 $template->setCurrentBlock("files");
331 $template->setVariable('FILES', $table_gui->getHTML());
332 $template->parseCurrentBlock();
333 }
334
335 if ($this->object->getAllowedExtensions() !== '') {
336 $template->setCurrentBlock("allowed_extensions");
337 $template->setVariable("TXT_ALLOWED_EXTENSIONS", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
338 $template->parseCurrentBlock();
339 }
340 $template->setVariable("QUESTIONTEXT", $this->renderLatex($this->object->getQuestionForHTMLOutput()));
341 $template->setVariable("CMD_UPLOAD", self::HANDLE_FILE_UPLOAD);
342 $template->setVariable("TEXT_UPLOAD", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('upload')));
343 $template->setVariable("TXT_UPLOAD_FILE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_add')));
344 $template->setVariable("TXT_MAX_SIZE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
345
346 $questionoutput = $template->get();
347 //if (!$show_question_only) {
348 // get page object output
349 $questionoutput = $this->getILIASPage($questionoutput);
350 //}
351 $questionoutput = $template->get();
352 $pageoutput = $this->outQuestionPage("", $is_question_postponed, $active_id, $questionoutput);
353 return $pageoutput;
354 }
355
356 private function getCommandButtonLangVarAndAction(): array
357 {
358 if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
359 return [self::REUSE_FILES_LANGVAR, self::REUSE_FILES_ACTION];
360 }
361 return [self::DELETE_FILES_LANGVAR, self::DELETE_FILES_ACTION];
362 }
363
364 public function getSpecificFeedbackOutput(array $userSolution): string
365 {
366 $output = "";
368 }
369
380 {
381 return [];
382 }
383
384 protected function getTestPresentationFileTablePostVar(): string
385 {
386 if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
388 }
389
391 }
392 // hey.
393
394 // hey: prevPassSolutions - overwrite common prevPassSolution-Checkbox
395 protected function getPreviousSolutionProvidedMessage(): string
396 {
397 return $this->lng->txt('use_previous_solution_advice_file_upload');
398 }
399
401 {
402 return '';
403 }
404 // hey.
405
406 public function getFormEncodingType(): string
407 {
408 return self::FORM_ENCODING_MULTIPART;
409 }
410
412 {
413 return false;
414 }
415
417 {
418 // points
419 $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
420 $points->allowDecimals(true);
421 $points->setValue(
422 is_numeric($this->object->getPoints()) && $this->object->getPoints(
423 ) >= 0 ? $this->object->getPoints() : ''
424 );
425 $points->setRequired(true);
426 $points->setSize(3);
427 $points->setMinValue(0.0);
428 $points->setMinvalueShouldBeGreater(true);
429 $form->addItem($points);
430
431 $subcompl = new ilCheckboxInputGUI($this->lng->txt(
432 'ass_completion_by_submission'
433 ), 'completion_by_submission');
434 $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
435 $subcompl->setValue(1);
436 $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
437 $form->addItem($subcompl);
438 }
439
444 {
445 $this->object->setPoints((float) str_replace(',', '.', $form->getInput('points')));
446 $this->object->setCompletionBySubmission((bool) $form->getInput('completion_by_submission'));
447 }
448}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
return true
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
__construct(int $id=-1)
assFileUploadGUI constructor
getTestOutput(int $active_id, int $pass, bool $is_question_postponed=false, array|bool $user_post_solutions=false, bool $show_specific_inline_feedback=false)
editQuestion(bool $checkonly=false, ?bool $is_save_cmd=null)
getSolutionOutput(int $active_id, ?int $pass=null, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_inline_feedback=true)
getPreview(bool $show_question_only=false, bool $show_inline_feedback=false)
writePostData(bool $always=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from the request and applies them to the data object.
getSpecificFeedbackOutput(array $userSolution)
Returns the answer specific feedback for the question.
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Adds the question specific forms parts to a question property form gui.
Class for file upload questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
renderEditForm(ilPropertyFormGUI $form)
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
setErrorMessage(string $errormessage)
This class represents a checkbox property in a property form.
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 number property in a property form.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc