ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExSubmissionGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
31 {
32  public const MODE_OVERVIEW_CONTENT = 1;
33 
34  protected ilCtrl $ctrl;
35  protected ilTabsGUI $tabs_gui;
36  protected ilLanguage $lng;
38  protected ilObjUser $user;
43  protected ?int $user_id;
44  protected GUIRequest $request;
45 
46  public function __construct(
47  ilObjExercise $a_exercise,
48  ilExAssignment $a_ass,
49  int $a_user_id = null
50  ) {
52  global $DIC;
53 
54  $this->user = $DIC->user();
55  $ilCtrl = $DIC->ctrl();
56  $ilTabs = $DIC->tabs();
57  $lng = $DIC->language();
58  $tpl = $DIC["tpl"];
59  $ilUser = $DIC->user();
60 
61  if (!$a_user_id) {
62  $a_user_id = $ilUser->getId();
63  }
64 
65  $this->assignment = $a_ass;
66  $this->exercise = $a_exercise;
67  $this->user_id = $a_user_id;
68 
69  $this->type_guis = ilExAssignmentTypesGUI::getInstance();
70 
71  // #12337
72  if (!$this->exercise->members_obj->isAssigned($a_user_id)) {
73  $this->exercise->members_obj->assignMember($a_user_id);
74  }
75 
76  // public submissions ???
77  $public_submissions = false;
78  if ($this->exercise->getShowSubmissions() &&
79  $this->exercise->getTimestamp() - time() <= 0) { // ???
80  $public_submissions = true;
81  }
82  $this->submission = new ilExSubmission($a_ass, $a_user_id, null, false, $public_submissions);
83 
84  // :TODO:
85  $this->ctrl = $ilCtrl;
86  $this->tabs_gui = $ilTabs;
87  $this->lng = $lng;
88  $this->tpl = $tpl;
89  $this->request = $DIC->exercise()->internal()->gui()->request();
90  }
91 
95  public function executeCommand(): void
96  {
97  $ilCtrl = $this->ctrl;
98 
99  $class = $ilCtrl->getNextClass($this);
100  $cmd = $ilCtrl->getCmd("listPublicSubmissions");
101 
102  switch ($class) {
103  case "ilexsubmissionteamgui":
104  // team gui has no base gui - see we have to handle tabs here
105 
106  $this->tabs_gui->clearTargets();
107  $this->tabs_gui->setBackTarget(
108  $this->lng->txt("back"),
109  $this->ctrl->getLinkTarget($this, "returnToParent")
110  );
111 
112  // forward to type gui
113  if ($this->submission->getSubmissionType() != ilExSubmission::TYPE_REPO_OBJECT) {
114  $this->tabs_gui->addTab(
115  "submission",
116  $this->lng->txt("exc_submission"),
117  $this->ctrl->getLinkTargetByClass("ilexsubmission" . $this->submission->getSubmissionType() . "gui", "")
118  );
119  }
120 
121  $gui = new ilExSubmissionTeamGUI($this->exercise, $this->submission);
122  $ilCtrl->forwardCommand($gui);
123  break;
124 
125  case "ilexsubmissiontextgui":
126  $gui = new ilExSubmissionTextGUI($this->exercise, $this->submission);
127  $ilCtrl->forwardCommand($gui);
128  break;
129 
130  case "ilexsubmissionfilegui":
131  $gui = new ilExSubmissionFileGUI($this->exercise, $this->submission);
132  $ilCtrl->forwardCommand($gui);
133  break;
134 
135  case "ilexsubmissionobjectgui":
136  $gui = new ilExSubmissionObjectGUI($this->exercise, $this->submission);
137  $ilCtrl->forwardCommand($gui);
138  break;
139 
140  case "ilexpeerreviewgui":
141  $this->tabs_gui->clearTargets();
142  $this->tabs_gui->setBackTarget(
143  $this->lng->txt("back"),
144  $this->ctrl->getLinkTarget($this, "returnToParent")
145  );
146 
147  $peer_gui = new ilExPeerReviewGUI($this->assignment, $this->submission);
148  $this->ctrl->forwardCommand($peer_gui);
149  break;
150 
151  default:
152 
153 
154  // forward to type gui
155  if ($this->type_guis->isExAssTypeGUIClass($class)) {
156  $type_gui = $this->type_guis->getByClassName($class);
157  $type_gui->setSubmission($this->submission);
158  $type_gui->setExercise($this->exercise);
159  $ilCtrl->forwardCommand($type_gui);
160  }
161 
162  $this->{$cmd . "Object"}();
163  break;
164  }
165  }
166 
167  public static function getOverviewContent(
168  ilInfoScreenGUI $a_info,
169  ilExSubmission $a_submission,
170  ilObjExercise $a_exc
171  ): void {
172  global $DIC;
173 
174  $ilCtrl = $DIC->ctrl();
175 
176  if (!$a_submission->canView()) {
177  return;
178  }
179 
180  $ilCtrl->setParameterByClass("ilExSubmissionGUI", "ass_id", $a_submission->getAssignment()->getId());
181 
182  if ($a_submission->getAssignment()->hasTeam()) {
183  ilExSubmissionTeamGUI::getOverviewContent($a_info, $a_submission);
184  }
185 
186  $submission_type = $a_submission->getSubmissionType();
187  // old handling -> forward to submission type gui class
188  // @todo migrate everything to new concept
189  if ($submission_type != ilExSubmission::TYPE_REPO_OBJECT) {
190  $class = "ilExSubmission" . $submission_type . "GUI";
192  $class::getOverviewContent($a_info, $a_submission);
193  } else { // new: get HTML from assignemt type gui class
194  $sub_gui = new ilExSubmissionGUI($a_exc, $a_submission->getAssignment());
195  $ilCtrl->getHTML($sub_gui, array(
196  "mode" => self::MODE_OVERVIEW_CONTENT,
197  "info" => $a_info,
198  "submission" => $a_submission
199  ));
200  }
201 
202  $ilCtrl->setParameterByClass("ilExSubmissionGUI", "ass_id", "");
203  }
204 
208  public function getHTML(array $par): string
209  {
210  switch ($par["mode"]) {
211  // get overview content from ass type gui
212  case self::MODE_OVERVIEW_CONTENT:
213  $type_gui = $this->type_guis->getById($par["submission"]->getAssignment()->getType());
214  $type_gui->getOverviewContent($par["info"], $par["submission"]);
215  break;
216  }
217  return "";
218  }
219 
220  public function listPublicSubmissionsObject(): void
221  {
222  $ilTabs = $this->tabs_gui;
223  $ilCtrl = $this->ctrl;
224  $lng = $this->lng;
225 
226  if (!$this->exercise->getShowSubmissions()) {
227  $this->returnToParentObject();
228  }
229 
230  $ilTabs->clearTargets();
231  $ilTabs->setBackTarget(
232  $lng->txt("back"),
233  $ilCtrl->getLinkTarget($this, "returnToParent")
234  );
235 
236  if ($this->assignment->getType() != ilExAssignment::TYPE_TEXT) {
237  $tab = new ilPublicSubmissionsTableGUI($this, "listPublicSubmissions", $this->assignment);
238  $this->tpl->setContent($tab->getHTML());
239  } else {
240  // #13271
241  $tbl = new ilExAssignmentListTextTableGUI($this, "listPublicSubmissions", $this->assignment, false, true);
242  $this->tpl->setContent($tbl->getHTML());
243  }
244  }
245 
249  public function downloadFeedbackFileObject(): bool
250  {
251  $file = $this->request->getFile();
252 
253  if (!isset($file)) {
254  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_select_one_file"), true);
255  $this->ctrl->redirect($this, "view");
256  }
257 
258  // check, whether file belongs to assignment
259  $storage = new ilFSStorageExercise($this->exercise->getId(), $this->assignment->getId());
260  $files = $storage->getFeedbackFiles($this->submission->getFeedbackId());
261  $file_exist = false;
262  foreach ($files as $fb_file) {
263  if ($fb_file == $file) {
264  $file_exist = true;
265  break;
266  }
267  }
268 
269  if (!$file_exist) {
270  return false;
271  }
272 
273  // check whether assignment has already started
274  if (!$this->assignment->notStartedYet()) {
275  // deliver file
276  $p = $storage->getFeedbackFilePath($this->submission->getFeedbackId(), $file);
278  }
279 
280  return true;
281  }
282 
283  public function downloadGlobalFeedbackFileObject(): void
284  {
285  $ilCtrl = $this->ctrl;
286 
287  $state = ilExcAssMemberState::getInstanceByIds($this->assignment->getId(), $this->user_id);
288 
289  // fix bug 28466, this code should be streamlined with the if above and
290  // the presentation of the download link in the ilExAssignmentGUI->addSubmission
291  if (!$state->isGlobalFeedbackFileAccessible($this->submission)) {
292  $ilCtrl->redirect($this, "returnToParent");
293  }
294 
295  // this is due to temporary bug in handleGlobalFeedbackFileUpload that missed the last "/"
296  $file = (is_file($this->assignment->getGlobalFeedbackFilePath()))
297  ? $this->assignment->getGlobalFeedbackFilePath()
298  : $this->assignment->getGlobalFeedbackFileStoragePath() . $this->assignment->getFeedbackFile();
299 
300  ilFileDelivery::deliverFileLegacy($file, $this->assignment->getFeedbackFile());
301  }
302 
303  public function downloadFileObject(): bool
304  {
305  $file = $this->request->getFile();
306 
307  if (!isset($file)) {
308  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_select_one_file"), true);
309  $this->ctrl->redirect($this, "view");
310  }
311 
312  // check whether assignment as already started
313  $state = ilExcAssMemberState::getInstanceByIds($this->assignment->getId(), $this->user_id);
314  if ($state->areInstructionsVisible()) {
315  // check, whether file belongs to assignment
316  $files = $this->assignment->getFiles();
317  $file_exist = false;
318  foreach ($files as $lfile) {
319  if ($lfile["name"] == $file) {
320  // deliver file
321  ilFileDelivery::deliverFileLegacy($lfile["fullpath"], $file);
322  exit();
323  }
324  }
325  if (!$file_exist) {
326  return false;
327  }
328  }
329 
330  return true;
331  }
332 
333  public function returnToParentObject(): void
334  {
335  $this->ctrl->returnToParent($this);
336  }
337 }
exit
Definition: login.php:28
Class ilInfoScreenGUI.
Exercise assignment.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
downloadFeedbackFileObject()
Download feedback file.
static getInstance()
Get instance.
ilExAssignmentTypesGUI $type_guis
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
Class ilObjExercise.
getNextClass($a_gui_class=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
$ilUser
Definition: imgupload.php:34
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFeedbackFiles(string $a_user_id)
Exercise gui request wrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Object-based submissions (ends up as static file)
Class ilExSubmissionGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...