ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.assFileUploadGUI.php
Go to the documentation of this file.
1 <?php
2 
19 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
20 
36 {
37  public const REUSE_FILES_TBL_POSTVAR = 'reusefiles';
38  public const REUSE_FILES_LANGVAR = 'ass_file_upload_reuse_btn';
39  public const REUSE_FILES_ACTION = 'reuse';
40  public const DELETE_FILES_TBL_POSTVAR = 'deletefiles';
41  public const DELETE_FILES_LANGVAR = 'delete';
42  public const DELETE_FILES_ACTION = 'delete';
43  private const HANDLE_FILE_UPLOAD = 'handleFileUpload';
44 
53  public function __construct($id = -1)
54  {
56 
57  $this->object = new assFileUpload();
58  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
59  if ($id >= 0) {
60  $this->object->loadFromDb($id);
61  }
62  }
63 
67  protected function writePostData(bool $always = false): int
68  {
69  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
70  if (!$hasErrors) {
73  $this->saveTaxonomyAssignments();
74  return 0;
75  }
76  return 1;
77  }
78 
79  public function writeQuestionSpecificPostData(ilPropertyFormGUI $form): void
80  {
81  $this->object->setPoints((float) str_replace(',', '.', $_POST["points"]));
82  $this->object->setMaxSize($this->request->int('maxsize') !== 0 ? $this->request->int('maxsize') : null);
83  $this->object->setAllowedExtensions($_POST["allowedextensions"] ?? '');
84  $this->object->setCompletionBySubmission(isset($_POST['completion_by_submission']) && $_POST['completion_by_submission'] == 1);
85  }
86 
92  public function editQuestion($checkonly = false): bool
93  {
94  $save = $this->isSaveCommand();
95  $this->getQuestionTemplate();
96 
97  $form = new ilPropertyFormGUI();
98  $this->editForm = $form;
99 
100  $form->setFormAction($this->ctrl->getFormAction($this));
101  $form->setTitle($this->outQuestionType());
102  $form->setMultipart(false);
103  $form->setTableWidth("100%");
104  $form->setId("assfileupload");
105 
106  $this->addBasicQuestionFormProperties($form);
107  $this->populateQuestionSpecificFormPart($form);
108 
109  $this->populateTaxonomyFormSection($form);
110  $this->addQuestionFormCommandButtons($form);
111 
112  $errors = false;
113 
114  if ($save) {
115  $form->setValuesByPost();
116  $errors = !$form->checkInput();
117  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and
118  // we need this if we don't want to have duplication of backslashes
119  if ($errors) {
120  $checkonly = false;
121  }
122  }
123 
124  if (!$checkonly) {
125  $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
126  }
127  return $errors;
128  }
129 
131  {
132  $maxsize = new ilNumberInputGUI($this->lng->txt("maxsize"), "maxsize");
133  $maxsize->allowDecimals(false);
134  $maxsize->setValue($this->object->getMaxSize() > 0 ? (string) $this->object->getMaxSize() : null);
135  $maxsize->setInfo($this->lng->txt("maxsize_info"));
136  $maxsize->setSize(10);
137  $maxsize->setMinValue(0);
138  $maxsize->setMaxValue((float) $this->object->determineMaxFilesize());
139  $maxsize->setRequired(false);
140  $form->addItem($maxsize);
141 
142  $allowedextensions = new ilTextInputGUI($this->lng->txt("allowedextensions"), "allowedextensions");
143  $allowedextensions->setInfo($this->lng->txt("allowedextensions_info"));
144  $allowedextensions->setValue($this->object->getAllowedExtensions());
145  $allowedextensions->setRequired(false);
146  $form->addItem($allowedextensions);
147 
148  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
149  $points->allowDecimals(true);
150  $points->setValue(
151  is_numeric($this->object->getPoints()) && $this->object->getPoints(
152  ) >= 0 ? $this->object->getPoints() : ''
153  );
154  $points->setRequired(true);
155  $points->setSize(3);
156  $points->setMinValue(0.0);
157  $points->setMinvalueShouldBeGreater(true);
158  $form->addItem($points);
159 
160  $subcompl = new ilCheckboxInputGUI($this->lng->txt(
161  'ass_completion_by_submission'
162  ), 'completion_by_submission');
163  $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
164  $subcompl->setValue('1');
165  $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
166  $form->addItem($subcompl);
167  return $form;
168  }
169 
182  public function getSolutionOutput(
183  $active_id,
184  $pass = null,
185  $graphicalOutput = false,
186  $result_output = false,
187  $show_question_only = true,
188  $show_feedback = false,
189  $show_correct_solution = false,
190  $show_manual_scoring = false,
191  $show_question_text = true
192  ): string {
193  // get the solution of the user for the active pass or from the last pass if allowed
194  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", true, true, "Modules/TestQuestionPool");
195 
196  $solutionvalue = "";
197  if (($active_id > 0) && (!$show_correct_solution)) {
198  $solutions = $this->object->getSolutionValues($active_id, $pass);
199 
200  $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
201  $table_gui = new assFileUploadFileTableGUI($this, 'gotoquestion');
202  $table_gui->setTitle(
203  $this->lng->txt('already_delivered_files'),
204  'standard/icon_file.svg',
205  $this->lng->txt('already_delivered_files')
206  );
207  $table_gui->setData($files);
208  $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "Modules/TestQuestionPool");
209  $table_gui->setSelectAllCheckbox("");
210  $table_gui->disable('numinfo');
211  $template->setCurrentBlock("files");
212  $template->setVariable('FILES', $table_gui->getHTML());
213  $template->parseCurrentBlock();
214  }
215 
216  if ($this->object->getAllowedExtensions() === '') {
217  $template->setCurrentBlock("allowed_extensions");
218  $template->setVariable("TXT_ALLOWED_EXTENSIONS", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
219  $template->parseCurrentBlock();
220  }
221  $template->setVariable("CMD_UPLOAD", self::HANDLE_FILE_UPLOAD);
222  $template->setVariable("TEXT_UPLOAD", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('upload')));
223  $template->setVariable("TXT_UPLOAD_FILE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_add')));
224  $template->setVariable("TXT_MAX_SIZE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
225 
226  if (($active_id > 0) && (!$show_correct_solution)) {
227  $reached_points = $this->object->getReachedPoints($active_id, $pass);
228  if ($graphicalOutput) {
229  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_NOT_OK);
230  if ($reached_points == $this->object->getMaximumPoints()) {
231  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_OK);
232  } elseif ($reached_points > 0) {
233  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_MOSTLY_OK);
234  }
235  $template->setCurrentBlock("icon_ok");
236  $template->setVariable("ICON_OK", $correctness_icon);
237  $template->parseCurrentBlock();
238  }
239  } else {
240  $reached_points = $this->object->getPoints();
241  }
242 
243  if ($result_output) {
244  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
245  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
246  }
247  if ($show_question_text == true) {
248  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
249  }
250  $questionoutput = $template->get();
251  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
252  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getGenericFeedbackOutput((int) $active_id, $pass) : "";
253  if (strlen($feedback)) {
254  $cssClass = (
255  $this->hasCorrectSolution($active_id, $pass) ?
257  );
258 
259  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
260  $solutiontemplate->setVariable("FEEDBACK", ilLegacyFormElementsUtil::prepareTextareaOutput($feedback, true));
261  }
262  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
263  $solutionoutput = $solutiontemplate->get();
264  if (!$show_question_only) {
265  // get page object output
266  $solutionoutput = $this->getILIASPage($solutionoutput);
267  }
268  return $solutionoutput;
269  }
270 
271  public function getPreview($show_question_only = false, $showInlineFeedback = false): string
272  {
273  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "Modules/TestQuestionPool");
274 
275  if (is_object($this->getPreviewSession())) {
276  $files = $this->object->getPreviewFileUploads($this->getPreviewSession());
277  $table_gui = new assFileUploadFileTableGUI(null, $this->getQuestionActionCmd(), 'ilAssQuestionPreview');
278  $table_gui->setTitle(
279  $this->lng->txt('already_delivered_files'),
280  'standard/icon_file.svg',
281  $this->lng->txt('already_delivered_files')
282  );
283  $table_gui->setData($files);
284  // hey: prevPassSolutions - support file reuse with table
285 
286  list($lang_var, $cmd) = $this->getCommandButtonLangVarAndAction();
287  $table_gui->initCommand(
288  $lang_var,
289  $cmd,
291  );
292  // hey.
293  $template->setCurrentBlock("files");
294  $template->setVariable('FILES', $table_gui->getHTML());
295  $template->parseCurrentBlock();
296  }
297 
298  if ($this->object->getAllowedExtensions() !== '') {
299  $template->setCurrentBlock("allowed_extensions");
300  $template->setVariable("TXT_ALLOWED_EXTENSIONS", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
301  $template->parseCurrentBlock();
302  }
303  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
304  $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
305  $template->setVariable("TEXT_UPLOAD", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('upload')));
306  $template->setVariable("TXT_UPLOAD_FILE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_add')));
307  $template->setVariable("TXT_MAX_SIZE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
308 
309  $questionoutput = $template->get();
310  if (!$show_question_only) {
311  // get page object output
312  $questionoutput = $this->getILIASPage($questionoutput);
313  }
314  return $questionoutput;
315  }
316 
317  public function getTestOutput($active_id, $pass, $is_postponed = false, $use_post_solutions = false, $show_feedback = false): string
318  {
319  // generate the question output
320  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "Modules/TestQuestionPool");
321 
322  if ($active_id) {
323  $files = $this->object->getTestOutputSolutions($active_id, $pass);
324  // hey.
325  $table_gui = new assFileUploadFileTableGUI(null, $this->getQuestionActionCmd());
326  $table_gui->setTitle(
327  $this->lng->txt('already_delivered_files'),
328  'standard/icon_file.svg',
329  $this->lng->txt('already_delivered_files')
330  );
331  $table_gui->setData($files);
332 
333  list($lang_var, $cmd) = $this->getCommandButtonLangVarAndAction();
334  $table_gui->initCommand(
335  $lang_var,
336  $cmd,
338  );
339  // hey.
340  $template->setCurrentBlock("files");
341  $template->setVariable('FILES', $table_gui->getHTML());
342  $template->parseCurrentBlock();
343  }
344 
345  if ($this->object->getAllowedExtensions() !== '') {
346  $template->setCurrentBlock("allowed_extensions");
347  $template->setVariable("TXT_ALLOWED_EXTENSIONS", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
348  $template->parseCurrentBlock();
349  }
350  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
351  $template->setVariable("CMD_UPLOAD", self::HANDLE_FILE_UPLOAD);
352  $template->setVariable("TEXT_UPLOAD", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('upload')));
353  $template->setVariable("TXT_UPLOAD_FILE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_add')));
354  $template->setVariable("TXT_MAX_SIZE", ilLegacyFormElementsUtil::prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
355 
356  $questionoutput = $template->get();
357  //if (!$show_question_only) {
358  // get page object output
359  $questionoutput = $this->getILIASPage($questionoutput);
360  //}
361  $questionoutput = $template->get();
362  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
363  return $pageoutput;
364  }
365 
366  private function getCommandButtonLangVarAndAction(): array
367  {
368  if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
369  return [self::REUSE_FILES_LANGVAR, self::REUSE_FILES_ACTION];
370  }
371  return [self::DELETE_FILES_LANGVAR, self::DELETE_FILES_ACTION];
372  }
373 
374  public function getSpecificFeedbackOutput(array $userSolution): string
375  {
376  $output = "";
378  }
379 
390  {
391  return [];
392  }
393 
400  public function getAggregatedAnswersView(array $relevant_answers): string
401  {
402  // Empty implementation here since a feasible way to aggregate answer is not known.
403  return ''; //print_r($relevant_answers,true);
404  }
405 
406  protected function getTestPresentationFileTablePostVar(): string
407  {
408  if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
410  }
411 
413  }
414  // hey.
415 
416  // hey: prevPassSolutions - overwrite common prevPassSolution-Checkbox
417  protected function getPreviousSolutionProvidedMessage(): string
418  {
419  return $this->lng->txt('use_previous_solution_advice_file_upload');
420  }
421 
422  protected function getPreviousSolutionConfirmationCheckboxHtml(): string
423  {
424  return '';
425  }
426  // hey.
427 
428  public function getFormEncodingType(): string
429  {
430  return self::FORM_ENCODING_MULTIPART;
431  }
432 
433  public function isAnswerFreuqencyStatisticSupported(): bool
434  {
435  return false;
436  }
437 
439  {
440  // points
441  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
442  $points->allowDecimals(true);
443  $points->setValue(
444  is_numeric($this->object->getPoints()) && $this->object->getPoints(
445  ) >= 0 ? $this->object->getPoints() : ''
446  );
447  $points->setRequired(true);
448  $points->setSize(3);
449  $points->setMinValue(0.0);
450  $points->setMinvalueShouldBeGreater(true);
451  $form->addItem($points);
452 
453  $subcompl = new ilCheckboxInputGUI($this->lng->txt(
454  'ass_completion_by_submission'
455  ), 'completion_by_submission');
456  $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
457  $subcompl->setValue(1);
458  $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
459  $form->addItem($subcompl);
460  }
461 
466  {
467  $this->object->setPoints((float) str_replace(',', '.', $form->getInput('points')));
468  $this->object->setCompletionBySubmission((bool) $form->getInput('completion_by_submission'));
469  }
470 }
hasCorrectSolution($activeId, $passIndex)
writePostData(bool $always=false)
{}
generateCorrectnessIconsForCorrectness(int $correctness)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
getTestOutput($active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
getSpecificFeedbackOutput(array $userSolution)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
Class for file upload questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
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-...
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
__construct(VocabulariesInterface $vocabularies)
setErrorMessage(string $errormessage)
getAggregatedAnswersView(array $relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
Basic GUI class for assessment questions.
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Adds the question specific forms parts to a question property form gui.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPreview($show_question_only=false, $showInlineFeedback=false)
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
__construct($id=-1)
assFileUploadGUI constructor
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
getSolutionOutput( $active_id, $pass=null, $graphicalOutput=false, $result_output=false, $show_question_only=true, $show_feedback=false, $show_correct_solution=false, $show_manual_scoring=false, $show_question_text=true)
Get the question solution output.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getGenericFeedbackOutput(int $active_id, ?int $pass)