ILIAS  Release_4_4_x_branch Revision 61816
 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 
121  $is_html = (strlen($a_data["instruction"]) != strlen(strip_tags($a_data["instruction"])));
122  if(!$is_html)
123  {
124  $a_data["instruction"] = nl2br(ilUtil::makeClickable($a_data["instruction"], true));
125  }
126  $info->addProperty("", $a_data["instruction"]);
127  }
128 
129  // schedule
130  $info->addSection($lng->txt("exc_schedule"));
131  if ($a_data["start_time"] > 0)
132  {
133  $info->addProperty($lng->txt("exc_start_time"),
134  ilDatePresentation::formatDate(new ilDateTime($a_data["start_time"],IL_CAL_UNIX)));
135  }
136  if ($a_data["deadline"] > 0)
137  {
138  $info->addProperty($lng->txt("exc_edit_until"),
139  ilDatePresentation::formatDate(new ilDateTime($a_data["deadline"],IL_CAL_UNIX)));
140  }
141  $time_str = $this->getTimeString($a_data["deadline"]);
142  if (!$not_started_yet)
143  {
144  $info->addProperty($lng->txt("exc_time_to_send"),
145  "<b>".$time_str."</b>");
146  }
147 
148  // public submissions
149  if ($this->exc->getShowSubmissions())
150  {
151  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
152  if ($a_data["deadline"] - time() <= 0)
153  {
154  $link = '<a class="submit" href="'.
155  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "listPublicSubmissions").'">'.
156  $lng->txt("exc_list_submission").'</a>';
157  $info->addProperty($lng->txt("exc_public_submission"), $link);
158  }
159  else
160  {
161  $info->addProperty($lng->txt("exc_public_submission"),
162  $lng->txt("exc_msg_public_submission"));
163  }
164  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $_GET["ass_id"]);
165  }
166 
167  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
168 
169  if (!$not_started_yet)
170  {
171  // download files
172  $files = ilExAssignment::getFiles($a_data["exc_id"], $a_data["id"]);
173  if (count($files) > 0)
174  {
175  $info->addSection($lng->txt("exc_files"));
176  foreach($files as $file)
177  {
178  // if download must be purchased first show a "buy"-button
179  if(IS_PAYMENT_ENABLED && (ilPaymentObject::_isBuyable($_GET['ref_id'],'download') &&
180  !ilPaymentObject::_hasAccess($_GET['ref_id'],'','download')))
181  {
182  $info->addProperty($file["name"],
183  $lng->txt("buy"),
184  $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails"));
185  }
186  else
187  {
188  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", urlencode($file["name"]));
189  $info->addProperty($file["name"],
190  $lng->txt("download"),
191  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadFile"));
192  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", "");
193  }
194  }
195  }
196 
197  // submission
198 
199  // if submission must be purchased first
200  if(IS_PAYMENT_ENABLED
201  && (ilPaymentObject::_isBuyable($_GET['ref_id'],'upload')
202  && !ilPaymentObject::_hasAccess($_GET['ref_id'],'','upload')))
203  {
204  $info->addSection($lng->txt("exc_your_submission"));
205 
206  $ilCtrl->clearParameters($this);
207 
208  $ilCtrl->setParameter($this, "ref_id", $_GET['ref_id']);
209  $ilCtrl->setParameter($this,'subtype','upload');
210  $info->addProperty($lng->txt('exc_hand_in'),
211  $lng->txt("buy"),
212  $ilCtrl->getLinkTargetByClass("ilShopPurchaseGUI", "showDetails"));
213  }
214  else
215  {
216  $info->addSection($lng->txt("exc_your_submission"));
217 
218  $delivered_files = ilExAssignment::getDeliveredFiles($a_data["exc_id"], $a_data["id"], $ilUser->getId());
219 
220  $times_up = false;
221  if(($a_data["deadline"] > 0) && $a_data["deadline"] - time() < 0)
222  {
223  $times_up = true;
224  }
225 
226  $team_members = null;
227  switch($a_data["type"])
228  {
230  $no_team_yet = false;
231  $team_members = ilExAssignment::getTeamMembersByAssignmentId($a_data["id"], $ilUser->getId());
232  if(sizeof($team_members))
233  {
234  $team = array();
235  foreach($team_members as $member_id)
236  {
237  $team[] = ilObjUser::_lookupFullname($member_id);
238  }
239  $info->addProperty($lng->txt("exc_team_members"), implode(", ", $team));
240  }
241  else
242  {
243  $no_team_yet = true;
244  if(!sizeof($delivered_files))
245  {
246  $info->addProperty($lng->txt("exc_team_members"), $lng->txt("exc_no_team_yet"));
247  }
248  else
249  {
250  $info->addProperty($lng->txt("exc_team_members"),
251  '<span class="warning">'.$lng->txt("exc_no_team_yet").'</span>');
252  }
253  }
254  // fallthrough
255 
257  $titles = array();
258  foreach($delivered_files as $file)
259  {
260  $titles[] = $file["filetitle"];
261  }
262  $files_str = implode($titles, ", ");
263  if ($files_str == "")
264  {
265  $files_str = $lng->txt("message_no_delivered_files");
266  }
267 
268  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
269 
270  if (!$times_up)
271  {
272  // #11957
273  if($no_team_yet && count($titles))
274  {
275  $title = $lng->txt("exc_create_team");
276  }
277  else
278  {
279  $title = (count($titles) == 0
280  ? $lng->txt("exc_hand_in")
281  : $lng->txt("exc_edit_submission"));
282  }
283  $files_str.= ' <a class="submit emphsubmit" href="'.
284  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "submissionScreen").'">'.
285  $title.'</a>';
286  }
287  else
288  {
289  if($no_team_yet)
290  {
291  $files_str .= '<div class="warning">'.
292  $lng->txt("exc_create_team_times_up_warning").'</div>';
293  }
294  else if (count($titles) > 0)
295  {
296  $files_str.= ' <a class="submit" href="'.
297  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "submissionScreen").'">'.
298  $lng->txt("already_delivered_files").'</a>';
299  }
300  }
301 
302  $info->addProperty($lng->txt("exc_files_returned"),
303  $files_str);
304  break;
305 
307  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
308  $wsp_tree = new ilWorkspaceTree($ilUser->getId());
309 
310  // #12939
311  if(!$wsp_tree->getRootId())
312  {
313  $wsp_tree->createTreeForUser($ilUser->getId());
314  }
315 
316  $files_str = "";
317  $valid_blog = false;
318  if(sizeof($delivered_files))
319  {
320  $delivered_files = array_pop($delivered_files);
321  $blog_id = (int)$delivered_files["filetitle"];
322  $node = $wsp_tree->getNodeData($blog_id);
323  if($node["title"])
324  {
325  // #10116
326  $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", $blog_id);
327  $blog_link = $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilpersonalworkspacegui", "ilobjbloggui"), "");
328  $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", "");
329  $files_str = '<a href="'.$blog_link.'">'.
330  $node["title"].'</a>';
331  $valid_blog = true;
332  }
333  // remove invalid resource if no upload yet (see download below)
334  else if(substr($delivered_files["filename"], -1) == "/")
335  {
336  $this->exc->deleteResourceObject($delivered_files["ass_id"],
337  $ilUser->getId(), $delivered_files["returned_id"]);
338  }
339  }
340  if(!$times_up)
341  {
342  if(!$valid_blog)
343  {
344  $files_str .= '<a class="submit" href="'.
345  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "createBlog").'">'.
346  $lng->txt("exc_create_blog").'</a>';
347  }
348  // #10462
349  $blogs = sizeof($wsp_tree->getObjectsFromType("blog"));
350  if((!$valid_blog && $blogs)
351  || ($valid_blog && $blogs > 1))
352  {
353  $files_str .=' <a class="submit" href="'.
354  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "selectBlog").'">'.
355  $lng->txt("exc_select_blog".($valid_blog ? "_change" : "")).'</a>';
356  }
357  }
358  if($files_str)
359  {
360  $info->addProperty($lng->txt("exc_blog_returned"), $files_str);
361  }
362  if($delivered_files && substr($delivered_files["filename"], -1) != "/")
363  {
364  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", $delivered_files["returned_id"]);
365  $dl_link = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "download");
366  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", "");
367 
368  $info->addProperty($lng->txt("exc_files_returned"),
369  "<a href=\"".$dl_link."\" class=\"submit\">".$lng->txt("download")."</a>");
370  }
371  break;
372 
374  include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
375 
376  $files_str = "";
377  $valid_prtf = false;
378  if(sizeof($delivered_files))
379  {
380  $delivered_files = array_pop($delivered_files);
381  $portfolio_id = (int)$delivered_files["filetitle"];
382 
383  // #11746
384  if(ilObject::_exists($portfolio_id, false, "prtf"))
385  {
386  $portfolio = new ilObjPortfolio($portfolio_id, false);
387  if($portfolio->getTitle())
388  {
389  // #10116 / #12791
390  $ilCtrl->setParameterByClass("ilobjportfoliogui", "prt_id", $portfolio_id);
391  $prtf_link = $ilCtrl->getLinkTargetByClass(array("ilpersonaldesktopgui", "ilportfoliorepositorygui", "ilobjportfoliogui"), "view");
392  $ilCtrl->setParameterByClass("ilobjportfoliogui", "prt_id", "");
393 
394  $files_str = '<a href="'.$prtf_link.
395  '">'.$portfolio->getTitle().'</a>';
396  $valid_prtf = true;
397  }
398  }
399  // remove invalid resource if no upload yet (see download below)
400  else if(substr($delivered_files["filename"], -1) == "/")
401  {
402  $this->exc->deleteResourceObject($delivered_files["ass_id"],
403  $ilUser->getId(), $delivered_files["returned_id"]);
404  }
405  }
406  if(!$times_up)
407  {
408  if(!$valid_prtf)
409  {
410  // if there are portfolio templates available show form first
411  include_once "Modules/Portfolio/classes/class.ilObjPortfolioTemplate.php";
413  ? "Template"
414  : "";
415 
416  $files_str .= '<a class="submit" href="'.
417  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "createPortfolio".$has_prtt).'">'.
418  $lng->txt("exc_create_portfolio").'</a>';
419  }
420  // #10462
421  $prtfs = sizeof(ilObjPortfolio::getPortfoliosOfUser($ilUser->getId()));
422  if((!$valid_prtf && $prtfs)
423  || ($valid_prtf && $prtfs > 1))
424  {
425  $files_str .= ' <a class="submit" href="'.
426  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "selectPortfolio").'">'.
427  $lng->txt("exc_select_portfolio".($valid_prtf ? "_change" : "")).'</a>';
428  }
429  }
430  if($files_str)
431  {
432  $info->addProperty($lng->txt("exc_portfolio_returned"), $files_str);
433  }
434  if($delivered_files && substr($delivered_files["filename"], -1) != "/")
435  {
436  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", $delivered_files["returned_id"]);
437  $dl_link = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "download");
438  $ilCtrl->setParameterByClass("ilobjexercisegui", "delivered", "");
439 
440  $info->addProperty($lng->txt("exc_files_returned"),
441  "<a href=\"".$dl_link."\" class=\"submit\">".$lng->txt("download")."</a>");
442  }
443  break;
444 
446  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_data["id"]);
447 
448  if(!$times_up)
449  {
450  $files_str = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "editAssignmentText");
451  $files_str = "<a href=\"".$files_str."\" class=\"submit emphsubmit\">".
452  $lng->txt("exc_text_assignment_edit")."</a>";
453  }
454  else
455  {
456  $files_str = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "showAssignmentText");
457  $files_str = "<a href=\"".$files_str."\" class=\"submit\">".
458  $lng->txt("exc_text_assignment_show")."</a>";
459  }
460 
461  $info->addProperty($lng->txt("exc_files_returned_text"),
462  $files_str);
463  break;
464  }
465 
466 
467  $last_sub = ilExAssignment::getLastSubmission($a_data["id"], $ilUser->getId());
468  if ($last_sub)
469  {
470  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub,IL_CAL_DATETIME));
471  }
472  else
473  {
474  $last_sub = "---";
475  }
476 
477  if ($last_sub != "---")
478  {
479  $info->addProperty($lng->txt("exc_last_submission"),
480  $last_sub);
481  }
482 
483 
484  // peer feedback
485  if($times_up && $a_data["peer"])
486  {
487  $nr_missing_fb = ilExAssignment::getNumberOfMissingFeedbacks($a_data["id"], $a_data["peer_min"]);
488 
489  if(!$a_data["peer_dl"] || $a_data["peer_dl"] > time())
490  {
491  $dl_info = "";
492  if($a_data["peer_dl"])
493  {
494  $dl_info = " (".sprintf($lng->txt("exc_peer_review_deadline_info_button"),
495  ilDatePresentation::formatDate(new ilDateTime($a_data["peer_dl"], IL_CAL_UNIX))).")";
496  }
497 
498  $emph = $nr_missing_fb ? " emphsubmit" : "";
499  $peer_url = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "editPeerReview");
500  $edit_pc = "<a href=\"".$peer_url."\" class=\"submit".$emph."\">".
501  $lng->txt("exc_peer_review_give").$dl_info."</a>";
502  }
503  else if($a_data["peer_dl"])
504  {
505  $edit_pc = $lng->txt("exc_peer_review_deadline_reached");
506  }
507  if((!$a_data["peer_dl"] || $a_data["peer_dl"] < time()) &&
508  !$nr_missing_fb)
509  {
510  $view_url = $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "showPersonalPeerReview");
511  $view_pc = "<a href=\"".$view_url."\" class=\"submit\">".
512  $lng->txt("exc_peer_review_show")."</a>";
513  }
514  /*
515  else
516  {
517  $view_pc = $lng->txt("exc_peer_review_show_not_rated_yet");
518  }
519  */
520 
521  $info->addProperty($lng->txt("exc_peer_review"),
522  $edit_pc." ".$view_pc);
523  }
524 
525 
526  // feedback from tutor
527  if($a_data["type"] == ilExAssignment::TYPE_UPLOAD_TEAM)
528  {
529  $feedback_id = "t".ilExAssignment::getTeamIdByAssignment($a_data["id"], $ilUser->getId());
530  }
531  else
532  {
533  $feedback_id = $ilUser->getId();
534  }
535  $storage = new ilFSStorageExercise($a_data["exc_id"], $a_data["id"]);
536  $cnt_files = $storage->countFeedbackFiles($feedback_id);
537  $lpcomment = ilExAssignment::lookupCommentForUser($a_data["id"], $ilUser->getId());
538  $mark = ilExAssignment::lookupMarkOfUser($a_data["id"], $ilUser->getId());
539  $status = ilExAssignment::lookupStatusOfUser($a_data["id"], $ilUser->getId());
540  if ($lpcomment != "" || $mark != "" || $status != "notgraded" ||
541  $cnt_files > 0 || ($times_up && $a_data["fb_file"]))
542  {
543  $info->addSection($lng->txt("exc_feedback_from_tutor"));
544  if ($lpcomment != "")
545  {
546  $info->addProperty($lng->txt("exc_comment"),
547  $lpcomment);
548  }
549  if ($mark != "")
550  {
551  $info->addProperty($lng->txt("exc_mark"),
552  $mark);
553  }
554 
555  if ($status == "")
556  {
557  // $info->addProperty($lng->txt("status"),
558  // $lng->txt("message_no_delivered_files"));
559  }
560  else if ($status != "notgraded")
561  {
562  $img = '<img src="'.ilUtil::getImagePath("scorm/".$status.".png").'" '.
563  ' alt="'.$lng->txt("exc_".$status).'" title="'.$lng->txt("exc_".$status).
564  '" />';
565  $info->addProperty($lng->txt("status"),
566  $img." ".$lng->txt("exc_".$status));
567  }
568 
569  if ($cnt_files > 0 || ($times_up && $a_data["fb_file"]))
570  {
571  $info->addSection($lng->txt("exc_fb_files").
572  '<a name="fb'.$a_data["id"].'"></a>');
573 
574  if($cnt_files > 0)
575  {
576  $files = $storage->getFeedbackFiles($feedback_id);
577  foreach($files as $file)
578  {
579  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", urlencode($file));
580  $info->addProperty($file,
581  $lng->txt("download"),
582  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadFeedbackFile"));
583  $ilCtrl->setParameterByClass("ilobjexercisegui", "file", "");
584  }
585  }
586 
587  // global feedback
588  if($times_up && $a_data["fb_file"])
589  {
590  $info->addProperty($a_data["fb_file"],
591  $lng->txt("download"),
592  $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "downloadGlobalFeedbackFile"));
593  }
594  }
595  }
596  }
597  }
598 
599  $tpl->setVariable("CONTENT", $info->getHTML());
600 
601  return $tpl->get();
602  }
603 
607  function getTimeString($a_deadline)
608  {
609  global $lng;
610 
611  if ($a_deadline == 0)
612  {
613  return $lng->txt("exc_no_deadline_specified");
614  }
615 
616  if ($a_deadline - time() <= 0)
617  {
618  $time_str = $lng->txt("exc_time_over_short");
619  }
620  else
621  {
622  $time_diff = ilUtil::int2array($a_deadline - time(),null);
623  // #11576 - order ascending!
624  if (isset($time_diff['minutes']))
625  {
626  unset($time_diff['seconds']);
627  }
628  if (isset($time_diff['days']))
629  {
630  unset($time_diff['minutes']);
631  }
632  if (isset($time_diff['months']))
633  {
634  unset($time_diff['hours']);
635  }
636  $time_str = ilUtil::timearray2string($time_diff);
637  }
638 
639  return $time_str;
640  }
641 
642 
643 }