ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
13{
17 protected $ctrl;
18
22 protected $user;
23
27 protected $lng;
28
29 protected $node_id; // [int]
30 protected $ass_id; // [int]
31 protected $file; // [string]
32
36 protected $ui;
37
38 public function __construct($a_node_id)
39 {
40 global $DIC;
41
42 $this->ctrl = $DIC->ctrl();
43 $this->user = $DIC->user();
44 $this->lng = $DIC->language();
45 $this->node_id = $a_node_id;
46 $this->ass_id = (int) $_GET["ass"];
47 $this->file = trim(ilUtil::stripSlashes($_GET["file"]));
48 $this->ui = $DIC->ui();
49 }
50
51 public function executeCommand()
52 {
54
55 if (!$this->ass_id) {
56 $this->ctrl->returnToParent($this);
57 }
58
59 $next_class = $ilCtrl->getNextClass($this);
60 $cmd = $ilCtrl->getCmd();
61
62 switch ($next_class) {
63 default:
64 $this->$cmd();
65 break;
66 }
67
68 return true;
69 }
70
71 public static function checkExercise($a_node_id)
72 {
73 $be = new ilBlogExercise($a_node_id);
74
75 foreach ($be->getAssignmentsOfBlog() as $ass) {
76 $part = self::getExerciseInfo($ass["ass_id"]);
77 if ($part) {
78 $info[] = $part;
79 }
80 }
81 if (sizeof($info)) {
82 return implode("<br />", $info);
83 }
84 return "";
85 }
86
87 protected static function getExerciseInfo($a_assignment_id)
88 {
89 global $DIC;
90
91 $ui = $DIC->ui();
92
93 $links = [];
94 $buttons = [];
95 $elements = [];
96
97 $lng = $DIC->language();
98 $ilCtrl = $DIC->ctrl();
99 $ilUser = $DIC->user();
100
101 $ass = new ilExAssignment($a_assignment_id);
102 $exercise_id = $ass->getExerciseId();
103 if (!$exercise_id) {
104 return;
105 }
106
107 // is the assignment still open?
108 $times_up = $ass->afterDeadlineStrict();
109
110 // exercise goto
111 $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
112 $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
113
114 $text = sprintf(
115 $lng->txt("blog_exercise_info"),
116 $ass->getTitle(),
117 ilObject::_lookupTitle($exercise_id)
118 );
119 $links[] = $ui->factory()->link()->standard(ilObject::_lookupTitle($exercise_id), $exc_link);
120
121 // submit button
122 if (!$times_up) {
123 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
124 $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
125 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
126
127 $buttons[] = $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
128 }
129
130 // submitted files
131 $submission = new ilExSubmission($ass, $ilUser->getId());
132 if ($submission->hasSubmitted()) {
133 // #16888
134 $submitted = $submission->getSelectedObject();
135
136 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
137 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
138 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
139
142
143 $text .= "<br />" . sprintf(
144 $lng->txt("blog_exercise_submitted_info"),
146 ""
147 );
148
150 $buttons[] = $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
151 }
152
153
154 // work instructions incl. files
155
156 $tooltip = "";
157
158 $inst = $ass->getInstruction();
159 if ($inst) {
160 $tooltip .= nl2br($inst);
161 }
162
163 $ass_files = $ass->getFiles();
164 if (count($ass_files) > 0) {
165 $tooltip .= "<br /><br />";
166
167 foreach ($ass_files as $file) {
168 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
169 $ilCtrl->setParameterByClass("ilblogexercisegui", "file", urlencode($file["name"]));
170 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcAssFile");
171 $ilCtrl->setParameterByClass("ilblogexercisegui", "file", "");
172 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
173
174 $items[] = $ui->renderer()->render($ui->factory()->button()->shy($file["name"], $dl_link));
175 }
176 $list = $ui->factory()->listing()->unordered($items);
177 $tooltip .= $ui->renderer()->render($list);
178 }
179
180 if ($tooltip) {
181 $modal = $ui->factory()->modal()->roundtrip($lng->txt("exc_instruction"), $ui->factory()->legacy($tooltip))
182 ->withCancelButtonLabel("close");
183 $elements[] = $modal;
184 $buttons[] = $ui->factory()->button()->standard($lng->txt("exc_instruction"), '#')
185 ->withOnClick($modal->getShowSignal());
186 }
187
188 $elements[] = $ui->factory()->messageBox()->info($text)
189 ->withLinks($links)
190 ->withButtons($buttons);
191
192 return $ui->renderer()->render($elements);
193 }
194
195 protected function downloadExcAssFile()
196 {
197 if ($this->file) {
198 $ass = new ilExAssignment($this->ass_id);
199 $ass_files = $ass->getFiles();
200 if (count($ass_files) > 0) {
201 foreach ($ass_files as $file) {
202 if ($file["name"] == $this->file) {
203 ilUtil::deliverFile($file["fullpath"], $file["name"]);
204 }
205 }
206 }
207 }
208 }
209
210 protected function downloadExcSubFile()
211 {
213
214 $ass = new ilExAssignment($this->ass_id);
215 $submission = new ilExSubmission($ass, $ilUser->getId());
216 $submitted = $submission->getFiles();
217 if (count($submitted) > 0) {
218 $submitted = array_pop($submitted);
219
220 $user_data = ilObjUser::_lookupName($submitted["user_id"]);
221 $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
222 $ass->getTitle() . " - " .
223 $user_data["firstname"] . " " .
224 $user_data["lastname"] . " (" .
225 $user_data["login"] . ").zip";
226
227 ilUtil::deliverFile($submitted["filename"], $title);
228 }
229 }
230
234 protected function finalize()
235 {
238
239 $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
240 $exc_gui->submitBlog($this->node_id);
241
242 ilUtil::sendSuccess($lng->txt("blog_finalized"), true);
243 $ilCtrl->returnToParent($this);
244 }
245
252 public function getSubmitButton(int $ass_id)
253 {
255 $ui = $this->ui;
257
258 $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user->getId());
259
260 if ($state->isSubmissionAllowed()) {
261 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
262 $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
263 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
264 $button = $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
265 return $button;
266 }
267 return null;
268 }
269
277 {
280 $ui = $this->ui;
281
282 // submitted files
283 $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user->getId());
284 if ($submission->hasSubmitted()) {
285 // #16888
286 $submitted = $submission->getSelectedObject();
287 if ($submitted["ts"] != "") {
288 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
289 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
290 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
291 $button = $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
292 return $button;
293 }
294 }
295 return null;
296 }
297
298
304 public function getActionButtons()
305 {
306 $be = new ilBlogExercise($this->node_id);
307
308 $buttons = [];
309 foreach ($be->getAssignmentsOfBlog() as $exercise) {
310 $ass_id = $exercise["ass_id"];
311 $buttons[$ass_id] = [];
312 $submit_button = $this->getSubmitButton($ass_id);
313 if ($submit_button != null) {
314 $buttons[$ass_id][] = $submit_button;
315 }
316 $download_button = $this->getDownloadSubmissionButton($ass_id);
317 if ($download_button != null) {
318 $buttons[$ass_id][] = $download_button;
319 }
320 }
321
322 return $buttons;
323 }
324}
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)
getDownloadSubmissionButton(int $ass_id)
Get download button.
getActionButtons()
Get action buttons.
finalize()
Finalize and submit blog to exercise.
getSubmitButton(int $ass_id)
Get submit link.
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
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
$ilUser
Definition: imgupload.php:18
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46