ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPortfolioExerciseGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
30  protected ilCtrl $ctrl;
31  protected ilLanguage $lng;
32  protected int $user_id;
33  protected int $obj_id;
34  protected int $ass_id;
35  protected string $file;
37  protected \ILIAS\DI\UIServices $ui;
38  private \ilGlobalTemplateInterface $main_tpl;
39 
40  public function __construct(
41  int $a_user_id,
42  int $a_obj_id
43  ) {
44  global $DIC;
45  $this->main_tpl = $DIC->ui()->mainTemplate();
46 
47  $this->ctrl = $DIC->ctrl();
48  $this->lng = $DIC->language();
49  $this->user_id = $a_user_id;
50  $this->obj_id = $a_obj_id;
51 
52  $this->port_request = $DIC->portfolio()
53  ->internal()
54  ->gui()
55  ->standardRequest();
56 
57  $this->ass_id = $this->port_request->getExcAssId();
58  $this->file = $this->port_request->getExcFile();
59  $this->ui = $DIC->ui();
60  }
61 
62  public function executeCommand(): void
63  {
64  $ilCtrl = $this->ctrl;
65 
66  if (!$this->ass_id ||
67  !$this->user_id) {
68  $this->ctrl->returnToParent($this);
69  }
70 
71  $next_class = $ilCtrl->getNextClass($this);
72  $cmd = $ilCtrl->getCmd();
73 
74  switch ($next_class) {
75  default:
76  $this->$cmd();
77  break;
78  }
79  }
80 
85  public static function checkExercise(
86  int $a_user_id,
87  int $a_obj_id,
88  bool $a_add_submit = false,
89  bool $as_array = false
90  ) {
91  $pe = new ilPortfolioExercise($a_user_id, $a_obj_id);
92 
93  $info = [];
94  foreach ($pe->getAssignmentsOfPortfolio() as $exercise) {
95  $part = self::getExerciseInfo($a_user_id, $exercise["ass_id"], $a_add_submit, $as_array);
96  if ($part) {
97  $info[] = $part;
98  }
99  }
100  if (count($info) && !$as_array) {
101  return implode("<br />", $info);
102  }
103 
104  if ($as_array) {
105  return $info;
106  }
107  }
108 
116  protected static function getExerciseInfo(
117  int $a_user_id,
118  int $a_assignment_id,
119  bool $a_add_submit = false,
120  bool $as_array = false
121  ) {
122  global $DIC;
123 
124  $ui = $DIC->ui();
125 
126  $links = [];
127  $buttons = [];
128  $elements = [];
129 
130  $lng = $DIC->language();
131  $ilCtrl = $DIC->ctrl();
132  $rel = false;
133 
134  $ass = new ilExAssignment($a_assignment_id);
135  $exercise_id = $ass->getExerciseId();
136  if (!$exercise_id) {
137  return "";
138  }
139 
140  // is the assignment still open?
141  $times_up = $ass->afterDeadlineStrict();
142 
143  // exercise goto
144  $ref_ids = ilObject::_getAllReferences($exercise_id);
145  $exc_ref_id = array_shift($ref_ids);
146  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
147 
148  $info_arr["ass_title"] = $ass->getTitle();
149  $text = sprintf(
150  $lng->txt("prtf_exercise_info"),
151  $ass->getTitle(),
152  ilObject::_lookupTitle($exercise_id)
153  );
154  $links[] = $ui->factory()->link()->standard(ilObject::_lookupTitle($exercise_id), $exc_link);
155  $info_arr["exc_title"] = ilObject::_lookupTitle($exercise_id);
156 
157  // submit button
158  if ($a_add_submit && !$times_up && !$as_array) {
159  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
160  $submit_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "finalize");
161  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
162 
163  $buttons[] = $ui->factory()->button()->primary($lng->txt("prtf_finalize_portfolio"), $submit_link);
164  }
165 
166  // submitted files
167  $submission = new ilExSubmission($ass, $a_user_id);
168  $info_arr["submitted"] = false;
169  if ($submission->hasSubmitted()) {
170  // #16888
171  $submitted = $submission->getSelectedObject();
172 
173  if (!$as_array) {
174  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
175  $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcSubFile");
176  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
177 
180 
181  $text .= "<p>" . sprintf(
182  $lng->txt("prtf_exercise_submitted_info"),
184  ""
185  ) . "</p>";
186  $buttons[] = $ui->factory()->button()->standard($lng->txt("prtf_download_submission"), $dl_link);
187  }
188 
190  $info_arr["submitted_date"] = ilDatePresentation::formatDate(new ilDateTime($submitted["ts"], IL_CAL_DATETIME));
191  $info_arr["submitted"] = true;
192  if ($submitted["ts"] == "") {
193  $info_arr["submitted"] = false;
194  }
195  }
196 
197  // work instructions incl. files
198 
199  $tooltip = "";
200 
201  $inst = $ass->getInstruction();
202  if ($inst) {
203  $tooltip .= nl2br($inst);
204  }
205 
206  $ass_files = $ass->getFiles();
207  if (!$as_array && count($ass_files) > 0) {
208  if ($tooltip) {
209  $tooltip .= "<br /><br />";
210  }
211 
212  $items = [];
213 
214  foreach ($ass_files as $file) {
215  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
216  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", urlencode($file["name"]));
217  $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcAssFile");
218  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", "");
219  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
220 
221  $items[] = $ui->renderer()->render($ui->factory()->button()->shy($file["name"], $dl_link));
222  }
223  $list = $ui->factory()->listing()->unordered($items);
224  $tooltip .= $ui->renderer()->render($list);
225  }
226 
227  if ($tooltip) {
228  $modal = $ui->factory()->modal()->roundtrip($lng->txt("exc_instruction"), $ui->factory()->legacy($tooltip))
229  ->withCancelButtonLabel("close");
230  $elements[] = $modal;
231  $buttons[] = $ui->factory()->button()->standard($lng->txt("exc_instruction"), '#')
232  ->withOnClick($modal->getShowSignal());
233  }
234 
235  if ($as_array) {
236  return $info_arr;
237  }
238 
239  $elements[] = $ui->factory()->messageBox()->info($text)
240  ->withLinks($links)
241  ->withButtons($buttons);
242 
243  return $ui->renderer()->render($elements);
244  }
245 
246  public function downloadExcAssFile(): void
247  {
248  if ($this->file) {
249  $ass = new ilExAssignment($this->ass_id);
250  $ass_files = $ass->getFiles();
251  if (count($ass_files) > 0) {
252  foreach ($ass_files as $file) {
253  if ($file["name"] == $this->file) {
254  ilFileDelivery::deliverFileLegacy($file["fullpath"], $file["name"]);
255  }
256  }
257  }
258  }
259  }
260 
261  public function downloadExcSubFile(): void
262  {
263  $ass = new ilExAssignment($this->ass_id);
264  $submission = new ilExSubmission($ass, $this->user_id);
265  $submitted = $submission->getFiles();
266  if (count($submitted) > 0) {
267  $submitted = array_pop($submitted);
268 
269  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
270  $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
271  $ass->getTitle() . " - " .
272  $user_data["firstname"] . " " .
273  $user_data["lastname"] . " (" .
274  $user_data["login"] . ").zip";
275 
276  ilFileDelivery::deliverFileLegacy($submitted["filename"], $title);
277  }
278  }
279 
283  protected function finalize(): void
284  {
285  $lng = $this->lng;
286  $ilCtrl = $this->ctrl;
287 
288  $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
289  $exc_gui->submitPortfolio($this->obj_id);
290 
291  $this->main_tpl->setOnScreenMessage('success', $lng->txt("prtf_finalized"), true);
292  $ilCtrl->returnToParent($this);
293  }
294 
299  public function getSubmitButton(
300  int $ass_id
301  ): ?\ILIAS\UI\Component\Button\Primary {
302  $ilCtrl = $this->ctrl;
303  $ui = $this->ui;
304  $lng = $this->lng;
305 
306  $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user_id);
307 
308  if ($state->isSubmissionAllowed()) {
309  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $ass_id);
310  $submit_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "finalize");
311  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
312  $button = $ui->factory()->button()->primary($lng->txt("prtf_finalize_portfolio"), $submit_link);
313  return $button;
314  }
315  return null;
316  }
317 
319  int $ass_id
320  ): ?\ILIAS\UI\Component\Button\Standard {
321  $ilCtrl = $this->ctrl;
322  $lng = $this->lng;
323  $ui = $this->ui;
324 
325  // submitted files
326  $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user_id);
327  if ($submission->hasSubmitted()) {
328  // #16888
329  $submitted = $submission->getSelectedObject();
330  if ($submitted["ts"] != "") {
331  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $ass_id);
332  $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcSubFile");
333  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
334  $button = $ui->factory()->button()->standard($lng->txt("prtf_download_submission"), $dl_link);
335  return $button;
336  }
337  }
338  return null;
339  }
340 
341 
345  public function getActionButtons(): array
346  {
347  $pe = new ilPortfolioExercise($this->user_id, $this->obj_id);
348 
349  $buttons = [];
350  foreach ($pe->getAssignmentsOfPortfolio() as $exercise) {
351  $ass_id = $exercise["ass_id"];
352  $buttons[$ass_id] = [];
353  $submit_button = $this->getSubmitButton($ass_id);
354  if ($submit_button) {
355  $buttons[$ass_id][] = $submit_button;
356  }
357  $download_button = $this->getDownloadSubmissionButton($ass_id);
358  if ($download_button) {
359  $buttons[$ass_id][] = $download_button;
360  }
361  }
362 
363  return $buttons;
364  }
365 }
Exercise assignment.
Class Factory.
const IL_CAL_DATETIME
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...
Class ChatMainBarProvider .
static checkExercise(int $a_user_id, int $a_obj_id, bool $a_add_submit=false, bool $as_array=false)
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
__construct(int $a_user_id, int $a_obj_id)
getSubmitButton(int $ass_id)
Get submit link.
Class ilPortfolioExerciseGUI.
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
static _lookupTitle(int $obj_id)
getActionButtons()
Get action buttons.
ilGlobalTemplateInterface $main_tpl
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
static initGUIForSubmit(int $a_ass_id, int $a_user_id=null)
static getExerciseInfo(int $a_user_id, int $a_assignment_id, bool $a_add_submit=false, bool $as_array=false)
finalize()
Finalize and submit portfolio to exercise.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setUseRelativeDates(bool $a_status)
set use relative dates
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...