ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExAssignmentGUI.php
Go to the documentation of this file.
1 <?php
2 include_once 'Services/Payment/classes/class.ilShopPurchaseGUI.php';
13 {
14 
18  function __construct($a_exc)
19  {
20  $this->exc = $a_exc;
21  }
22 
23 
27  function getOverviewHeader($a_data)
28  {
29  global $lng, $ilUser;
30 
31  $tpl = new ilTemplate("tpl.assignment_head.html", true, true, "Modules/Exercise");
32 
33  if ($a_data["deadline"] - time() <= 0)
34  {
35  $tpl->setCurrentBlock("prop");
36  $tpl->setVariable("PROP", $lng->txt("exc_ended_on"));
37  $tpl->setVariable("PROP_VAL",
38  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
39  $tpl->parseCurrentBlock();
40  }
41  else if ($a_data["start_time"] > 0 && time() - $a_data["start_time"] <= 0)
42  {
43  $tpl->setCurrentBlock("prop");
44  $tpl->setVariable("PROP", $lng->txt("exc_starting_on"));
45  $tpl->setVariable("PROP_VAL",
46  ilDatePresentation::formatDate(new ilDateTime($a_data["start_time"],IL_CAL_UNIX)));
47  $tpl->parseCurrentBlock();
48  }
49  else
50  {
51  $time_str = $this->getTimeString($a_data["deadline"]);
52  $tpl->setCurrentBlock("prop");
53  $tpl->setVariable("PROP", $lng->txt("exc_time_to_send"));
54  $tpl->setVariable("PROP_VAL", $time_str);
55  $tpl->parseCurrentBlock();
56 
57  $tpl->setCurrentBlock("prop");
58  $tpl->setVariable("PROP", $lng->txt("exc_edit_until"));
59  $tpl->setVariable("PROP_VAL",
60  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
61  $tpl->parseCurrentBlock();
62 
63  }
64 
65  $mand = "";
66  if ($a_data["mandatory"])
67  {
68  $mand = " (".$lng->txt("exc_mandatory").")";
69  }
70  $tpl->setVariable("TITLE", $a_data["title"].$mand);
71 // $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("accordion_arrow.gif"));
72 
73  // status icon
74  $stat = ilExAssignment::lookupStatusOfUser($a_data["id"], $ilUser->getId());
75  switch ($stat)
76  {
77  case "passed": $pic = "scorm/passed.gif"; break;
78  case "failed": $pic = "scorm/failed.gif"; break;
79  default: $pic = "scorm/not_attempted.gif"; break;
80  }
81  $tpl->setVariable("IMG_STATUS", ilUtil::getImagePath($pic));
82  $tpl->setVariable("ALT_STATUS", $lng->txt("exc_".$stat));
83 
84  return $tpl->get();
85  }
86 
90  function getOverviewBody($a_data)
91  {
92  global $lng, $ilCtrl, $ilUser;
93 
94  $tpl = new ilTemplate("tpl.assignment_body.html", true, true, "Modules/Exercise");
95 
96  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
97  if(IS_PAYMENT_ENABLED)
98  {
99  include_once './Services/Payment/classes/class.ilPaymentObject.php';
100  }
101 
102  $info = new ilInfoScreenGUI(null);
103  $info->setTableClass("");
104 
105  $not_started_yet = false;
106  if ($a_data["start_time"] > 0 && time() - $a_data["start_time"] <= 0)
107  {
108  $not_started_yet = true;
109  }
110 
111  if (!$not_started_yet)
112  {
113  // instructions
114  $info->addSection($lng->txt("exc_instruction"));
115  $info->addProperty("",
116  nl2br(ilUtil::makeClickable($a_data["instruction"], true)));
117  }
118 
119  // schedule
120  $info->addSection($lng->txt("exc_schedule"));
121  if ($a_data["start_time"] > 0)
122  {
123  $info->addProperty($lng->txt("exc_start_time"),
124  ilDatePresentation::formatDate(new ilDateTime($a_data["start_time"],IL_CAL_UNIX)));
125  }
126  $info->addProperty($lng->txt("exc_edit_until"),
127  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
128  $time_str = $this->getTimeString($a_data["deadline"]);
129  if (!$not_started_yet)
130  {
131  $info->addProperty($lng->txt("exc_time_to_send"),
132  "<b>".$time_str."</b>");
133  }
134 
135  // public submissions
136  if ($this->exc->getShowSubmissions())
137  {
138  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
139  if ($a_data["deadline"] - time() <= 0)
140  {
141  $link = '<a class="submit" href="'.
142  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "listPublicSubmissions").'">'.
143  $lng->txt("exc_list_submission").'</a>';
144  $info->addProperty($lng->txt("exc_public_submission"), $link);
145  }
146  else
147  {
148  $info->addProperty($lng->txt("exc_public_submission"),
149  $lng->txt("exc_msg_public_submission"));
150  }
151  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $_GET["ass_id"]);
152  }
153 
154  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
155 
156  if (!$not_started_yet)
157  {
158  // download files
159  $files = ilExAssignment::getFiles($a_data["exc_id"], $a_data["id"]);
160  if (count($files) > 0)
161  {
162  $info->addSection($lng->txt("exc_files"));
163  foreach($files as $file)
164  {
165  // if download must be purchased first show a "buy"-button
166  if(IS_PAYMENT_ENABLED && (ilPaymentObject::_isBuyable($_GET['ref_id'],'download') &&
167  !ilPaymentObject::_hasAccess($_GET['ref_id'],'','download')))
168  {
169  $info->addProperty($file["name"],
170  $lng->txt("buy"),
171  $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails"));
172  }
173  else
174  {
175  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", urlencode($file["name"]));
176  $info->addProperty($file["name"],
177  $lng->txt("download"),
178  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadFile"));
179  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", "");
180  }
181  }
182  }
183 
184  // submission
185 
186  // if submission must be purchased first
187  if(IS_PAYMENT_ENABLED
188  && (ilPaymentObject::_isBuyable($_GET['ref_id'],'upload')
189  && !ilPaymentObject::_hasAccess($_GET['ref_id'],'','upload')))
190  {
191  $info->addSection($lng->txt("exc_your_submission"));
192 
193  $ilCtrl->clearParameters($this);
194 
195  $ilCtrl->setParameter($this, "ref_id", $_GET['ref_id']);
196  $ilCtrl->setParameter($this,'subtype','upload');
197  $info->addProperty($lng->txt('exc_hand_in'),
198  $lng->txt("buy"),
199  $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails"));
200  }
201  else
202  {
203  $info->addSection($lng->txt("exc_your_submission"));
204 
205  $delivered_files = ilExAssignment::getDeliveredFiles($a_data["exc_id"], $a_data["id"], $ilUser->getId());
206 
207  $times_up = false;
208  if($a_data["deadline"] - time() < 0)
209  {
210  $times_up = true;
211  }
212 
213  switch($a_data["type"])
214  {
216  $titles = array();
217  foreach($delivered_files as $file)
218  {
219  $titles[] = $file["filetitle"];
220  }
221  $files_str = implode($titles, ", ");
222  if ($files_str == "")
223  {
224  $files_str = $lng->txt("message_no_delivered_files");
225  }
226 
227  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
228 
229  if (!$times_up)
230  {
231  $files_str.= ' <a class="submit" href="'.
232  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "submissionScreen").'">'.
233  (count($titles) == 0
234  ? $lng->txt("exc_hand_in")
235  : $lng->txt("exc_edit_submission")).'</a>';
236  }
237  else
238  {
239  if (count($titles) > 0)
240  {
241  $files_str.= ' <a class="submit" href="'.
242  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "submissionScreen").'">'.
243  $lng->txt("already_delivered_files").'</a>';
244  }
245  }
246 
247  $info->addProperty($lng->txt("exc_files_returned"),
248  $files_str);
249  break;
250 
252  $files_str = "";
253  $valid_blog = false;
254  if(sizeof($delivered_files))
255  {
256  $delivered_files = array_pop($delivered_files);
257  $blog_id = (int)$delivered_files["filetitle"];
258 
259  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
260  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
261  $wsp_tree = new ilWorkspaceTree($ilUser->getId());
262  $node = $wsp_tree->getNodeData($blog_id);
263 
264  if($node["title"])
265  {
266  $blog_link = ilWorkspaceAccessHandler::getGotoLink($blog_id, $node["obj_id"]);
267  $files_str = '<a href="'.$blog_link.'">'.
268  $node["title"].'</a>';
269  $valid_blog = true;
270  }
271  }
272  if(!$times_up)
273  {
274  if(!$valid_blog)
275  {
276  $files_str .= '<a class="submit" href="'.
277  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "createBlog").'">'.
278  $lng->txt("exc_create_blog").'</a>';
279  }
280  $files_str .=' <a class="submit" href="'.
281  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "selectBlog").'">'.
282  $lng->txt("exc_select_blog".($valid_blog ? "_change" : "")).'</a>';
283  }
284  if($files_str)
285  {
286  $info->addProperty($lng->txt("exc_blog_returned"), $files_str);
287  }
288  if($delivered_files && substr($delivered_files["filename"], -1) != "/")
289  {
290  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", $delivered_files["returned_id"]);
291  $dl_link = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "download");
292  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", "");
293 
294  $info->addProperty($lng->txt("exc_files_returned"),
295  "<a href=\"".$dl_link."\">".$lng->txt("download")."</a>");
296  }
297  break;
298 
300  $files_str = "";
301  $valid_prtf = false;
302  if(sizeof($delivered_files))
303  {
304  $delivered_files = array_pop($delivered_files);
305  $portfolio_id = (int)$delivered_files["filetitle"];
306 
307  // #11746
308  if(ilObject::_exists($portfolio_id, false))
309  {
310  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
311  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
312  $portfolio = new ilObjPortfolio($portfolio_id, false);
313 
314  if($portfolio->getTitle())
315  {
316  $files_str = '<a href="'.ilWorkspaceAccessHandler::getGotoLink($portfolio_id, $portfolio_id).
317  '">'.$portfolio->getTitle().'</a>';
318  $valid_prtf = true;
319  }
320  }
321  }
322  if(!$times_up)
323  {
324  if(!$valid_prtf)
325  {
326  $files_str .= '<a class="submit" href="'.
327  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "createPortfolio").'">'.
328  $lng->txt("exc_create_portfolio").'</a>';
329  }
330  $files_str .= ' <a class="submit" href="'.
331  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "selectPortfolio").'">'.
332  $lng->txt("exc_select_portfolio".($valid_prtf ? "_change" : "")).'</a>';
333  }
334  if($files_str)
335  {
336  $info->addProperty($lng->txt("exc_portfolio_returned"), $files_str);
337  }
338  if($delivered_files && substr($delivered_files["filename"], -1) != "/")
339  {
340  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", $delivered_files["returned_id"]);
341  $dl_link = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "download");
342  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", "");
343 
344  $info->addProperty($lng->txt("exc_files_returned"),
345  "<a href=\"".$dl_link."\">".$lng->txt("download")."</a>");
346  }
347  break;
348  }
349 
350 
351  $last_sub = ilExAssignment::getLastSubmission($a_data["id"], $ilUser->getId());
352  if ($last_sub)
353  {
354  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub,IL_CAL_DATETIME));
355  }
356  else
357  {
358  $last_sub = "---";
359  }
360 
361  if ($last_sub != "---")
362  {
363  $info->addProperty($lng->txt("exc_last_submission"),
364  $last_sub);
365  }
366 
367  // feedback from tutor
368  $storage = new ilFSStorageExercise($a_data["exc_id"], $a_data["id"]);
369  $cnt_files = $storage->countFeedbackFiles($ilUser->getId());
370  $lpcomment = ilExAssignment::lookupCommentForUser($a_data["id"], $ilUser->getId());
371  $mark = ilExAssignment::lookupMarkOfUser($a_data["id"], $ilUser->getId());
372  $status = ilExAssignment::lookupStatusOfUser($a_data["id"], $ilUser->getId());
373  if ($lpcomment != "" || $mark != "" || $status != "notgraded" || $cnt_files > 0)
374  {
375  $info->addSection($lng->txt("exc_feedback_from_tutor"));
376  if ($lpcomment != "")
377  {
378  $info->addProperty($lng->txt("exc_comment"),
379  $lpcomment);
380  }
381  if ($mark != "")
382  {
383  $info->addProperty($lng->txt("exc_mark"),
384  $mark);
385  }
386 
387  if ($status == "")
388  {
389  // $info->addProperty($lng->txt("status"),
390  // $lng->txt("message_no_delivered_files"));
391  }
392  else if ($status != "notgraded")
393  {
394  $img = '<img border="0" src="'.ilUtil::getImagePath("scorm/".$status.".gif").'" '.
395  ' alt="'.$lng->txt("exc_".$status).'" title="'.$lng->txt("exc_".$status).
396  '" style="vertical-align:middle;"/>';
397  $info->addProperty($lng->txt("status"),
398  $img." ".$lng->txt("exc_".$status));
399  }
400 
401  if ($cnt_files > 0)
402  {
403  $info->addSection($lng->txt("exc_fb_files"));
404  $files = $storage->getFeedbackFiles($ilUser->getId());
405  foreach($files as $file)
406  {
407  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", urlencode($file));
408  $info->addProperty($file,
409  $lng->txt("download"),
410  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadFeedbackFile"));
411  $ilCtrl->setParameter($this, "file", "");
412  }
413  }
414  }
415  }
416  }
417 
418  $tpl->setVariable("CONTENT", $info->getHTML());
419 
420  return $tpl->get();
421  }
422 
426  function getTimeString($a_deadline)
427  {
428  global $lng;
429 
430  if ($a_deadline - time() <= 0)
431  {
432  $time_str = $lng->txt("exc_time_over_short");
433  }
434  else
435  {
436  $time_diff = ilUtil::int2array($a_deadline - time(),null);
437  if (isset($time_diff['days']))
438  {
439  unset($time_diff['minutes']);
440  }
441  if (isset($time_diff['months']))
442  {
443  unset($time_diff['hours']);
444  }
445  if (isset($time_diff['minutes']))
446  {
447  unset($time_diff['seconds']);
448  }
449  $time_str = ilUtil::timearray2string($time_diff);
450  }
451 
452  return $time_str;
453  }
454 
455 
456 }