ILIAS  release_7 Revision v7.30-3-g800a261c036
class.assFileUploadGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
6 require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
7 
23 {
24  const REUSE_FILES_TBL_POSTVAR = 'reusefiles';
25  const DELETE_FILES_TBL_POSTVAR = 'deletefiles';
26  private const HANDLE_FILE_UPLOAD = 'handleFileUpload';
27 
36  public function __construct($id = -1)
37  {
39  include_once "./Modules/TestQuestionPool/classes/class.assFileUpload.php";
40  $this->object = new assFileUpload();
41  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
42  if ($id >= 0) {
43  $this->object->loadFromDb($id);
44  }
45  }
46 
50  protected function writePostData($always = false)
51  {
52  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
53  if (!$hasErrors) {
54  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
57  $this->saveTaxonomyAssignments();
58  return 0;
59  }
60  return 1;
61  }
62 
64  {
65  $this->object->setPoints($_POST["points"]);
66  $this->object->setMaxSize($_POST["maxsize"]);
67  $this->object->setAllowedExtensions($_POST["allowedextensions"]);
68  $this->object->setCompletionBySubmission($_POST['completion_by_submission'] == 1 ? true : false);
69  }
70 
76  public function editQuestion($checkonly = false)
77  {
78  $save = $this->isSaveCommand();
79  $this->getQuestionTemplate();
80 
81  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
82  $form = new ilPropertyFormGUI();
83  $this->editForm = $form;
84 
85  $form->setFormAction($this->ctrl->getFormAction($this));
86  $form->setTitle($this->outQuestionType());
87  $form->setMultipart(false);
88  $form->setTableWidth("100%");
89  $form->setId("assfileupload");
90 
91  $this->addBasicQuestionFormProperties($form);
93 
94  $this->populateTaxonomyFormSection($form);
95  $this->addQuestionFormCommandButtons($form);
96 
97  $errors = false;
98 
99  if ($save) {
100  $form->setValuesByPost();
101  $errors = !$form->checkInput();
102  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and
103  // we need this if we don't want to have duplication of backslashes
104  if ($errors) {
105  $checkonly = false;
106  }
107  }
108 
109  if (!$checkonly) {
110  $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
111  }
112  return $errors;
113  }
114 
116  {
117  // maxsize
118  $maxsize = new ilNumberInputGUI($this->lng->txt("maxsize"), "maxsize");
119  $maxsize->setValue($this->object->getMaxSize());
120  $maxsize->setInfo($this->lng->txt("maxsize_info"));
121  $maxsize->setSize(10);
122  $maxsize->setMinValue(0);
123  $maxsize->setMaxValue($this->determineMaxFilesize());
124  $maxsize->setRequired(false);
125  $form->addItem($maxsize);
126 
127  // allowedextensions
128  $allowedextensions = new ilTextInputGUI($this->lng->txt("allowedextensions"), "allowedextensions");
129  $allowedextensions->setInfo($this->lng->txt("allowedextensions_info"));
130  $allowedextensions->setValue($this->object->getAllowedExtensions());
131  $allowedextensions->setRequired(false);
132  $form->addItem($allowedextensions);
133 
134  // points
135  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
136  $points->allowDecimals(true);
137  $points->setValue(
138  is_numeric($this->object->getPoints()) && $this->object->getPoints(
139  ) >= 0 ? $this->object->getPoints() : ''
140  );
141  $points->setRequired(true);
142  $points->setSize(3);
143  $points->setMinValue(0.0);
144  $points->setMinvalueShouldBeGreater(false);
145  $form->addItem($points);
146 
147  $subcompl = new ilCheckboxInputGUI($this->lng->txt(
148  'ass_completion_by_submission'
149  ), 'completion_by_submission');
150  $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
151  $subcompl->setValue(1);
152  $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
153  $form->addItem($subcompl);
154  return $form;
155  }
156 
160  public function determineMaxFilesize()
161  {
162  //mbecker: Quick fix for mantis bug 8595: Change size file
163  $upload_max_filesize = get_cfg_var("upload_max_filesize");
164  // get the value for the maximal post data from the php.ini (if available)
165  $post_max_size = get_cfg_var("post_max_size");
166 
167  //convert from short-string representation to "real" bytes
168  $multiplier_a = array( "K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024 );
169  $umf_parts = preg_split(
170  "/(\d+)([K|G|M])/",
171  $upload_max_filesize,
172  -1,
173  PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
174  );
175  $pms_parts = preg_split(
176  "/(\d+)([K|G|M])/",
177  $post_max_size,
178  -1,
179  PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
180  );
181 
182  if (count($umf_parts) == 2) {
183  $upload_max_filesize = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
184  }
185 
186  if (count($pms_parts) == 2) {
187  $post_max_size = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
188  }
189 
190  // use the smaller one as limit
191  $max_filesize = min($upload_max_filesize, $post_max_size);
192 
193  if (!$max_filesize) {
194  $max_filesize = max($upload_max_filesize, $post_max_size);
195  return $max_filesize;
196  }
197  return $max_filesize;
198  }
199 
213  public function getSolutionOutput(
214  $active_id,
215  $pass = null,
216  $graphicalOutput = false,
217  $result_output = false,
218  $show_question_only = true,
219  $show_feedback = false,
220  $show_correct_solution = false,
221  $show_manual_scoring = false,
222  $show_question_text = true
223  ) {
224  // get the solution of the user for the active pass or from the last pass if allowed
225  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output_solution.html", true, true, "Modules/TestQuestionPool");
226 
227  $solutionvalue = "";
228  if (($active_id > 0) && (!$show_correct_solution)) {
229  $solutions = &$this->object->getSolutionValues($active_id, $pass);
230  include_once "./Modules/Test/classes/class.ilObjTest.php";
231  if (!ilObjTest::_getUsePreviousAnswers($active_id, true)) {
232  if (is_null($pass)) {
233  $pass = ilObjTest::_getPass($active_id);
234  }
235  }
236  $solutions = &$this->object->getSolutionValues($active_id, $pass);
237 
238  $files = ($show_manual_scoring) ? $this->object->getUploadedFilesForWeb($active_id, $pass) : $this->object->getUploadedFiles($active_id, $pass);
239  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
240  $table_gui = new assFileUploadFileTableGUI($this->getTargetGuiClass(), 'gotoquestion');
241  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
242  $table_gui->setData($files);
243  // hey: prevPassSolutions - table refactored
244  #$table_gui->initCommand(
245  #$this->buildFileTableDeleteButtonInstance(), assFileUploadGUI::DELETE_FILES_TBL_POSTVAR
246  #);
247  // hey.
248  $table_gui->setRowTemplate("tpl.il_as_qpl_fileupload_file_view_row.html", "Modules/TestQuestionPool");
249  $table_gui->setSelectAllCheckbox("");
250  // hey: prevPassSolutions - table refactored
251  #$table_gui->clearCommandButtons();
252  #$table_gui->disable('select_all');
253  // hey.
254  $table_gui->disable('numinfo');
255  $template->setCurrentBlock("files");
256  $template->setVariable('FILES', $table_gui->getHTML());
257  $template->parseCurrentBlock();
258  }
259 
260  if (strlen($this->object->getAllowedExtensions())) {
261  $template->setCurrentBlock("allowed_extensions");
262  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
263  $template->parseCurrentBlock();
264  }
265  $template->setVariable("CMD_UPLOAD", self::HANDLE_FILE_UPLOAD);
266  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
267  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
268  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
269 
270  if (($active_id > 0) && (!$show_correct_solution)) {
271  $reached_points = $this->object->getReachedPoints($active_id, $pass);
272  if ($graphicalOutput) {
273  // output of ok/not ok icons for user entered solutions
274  if ($reached_points == $this->object->getMaximumPoints()) {
275  $template->setCurrentBlock("icon_ok");
276  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
277  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
278  $template->parseCurrentBlock();
279  } else {
280  $template->setCurrentBlock("icon_ok");
281  if ($reached_points > 0) {
282  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.svg"));
283  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
284  } else {
285  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.svg"));
286  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
287  }
288  $template->parseCurrentBlock();
289  }
290  }
291  } else {
292  $reached_points = $this->object->getPoints();
293  }
294 
295  if ($result_output) {
296  $resulttext = ($reached_points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
297  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $reached_points));
298  }
299  if ($show_question_text == true) {
300  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
301  }
302  $questionoutput = $template->get();
303  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
304  $feedback = ($show_feedback && !$this->isTestPresentationContext()) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
305  if (strlen($feedback)) {
306  $cssClass = (
307  $this->hasCorrectSolution($active_id, $pass) ?
309  );
310 
311  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
312  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
313  }
314  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
315  $solutionoutput = $solutiontemplate->get();
316  if (!$show_question_only) {
317  // get page object output
318  $solutionoutput = $this->getILIASPage($solutionoutput);
319  }
320  return $solutionoutput;
321  }
322 
323  public function getPreview($show_question_only = false, $showInlineFeedback = false)
324  {
325  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "Modules/TestQuestionPool");
326 
327  if (is_object($this->getPreviewSession())) {
328  $files = $this->object->getPreviewFileUploads($this->getPreviewSession());
329  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
330  $table_gui = new assFileUploadFileTableGUI(null, $this->getQuestionActionCmd(), 'ilAssQuestionPreview');
331  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
332  $table_gui->setData($files);
333  // hey: prevPassSolutions - support file reuse with table
334  $table_gui->initCommand(
337  );
338  // hey.
339  $template->setCurrentBlock("files");
340  $template->setVariable('FILES', $table_gui->getHTML());
341  $template->parseCurrentBlock();
342  }
343 
344  if (strlen($this->object->getAllowedExtensions())) {
345  $template->setCurrentBlock("allowed_extensions");
346  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
347  $template->parseCurrentBlock();
348  }
349  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
350  $template->setVariable("CMD_UPLOAD", $this->getQuestionActionCmd());
351  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
352  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
353  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
354 
355  $questionoutput = $template->get();
356  if (!$show_question_only) {
357  // get page object output
358  $questionoutput = $this->getILIASPage($questionoutput);
359  }
360  return $questionoutput;
361  }
362 
363  // hey: prevPassSolutions - pass will be always available from now on
364  public function getTestOutput($active_id, $pass, $is_postponed = false, $use_post_solutions = false, $show_feedback = false)
365  // hey.
366  {
367  // generate the question output
368  $template = new ilTemplate("tpl.il_as_qpl_fileupload_output.html", true, true, "Modules/TestQuestionPool");
369 
370  if ($active_id) {
371  // hey: prevPassSolutions - obsolete due to central check
372  #$solutions = NULL;
373  #include_once "./Modules/Test/classes/class.ilObjTest.php";
374  #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
375  #{
376  # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
377  #}
378  $files = $this->object->getTestOutputSolutions($active_id, $pass);
379  // hey.
380  include_once "./Modules/TestQuestionPool/classes/tables/class.assFileUploadFileTableGUI.php";
381  $table_gui = new assFileUploadFileTableGUI(null, $this->getQuestionActionCmd());
382  $table_gui->setTitle($this->lng->txt('already_delivered_files'), 'icon_file.svg', $this->lng->txt('already_delivered_files'));
383  $table_gui->setData($files);
384  // hey: prevPassSolutions - support file reuse with table
385  $table_gui->initCommand(
388  );
389  // hey.
390  $template->setCurrentBlock("files");
391  $template->setVariable('FILES', $table_gui->getHTML());
392  $template->parseCurrentBlock();
393  }
394 
395  if (strlen($this->object->getAllowedExtensions())) {
396  $template->setCurrentBlock("allowed_extensions");
397  $template->setVariable("TXT_ALLOWED_EXTENSIONS", $this->object->prepareTextareaOutput($this->lng->txt("allowedextensions") . ": " . $this->object->getAllowedExtensions()));
398  $template->parseCurrentBlock();
399  }
400  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
401  $template->setVariable("CMD_UPLOAD", self::HANDLE_FILE_UPLOAD);
402  $template->setVariable("TEXT_UPLOAD", $this->object->prepareTextareaOutput($this->lng->txt('upload')));
403  $template->setVariable("TXT_UPLOAD_FILE", $this->object->prepareTextareaOutput($this->lng->txt('file_add')));
404  $template->setVariable("TXT_MAX_SIZE", $this->object->prepareTextareaOutput($this->lng->txt('file_notice') . " " . $this->object->getMaxFilesizeAsString()));
405 
406  $questionoutput = $template->get();
407  if (!$show_question_only) {
408  // get page object output
409  $questionoutput = $this->getILIASPage($questionoutput);
410  }
411  $questionoutput = $template->get();
412  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
413  return $pageoutput;
414  }
415 
416  public function getSpecificFeedbackOutput($userSolution)
417  {
418  $output = "";
419  return $this->object->prepareTextareaOutput($output, true);
420  }
421 
432  {
433  return array();
434  }
435 
444  public function getAggregatedAnswersView($relevant_answers)
445  {
446  // Empty implementation here since a feasible way to aggregate answer is not known.
447  return ''; //print_r($relevant_answers,true);
448  }
449 
450  // hey: prevPassSolutions - shown files needs to be chosen so upload can replace or complete fileset
455  {
456  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssFileUploadFileTableDeleteButton.php';
458  }
459 
464  {
465  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssFileUploadFileTableReuseButton.php';
467  }
468 
473  {
474  if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
475  return $this->buildFileTableReuseButtonInstance();
476  }
477 
478  return $this->buildFileTableDeleteButtonInstance();
479  }
480 
482  {
483  if ($this->object->getTestPresentationConfig()->isSolutionInitiallyPrefilled()) {
485  }
486 
488  }
489  // hey.
490 
491  // hey: prevPassSolutions - overwrite common prevPassSolution-Checkbox
493  {
494  return $this->lng->txt('use_previous_solution_advice_file_upload');
495  }
496 
498  {
499  return '';
500  }
501  // hey.
502 
503  public function getFormEncodingType()
504  {
505  return self::FORM_ENCODING_MULTIPART;
506  }
507 
509  {
510  return false;
511  }
512 
514  {
515  // points
516  $points = new ilNumberInputGUI($this->lng->txt("points"), "points");
517  $points->allowDecimals(true);
518  $points->setValue(
519  is_numeric($this->object->getPoints()) && $this->object->getPoints(
520  ) >= 0 ? $this->object->getPoints() : ''
521  );
522  $points->setRequired(true);
523  $points->setSize(3);
524  $points->setMinValue(0.0);
525  $points->setMinvalueShouldBeGreater(false);
526  $form->addItem($points);
527 
528  $subcompl = new ilCheckboxInputGUI($this->lng->txt(
529  'ass_completion_by_submission'
530  ), 'completion_by_submission');
531  $subcompl->setInfo($this->lng->txt('ass_completion_by_submission_info'));
532  $subcompl->setValue(1);
533  $subcompl->setChecked($this->object->isCompletionBySubmissionEnabled());
534  $form->addItem($subcompl);
535  }
536 
541  {
542  $this->object->setPoints((float) $form->getInput('points'));
543  $this->object->setCompletionBySubmission((bool) $form->getInput('completion_by_submission'));
544  }
545 }
hasCorrectSolution($activeId, $passIndex)
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question, working time.
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
setValue($a_value)
Set Value.
$errors
Definition: imgupload.php:49
This class represents a property form user interface.
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($userSolution)
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
getQuestionTemplate()
get question template
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
populateTaxonomyFormSection(ilPropertyFormGUI $form)
allowDecimals($a_value)
Toggle Decimals.
setInfo($a_info)
Set Information Text.
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
writePostData($always=false)
{}
getILIASPage($html="")
Returns the ILIAS Page around a question.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class represents a number property in a property form.
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
Basic GUI class for assessment questions.
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
Adds the question specific forms parts to a question property form gui.
setErrorMessage($errormessage)
The assFileUploadGUI class encapsulates the GUI representation for file upload questions.
getAnswerFeedbackOutput($active_id, $pass)
Returns the answer generic feedback depending on the results of the question.
getPreview($show_question_only=false, $showInlineFeedback=false)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
output question page
__construct(Container $dic, ilPlugin $plugin)
__construct($id=-1)
assFileUploadGUI constructor
Interface ilGuiQuestionScoringAdjustable.
static _getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
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...
$_POST["username"]
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.