ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExSubmissionFileGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
30 {
32  protected ilHelpGUI $help;
33  protected ilObjUser $user;
34  protected UIServices $ui;
35 
36  public function __construct(
37  ilObjExercise $a_exercise,
38  ilExSubmission $a_submission
39  ) {
40  global $DIC;
41 
42  parent::__construct($a_exercise, $a_submission);
43 
44  $this->toolbar = $DIC->toolbar();
45  $this->help = $DIC["ilHelp"];
46  $this->user = $DIC->user();
47  $this->ui = $DIC->ui();
48  }
49 
50  public function executeCommand(): void
51  {
52  $ilCtrl = $this->ctrl;
53 
54  if (!$this->submission->canView()) {
55  $this->returnToParentObject();
56  }
57 
58  $class = $ilCtrl->getNextClass($this);
59  $cmd = $ilCtrl->getCmd("submissionScreen");
60 
61  switch ($class) {
62  case strtolower(ilRepoStandardUploadHandlerGUI::class):
63  $form = $this->getUploadForm();
64  $gui = $form->getRepoStandardUploadHandlerGUI("deliver");
65  $this->ctrl->forwardCommand($gui);
66  break;
67 
68  default:
69  $this->{$cmd . "Object"}();
70  break;
71  }
72  }
73 
74  public static function getOverviewContent(
75  ilInfoScreenGUI $a_info,
76  ilExSubmission $a_submission
77  ): void {
78  global $DIC;
79 
80  $lng = $DIC->language();
81  $ilCtrl = $DIC->ctrl();
82  $gui = $DIC->exercise()->internal()->gui();
83 
84  $titles = array();
85  foreach ($a_submission->getFiles() as $file) {
86  $titles[] = htmlentities($file["filetitle"]);
87  }
88  $files_str = implode("<br>", $titles);
89  if ($files_str == "") {
90  $files_str = $lng->txt("message_no_delivered_files");
91  }
92 
93  // no team == no submission
94  if (!$a_submission->hasNoTeamYet()) {
95  if ($a_submission->canSubmit()) {
96  $title = (count($titles) == 0
97  ? $lng->txt("exc_hand_in")
98  : $lng->txt("exc_edit_submission"));
99 
100  $button = $gui->link(
101  $title,
102  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen")
103  )->primary();
104  $files_str .= "<br><br>" . $button->render();
105  } else {
106  if (count($titles) > 0) {
107  $link = $gui->link(
108  $lng->txt("already_delivered_files"),
109  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen")
110  )->emphasised();
111  $files_str .= "<br><br>" . $link->render();
112  }
113  }
114  }
115 
116  $a_info->addProperty($lng->txt("exc_files_returned"), $files_str);
117  }
118 
119  // Displays a form which allows members to deliver their solutions
120  public function submissionScreenObject(): void
121  {
122  $ilToolbar = $this->toolbar;
123  $ilHelp = $this->help;
124  $ilUser = $this->user;
125 
126  $this->triggerAssignmentTool();
127 
128  $this->handleTabs();
129 
130  $ilHelp->setScreenIdComponent("exc");
131  $ilHelp->setScreenId("submissions");
132 
133  if (!$this->submission->canSubmit()) {
134  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"));
135  } else {
136  $max_files = $this->submission->getAssignment()->getMaxFile();
137 
138  if ($this->submission->canAddFile()) {
139  // #15883 - extended deadline warning
140  $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
141  if ($deadline &&
142  time() > $deadline) {
144  $dl = sprintf($this->lng->txt("exc_late_submission_warning"), $dl);
145  $dl = '<span class="warning">' . $dl . '</span>';
146  $ilToolbar->addText($dl);
147  }
148 
149  $b = $this->ui->factory()->button()->standard(
150  $this->lng->txt("file_add"),
151  $this->ctrl->getLinkTarget($this, "uploadForm")
152  );
153  $ilToolbar->addStickyItem($b);
154 
155  if (!$max_files ||
156  $max_files > 1) {
157  $ilToolbar->addButton(
158  $this->lng->txt("header_zip"),
159  $this->ctrl->getLinkTarget($this, "uploadZipForm")
160  );
161  }
162  }
163 
164  if ($max_files) {
165  $this->tpl->setOnScreenMessage('info', sprintf($this->lng->txt("exc_max_file_reached"), $max_files));
166  }
167  }
168 
169  $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->submission);
170  $this->tpl->setContent($tab->getHTML());
171  }
172 
173  // Display form for single file upload
174  public function uploadFormObject(
175  ilPropertyFormGUI $a_form = null
176  ): void {
177  if (!$this->submission->canSubmit()) {
178  $this->ctrl->redirect($this, "submissionScreen");
179  }
180 
181  $this->tabs_gui->clearTargets();
182  $this->tabs_gui->setBackTarget(
183  $this->lng->txt("back"),
184  $this->ctrl->getLinkTarget($this, "submissionScreen")
185  );
186 
187  $ilHelp = $this->help;
188  $ilHelp->setScreenIdComponent("exc");
189  $ilHelp->setScreenId("upload_submission");
190 
191  if (!$a_form) {
192  $a_form = $this->initUploadForm();
193  $a_form = $this->getUploadForm();
194  $this->tpl->setContent($a_form->render());
195  return;
196  }
197  $this->tpl->setContent($a_form->getHTML());
198  }
199 
200  public function uploadZipFormObject(
201  ilPropertyFormGUI $a_form = null
202  ): void {
203  if (!$this->submission->canSubmit()) {
204  $this->ctrl->redirect($this, "submissionScreen");
205  }
206 
207  $this->tabs_gui->clearTargets();
208  $this->tabs_gui->setBackTarget(
209  $this->lng->txt("back"),
210  $this->ctrl->getLinkTarget($this, "submissionScreen")
211  );
212 
213  if (!$a_form) {
214  $a_form = $this->initZipUploadForm();
215  }
216  $this->tpl->setContent($a_form->getHTML());
217  }
218 
222  protected function initUploadForm(): ilPropertyFormGUI
223  {
224  $lng = $this->lng;
225  $ilCtrl = $this->ctrl;
226 
227  $form = new ilPropertyFormGUI();
228 
229  // file input
230  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
231  $fi->setFilenames(array(0 => ''));
232  $fi->setRequired(true);
233  $form->addItem($fi);
234 
235  $form->addCommandButton("uploadFile", $lng->txt("upload"));
236  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
237 
238  $form->setTitle($lng->txt("file_add"));
239  $form->setFormAction($ilCtrl->getFormAction($this, "uploadFile"));
240 
241  return $form;
242  }
243 
244  protected function getUploadForm(): \ILIAS\Repository\Form\FormAdapterGUI
245  {
246  $max_file = $this->submission->getAssignment()->getMaxFile();
247  if ($max_file > 0) {
248  $max_file = $this->submission->getAssignment()->getMaxFile() - count($this->submission->getFiles());
249  } else {
250  $max_file = 20;
251  }
252 
253  $form_adapter = $this->gui
254  ->form(self::class, 'addUpload')
255  ->section("props", $this->lng->txt('file_add'))
256  ->file(
257  "deliver",
258  $this->lng->txt("files"),
259  \Closure::fromCallable([$this, 'handleUploadResult']),
260  "deliver",
261  "",
262  $max_file
263  );
264  return $form_adapter;
265  }
266 
267  protected function handleUploadResult(
268  \ILIAS\FileUpload\FileUpload $upload,
269  \ILIAS\FileUpload\DTO\UploadResult $result
270  ): \ILIAS\FileUpload\Handler\BasicHandlerResult {
271  $title = $result->getName();
272 
273  $this->submission->addFileUpload($result);
274 
275  if ($result->isOK()) {
276  return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
277  'deliver',
278  \ILIAS\FileUpload\Handler\HandlerResult::STATUS_OK,
279  $title,
280  ''
281  );
282  } else {
283  return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
284  'deliver',
285  \ILIAS\FileUpload\Handler\HandlerResult::STATUS_FAILED,
286  $title,
287  $result->getStatus()->getMessage()
288  );
289  }
290  }
291 
292  public function addUploadObject(): void
293  {
294  $form = $this->getUploadForm();
295  if ($form->isValid()) {
296  $data = (string) $form->getData("deliver");
297  if ($data !== "") {
298  $this->tpl->setOnScreenMessage('success', $this->lng->txt("file_added"), true);
299  $this->handleNewUpload();
300  } else {
301  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_file"), true);
302  }
303  }
304  $ilCtrl = $this->ctrl;
305 
306  $ilCtrl->redirect($this, "submissionScreen");
307  }
308 
309 
313  protected function initZipUploadForm(): ilPropertyFormGUI
314  {
315  $lng = $this->lng;
316  $ilCtrl = $this->ctrl;
317 
318  $form = new ilPropertyFormGUI();
319 
320  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
321  $fi->setSuffixes(array("zip"));
322  $fi->setRequired(true);
323  $form->addItem($fi);
324 
325  $form->addCommandButton("uploadZip", $lng->txt("upload"));
326  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
327 
328  $form->setTitle($lng->txt("header_zip"));
329  $form->setFormAction($ilCtrl->getFormAction($this, "uploadZip"));
330 
331  return $form;
332  }
333 
337  public function uploadFileObject(): void
338  {
339  $ilCtrl = $this->ctrl;
340 
341  // #15322
342  if (!$this->submission->canSubmit()) {
343  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
344  } else {
345  $form = $this->initUploadForm();
346  if (!$form->checkInput()) {
347  $this->uploadFormObject($form);
348  return;
349  }
350 
351  $success = false;
352  foreach ($_FILES["deliver"]["name"] as $k => $v) {
353  $file = array(
354  "name" => $_FILES["deliver"]["name"][$k],
355  "type" => $_FILES["deliver"]["type"][$k],
356  "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
357  "error" => $_FILES["deliver"]["error"][$k],
358  "size" => $_FILES["deliver"]["size"][$k],
359  );
360  if (!$this->submission->uploadFile($file)) {
361  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_upload_error") . " [Single File]", true);
362  } else {
363  $success = true;
364  }
365  }
366 
367  if ($success) {
368  $this->tpl->setOnScreenMessage('success', $this->lng->txt("file_added"), true);
369  $this->handleNewUpload();
370  }
371  }
372 
373  $ilCtrl->redirect($this, "submissionScreen");
374  }
375 
379  public function uploadZipObject(): void
380  {
381  $ilCtrl = $this->ctrl;
382 
383  // #15322
384  if (!$this->submission->canSubmit()) {
385  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
386  } else {
387  $form = $this->initZipUploadForm();
388  if (!$form->checkInput()) {
389  $this->uploadZipFormObject($form);
390  return;
391  }
392 
393  if (preg_match("/zip/", $_FILES["deliver"]["type"]) == 1) {
394  try {
395  if ($this->submission->processUploadedZipFile($_FILES["deliver"]["tmp_name"])) {
396  $this->tpl->setOnScreenMessage('success', $this->lng->txt("file_added"), true);
397  $this->handleNewUpload();
398  }
399  } catch (ilException $e) {
400  $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
401  $ilCtrl->redirect($this, "submissionScreen");
402  }
403  }
404  }
405 
406  $ilCtrl->redirect($this, "submissionScreen");
407  }
408 
412  public function confirmDeleteDeliveredObject(): void
413  {
414  $ilCtrl = $this->ctrl;
415  $tpl = $this->tpl;
416  $lng = $this->lng;
417 
418  $file_ids = $this->request->getSubmittedFileIds();
419  if (!$this->submission->canSubmit()) {
420  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
421  $ilCtrl->redirect($this, "submissionScreen");
422  }
423 
424  if (count($file_ids) == 0) {
425  $this->tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
426  $ilCtrl->redirect($this, "submissionScreen");
427  } else {
428  $this->tabs_gui->clearTargets();
429  $this->tabs_gui->setBackTarget(
430  $this->lng->txt("back"),
431  $this->ctrl->getLinkTarget($this, "submissionScreen")
432  );
433 
434  $cgui = new ilConfirmationGUI();
435  $cgui->setFormAction($ilCtrl->getFormAction($this));
436  $cgui->setHeaderText($lng->txt("info_delete_sure"));
437  $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
438  $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
439 
440  $files = $this->submission->getFiles();
441 
442  foreach ($file_ids as $i) {
443  reset($files);
444  $title = "";
445  foreach ($files as $f) {
446  if ($f["returned_id"] == $i) {
447  $title = $f["filetitle"];
448  }
449  }
450  $cgui->addItem("delivered[]", $i, $title);
451  }
452 
453  $tpl->setContent($cgui->getHTML());
454  }
455  }
456 
460  public function deleteDeliveredObject(): void
461  {
462  $ilCtrl = $this->ctrl;
463 
464  $file_ids = $this->request->getSubmittedFileIds();
465 
466  if (!$this->submission->canSubmit()) {
467  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
468  } elseif (count($file_ids) == 0) {
469  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("please_select_a_delivered_file_to_delete"), true);
470  } else {
471  $this->submission->deleteSelectedFiles($file_ids);
472  $this->handleRemovedUpload();
473 
474  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_submitted_files_deleted"), true);
475  }
476  $ilCtrl->redirect($this, "submissionScreen");
477  }
478 
482  public function downloadReturnedObject(bool $a_only_new = false): void
483  {
484  $lng = $this->lng;
485 
486  if ($this->submission->canView()) {
487  $peer_review_mask_filename = $this->submission->hasPeerReviewAccess();
488  } else {
489  // no access
490  return;
491  }
492 
493  $this->submission->downloadFiles(null, $a_only_new, $peer_review_mask_filename);
494  // we only get here, if no files have been found for download
495  if ($a_only_new) {
496  $this->tpl->setOnScreenMessage('info', $lng->txt("exc_all_new_files_offered_already"), true);
497  }
498  $this->returnToParentObject();
499  }
500 
504  public function downloadNewReturnedObject(): void
505  {
506  $this->downloadReturnedObject(true);
507  }
508 
512  public function downloadObject(): void
513  {
514  $ilCtrl = $this->ctrl;
515 
516  $delivered_id = $this->request->getSubmittedFileId();
517 
518  if (!$this->submission->canView()) {
519  $this->returnToParentObject();
520  }
521 
522  if (!is_array($delivered_id) && $delivered_id > 0) {
523  $delivered_id = [$delivered_id];
524  }
525  if (is_array($delivered_id) && $delivered_id !== []) {
526  $this->submission->downloadFiles($delivered_id);
527  exit;
528  } else {
529  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("please_select_a_delivered_file_to_download"), true);
530  $ilCtrl->redirect($this, "submissionScreen");
531  }
532  }
533 }
handleNewUpload(bool $a_no_notifications=false)
setFilenames(array $a_filenames)
getFiles(array $a_file_ids=null, bool $a_only_valid=false, string $a_min_timestamp=null, bool $print_versions=false)
Get submission items (not only files)
ILIAS Exercise InternalGUIService $gui
exit
Definition: login.php:29
Class ilInfoScreenGUI.
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
This class represents a file property in a property form.
Class ChatMainBarProvider .
downloadNewReturnedObject()
Download newly submitted files of user.
Help GUI class.
Exercise submission base gui.
This class represents a file wizard property in a property form.
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
uploadFormObject(ilPropertyFormGUI $a_form=null)
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
setSuffixes(array $a_suffixes)
const IL_CAL_UNIX
ilGlobalTemplateInterface $tpl
global $DIC
Definition: feed.php:28
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
Class ilObjExercise.
__construct(VocabulariesInterface $vocabularies)
downloadObject()
User downloads (own) submitted files.
setContent(string $a_html)
Sets content for standard template.
handleUploadResult(\ILIAS\FileUpload\FileUpload $upload, \ILIAS\FileUpload\DTO\UploadResult $result)
setScreenIdComponent(string $a_comp)
initUploadForm()
Init upload form form.
confirmDeleteDeliveredObject()
Confirm deletion of delivered files.
downloadReturnedObject(bool $a_only_new=false)
Download submitted files of user.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
uploadZipFormObject(ilPropertyFormGUI $a_form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initZipUploadForm()
Init upload form form.
deleteDeliveredObject()
Delete file(s) submitted by user.