ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPortfolioExerciseGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $ctrl;
18
22 protected $lng;
23
24 protected $user_id; // [int]
25 protected $obj_id; // [int]
26 protected $ass_id; // [int]
27 protected $file; // [string]
28
32 protected $pe;
33
37 protected $ui;
38
39 public function __construct($a_user_id, $a_obj_id)
40 {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->lng = $DIC->language();
45 $this->user_id = $a_user_id;
46 $this->obj_id = $a_obj_id;
47 $this->ass_id = (int) $_GET["ass"];
48 $this->file = trim($_GET["file"]);
49 $this->ui = $DIC->ui();
50 }
51
52 public function executeCommand()
53 {
55
56 if (!$this->ass_id ||
57 !$this->user_id) {
58 $this->ctrl->returnToParent($this);
59 }
60
61 $next_class = $ilCtrl->getNextClass($this);
62 $cmd = $ilCtrl->getCmd();
63
64 switch ($next_class) {
65 default:
66 $this->$cmd();
67 break;
68 }
69
70 return true;
71 }
72
73 public static function checkExercise($a_user_id, $a_obj_id, $a_add_submit = false, $as_array = false)
74 {
75 $pe = new ilPortfolioExercise($a_user_id, $a_obj_id);
76
77 $info = [];
78 foreach ($pe->getAssignmentsOfPortfolio() as $exercise) {
79 $part = self::getExerciseInfo($a_user_id, $exercise["ass_id"], $a_add_submit, $as_array);
80 if ($part) {
81 $info[] = $part;
82 }
83 }
84 if (sizeof($info) && !$as_array) {
85 return implode("<br />", $info);
86 }
87
88 if ($as_array) {
89 return $info;
90 }
91 }
92
101 protected static function getExerciseInfo($a_user_id, $a_assignment_id, $a_add_submit = false, $as_array = false)
102 {
103 global $DIC;
104
105 $ui = $DIC->ui();
106
107 $links = [];
108 $buttons = [];
109 $elements = [];
110
111 $lng = $DIC->language();
112 $ilCtrl = $DIC->ctrl();
113
114 $ass = new ilExAssignment($a_assignment_id);
115 $exercise_id = $ass->getExerciseId();
116 if (!$exercise_id) {
117 return;
118 }
119
120 // is the assignment still open?
121 $times_up = $ass->afterDeadlineStrict();
122
123 // exercise goto
124 $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
125 $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
126
127 $info_arr["ass_title"] = $ass->getTitle();
128 $text = sprintf(
129 $lng->txt("prtf_exercise_info"),
130 $ass->getTitle(),
131 ilObject::_lookupTitle($exercise_id)
132 );
133 $links[] = $ui->factory()->link()->standard(ilObject::_lookupTitle($exercise_id), $exc_link);
134 $info_arr["exc_title"] = ilObject::_lookupTitle($exercise_id);
135
136 // submit button
137 if ($a_add_submit && !$times_up && !$as_array) {
138 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
139 $submit_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "finalize");
140 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
141
142 $buttons[] = $ui->factory()->button()->primary($lng->txt("prtf_finalize_portfolio"), $submit_link);
143 }
144
145 // submitted files
146 $submission = new ilExSubmission($ass, $a_user_id);
147 $info_arr["submitted"] = false;
148 if ($submission->hasSubmitted()) {
149 // #16888
150 $submitted = $submission->getSelectedObject();
151
152 if (!$as_array) {
153 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
154 $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcSubFile");
155 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
156
159
160 $text .= "<p>" . sprintf(
161 $lng->txt("prtf_exercise_submitted_info"),
163 ""
164 ) . "</p>";
165 $buttons[] = $ui->factory()->button()->standard($lng->txt("prtf_download_submission"), $dl_link);
166 }
167
169 $info_arr["submitted_date"] = ilDatePresentation::formatDate(new ilDateTime($submitted["ts"], IL_CAL_DATETIME));
170 $info_arr["submitted"] = true;
171 if ($submitted["ts"] == "") {
172 $info_arr["submitted"] = false;
173 }
174 }
175
176 // work instructions incl. files
177
178 $tooltip = "";
179
180 $inst = $ass->getInstruction();
181 if ($inst) {
182 $tooltip .= nl2br($inst);
183 }
184
185 $ass_files = $ass->getFiles();
186 if (!$as_array) {
187 if (count($ass_files) > 0) {
188 if ($tooltip) {
189 $tooltip .= "<br /><br />";
190 }
191
192 $items = [];
193
194 foreach ($ass_files as $file) {
195 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
196 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", urlencode($file["name"]));
197 $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcAssFile");
198 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", "");
199 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
200
201 $items[] = $ui->renderer()->render($ui->factory()->button()->shy($file["name"], $dl_link));
202 }
203 $list = $ui->factory()->listing()->unordered($items);
204 $tooltip .= $ui->renderer()->render($list);
205 }
206 }
207
208 if ($tooltip) {
209 $modal = $ui->factory()->modal()->roundtrip($lng->txt("exc_instruction"), $ui->factory()->legacy($tooltip))
210 ->withCancelButtonLabel("close");
211 $elements[] = $modal;
212 $buttons[] = $ui->factory()->button()->standard($lng->txt("exc_instruction"), '#')
213 ->withOnClick($modal->getShowSignal());
214 }
215
216 if ($as_array) {
217 return $info_arr;
218 }
219
220 $elements[] = $ui->factory()->messageBox()->info($text)
221 ->withLinks($links)
222 ->withButtons($buttons);
223
224 return $ui->renderer()->render($elements);
225 }
226
227 public function downloadExcAssFile()
228 {
229 if ($this->file) {
230 $ass = new ilExAssignment($this->ass_id);
231 $ass_files = $ass->getFiles();
232 if (count($ass_files) > 0) {
233 foreach ($ass_files as $file) {
234 if ($file["name"] == $this->file) {
235 ilUtil::deliverFile($file["fullpath"], $file["name"]);
236 }
237 }
238 }
239 }
240 }
241
242 public function downloadExcSubFile()
243 {
244 $ass = new ilExAssignment($this->ass_id);
245 $submission = new ilExSubmission($ass, $this->user_id);
246 $submitted = $submission->getFiles();
247 if (count($submitted) > 0) {
248 $submitted = array_pop($submitted);
249
250 $user_data = ilObjUser::_lookupName($submitted["user_id"]);
251 $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
252 $ass->getTitle() . " - " .
253 $user_data["firstname"] . " " .
254 $user_data["lastname"] . " (" .
255 $user_data["login"] . ").zip";
256
257 ilUtil::deliverFile($submitted["filename"], $title);
258 }
259 }
260
264 protected function finalize()
265 {
268
269 $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
270 $exc_gui->submitPortfolio($this->obj_id);
271
272 ilUtil::sendSuccess($lng->txt("prtf_finalized"), true);
273 $ilCtrl->returnToParent($this);
274 }
275
282 public function getSubmitButton(int $ass_id)
283 {
285 $ui = $this->ui;
287
288 $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user_id);
289
290 if ($state->isSubmissionAllowed()) {
291 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $ass_id);
292 $submit_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "finalize");
293 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
294 $button = $ui->factory()->button()->primary($lng->txt("prtf_finalize_portfolio"), $submit_link);
295 return $button;
296 }
297 return null;
298 }
299
307 {
310 $ui = $this->ui;
311
312 // submitted files
313 $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user_id);
314 if ($submission->hasSubmitted()) {
315 // #16888
316 $submitted = $submission->getSelectedObject();
317 if ($submitted["ts"] != "") {
318 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $ass_id);
319 $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcSubFile");
320 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
321 $button = $ui->factory()->button()->standard($lng->txt("prtf_download_submission"), $dl_link);
322 return $button;
323 }
324 }
325 return null;
326 }
327
328
334 public function getActionButtons()
335 {
336 $pe = new ilPortfolioExercise($this->user_id, $this->obj_id);
337
338 $buttons = [];
339 foreach ($pe->getAssignmentsOfPortfolio() as $exercise) {
340 $ass_id = $exercise["ass_id"];
341 $buttons[$ass_id] = [];
342 $submit_button = $this->getSubmitButton($ass_id);
343 if ($submit_button != null) {
344 $buttons[$ass_id][] = $submit_button;
345 }
346 $download_button = $this->getDownloadSubmissionButton($ass_id);
347 if ($download_button != null) {
348 $buttons[$ass_id][] = $download_button;
349 }
350 }
351
352 return $buttons;
353 }
354}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
Exercise assignment.
static initGUIForSubmit($a_ass_id, $a_user_id=null)
Exercise submission //TODO: This class has to much static methods related to delivered "files".
static getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
static _lookupName($a_user_id)
lookup user name
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
Class ilPortfolioExerciseGUI.
__construct($a_user_id, $a_obj_id)
getSubmitButton(int $ass_id)
Get submit link.
getDownloadSubmissionButton(int $ass_id)
Get download button.
static getExerciseInfo($a_user_id, $a_assignment_id, $a_add_submit=false, $as_array=false)
static checkExercise($a_user_id, $a_obj_id, $a_add_submit=false, $as_array=false)
finalize()
Finalize and submit portfolio to exercise.
Exercise info for portfolios.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
global $ilCtrl
Definition: ilias.php:18
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46