ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilExSubmissionFileGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $toolbar;
18
22 protected $help;
23
27 protected $user;
28
32 protected $ui;
33
37 public function __construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
38 {
39 global $DIC;
40
41 parent::__construct($a_exercise, $a_submission);
42
43 $this->toolbar = $DIC->toolbar();
44 $this->help = $DIC["ilHelp"];
45 $this->user = $DIC->user();
46
47 $this->ui = $DIC->ui();
48 }
49
50 public function executeCommand()
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 default:
63 $this->{$cmd . "Object"}();
64 break;
65 }
66 }
67
68 public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
69 {
70 global $DIC;
71
72 $lng = $DIC->language();
73 $ilCtrl = $DIC->ctrl();
74
75 $titles = array();
76 foreach ($a_submission->getFiles() as $file) {
77 $titles[] = htmlentities($file["filetitle"]);
78 }
79 $files_str = implode("<br>", $titles);
80 if ($files_str == "") {
81 $files_str = $lng->txt("message_no_delivered_files");
82 }
83
84 // no team == no submission
85 if (!$a_submission->hasNoTeamYet()) {
86 if ($a_submission->canSubmit()) {
87 $title = (count($titles) == 0
88 ? $lng->txt("exc_hand_in")
89 : $lng->txt("exc_edit_submission"));
90
91 $button = ilLinkButton::getInstance();
92 $button->setPrimary(true);
93 $button->setCaption($title, false);
94 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
95 $files_str .= "<br><br>" . $button->render();
96 } else {
97 if (count($titles) > 0) {
98 $button = ilLinkButton::getInstance();
99 $button->setCaption("already_delivered_files");
100 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "submissionScreen"));
101 $files_str .= "<br><br>" . $button->render();
102 }
103 }
104 }
105
106 $a_info->addProperty($lng->txt("exc_files_returned"), $files_str);
107 }
108
114 public function submissionScreenObject()
115 {
116 $ilToolbar = $this->toolbar;
117 $ilHelp = $this->help;
119
120
121 $this->triggerAssignmentTool();
122
123 $this->handleTabs();
124
125 $ilHelp->setScreenIdComponent("exc");
126 $ilHelp->setScreenId("submissions");
127
128 if (!$this->submission->canSubmit()) {
129 ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
130 } else {
131 $max_files = $this->submission->getAssignment()->getMaxFile();
132
133 if ($this->submission->canAddFile()) {
134 // #15883 - extended deadline warning
135 $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
136 if ($deadline &&
137 time() > $deadline) {
139 $dl = sprintf($this->lng->txt("exc_late_submission_warning"), $dl);
140 $dl = '<span class="warning">' . $dl . '</span>';
141 $ilToolbar->addText($dl);
142 }
143
144 $b = $this->ui->factory()->button()->standard(
145 $this->lng->txt("file_add"),
146 $this->ctrl->getLinkTarget($this, "uploadForm")
147 );
148 $ilToolbar->addStickyItem($b);
149
150 if (!$max_files ||
151 $max_files > 1) {
152 $ilToolbar->addButton(
153 $this->lng->txt("header_zip"),
154 $this->ctrl->getLinkTarget($this, "uploadZipForm")
155 );
156 }
157 }
158
159 if ($max_files) {
160 ilUtil::sendInfo(sprintf($this->lng->txt("exc_max_file_reached"), $max_files));
161 }
162 }
163
164 $tab = new ilExcDeliveredFilesTableGUI($this, "submissionScreen", $this->submission);
165 $this->tpl->setContent($tab->getHTML());
166 }
167
171 public function uploadFormObject(ilPropertyFormGUI $a_form = null)
172 {
173 if (!$this->submission->canSubmit()) {
174 $this->ctrl->redirect($this, "submissionScreen");
175 }
176
177 $this->tabs_gui->clearTargets();
178 $this->tabs_gui->setBackTarget(
179 $this->lng->txt("back"),
180 $this->ctrl->getLinkTarget($this, "submissionScreen")
181 );
182
183 $ilHelp = $this->help;
184 $ilHelp->setScreenIdComponent("exc");
185 $ilHelp->setScreenId("upload_submission");
186
187 if (!$a_form) {
188 $a_form = $this->initUploadForm();
189 }
190 $this->tpl->setContent($a_form->getHTML());
191 }
192
196 public function uploadZipFormObject(ilPropertyFormGUI $a_form = null)
197 {
198 if (!$this->submission->canSubmit()) {
199 $this->ctrl->redirect($this, "submissionScreen");
200 }
201
202 $this->tabs_gui->clearTargets();
203 $this->tabs_gui->setBackTarget(
204 $this->lng->txt("back"),
205 $this->ctrl->getLinkTarget($this, "submissionScreen")
206 );
207
208 if (!$a_form) {
209 $a_form = $this->initZipUploadForm();
210 }
211 $this->tpl->setContent($a_form->getHTML());
212 }
213
217 protected function initUploadForm()
218 {
220 $ilCtrl = $this->ctrl;
221
222 $form = new ilPropertyFormGUI();
223
224 // file input
225 $fi = new ilFileWizardInputGUI($lng->txt("file"), "deliver");
226 $fi->setFilenames(array(0 => ''));
227 $fi->setRequired(true);
228 $form->addItem($fi);
229
230 $form->addCommandButton("uploadFile", $lng->txt("upload"));
231 $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
232
233 $form->setTitle($lng->txt("file_add"));
234 $form->setFormAction($ilCtrl->getFormAction($this, "uploadFile"));
235
236 return $form;
237 }
238
242 protected function initZipUploadForm()
243 {
245 $ilCtrl = $this->ctrl;
246
247 $form = new ilPropertyFormGUI();
248
249 $fi = new ilFileInputGUI($lng->txt("file"), "deliver");
250 $fi->setSuffixes(array("zip"));
251 $fi->setRequired(true);
252 $form->addItem($fi);
253
254 $form->addCommandButton("uploadZip", $lng->txt("upload"));
255 $form->addCommandButton("submissionScreen", $lng->txt("cancel"));
256
257 $form->setTitle($lng->txt("header_zip"));
258 $form->setFormAction($ilCtrl->getFormAction($this, "uploadZip"));
259
260 return $form;
261 }
262
266 public function uploadFileObject()
267 {
268 $ilCtrl = $this->ctrl;
269
270 // #15322
271 if (!$this->submission->canSubmit()) {
272 ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
273 } else {
274 $form = $this->initUploadForm();
275 if (!$form->checkInput()) {
276 return $this->uploadFormObject($form);
277 }
278
279 $success = false;
280 foreach ($_FILES["deliver"]["name"] as $k => $v) {
281 $file = array(
282 "name" => $_FILES["deliver"]["name"][$k],
283 "type" => $_FILES["deliver"]["type"][$k],
284 "tmp_name" => $_FILES["deliver"]["tmp_name"][$k],
285 "error" => $_FILES["deliver"]["error"][$k],
286 "size" => $_FILES["deliver"]["size"][$k],
287 );
288 if (!$this->submission->uploadFile($file)) {
289 ilUtil::sendFailure($this->lng->txt("exc_upload_error") . " [Single File]", true);
290 } else {
291 $success = true;
292 }
293 }
294
295 if ($success) {
296 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
297 $this->handleNewUpload();
298 }
299 }
300
301 $ilCtrl->redirect($this, "submissionScreen");
302 }
303
307 public function uploadZipObject()
308 {
309 $ilCtrl = $this->ctrl;
310
311 // #15322
312 if (!$this->submission->canSubmit()) {
313 ilUtil::sendInfo($this->lng->txt("exercise_time_over"), true);
314 } else {
315 $form = $this->initZipUploadForm();
316 if (!$form->checkInput()) {
317 return $this->uploadZipFormObject($form);
318 }
319
320 if (preg_match("/zip/", $_FILES["deliver"]["type"]) == 1) {
321 if ($this->submission->processUploadedZipFile($_FILES["deliver"]["tmp_name"])) {
322 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
323 $this->handleNewUpload();
324 }
325 }
326 }
327
328 $ilCtrl->redirect($this, "submissionScreen");
329 }
330
335 {
336 $ilCtrl = $this->ctrl;
339
340 if (!$this->submission->canSubmit()) {
341 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
342 $ilCtrl->redirect($this, "submissionScreen");
343 }
344
345 if (!is_array($_POST["delivered"]) || count($_POST["delivered"]) == 0) {
346 ilUtil::sendFailure($lng->txt("no_checkbox"), true);
347 $ilCtrl->redirect($this, "submissionScreen");
348 } else {
349 $this->tabs_gui->clearTargets();
350 $this->tabs_gui->setBackTarget(
351 $this->lng->txt("back"),
352 $this->ctrl->getLinkTarget($this, "submissionScreen")
353 );
354
355 $cgui = new ilConfirmationGUI();
356 $cgui->setFormAction($ilCtrl->getFormAction($this));
357 $cgui->setHeaderText($lng->txt("info_delete_sure"));
358 $cgui->setCancel($lng->txt("cancel"), "submissionScreen");
359 $cgui->setConfirm($lng->txt("delete"), "deleteDelivered");
360
361 $files = $this->submission->getFiles();
362
363 foreach ($_POST["delivered"] as $i) {
364 reset($files);
365 $title = "";
366 foreach ($files as $f) {
367 if ($f["returned_id"] == $i) {
368 $title = $f["filetitle"];
369 }
370 }
371 $cgui->addItem("delivered[]", $i, $title);
372 }
373
374 $tpl->setContent($cgui->getHTML());
375 }
376 }
377
384 public function deleteDeliveredObject()
385 {
386 $ilCtrl = $this->ctrl;
387
388 if (!$this->submission->canSubmit()) {
389 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
390 } elseif (!count($_POST["delivered"])) {
391 ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_delete"), true);
392 } else {
393 $this->submission->deleteSelectedFiles($_POST["delivered"]);
394 $this->handleRemovedUpload();
395
396 ilUtil::sendSuccess($this->lng->txt("exc_submitted_files_deleted"), true);
397 }
398 $ilCtrl->redirect($this, "submissionScreen");
399 }
400
404 public function downloadReturnedObject($a_only_new = false)
405 {
407
408 $peer_review_mask_filename = false;
409
410 if ($this->submission->canView()) {
411 $peer_review_mask_filename = $this->submission->hasPeerReviewAccess();
412 } else {
413 // no access
414 return;
415 }
416
417 $this->submission->downloadFiles(null, $a_only_new, $peer_review_mask_filename);
418 // we only get here, if no files have been found for download
419 if ($a_only_new) {
420 ilUtil::sendInfo($lng->txt("exc_all_new_files_offered_already"), true);
421 }
422 $this->returnToParentObject();
423 }
424
429 {
430 $this->downloadReturnedObject(true);
431 }
432
439 public function downloadObject()
440 {
441 $ilCtrl = $this->ctrl;
442
443 $delivered_id = $_REQUEST["delivered"];
444
445 if (!$this->submission->canView()) {
446 $this->returnToParentObject();
447 }
448
449 if (!is_array($delivered_id) && $delivered_id > 0) {
450 $delivered_id = [$delivered_id];
451 }
452 if (is_array($delivered_id) && count($delivered_id) > 0) {
453 $this->submission->downloadFiles($delivered_id);
454 exit;
455 } else {
456 ilUtil::sendFailure($this->lng->txt("please_select_a_delivered_file_to_download"), true);
457 $ilCtrl->redirect($this, "submissionScreen");
458 }
459 }
460}
user()
Definition: user.php:4
$success
Definition: Utf8Test.php:86
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Confirmation screen class.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Exercise submission base gui.
triggerAssignmentTool()
Trigger assigment tool.
handleNewUpload($a_no_notifications=false)
uploadZipFormObject(ilPropertyFormGUI $a_form=null)
Display form for zip file upload.
confirmDeleteDeliveredObject()
Confirm deletion of delivered files.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initZipUploadForm()
Init upload form form.
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
Constructor.
deleteDeliveredObject()
Delete file(s) submitted by user.
downloadNewReturnedObject()
Download newly submitted files of user.
downloadObject()
User downloads (own) submitted files.
initUploadForm()
Init upload form form.
submissionScreenObject()
Displays a form which allows members to deliver their solutions.
downloadReturnedObject($a_only_new=false)
Download submitted files of user.
uploadFormObject(ilPropertyFormGUI $a_form=null)
Display form for single file upload.
Exercise submission //TODO: This class has to much static methods related to delivered "files".
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)
Get submission items (not only files)
This class represents a file property in a property form.
This class represents a file wizard property in a property form.
Class ilInfoScreenGUI.
addProperty($a_name, $a_value, $a_link="")
add a property to current section
static getInstance()
Factory.
Class ilObjExercise.
This class represents a property form user interface.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18
exit
Definition: login.php:29
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
ui()
Definition: ui.php:5