ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBlogExerciseGUI.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 $user;
27
31 protected $lng;
32
33 protected $node_id; // [int]
34 protected $ass_id; // [int]
35 protected $file; // [string]
36
37 public function __construct($a_node_id)
38 {
39 global $DIC;
40
41 $this->ctrl = $DIC->ctrl();
42 $this->user = $DIC->user();
43 $this->lng = $DIC->language();
44 $this->node_id = $a_node_id;
45 $this->ass_id = (int) $_GET["ass"];
46 $this->file = trim(ilUtil::stripSlashes($_GET["file"]));
47 }
48
49 public function executeCommand()
50 {
52
53 if (!$this->ass_id) {
54 $this->ctrl->returnToParent($this);
55 }
56
57 $next_class = $ilCtrl->getNextClass($this);
58 $cmd = $ilCtrl->getCmd();
59
60 switch ($next_class) {
61 default:
62 $this->$cmd();
63 break;
64 }
65
66 return true;
67 }
68
69 public static function checkExercise($a_node_id)
70 {
71 global $DIC;
72
73 $tree = $DIC->repositoryTree();
74 $ilUser = $DIC->user();
75
76 $exercises = ilExSubmission::findUserFiles($ilUser->getId(), $a_node_id);
77 // #0022794
78 if (!$exercises) {
79 $exercises = ilExSubmission::findUserFiles($ilUser->getId(), $a_node_id . ".sec");
80 }
81 if ($exercises) {
82 $info = array();
83 foreach ($exercises as $exercise) {
84 // #9988
85 $active_ref = false;
86 foreach (ilObject::_getAllReferences($exercise["obj_id"]) as $ref_id) {
87 if (!$tree->isSaved($ref_id)) {
88 $active_ref = true;
89 break;
90 }
91 }
92 if ($active_ref) {
93 $part = self::getExerciseInfo($exercise["ass_id"]);
94 if ($part) {
95 $info[] = $part;
96 }
97 }
98 }
99 if (sizeof($info)) {
100 return implode("<br />", $info);
101 }
102 }
103 }
104
105 protected static function getExerciseInfo($a_assignment_id)
106 {
107 global $DIC;
108
109 $lng = $DIC->language();
110 $ilCtrl = $DIC->ctrl();
111 $ilUser = $DIC->user();
112 $ass = new ilExAssignment($a_assignment_id);
113 $exercise_id = $ass->getExerciseId();
114 if (!$exercise_id) {
115 return;
116 }
117
118 // is the assignment still open?
119 $times_up = $ass->afterDeadlineStrict();
120
121 // exercise goto
122 include_once "./Services/Link/classes/class.ilLink.php";
123 $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
124 $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
125
126 $info = sprintf(
127 $lng->txt("blog_exercise_info"),
128 $ass->getTitle(),
129 "<a href=\"" . $exc_link . "\">" .
130 ilObject::_lookupTitle($exercise_id) . "</a>"
131 );
132
133 // submit button
134 if (!$times_up) {
135 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
136 $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
137 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
138
139 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
140 $button = ilLinkButton::getInstance();
141 $button->setCaption("blog_finalize_blog");
142 $button->setPrimary(true);
143 $button->setUrl($submit_link);
144 $info .= " " . $button->render();
145 }
146
147 // submitted files
148 include_once "Modules/Exercise/classes/class.ilExSubmission.php";
149 $submission = new ilExSubmission($ass, $ilUser->getId());
150 if ($submission->hasSubmitted()) {
151 // #16888
152 $submitted = $submission->getSelectedObject();
153
154 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
155 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
156 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
157
160
161 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
162 $button = ilLinkButton::getInstance();
163 $button->setCaption("download");
164 $button->setUrl($dl_link);
165
166 $info .= "<br />" . sprintf(
167 $lng->txt("blog_exercise_submitted_info"),
169 $button->render()
170 );
171
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 (count($ass_files) > 0) {
187 $tooltip .= "<br /><br />";
188
189 foreach ($ass_files as $file) {
190 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
191 $ilCtrl->setParameterByClass("ilblogexercisegui", "file", urlencode($file["name"]));
192 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcAssFile");
193 $ilCtrl->setParameterByClass("ilblogexercisegui", "file", "");
194 $ilCtrl->setParameterByClass("ilblogexercisegui", "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->add();
211
212 $info .= "<div id=\"" . $ol_id . "_tr\"><a href=\"#\">" . $lng->txt("exc_instruction") . "</a></div>" .
213 "<div id=\"" . $ol_id . "\" style=\"display:none; padding:10px;\" class=\"ilOverlay\">" . $tooltip . "</div>";
214 }
215
216 return "<div>" . $info . "</div>";
217 }
218
219 protected function downloadExcAssFile()
220 {
221 if ($this->file) {
222 include_once "Modules/Exercise/classes/class.ilExAssignment.php";
223 $ass = new ilExAssignment($this->ass_id);
224 $ass_files = $ass->getFiles();
225 if (count($ass_files) > 0) {
226 foreach ($ass_files as $file) {
227 if ($file["name"] == $this->file) {
228 ilUtil::deliverFile($file["fullpath"], $file["name"]);
229 }
230 }
231 }
232 }
233 }
234
235 protected function downloadExcSubFile()
236 {
238
239 $ass = new ilExAssignment($this->ass_id);
240 $submission = new ilExSubmission($ass, $ilUser->getId());
241 $submitted = $submission->getFiles();
242 if (count($submitted) > 0) {
243 $submitted = array_pop($submitted);
244
245 $user_data = ilObjUser::_lookupName($submitted["user_id"]);
246 $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
247 $ass->getTitle() . " - " .
248 $user_data["firstname"] . " " .
249 $user_data["lastname"] . " (" .
250 $user_data["login"] . ").zip";
251
252 ilUtil::deliverFile($submitted["filename"], $title);
253 }
254 }
255
259 protected function finalize()
260 {
263
264 include_once "Modules/Exercise/classes/class.ilExSubmissionBaseGUI.php";
265 include_once "Modules/Exercise/classes/class.ilExSubmissionObjectGUI.php";
266 $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
267 $exc_gui->submitBlog($this->node_id);
268
269 ilUtil::sendSuccess($lng->txt("blog_finalized"), true);
270 $ilCtrl->returnToParent($this);
271 }
272}
sprintf('%.4f', $callTime)
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Class ilBlogExerciseGUI.
static checkExercise($a_node_id)
static getExerciseInfo($a_assignment_id)
finalize()
Finalize and submit blog to exercise.
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.
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.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilCtrl
Definition: ilias.php:18
$info
Definition: index.php:5
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18