ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
18  protected $node_id; // [int]
19  protected $ass_id; // [int]
20  protected $file; // [string]
21 
22  public function __construct($a_node_id)
23  {
24  $this->node_id = $a_node_id;
25  $this->ass_id = (int)$_GET["ass"];
26  $this->file = trim($_GET["file"]);
27  }
28 
29  function executeCommand()
30  {
31  global $ilCtrl;
32 
33  if(!$this->ass_id)
34  {
35  $this->ctrl->returnToParent($this);
36  }
37 
38  $next_class = $ilCtrl->getNextClass($this);
39  $cmd = $ilCtrl->getCmd();
40 
41  switch($next_class)
42  {
43  default:
44  $this->$cmd();
45  break;
46  }
47 
48  return true;
49  }
50 
51  public static function checkExercise($a_node_id)
52  {
53  global $tree, $ilUser;
54 
55  $exercises = ilExSubmission::findUserFiles($ilUser->getId(), $a_node_id);
56  // #0022794
57  if (!$exercises)
58  {
59  $exercises = ilExSubmission::findUserFiles($ilUser->getId(), $a_node_id.".sec");
60  }
61  if($exercises)
62  {
63  $info = array();
64  foreach($exercises as $exercise)
65  {
66  // #9988
67  $active_ref = false;
68  foreach(ilObject::_getAllReferences($exercise["obj_id"]) as $ref_id)
69  {
70  if(!$tree->isSaved($ref_id))
71  {
72  $active_ref = true;
73  break;
74  }
75  }
76  if($active_ref)
77  {
78  $part = self::getExerciseInfo($exercise["ass_id"]);
79  if($part)
80  {
81  $info[] = $part;
82  }
83  }
84  }
85  if(sizeof($info))
86  {
87  return implode("<br />", $info);
88  }
89  }
90  }
91 
92  protected static function getExerciseInfo($a_assignment_id)
93  {
94  global $lng, $ilCtrl, $ilUser;
95 
96  $ass = new ilExAssignment($a_assignment_id);
97  $exercise_id = $ass->getExerciseId();
98  if(!$exercise_id)
99  {
100  return;
101  }
102 
103  // is the assignment still open?
104  $times_up = $ass->afterDeadlineStrict();
105 
106  // exercise goto
107  include_once "./Services/Link/classes/class.ilLink.php";
108  $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
109  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
110 
111  $info = sprintf($lng->txt("blog_exercise_info"),
112  $ass->getTitle(),
113  "<a href=\"".$exc_link."\">".
114  ilObject::_lookupTitle($exercise_id)."</a>");
115 
116  // submit button
117  if(!$times_up)
118  {
119  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
120  $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
121  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
122 
123  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
124  $button = ilLinkButton::getInstance();
125  $button->setCaption("blog_finalize_blog");
126  $button->setPrimary(true);
127  $button->setUrl($submit_link);
128  $info .= " ".$button->render();
129  }
130 
131  // submitted files
132  include_once "Modules/Exercise/classes/class.ilExSubmission.php";
133  $submission = new ilExSubmission($ass, $ilUser->getId());
134  if($submission->hasSubmitted())
135  {
136  // #16888
137  $submitted = $submission->getSelectedObject();
138 
139  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
140  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
141  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
142 
145 
146  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
147  $button = ilLinkButton::getInstance();
148  $button->setCaption("download");
149  $button->setUrl($dl_link);
150 
151  $info .= "<br />".sprintf($lng->txt("blog_exercise_submitted_info"),
153  $button->render());
154 
156  }
157 
158 
159  // work instructions incl. files
160 
161  $tooltip = "";
162 
163  $inst = $ass->getInstruction();
164  if($inst)
165  {
166  $tooltip .= nl2br($inst);
167  }
168 
169  $ass_files = $ass->getFiles();
170  if (count($ass_files) > 0)
171  {
172  $tooltip .= "<br /><br />";
173 
174  foreach($ass_files as $file)
175  {
176  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
177  $ilCtrl->setParameterByClass("ilblogexercisegui", "file", urlencode($file["name"]));
178  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcAssFile");
179  $ilCtrl->setParameterByClass("ilblogexercisegui", "file", "");
180  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
181 
182  $tooltip .= $file["name"].": <a href=\"".$dl_link."\">".
183  $lng->txt("download")."</a>";
184  }
185  }
186 
187  if($tooltip)
188  {
189  $ol_id = "exc_ass_".$a_assignment_id;
190 
191  include_once "Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
192  $overlay = new ilOverlayGUI($ol_id);
193 
194  // overlay
195  $overlay->setAnchor($ol_id."_tr");
196  $overlay->setTrigger($ol_id."_tr", "click", $ol_id."_tr");
197  $overlay->add();
198 
199  $info .= "<div id=\"".$ol_id."_tr\"><a href=\"#\">".$lng->txt("exc_instruction")."</a></div>".
200  "<div id=\"".$ol_id."\" style=\"display:none; padding:10px;\" class=\"ilOverlay\">".$tooltip."</div>";
201  }
202 
203  return "<div>".$info."</div>";
204  }
205 
206  protected function downloadExcAssFile()
207  {
208  if($this->file)
209  {
210  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
211  $ass = new ilExAssignment($this->ass_id);
212  $ass_files = $ass->getFiles();
213  if (count($ass_files) > 0)
214  {
215  foreach($ass_files as $file)
216  {
217  if($file["name"] == $this->file)
218  {
219  ilUtil::deliverFile($file["fullpath"], $file["name"]);
220  }
221  }
222  }
223  }
224  }
225 
226  protected function downloadExcSubFile()
227  {
228  global $ilUser;
229 
230  $ass = new ilExAssignment($this->ass_id);
231  $submission = new ilExSubmission($ass, $ilUser->getId());
232  $submitted = $submission->getFiles();
233  if (count($submitted) > 0)
234  {
235  $submitted = array_pop($submitted);
236 
237  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
238  $title = ilObject::_lookupTitle($submitted["obj_id"])." - ".
239  $ass->getTitle()." - ".
240  $user_data["firstname"]." ".
241  $user_data["lastname"]." (".
242  $user_data["login"].").zip";
243 
244  ilUtil::deliverFile($submitted["filename"], $title);
245  }
246  }
247 
251  protected function finalize()
252  {
253  global $ilCtrl, $lng;
254 
255  include_once "Modules/Exercise/classes/class.ilExSubmissionBaseGUI.php";
256  include_once "Modules/Exercise/classes/class.ilExSubmissionObjectGUI.php";
257  $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
258  $exc_gui->submitBlog($this->node_id);
259 
260  ilUtil::sendSuccess($lng->txt("blog_finalized"), true);
261  $ilCtrl->returnToParent($this);
262  }
263 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupName($a_user_id)
lookup user name
Exercise assignment.
const IL_CAL_DATETIME
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
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 _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)
$info
Definition: example_052.php:80
This is a utility class for the yui overlays.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
$ilUser
Definition: imgupload.php:18
Reload workbook from saved file
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Create styles array
The data for the language used.
static findUserFiles($a_user_id, $a_filetitle)
Check if given file was assigned.
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
Exercise submission.
static checkExercise($a_node_id)
getFiles(array $a_file_ids=null, $a_only_valid=false, $a_min_timestamp=null)