ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_once "Modules/Exercise/classes/class.ilExAssignment.php";
6 include_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  $ui = $DIC->ui();
110 
111  $links = [];
112  $buttons = [];
113  $elements = [];
114 
115  $lng = $DIC->language();
116  $ilCtrl = $DIC->ctrl();
117  $ilUser = $DIC->user();
118 
119  $ass = new ilExAssignment($a_assignment_id);
120  $exercise_id = $ass->getExerciseId();
121  if (!$exercise_id) {
122  return;
123  }
124 
125  // is the assignment still open?
126  $times_up = $ass->afterDeadlineStrict();
127 
128  // exercise goto
129  include_once "./Services/Link/classes/class.ilLink.php";
130  $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
131  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
132 
133  $text = sprintf(
134  $lng->txt("blog_exercise_info"),
135  $ass->getTitle(),
136  ilObject::_lookupTitle($exercise_id)
137  );
138  $links[] = $ui->factory()->link()->standard(ilObject::_lookupTitle($exercise_id), $exc_link);
139 
140  // submit button
141  if (!$times_up) {
142  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
143  $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
144  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
145 
146  $buttons[] = $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
147  }
148 
149  // submitted files
150  include_once "Modules/Exercise/classes/class.ilExSubmission.php";
151  $submission = new ilExSubmission($ass, $ilUser->getId());
152  if ($submission->hasSubmitted()) {
153  // #16888
154  $submitted = $submission->getSelectedObject();
155 
156  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
157  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
158  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
159 
162 
163  $text .= "<br />" . sprintf(
164  $lng->txt("blog_exercise_submitted_info"),
166  ""
167  );
168 
170  $buttons[] = $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
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  $tooltip .= "<br /><br />";
186 
187  foreach ($ass_files as $file) {
188  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
189  $ilCtrl->setParameterByClass("ilblogexercisegui", "file", urlencode($file["name"]));
190  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcAssFile");
191  $ilCtrl->setParameterByClass("ilblogexercisegui", "file", "");
192  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
193 
194  $items[] = $ui->renderer()->render($ui->factory()->button()->shy($file["name"], $dl_link));
195  }
196  $list = $ui->factory()->listing()->unordered($items);
197  $tooltip .= $ui->renderer()->render($list);
198  }
199 
200  if ($tooltip) {
201  $modal = $ui->factory()->modal()->roundtrip($lng->txt("exc_instruction"), $ui->factory()->legacy($tooltip))
202  ->withCancelButtonLabel("close");
203  $elements[] = $modal;
204  $buttons[] = $ui->factory()->button()->standard($lng->txt("exc_instruction"), '#')
205  ->withOnClick($modal->getShowSignal());
206  }
207 
208  $elements[] = $ui->factory()->messageBox()->info($text)
209  ->withLinks($links)
210  ->withButtons($buttons);
211 
212  return $ui->renderer()->render($elements);
213  }
214 
215  protected function downloadExcAssFile()
216  {
217  if ($this->file) {
218  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
219  $ass = new ilExAssignment($this->ass_id);
220  $ass_files = $ass->getFiles();
221  if (count($ass_files) > 0) {
222  foreach ($ass_files as $file) {
223  if ($file["name"] == $this->file) {
224  ilUtil::deliverFile($file["fullpath"], $file["name"]);
225  }
226  }
227  }
228  }
229  }
230 
231  protected function downloadExcSubFile()
232  {
234 
235  $ass = new ilExAssignment($this->ass_id);
236  $submission = new ilExSubmission($ass, $ilUser->getId());
237  $submitted = $submission->getFiles();
238  if (count($submitted) > 0) {
239  $submitted = array_pop($submitted);
240 
241  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
242  $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
243  $ass->getTitle() . " - " .
244  $user_data["firstname"] . " " .
245  $user_data["lastname"] . " (" .
246  $user_data["login"] . ").zip";
247 
248  ilUtil::deliverFile($submitted["filename"], $title);
249  }
250  }
251 
255  protected function finalize()
256  {
258  $lng = $this->lng;
259 
260  include_once "Modules/Exercise/classes/class.ilExSubmissionBaseGUI.php";
261  include_once "Modules/Exercise/classes/class.ilExSubmissionObjectGUI.php";
262  $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
263  $exc_gui->submitBlog($this->node_id);
264 
265  ilUtil::sendSuccess($lng->txt("blog_finalized"), true);
266  $ilCtrl->returnToParent($this);
267  }
268 }
static _lookupName($a_user_id)
lookup user name
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
Exercise assignment.
const IL_CAL_DATETIME
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static setUseRelativeDates($a_status)
set use relative dates
static _lookupTitle($a_id)
lookup object title
static getExerciseInfo($a_assignment_id)
finalize()
Finalize and submit blog to exercise.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
Class ilBlogExerciseGUI.
static useRelativeDates()
check if relative dates are used
global $ilCtrl
Definition: ilias.php:18
static initGUIForSubmit($a_ass_id, $a_user_id=null)
$text
Definition: errorreport.php:18
Date and time handling
$ilUser
Definition: imgupload.php:18
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static findUserFiles($a_user_id, $a_filetitle)
Check if given file was assigned.
Exercise submission //TODO: This class has to much static methods related to delivered "files"...
$links
$info
Definition: index.php:5
static checkExercise($a_node_id)
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)
Get submission items (not only files)
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.