ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilExSubmissionFileGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
30 {
31  protected \ILIAS\Exercise\Submission\SubmissionManager $subm;
32  protected $log;
34  protected ilHelpGUI $help;
35  protected ilObjUser $user;
36  protected UIServices $ui;
37 
38  public function __construct(
39  ilObjExercise $a_exercise,
40  ilExSubmission $a_submission
41  ) {
42  global $DIC;
43 
44  parent::__construct($a_exercise, $a_submission);
45 
46  $this->toolbar = $DIC->toolbar();
47  $this->help = $DIC["ilHelp"];
48  $this->user = $DIC->user();
49  $this->ui = $DIC->ui();
50  $this->log = $DIC->logger()->exc();
51  $this->subm = $DIC->exercise()->internal()->domain()->submission(
52  $a_submission->getAssignment()->getId()
53  );
54  }
55 
56  public function executeCommand(): void
57  {
58  $ilCtrl = $this->ctrl;
59 
60  if (!$this->submission->canView()) {
61  $this->returnToParentObject();
62  }
63 
64  $class = $ilCtrl->getNextClass($this);
65  $cmd = $ilCtrl->getCmd("submissionScreen");
66 
67  switch ($class) {
68  case strtolower(ilRepoStandardUploadHandlerGUI::class):
69  if ($this->request->getZip()) {
70  $form = $this->getZipUploadForm();
71  } else {
72  $form = $this->getUploadForm();
73  }
74  $gui = $form->getRepoStandardUploadHandlerGUI("deliver");
75  $this->ctrl->forwardCommand($gui);
76  break;
77 
78  default:
79  $this->{$cmd . "Object"}();
80  break;
81  }
82  }
83 
84  public static function getOverviewContent(
85  ilInfoScreenGUI $a_info,
86  ilExSubmission $a_submission
87  ): void {
88  global $DIC;
89 
90  $lng = $DIC->language();
91  $ilCtrl = $DIC->ctrl();
92  $gui = $DIC->exercise()->internal()->gui();
93  $subm = $DIC->exercise()->internal()->domain()->submission(
94  $a_submission->getAssignment()->getId()
95  );
96 
97  $titles = array();
98  foreach ($subm->getSubmissionsOfUser($a_submission->getUserId()) as $sub) {
99  $titles[] = htmlentities($sub->getTitle());
100  }
101  $files_str = implode("<br>", $titles);
102  if ($files_str == "") {
103  $files_str = $lng->txt("message_no_delivered_files");
104  }
105 
106  // no team == no submission
107  if (!$a_submission->hasNoTeamYet()) {
108  if ($a_submission->canSubmit()) {
109  $title = (count($titles) == 0
110  ? $lng->txt("exc_hand_in")
111  : $lng->txt("exc_edit_submission"));
112 
113  $button = $gui->link(
114  $title,
115  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen")
116  )->primary();
117  $files_str .= "<br><br>" . $button->render();
118  } else {
119  if (count($titles) > 0) {
120  $link = $gui->link(
121  $lng->txt("already_delivered_files"),
122  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen")
123  )->emphasised();
124  $files_str .= "<br><br>" . $link->render();
125  }
126  }
127  }
128 
129  $a_info->addProperty($lng->txt("exc_files_returned"), $files_str);
130  }
131 
132  // Displays a form which allows members to deliver their solutions
133  public function submissionScreenObject(): void
134  {
135  $ilToolbar = $this->toolbar;
136  $ilHelp = $this->help;
137  $ilUser = $this->user;
138 
139  $this->triggerAssignmentTool();
140 
141  $this->handleTabs();
142 
143  $ilHelp->setScreenIdComponent("exc");
144  $ilHelp->setScreenId("submissions");
145 
146  if (!$this->submission->canSubmit()) {
147  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"));
148  } else {
149  $max_files = $this->submission->getAssignment()->getMaxFile();
150 
151  if ($this->submission->canAddFile()) {
152  // #15883 - extended deadline warning
153  $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
154  if ($deadline &&
155  time() > $deadline) {
157  $dl = sprintf($this->lng->txt("exc_late_submission_warning"), $dl);
158  $dl = '<span class="warning">' . $dl . '</span>';
159  $ilToolbar->addText($dl);
160  }
161 
162  $b = $this->ui->factory()->button()->standard(
163  $this->lng->txt("file_add"),
164  $this->ctrl->getLinkTarget($this, "uploadForm")
165  );
166  $ilToolbar->addStickyItem($b);
167 
168  if (!$max_files ||
169  $max_files > 1) {
170  $ilToolbar->addButton(
171  $this->lng->txt("header_zip"),
172  $this->ctrl->getLinkTarget($this, "uploadZipForm")
173  );
174  }
175  }
176 
177  if ($max_files) {
178  $this->tpl->setOnScreenMessage('info', sprintf($this->lng->txt("exc_max_file_reached"), $max_files));
179  }
180  }
181 
182  $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->submission);
183  $this->tpl->setContent($tab->getHTML());
184  }
185 
186  // Display form for single file upload
187  public function uploadFormObject(
188  ?ilPropertyFormGUI $a_form = null
189  ): void {
190  if (!$this->submission->canSubmit()) {
191  $this->ctrl->redirect($this, "submissionScreen");
192  }
193 
194  $this->tabs_gui->clearTargets();
195  $this->tabs_gui->setBackTarget(
196  $this->lng->txt("back"),
197  $this->ctrl->getLinkTarget($this, "submissionScreen")
198  );
199 
200  $ilHelp = $this->help;
201  $ilHelp->setScreenIdComponent("exc");
202  $ilHelp->setScreenId("upload_submission");
203 
204  if (!$a_form) {
205  $a_form = $this->getUploadForm();
206  $this->tpl->setContent($a_form->render());
207  return;
208  }
209  $this->tpl->setContent($a_form->getHTML());
210  }
211 
212  public function uploadZipFormObject(
213  ?\ILIAS\Repository\Form\FormAdapterGUI $a_form = null
214  ): void {
215  if (!$this->submission->canSubmit()) {
216  $this->ctrl->redirect($this, "submissionScreen");
217  }
218 
219  $this->tabs_gui->clearTargets();
220  $this->tabs_gui->setBackTarget(
221  $this->lng->txt("back"),
222  $this->ctrl->getLinkTarget($this, "submissionScreen")
223  );
224 
225  if (!$a_form) {
226  $a_form = $this->getZipUploadForm();
227  }
228  $this->tpl->setContent($a_form->render());
229  }
230 
234  protected function initUploadForm(): ilPropertyFormGUI
235  {
236  $lng = $this->lng;
237  $ilCtrl = $this->ctrl;
238 
239  $form = new ilPropertyFormGUI();
240 
241  // file input
242  $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
243  $fi->setFilenames(array(0 => ''));
244  $fi->setRequired(true);
245  $form->addItem($fi);
246 
247  $form->addCommandButton("uploadFile", $lng->txt("upload"));
248  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
249 
250  $form->setTitle($lng->txt("file_add"));
251  $form->setFormAction($ilCtrl->getFormAction($this, "uploadFile"));
252 
253  return $form;
254  }
255 
256  protected function getUploadForm(): \ILIAS\Repository\Form\FormAdapterGUI
257  {
258  $max_file = $this->submission->getAssignment()->getMaxFile();
259  $cnt_sub = $this->subm->countSubmissionsOfUser($this->submission->getUserId());
260  if ($max_file > 0) {
261  $max_file = $this->submission->getAssignment()->getMaxFile() - $cnt_sub;
262  } else {
263  $max_file = 20;
264  }
265 
266  $form_adapter = $this->gui
267  ->form(self::class, 'addUpload')
268  ->section("props", $this->lng->txt('file_add'))
269  ->file(
270  "deliver",
271  $this->lng->txt("files"),
272  $this->handleUploadResult(...),
273  "mep_id",
274  "",
275  $max_file
276  );
277  return $form_adapter;
278  }
279 
280  protected function handleUploadResult(
281  \ILIAS\FileUpload\FileUpload $upload,
282  \ILIAS\FileUpload\DTO\UploadResult $result
283  ): \ILIAS\FileUpload\Handler\BasicHandlerResult {
284  $title = $result->getName();
285 
286  //$this->submission->addFileUpload($result);
287  $subm = $this->domain->submission($this->assignment->getId());
288  $subm->addUpload(
289  $this->user->getid(),
290  $result,
291  $title
292  );
293 
294  return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
295  '',
296  \ILIAS\FileUpload\Handler\HandlerResult::STATUS_OK,
297  $title,
298  ''
299  );
300  }
301 
302  public function addUploadObject(): void
303  {
304  $ilCtrl = $this->ctrl;
305  $this->tpl->setOnScreenMessage('success', $this->lng->txt("file_added"), true);
306  $this->handleNewUpload();
307 
308  $ilCtrl->redirect($this, "submissionScreen");
309  }
310 
311 
315  /*
316  protected function initZipUploadForm(): ilPropertyFormGUI
317  {
318  $lng = $this->lng;
319  $ilCtrl = $this->ctrl;
320 
321  $form = new ilPropertyFormGUI();
322 
323  $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
324  $fi->setSuffixes(array("zip"));
325  $fi->setRequired(true);
326  $form->addItem($fi);
327 
328  $form->addCommandButton("uploadZip", $lng->txt("upload"));
329  $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
330 
331  $form->setTitle($lng->txt("header_zip"));
332  $form->setFormAction($ilCtrl->getFormAction($this, "uploadZip"));
333 
334  return $form;
335  }*/
336 
337  protected function getZipUploadForm(): \ILIAS\Repository\Form\FormAdapterGUI
338  {
339  /*
340  $max_file = $this->submission->getAssignment()->getMaxFile();
341  if ($max_file > 0) {
342  $max_file = $this->submission->getAssignment()->getMaxFile() - count($this->submission->getFiles());
343  } else {
344  $max_file = 20;
345  }*/
346  $this->ctrl->setParameterByClass(self::class, "zip", "1");
347  $form_adapter = $this->gui
348  ->form(self::class, 'addUpload')
349  ->section("props", $this->lng->txt('file_add'))
350  ->file(
351  "deliver",
352  $this->lng->txt("files"),
353  \Closure::fromCallable([$this, 'handleZipUploadResult']),
354  "mep_id",
355  "",
356  1,
357  ["application/zip"]
358  );
359  return $form_adapter;
360  }
361 
362 
363 
364  protected function handleZipUploadResult(
365  \ILIAS\FileUpload\FileUpload $upload,
366  \ILIAS\FileUpload\DTO\UploadResult $result
367  ): \ILIAS\FileUpload\Handler\BasicHandlerResult {
368  $title = $result->getName();
369  //$this->submission->addFileUpload($result);
370  $subm = $this->domain->submission($this->assignment->getId());
371  $mess = "";
372  if ($this->submission->canSubmit()) {
373  try {
374  $subm->addZipUploads(
375  $this->user->getid(),
376  $result
377  );
378  return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
379  '',
380  \ILIAS\FileUpload\Handler\HandlerResult::STATUS_OK,
381  $title,
382  ''
383  );
385  $mess = $this->lng->txt("exc_too_many_files");
386  }
387  } else {
388  $mess = $this->lng->txt("exc_cannot_submit_any_files");
389  }
390  return new \ILIAS\FileUpload\Handler\BasicHandlerResult(
391  '',
392  \ILIAS\FileUpload\Handler\HandlerResult::STATUS_FAILED,
393  $title,
394  $mess
395  );
396  }
397 
401  public function confirmDeleteDeliveredObject(): void
402  {
403  $ilCtrl = $this->ctrl;
404  $tpl = $this->tpl;
405  $lng = $this->lng;
406 
407  $file_ids = $this->request->getSubmittedFileIds();
408  if (!$this->submission->canSubmit()) {
409  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
410  $ilCtrl->redirect($this, "submissionScreen");
411  }
412 
413  if (count($file_ids) == 0) {
414  $this->tpl->setOnScreenMessage('failure', $lng->txt("no_checkbox"), true);
415  $ilCtrl->redirect($this, "submissionScreen");
416  } else {
417  $this->tabs_gui->clearTargets();
418  $this->tabs_gui->setBackTarget(
419  $this->lng->txt("back"),
420  $this->ctrl->getLinkTarget($this, "submissionScreen")
421  );
422 
423  $cgui = new ilConfirmationGUI();
424  $cgui->setFormAction($ilCtrl->getFormAction($this));
425  $cgui->setHeaderText($lng->txt("info_delete_sure"));
426  $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
427  $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
428 
429  $subs = $this->subm->getSubmissionsOfUser(
430  $this->submission->getUserId(),
431  $file_ids
432  );
433 
434  foreach ($subs as $sub) {
435  $cgui->addItem("delivered[]", $sub->getId(), $sub->getTitle());
436  }
437 
438  $tpl->setContent($cgui->getHTML());
439  }
440  }
441 
445  public function deleteDeliveredObject(): void
446  {
447  $ilCtrl = $this->ctrl;
448 
449  $file_ids = $this->request->getSubmittedFileIds();
450 
451  if (!$this->submission->canSubmit()) {
452  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
453  } elseif (count($file_ids) == 0) {
454  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("please_select_a_delivered_file_to_delete"), true);
455  } else {
456  $this->subm->deleteSubmissions(
457  $this->submission->getUserId(),
458  $file_ids
459  );
460  $this->handleRemovedUpload();
461 
462  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_submitted_files_deleted"), true);
463  }
464  $ilCtrl->redirect($this, "submissionScreen");
465  }
466 
470  public function downloadReturnedObject(bool $a_only_new = false): void
471  {
472  $lng = $this->lng;
473 
474  if ($this->submission->canView()) {
475  $peer_review_mask_filename = $this->submission->hasPeerReviewAccess();
476  } else {
477  // no access
478  return;
479  }
480 
481  $this->submission->downloadFiles(null, $a_only_new, $peer_review_mask_filename);
482  // we only get here, if no files have been found for download
483  if ($a_only_new) {
484  $this->tpl->setOnScreenMessage('info', $lng->txt("exc_all_new_files_offered_already"), true);
485  }
486  $this->returnToParentObject();
487  }
488 
492  public function downloadNewReturnedObject(): void
493  {
494  $this->downloadReturnedObject(true);
495  }
496 
500  public function downloadObject(): void
501  {
502  $ilCtrl = $this->ctrl;
503 
504  $delivered_id = $this->request->getSubmittedFileId();
505 
506  if (!$this->submission->canView()) {
507  $this->returnToParentObject();
508  }
509 
510  if (!is_array($delivered_id) && $delivered_id > 0) {
511  $delivered_id = [$delivered_id];
512  }
513  if (is_array($delivered_id) && $delivered_id !== []) {
514  $this->submission->downloadFiles($delivered_id);
515  exit;
516  } else {
517  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("please_select_a_delivered_file_to_download"), true);
518  $ilCtrl->redirect($this, "submissionScreen");
519  }
520  }
521 }
handleNewUpload(bool $a_no_notifications=false)
setFilenames(array $a_filenames)
ILIAS Exercise InternalGUIService $gui
uploadZipFormObject(?\ILIAS\Repository\Form\FormAdapterGUI $a_form=null)
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...
Interface Observer Contains several chained tasks and infos about them.
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
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
const IL_CAL_UNIX
ilGlobalTemplateInterface $tpl
uploadFormObject(?ilPropertyFormGUI $a_form=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Provides fluid interface to RBAC services.
Definition: UIServices.php:24
Class ilObjExercise.
downloadObject()
User downloads (own) submitted files.
handleUploadResult(\ILIAS\FileUpload\FileUpload $upload, \ILIAS\FileUpload\DTO\UploadResult $result)
setScreenIdComponent(string $a_comp)
global $DIC
Definition: shib_login.php:22
initUploadForm()
Init upload form form.
ILIAS Exercise Submission SubmissionManager $subm
confirmDeleteDeliveredObject()
Confirm deletion of delivered files.
__construct(Container $dic, ilPlugin $plugin)
downloadReturnedObject(bool $a_only_new=false)
Download submitted files of user.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
getZipUploadForm()
Init upload form form.
handleZipUploadResult(\ILIAS\FileUpload\FileUpload $upload, \ILIAS\FileUpload\DTO\UploadResult $result)
Exercise submission //TODO: This class has many static methods related to delivered "files"...
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteDeliveredObject()
Delete file(s) submitted by user.