ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExSubmissionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Modules/Exercise/classes/class.ilExSubmissionBaseGUI.php";
5 include_once "Modules/Exercise/classes/class.ilExSubmission.php";
6 
18 {
20 
24  protected $ctrl;
25 
29  protected $tabs_gui;
30 
34  protected $lng;
35 
39  protected $tpl;
40 
44  protected $user;
45 
46  protected $exercise; // [ilObjExercise]
47  protected $submission; // [ilExSubmission]
48  protected $assignment; // [ilExAssignment]
49 
53  protected $type_guis;
54 
63  public function __construct(ilObjExercise $a_exercise, ilExAssignment $a_ass, $a_user_id = null)
64  {
65  global $DIC;
66 
67  $this->user = $DIC->user();
68  $ilCtrl = $DIC->ctrl();
69  $ilTabs = $DIC->tabs();
70  $lng = $DIC->language();
71  $tpl = $DIC["tpl"];
72  $ilUser = $DIC->user();
73 
74  if (!$a_user_id) {
75  $a_user_id = $ilUser->getId();
76  }
77 
78  $this->assignment = $a_ass;
79  $this->exercise = $a_exercise;
80  $this->user_id = $a_user_id;
81 
82  include_once("./Modules/Exercise/AssignmentTypes/GUI/classes/class.ilExAssignmentTypesGUI.php");
83  $this->type_guis = ilExAssignmentTypesGUI::getInstance();
84 
85  // #12337
86  if (!$this->exercise->members_obj->isAssigned($a_user_id)) {
87  $this->exercise->members_obj->assignMember($a_user_id);
88  }
89 
90  // public submissions ???
91  $public_submissions = false;
92  if ($this->exercise->getShowSubmissions() &&
93  $this->exercise->getTimestamp() - time() <= 0) { // ???
94  $public_submissions = true;
95  }
96  $this->submission = new ilExSubmission($a_ass, $a_user_id, null, false, $public_submissions);
97 
98  // :TODO:
99  $this->ctrl = $ilCtrl;
100  $this->tabs_gui = $ilTabs;
101  $this->lng = $lng;
102  $this->tpl = $tpl;
103  }
104 
105  public function executeCommand()
106  {
108 
109  $class = $ilCtrl->getNextClass($this);
110  $cmd = $ilCtrl->getCmd("listPublicSubmissions");
111 
112  switch ($class) {
113  case "ilexsubmissionteamgui":
114  // team gui has no base gui - see we have to handle tabs here
115 
116  $this->tabs_gui->clearTargets();
117  $this->tabs_gui->setBackTarget(
118  $this->lng->txt("back"),
119  $this->ctrl->getLinkTarget($this, "returnToParent")
120  );
121 
122  // forward to type gui
123  if ($this->submission->getSubmissionType() != ilExSubmission::TYPE_REPO_OBJECT) {
124  $this->tabs_gui->addTab(
125  "submission",
126  $this->lng->txt("exc_submission"),
127  $this->ctrl->getLinkTargetByClass("ilexsubmission" . $this->submission->getSubmissionType() . "gui", "")
128  );
129  }
130 
131  include_once "Modules/Exercise/classes/class.ilExSubmissionTeamGUI.php";
132  $gui = new ilExSubmissionTeamGUI($this->exercise, $this->submission);
133  $ilCtrl->forwardCommand($gui);
134  break;
135 
136  case "ilexsubmissiontextgui":
137  include_once "Modules/Exercise/classes/class.ilExSubmissionTextGUI.php";
138  $gui = new ilExSubmissionTextGUI($this->exercise, $this->submission);
139  $ilCtrl->forwardCommand($gui);
140  break;
141 
142  case "ilexsubmissionfilegui":
143  include_once "Modules/Exercise/classes/class.ilExSubmissionFileGUI.php";
144  $gui = new ilExSubmissionFileGUI($this->exercise, $this->submission);
145  $ilCtrl->forwardCommand($gui);
146  break;
147 
148  case "ilexsubmissionobjectgui":
149  include_once "Modules/Exercise/classes/class.ilExSubmissionObjectGUI.php";
150  $gui = new ilExSubmissionObjectGUI($this->exercise, $this->submission);
151  $ilCtrl->forwardCommand($gui);
152  break;
153 
154  case "ilexpeerreviewgui":
155  $this->tabs_gui->clearTargets();
156  $this->tabs_gui->setBackTarget(
157  $this->lng->txt("back"),
158  $this->ctrl->getLinkTarget($this, "returnToParent")
159  );
160 
161  include_once("./Modules/Exercise/classes/class.ilExPeerReviewGUI.php");
162  $peer_gui = new ilExPeerReviewGUI($this->assignment, $this->submission);
163  $this->ctrl->forwardCommand($peer_gui);
164  break;
165 
166  default:
167 
168 
169  // forward to type gui
170  if ($this->type_guis->isExAssTypeGUIClass($class)) {
171  $type_gui = $this->type_guis->getByClassName($class);
172  $type_gui->setSubmission($this->submission);
173  $type_gui->setExercise($this->exercise);
174  return $ilCtrl->forwardCommand($type_gui);
175  }
176 
177  $this->{$cmd . "Object"}();
178  break;
179  }
180  }
181 
189  public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission, ilObjExercise $a_exc)
190  {
191  global $DIC;
192 
193  $ilCtrl = $DIC->ctrl();
194 
195  if (!$a_submission->canView()) {
196  return;
197  }
198 
199  $ilCtrl->setParameterByClass("ilExSubmissionGUI", "ass_id", $a_submission->getAssignment()->getId());
200 
201  if ($a_submission->getAssignment()->hasTeam()) {
202  include_once "Modules/Exercise/classes/class.ilExSubmissionTeamGUI.php";
203  ilExSubmissionTeamGUI::getOverviewContent($a_info, $a_submission);
204  }
205 
206  $submission_type = $a_submission->getSubmissionType();
207  // old handling -> forward to submission type gui class
208  // @todo migrate everything to new concept
209  if ($submission_type != ilExSubmission::TYPE_REPO_OBJECT) {
210  $class = "ilExSubmission" . $submission_type . "GUI";
211  include_once "Modules/Exercise/classes/class." . $class . ".php";
212  $class::getOverviewContent($a_info, $a_submission);
213  } else { // new: get HTML from assignemt type gui class
214  include_once("./Modules/Exercise/classes/class.ilExSubmissionGUI.php");
215  $sub_gui = new ilExSubmissionGUI($a_exc, $a_submission->getAssignment());
216  $ilCtrl->getHTML($sub_gui, array(
217  "mode" => self::MODE_OVERVIEW_CONTENT,
218  "info" => $a_info,
219  "submission" => $a_submission
220  ));
221  }
222 
223  $ilCtrl->setParameterByClass("ilExSubmissionGUI", "ass_id", "");
224  }
225 
232  public function getHTML($par)
233  {
234  switch ($par["mode"]) {
235  // get overview content from ass type gui
236  case self::MODE_OVERVIEW_CONTENT:
237  $type_gui = $this->type_guis->getById($par["submission"]->getAssignment()->getType());
238  return $type_gui->getOverviewContent($par["info"], $par["submission"]);
239  break;
240  }
241  }
242 
243 
247  public function listPublicSubmissionsObject()
248  {
249  $ilTabs = $this->tabs_gui;
251  $lng = $this->lng;
252 
253  if (!$this->exercise->getShowSubmissions()) {
254  $this->returnToParentObject();
255  }
256 
257  $ilTabs->clearTargets();
258  $ilTabs->setBackTarget(
259  $lng->txt("back"),
260  $ilCtrl->getLinkTarget($this, "returnToParent")
261  );
262 
263  if ($this->assignment->getType() != ilExAssignment::TYPE_TEXT) {
264  include_once("./Modules/Exercise/classes/class.ilPublicSubmissionsTableGUI.php");
265  $tab = new ilPublicSubmissionsTableGUI($this, "listPublicSubmissions", $this->assignment);
266  $this->tpl->setContent($tab->getHTML());
267  } else {
268  // #13271
269  include_once "Modules/Exercise/classes/class.ilExAssignmentListTextTableGUI.php";
270  $tbl = new ilExAssignmentListTextTableGUI($this, "listPublicSubmissions", $this->assignment, false, true);
271  $this->tpl->setContent($tbl->getHTML());
272  }
273  }
274 
278  public function downloadFeedbackFileObject()
279  {
281 
282  $file = $_REQUEST["file"];
283 
284  if (!isset($file)) {
285  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"), true);
286  $this->ctrl->redirect($this, "view");
287  }
288 
289  // check, whether file belongs to assignment
290  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
291  $storage = new ilFSStorageExercise($this->exercise->getId(), $this->assignment->getId());
292  $files = $storage->getFeedbackFiles($this->submission->getFeedbackId());
293  $file_exist = false;
294  foreach ($files as $fb_file) {
295  if ($fb_file == $file) {
296  $file_exist = true;
297  break;
298  }
299  }
300  if (!$file_exist) {
301  echo "FILE DOES NOT EXIST";
302  exit;
303  }
304 
305  // check whether assignment has already started
306  if (!$this->assignment->notStartedYet()) {
307  // deliver file
308  $p = $storage->getFeedbackFilePath($this->submission->getFeedbackId(), $file);
309  ilUtil::deliverFile($p, $file);
310  }
311 
312  return true;
313  }
314 
316  {
318 
319  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
320  $state = ilExcAssMemberState::getInstanceByIds($this->assignment->getId(), $this->user_id);
321 
322  // fix bug 28466, this code should be streamlined with the if above and
323  // the presentation of the download link in the ilExAssignmentGUI->addSubmission
324  if (!$state->isGlobalFeedbackFileAccessible($this->submission)) {
325  $ilCtrl->redirect($this, "returnToParent");
326  }
327 
328  // this is due to temporary bug in handleGlobalFeedbackFileUpload that missed the last "/"
329  $file = (is_file($this->assignment->getGlobalFeedbackFilePath()))
330  ? $this->assignment->getGlobalFeedbackFilePath()
331  : $this->assignment->getGlobalFeedbackFileStoragePath() . $this->assignment->getFeedbackFile();
332 
333  ilUtil::deliverFile($file, $this->assignment->getFeedbackFile());
334  }
335 
339  public function downloadFileObject()
340  {
341  $file = $_REQUEST["file"];
342 
343  if (!isset($file)) {
344  ilUtil::sendFailure($this->lng->txt("exc_select_one_file"), true);
345  $this->ctrl->redirect($this, "view");
346  }
347 
348  // check whether assignment as already started
349  $state = ilExcAssMemberState::getInstanceByIds($this->assignment->getId(), $this->user_id);
350  if ($state->areInstructionsVisible()) {
351  // check, whether file belongs to assignment
352  $files = $this->assignment->getFiles();
353  $file_exist = false;
354  foreach ($files as $lfile) {
355  if ($lfile["name"] == $file) {
356  // deliver file
357  ilUtil::deliverFile($lfile["fullpath"], $file);
358  exit();
359  }
360  }
361  if (!$file_exist) {
362  echo "FILE DOES NOT EXIST";
363  exit;
364  }
365  }
366 
367  return true;
368  }
369 
370  public function returnToParentObject()
371  {
372  $this->ctrl->returnToParent($this);
373  }
374 }
downloadFileObject()
Download assignment file.
Class ilInfoScreenGUI.
Exercise assignment.
$files
Definition: metarefresh.php:49
global $DIC
Definition: saml.php:7
$tbl
Definition: example_048.php:81
downloadFeedbackFileObject()
Download feedback file.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission, ilObjExercise $a_exc)
listPublicSubmissionsObject()
List all submissions.
static getInstance()
Get instance.
user()
Definition: user.php:4
static getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
global $ilCtrl
Definition: ilias.php:18
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Class ilObjExercise.
Class ilExPeerReviewGUI.
$ilUser
Definition: imgupload.php:18
__construct(ilObjExercise $a_exercise, ilExAssignment $a_ass, $a_user_id=null)
Constructor.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
exit
Definition: backend.php:16
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
Exercise submission //TODO: This class has to much static methods related to delivered "files"...
Object-based submissions (ends up as static file)
Object-based submissions (ends up as static file)
Class ilExSubmissionGUI.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.