ILIAS  release_4-3 Revision
 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  $lng->loadLanguageModule("exc");
32 
33  $tpl = new ilTemplate("tpl.assignment_head.html", true, true, "Modules/Exercise");
34 
35  if (($a_data["deadline"] > 0) && $a_data["deadline"] - time() <= 0)
36  {
37  $tpl->setCurrentBlock("prop");
38  $tpl->setVariable("PROP", $lng->txt("exc_ended_on"));
39  $tpl->setVariable("PROP_VAL",
40  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
41  $tpl->parseCurrentBlock();
42  }
43  else if ($a_data["start_time"] > 0 && time() - $a_data["start_time"] <= 0)
44  {
45  $tpl->setCurrentBlock("prop");
46  $tpl->setVariable("PROP", $lng->txt("exc_starting_on"));
47  $tpl->setVariable("PROP_VAL",
48  ilDatePresentation::formatDate(new ilDateTime($a_data["start_time"],IL_CAL_UNIX)));
49  $tpl->parseCurrentBlock();
50  }
51  else
52  {
53  $time_str = $this->getTimeString($a_data["deadline"]);
54  $tpl->setCurrentBlock("prop");
55  $tpl->setVariable("PROP", $lng->txt("exc_time_to_send"));
56  $tpl->setVariable("PROP_VAL", $time_str);
57  $tpl->parseCurrentBlock();
58 
59  if ($a_data["deadline"] > 0)
60  {
61  $tpl->setCurrentBlock("prop");
62  $tpl->setVariable("PROP", $lng->txt("exc_edit_until"));
63  $tpl->setVariable("PROP_VAL",
64  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
65  $tpl->parseCurrentBlock();
66  }
67 
68  }
69 
70  $mand = "";
71  if ($a_data["mandatory"])
72  {
73  $mand = " (".$lng->txt("exc_mandatory").")";
74  }
75  $tpl->setVariable("TITLE", $a_data["title"].$mand);
76 // $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("accordion_arrow.png"));
77 
78  // status icon
79  $stat = ilExAssignment::lookupStatusOfUser($a_data["id"], $ilUser->getId());
80  switch ($stat)
81  {
82  case "passed": $pic = "scorm/passed.png"; break;
83  case "failed": $pic = "scorm/failed.png"; break;
84  default: $pic = "scorm/not_attempted.png"; break;
85  }
86  $tpl->setVariable("IMG_STATUS", ilUtil::getImagePath($pic));
87  $tpl->setVariable("ALT_STATUS", $lng->txt("exc_".$stat));
88 
89  return $tpl->get();
90  }
91 
95  function getOverviewBody($a_data)
96  {
97  global $lng, $ilCtrl, $ilUser;
98 
99  $tpl = new ilTemplate("tpl.assignment_body.html", true, true, "Modules/Exercise");
100 
101  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
102  if(IS_PAYMENT_ENABLED)
103  {
104  include_once './Services/Payment/classes/class.ilPaymentObject.php';
105  }
106 
107  $info = new ilInfoScreenGUI(null);
108  $info->setTableClass("");
109 
110  $not_started_yet = false;
111  if ($a_data["start_time"] > 0 && time() - $a_data["start_time"] <= 0)
112  {
113  $not_started_yet = true;
114  }
115 
116  if (!$not_started_yet)
117  {
118  // instructions
119  $info->addSection($lng->txt("exc_instruction"));
120  $info->addProperty("",
121  nl2br(ilUtil::makeClickable($a_data["instruction"], true)));
122  }
123 
124  // schedule
125  $info->addSection($lng->txt("exc_schedule"));
126  if ($a_data["start_time"] > 0)
127  {
128  $info->addProperty($lng->txt("exc_start_time"),
129  ilDatePresentation::formatDate(new ilDateTime($a_data["start_time"],IL_CAL_UNIX)));
130  }
131  if ($a_data["deadline"] > 0)
132  {
133  $info->addProperty($lng->txt("exc_edit_until"),
134  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
135  }
136  $time_str = $this->getTimeString($a_data["deadline"]);
137  if (!$not_started_yet)
138  {
139  $info->addProperty($lng->txt("exc_time_to_send"),
140  "<b>".$time_str."</b>");
141  }
142 
143  // public submissions
144  if ($this->exc->getShowSubmissions())
145  {
146  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
147  if ($a_data["deadline"] - time() <= 0)
148  {
149  $link = '<a class="submit" href="'.
150  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "listPublicSubmissions").'">'.
151  $lng->txt("exc_list_submission").'</a>';
152  $info->addProperty($lng->txt("exc_public_submission"), $link);
153  }
154  else
155  {
156  $info->addProperty($lng->txt("exc_public_submission"),
157  $lng->txt("exc_msg_public_submission"));
158  }
159  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $_GET["ass_id"]);
160  }
161 
162  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
163 
164  if (!$not_started_yet)
165  {
166  // download files
167  $files = ilExAssignment::getFiles($a_data["exc_id"], $a_data["id"]);
168  if (count($files) > 0)
169  {
170  $info->addSection($lng->txt("exc_files"));
171  foreach($files as $file)
172  {
173  // if download must be purchased first show a "buy"-button
174  if(IS_PAYMENT_ENABLED && (ilPaymentObject::_isBuyable($_GET['ref_id'],'download') &&
175  !ilPaymentObject::_hasAccess($_GET['ref_id'],'','download')))
176  {
177  $info->addProperty($file["name"],
178  $lng->txt("buy"),
179  $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails"));
180  }
181  else
182  {
183  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", urlencode($file["name"]));
184  $info->addProperty($file["name"],
185  $lng->txt("download"),
186  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadFile"));
187  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", "");
188  }
189  }
190  }
191 
192  // submission
193 
194  // if submission must be purchased first
195  if(IS_PAYMENT_ENABLED
196  && (ilPaymentObject::_isBuyable($_GET['ref_id'],'upload')
197  && !ilPaymentObject::_hasAccess($_GET['ref_id'],'','upload')))
198  {
199  $info->addSection($lng->txt("exc_your_submission"));
200 
201  $ilCtrl->clearParameters($this);
202 
203  $ilCtrl->setParameter($this, "ref_id", $_GET['ref_id']);
204  $ilCtrl->setParameter($this,'subtype','upload');
205  $info->addProperty($lng->txt('exc_hand_in'),
206  $lng->txt("buy"),
207  $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails"));
208  }
209  else
210  {
211  $info->addSection($lng->txt("exc_your_submission"));
212 
213  $delivered_files = ilExAssignment::getDeliveredFiles($a_data["exc_id"], $a_data["id"], $ilUser->getId());
214 
215  $times_up = false;
216  if(($a_data["deadline"] > 0) && $a_data["deadline"] - time() < 0)
217  {
218  $times_up = true;
219  }
220 
221  $team_members = null;
222  switch($a_data["type"])
223  {
225  $no_team_yet = false;
226  $team_members = ilExAssignment::getTeamMembersByAssignmentId($a_data["id"], $ilUser->getId());
227  if(sizeof($team_members))
228  {
229  $team = array();
230  foreach($team_members as $member_id)
231  {
232  $team[] = ilObjUser::_lookupFullname($member_id);
233  }
234  $info->addProperty($lng->txt("exc_team_members"), implode(", ", $team));
235  }
236  else
237  {
238  $no_team_yet = true;
239  if(!sizeof($delivered_files))
240  {
241  $info->addProperty($lng->txt("exc_team_members"), $lng->txt("exc_no_team_yet"));
242  }
243  else
244  {
245  $info->addProperty($lng->txt("exc_team_members"),
246  '<span class="warning">'.$lng->txt("exc_no_team_yet").'</span>');
247  }
248  }
249  // fallthrough
250 
252  $titles = array();
253  foreach($delivered_files as $file)
254  {
255  $titles[] = $file["filetitle"];
256  }
257  $files_str = implode($titles, ", ");
258  if ($files_str == "")
259  {
260  $files_str = $lng->txt("message_no_delivered_files");
261  }
262 
263  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
264 
265  if (!$times_up)
266  {
267  // #11957
268  if($no_team_yet && count($titles))
269  {
270  $title = $lng->txt("exc_create_team");
271  }
272  else
273  {
274  $title = (count($titles) == 0
275  ? $lng->txt("exc_hand_in")
276  : $lng->txt("exc_edit_submission"));
277  }
278  $files_str.= ' <a class="submit" href="'.
279  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "submissionScreen").'">'.
280  $title.'</a>';
281  }
282  else
283  {
284  if($no_team_yet)
285  {
286  $files_str .= '<div class="warning">'.
287  $lng->txt("exc_create_team_times_up_warning").'</div>';
288  }
289  else if (count($titles) > 0)
290  {
291  $files_str.= ' <a class="submit" href="'.
292  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "submissionScreen").'">'.
293  $lng->txt("already_delivered_files").'</a>';
294  }
295  }
296 
297  $info->addProperty($lng->txt("exc_files_returned"),
298  $files_str);
299  break;
300 
302  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
303  $wsp_tree = new ilWorkspaceTree($ilUser->getId());
304 
305  // #12939
306  if(!$wsp_tree->getRootId())
307  {
308  $wsp_tree->createTreeForUser($ilUser->getId());
309  }
310 
311  $files_str = "";
312  $valid_blog = false;
313  if(sizeof($delivered_files))
314  {
315  $delivered_files = array_pop($delivered_files);
316  $blog_id = (int)$delivered_files["filetitle"];
317  $node = $wsp_tree->getNodeData($blog_id);
318  if($node["title"])
319  {
320  // #10116
321  $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", $blog_id);
322  $blog_link = $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilpersonalworkspacegui", "ilobjbloggui"), "");
323  $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", "");
324  $files_str = '<a href="'.$blog_link.'">'.
325  $node["title"].'</a>';
326  $valid_blog = true;
327  }
328  }
329  if(!$times_up)
330  {
331  if(!$valid_blog)
332  {
333  $files_str .= '<a class="submit" href="'.
334  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "createBlog").'">'.
335  $lng->txt("exc_create_blog").'</a>';
336  }
337  // #10462
338  $blogs = sizeof($wsp_tree->getObjectsFromType("blog"));
339  if((!$valid_blog && $blogs)
340  || ($valid_blog && $blogs > 1))
341  {
342  $files_str .=' <a class="submit" href="'.
343  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "selectBlog").'">'.
344  $lng->txt("exc_select_blog".($valid_blog ? "_change" : "")).'</a>';
345  }
346  }
347  if($files_str)
348  {
349  $info->addProperty($lng->txt("exc_blog_returned"), $files_str);
350  }
351  if($delivered_files && substr($delivered_files["filename"], -1) != "/")
352  {
353  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", $delivered_files["returned_id"]);
354  $dl_link = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "download");
355  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", "");
356 
357  $info->addProperty($lng->txt("exc_files_returned"),
358  "<a href=\"".$dl_link."\">".$lng->txt("download")."</a>");
359  }
360  break;
361 
363  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
364 
365  $files_str = "";
366  $valid_prtf = false;
367  if(sizeof($delivered_files))
368  {
369  $delivered_files = array_pop($delivered_files);
370  $portfolio_id = (int)$delivered_files["filetitle"];
371 
372  // #11746
373  if(ilObject::_exists($portfolio_id, false))
374  {
375  $portfolio = new ilObjPortfolio($portfolio_id, false);
376  if($portfolio->getTitle())
377  {
378  // #10116
379  $ilCtrl->setParameterByClass("ilobjportfoliogui", "prt_id", $portfolio_id);
380  $prtf_link = $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilobjportfoliogui"), "pages");
381  $ilCtrl->setParameterByClass("ilobjportfoliogui", "prt_id", "");
382 
383  $files_str = '<a href="'.$prtf_link.
384  '">'.$portfolio->getTitle().'</a>';
385  $valid_prtf = true;
386  }
387  }
388  }
389  if(!$times_up)
390  {
391  if(!$valid_prtf)
392  {
393  $files_str .= '<a class="submit" href="'.
394  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "createPortfolio").'">'.
395  $lng->txt("exc_create_portfolio").'</a>';
396  }
397  // #10462
398  $prtfs = sizeof(ilObjPortfolio::getPortfoliosOfUser($ilUser->getId()));
399  if((!$valid_prtf && $prtfs)
400  || ($valid_prtf && $prtfs > 1))
401  {
402  $files_str .= ' <a class="submit" href="'.
403  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "selectPortfolio").'">'.
404  $lng->txt("exc_select_portfolio".($valid_prtf ? "_change" : "")).'</a>';
405  }
406  }
407  if($files_str)
408  {
409  $info->addProperty($lng->txt("exc_portfolio_returned"), $files_str);
410  }
411  if($delivered_files && substr($delivered_files["filename"], -1) != "/")
412  {
413  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", $delivered_files["returned_id"]);
414  $dl_link = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "download");
415  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", "");
416 
417  $info->addProperty($lng->txt("exc_files_returned"),
418  "<a href=\"".$dl_link."\">".$lng->txt("download")."</a>");
419  }
420  break;
421  }
422 
423 
424  $last_sub = ilExAssignment::getLastSubmission($a_data["id"], $ilUser->getId());
425  if ($last_sub)
426  {
427  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub,IL_CAL_DATETIME));
428  }
429  else
430  {
431  $last_sub = "---";
432  }
433 
434  if ($last_sub != "---")
435  {
436  $info->addProperty($lng->txt("exc_last_submission"),
437  $last_sub);
438  }
439 
440  // feedback from tutor
441  if($a_data["type"] == ilExAssignment::TYPE_UPLOAD_TEAM)
442  {
443  $feedback_id = "t".ilExAssignment::getTeamIdByAssignment($a_data["id"], $ilUser->getId());
444  }
445  else
446  {
447  $feedback_id = $ilUser->getId();
448  }
449  $storage = new ilFSStorageExercise($a_data["exc_id"], $a_data["id"]);
450  $cnt_files = $storage->countFeedbackFiles($feedback_id);
451  $lpcomment = ilExAssignment::lookupCommentForUser($a_data["id"], $ilUser->getId());
452  $mark = ilExAssignment::lookupMarkOfUser($a_data["id"], $ilUser->getId());
453  $status = ilExAssignment::lookupStatusOfUser($a_data["id"], $ilUser->getId());
454  if ($lpcomment != "" || $mark != "" || $status != "notgraded" || $cnt_files > 0)
455  {
456  $info->addSection($lng->txt("exc_feedback_from_tutor"));
457  if ($lpcomment != "")
458  {
459  $info->addProperty($lng->txt("exc_comment"),
460  $lpcomment);
461  }
462  if ($mark != "")
463  {
464  $info->addProperty($lng->txt("exc_mark"),
465  $mark);
466  }
467 
468  if ($status == "")
469  {
470  // $info->addProperty($lng->txt("status"),
471  // $lng->txt("message_no_delivered_files"));
472  }
473  else if ($status != "notgraded")
474  {
475  $img = '<img border="0" src="'.ilUtil::getImagePath("scorm/".$status.".png").'" '.
476  ' alt="'.$lng->txt("exc_".$status).'" title="'.$lng->txt("exc_".$status).
477  '" style="vertical-align:middle;"/>';
478  $info->addProperty($lng->txt("status"),
479  $img." ".$lng->txt("exc_".$status));
480  }
481 
482  if ($cnt_files > 0)
483  {
484  $info->addSection($lng->txt("exc_fb_files"));
485  $files = $storage->getFeedbackFiles($feedback_id);
486  foreach($files as $file)
487  {
488  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", urlencode($file));
489  $info->addProperty($file,
490  $lng->txt("download"),
491  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadFeedbackFile"));
492  $ilCtrl->setParameter($this, "file", "");
493  }
494  }
495  }
496  }
497  }
498 
499  $tpl->setVariable("CONTENT", $info->getHTML());
500 
501  return $tpl->get();
502  }
503 
507  function getTimeString($a_deadline)
508  {
509  global $lng;
510 
511  if ($a_deadline == 0)
512  {
513  return $lng->txt("exc_no_deadline_specified");
514  }
515 
516  if ($a_deadline - time() <= 0)
517  {
518  $time_str = $lng->txt("exc_time_over_short");
519  }
520  else
521  {
522  $time_diff = ilUtil::int2array($a_deadline - time(),null);
523  // #11576 - order ascending!
524  if (isset($time_diff['minutes']))
525  {
526  unset($time_diff['seconds']);
527  }
528  if (isset($time_diff['days']))
529  {
530  unset($time_diff['minutes']);
531  }
532  if (isset($time_diff['months']))
533  {
534  unset($time_diff['hours']);
535  }
536  $time_str = ilUtil::timearray2string($time_diff);
537  }
538 
539  return $time_str;
540  }
541 
542 
543 }