ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPortfolioExerciseGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Modules/Exercise/classes/class.ilExAssignment.php";
6include_once "Modules/Exercise/classes/class.ilExSubmission.php";
7
17{
21 protected $ctrl;
22
26 protected $lng;
27
28 protected $user_id; // [int]
29 protected $obj_id; // [int]
30 protected $ass_id; // [int]
31 protected $file; // [string]
32
33 public function __construct($a_user_id, $a_obj_id)
34 {
35 global $DIC;
36
37 $this->ctrl = $DIC->ctrl();
38 $this->lng = $DIC->language();
39 $this->user_id = $a_user_id;
40 $this->obj_id = $a_obj_id;
41 $this->ass_id = (int) $_GET["ass"];
42 $this->file = trim($_GET["file"]);
43 }
44
45 public function executeCommand()
46 {
48
49 if (!$this->ass_id ||
50 !$this->user_id) {
51 $this->ctrl->returnToParent($this);
52 }
53
54 $next_class = $ilCtrl->getNextClass($this);
55 $cmd = $ilCtrl->getCmd();
56
57 switch ($next_class) {
58 default:
59 $this->$cmd();
60 break;
61 }
62
63 return true;
64 }
65
66 public static function checkExercise($a_user_id, $a_obj_id, $a_add_submit = false)
67 {
68 global $DIC;
69
70 $tree = $DIC->repositoryTree();
71
72 $info = array();
73
74 $exercises = ilExSubmission::findUserFiles($a_user_id, $a_obj_id);
75 // #0022794
76 if (!$exercises) {
77 $exercises = ilExSubmission::findUserFiles($a_user_id, $a_obj_id . ".sec");
78 }
79 if ($exercises) {
80 foreach ($exercises as $exercise) {
81 // #9988
82 $active_ref = false;
83 foreach (ilObject::_getAllReferences($exercise["obj_id"]) as $ref_id) {
84 if (!$tree->isSaved($ref_id)) {
85 $active_ref = true;
86 break;
87 }
88 }
89 if ($active_ref) {
90 $part = self::getExerciseInfo($a_user_id, $exercise["ass_id"], $a_add_submit);
91 if ($part) {
92 $info[] = $part;
93 }
94 }
95 }
96 if (sizeof($info)) {
97 return implode("<br />", $info);
98 }
99 }
100 }
101
102 protected static function getExerciseInfo($a_user_id, $a_assignment_id, $a_add_submit = false)
103 {
104 global $DIC;
105
106 $lng = $DIC->language();
107 $ilCtrl = $DIC->ctrl();
108
109 include_once "Modules/Exercise/classes/class.ilExAssignment.php";
110 $ass = new ilExAssignment($a_assignment_id);
111 $exercise_id = $ass->getExerciseId();
112 if (!$exercise_id) {
113 return;
114 }
115
116 // is the assignment still open?
117 $times_up = $ass->afterDeadlineStrict();
118
119 // exercise goto
120 include_once "./Services/Link/classes/class.ilLink.php";
121 $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
122 $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
123
124 $info = sprintf(
125 $lng->txt("prtf_exercise_info"),
126 $ass->getTitle(),
127 "<a href=\"" . $exc_link . "\">" .
128 ilObject::_lookupTitle($exercise_id) . "</a>"
129 );
130
131 // submit button
132 if ($a_add_submit && !$times_up) {
133 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
134 $submit_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "finalize");
135 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
136
137 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
138 $button = ilLinkButton::getInstance();
139 $button->setCaption("prtf_finalize_portfolio");
140 $button->setPrimary(true);
141 $button->setUrl($submit_link);
142 $info .= " " . $button->render();
143 }
144
145 // submitted files
146 include_once "Modules/Exercise/classes/class.ilExSubmission.php";
147 $submission = new ilExSubmission($ass, $a_user_id);
148 if ($submission->hasSubmitted()) {
149 // #16888
150 $submitted = $submission->getSelectedObject();
151
152 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
153 $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcSubFile");
154 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
155
158
159 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
160 $button = ilLinkButton::getInstance();
161 $button->setCaption("download");
162 $button->setUrl($dl_link);
163
164 $info .= "<p>" . sprintf(
165 $lng->txt("prtf_exercise_submitted_info"),
167 $button->render()
168 ) . "</p>";
169
171 }
172
173
174 // work instructions incl. files
175
176 $tooltip = "";
177
178 $inst = $ass->getInstruction();
179 if ($inst) {
180 $tooltip .= nl2br($inst);
181 }
182
183 $ass_files = $ass->getFiles();
184 if (count($ass_files) > 0) {
185 if ($tooltip) {
186 $tooltip .= "<br /><br />";
187 }
188
189 foreach ($ass_files as $file) {
190 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
191 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", urlencode($file["name"]));
192 $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcAssFile");
193 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", "");
194 $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
195
196 $tooltip .= $file["name"] . ": <a href=\"" . $dl_link . "\">" .
197 $lng->txt("download") . "</a>";
198 }
199 }
200
201 if ($tooltip) {
202 $ol_id = "exc_ass_" . $a_assignment_id;
203
204 include_once "Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
205 $overlay = new ilOverlayGUI($ol_id);
206
207 // overlay
208 $overlay->setAnchor($ol_id . "_tr");
209 $overlay->setTrigger($ol_id . "_tr", "click", $ol_id . "_tr");
210 $overlay->setAutoHide(false);
211 // $overlay->setCloseElementId($cl_id);
212 $overlay->add();
213
214 // trigger
215 $overlay->addTrigger($ol_id . "_tr", "click", $ol_id . "_tr");
216
217 $info .= "<p id=\"" . $ol_id . "_tr\"><a href=\"#\">" . $lng->txt("exc_instruction") . "</a></p>" .
218 "<div id=\"" . $ol_id . "\" style=\"display:none; background-color:white; border: 1px solid #bbb; padding: 10px;\">" . $tooltip . "</div>";
219 }
220
221 return $info;
222 }
223
224 public function downloadExcAssFile()
225 {
226 if ($this->file) {
227 include_once "Modules/Exercise/classes/class.ilExAssignment.php";
228 $ass = new ilExAssignment($this->ass_id);
229 $ass_files = $ass->getFiles();
230 if (count($ass_files) > 0) {
231 foreach ($ass_files as $file) {
232 if ($file["name"] == $this->file) {
233 ilUtil::deliverFile($file["fullpath"], $file["name"]);
234 }
235 }
236 }
237 }
238 }
239
240 public function downloadExcSubFile()
241 {
242 $ass = new ilExAssignment($this->ass_id);
243 $submission = new ilExSubmission($ass, $this->user_id);
244 $submitted = $submission->getFiles();
245 if (count($submitted) > 0) {
246 $submitted = array_pop($submitted);
247
248 $user_data = ilObjUser::_lookupName($submitted["user_id"]);
249 $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
250 $ass->getTitle() . " - " .
251 $user_data["firstname"] . " " .
252 $user_data["lastname"] . " (" .
253 $user_data["login"] . ").zip";
254
255 ilUtil::deliverFile($submitted["filename"], $title);
256 }
257 }
258
262 protected function finalize()
263 {
266
267 include_once "Modules/Exercise/classes/class.ilExSubmissionBaseGUI.php";
268 include_once "Modules/Exercise/classes/class.ilExSubmissionObjectGUI.php";
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}
sprintf('%.4f', $callTime)
$_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)
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.
static findUserFiles($a_user_id, $a_filetitle)
Check if given file was assigned.
static getInstance()
Factory.
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
This is a utility class for the yui overlays.
Class ilPortfolioExerciseGUI.
static getExerciseInfo($a_user_id, $a_assignment_id, $a_add_submit=false)
__construct($a_user_id, $a_obj_id)
static checkExercise($a_user_id, $a_obj_id, $a_add_submit=false)
finalize()
Finalize and submit portfolio to exercise.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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
$info
Definition: index.php:5
global $DIC
Definition: saml.php:7