ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExAssignmentGUI.php
Go to the documentation of this file.
1 <?php
2 
12 {
16  protected $lng;
17 
21  protected $user;
22 
26  protected $ctrl;
27 
28  protected $exc; // [ilObjExercise]
29  protected $current_ass_id; // [int]
30 
34  public function __construct(ilObjExercise $a_exc)
35  {
36  global $DIC;
37 
38  $this->lng = $DIC->language();
39  $this->user = $DIC->user();
40  $this->ctrl = $DIC->ctrl();
41  $this->ui = $DIC->ui();
42 
43  $this->exc = $a_exc;
44  }
45 
49  public function getOverviewHeader(ilExAssignment $a_ass)
50  {
51  $lng = $this->lng;
53 
54  $lng->loadLanguageModule("exc");
55 
56  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
58 
59  $tpl = new ilTemplate("tpl.assignment_head.html", true, true, "Modules/Exercise");
60 
61  // we are completely ignoring the extended deadline here
62 
63  $idl = $a_ass->getPersonalDeadline($ilUser->getId());
64 
65  // :TODO: meaning of "ended on"
66  $dl = max($a_ass->getDeadline(), $idl);
67  // if ($dl &&
68  // $dl < time())
69  if ($state->exceededOfficialDeadline()) {
70  $tpl->setCurrentBlock("prop");
71  $tpl->setVariable("PROP", $lng->txt("exc_ended_on"));
72  $tpl->setVariable("PROP_VAL", $state->getCommonDeadlinePresentation());
73  $tpl->parseCurrentBlock();
74 
75  // #14077 // this currently shows the feedback deadline during grace period
76  if ($state->getPeerReviewDeadline()) {
77  $tpl->setCurrentBlock("prop");
78  $tpl->setVariable("PROP", $lng->txt("exc_peer_review_deadline"));
79  $tpl->setVariable("PROP_VAL", $state->getPeerReviewDeadlinePresentation());
80  $tpl->parseCurrentBlock();
81  }
82  } elseif (!$state->hasGenerallyStarted()) {
83  if ($state->getRelativeDeadline()) {
84  $tpl->setCurrentBlock("prop");
85  $tpl->setVariable("PROP", $lng->txt("exc_earliest_start_time"));
86  $tpl->setVariable("PROP_VAL", $state->getGeneralStartPresentation());
87  $tpl->parseCurrentBlock();
88  } else {
89  $tpl->setCurrentBlock("prop");
90  $tpl->setVariable("PROP", $lng->txt("exc_starting_on"));
91  $tpl->setVariable("PROP_VAL", $state->getGeneralStartPresentation());
92  $tpl->parseCurrentBlock();
93  }
94  } else {
95  if ($state->getCommonDeadline() > 0) {
96  $tpl->setCurrentBlock("prop");
97  $tpl->setVariable("PROP", $lng->txt("exc_time_to_send"));
98  $tpl->setVariable("PROP_VAL", $state->getRemainingTimePresentation());
99  $tpl->parseCurrentBlock();
100 
101  $tpl->setCurrentBlock("prop");
102  $tpl->setVariable("PROP", $lng->txt("exc_edit_until"));
103  $tpl->setVariable("PROP_VAL", $state->getCommonDeadlinePresentation());
104  $tpl->parseCurrentBlock();
105  } elseif ($state->getRelativeDeadline()) { // if we only have a relative deadline (not started yet)
106  $tpl->setCurrentBlock("prop");
107  $tpl->setVariable("PROP", $lng->txt("exc_rem_time_after_start"));
108  $tpl->setVariable("PROP_VAL", $state->getRelativeDeadlinePresentation());
109  $tpl->parseCurrentBlock();
110  }
111 
112 
113  if ($state->getIndividualDeadline() > 0) {
114  $tpl->setCurrentBlock("prop");
115  $tpl->setVariable("PROP", $lng->txt("exc_individual_deadline"));
116  $tpl->setVariable("PROP_VAL", $state->getIndividualDeadlinePresentation());
117  $tpl->parseCurrentBlock();
118  }
119  }
120 
121  $mand = "";
122  if ($a_ass->getMandatory()) {
123  $mand = " (" . $lng->txt("exc_mandatory") . ")";
124  }
125  $tpl->setVariable("TITLE", $a_ass->getTitle() . $mand);
126 
127  // status icon
128  $stat = $a_ass->getMemberStatus()->getStatus();
129  $pic = $a_ass->getMemberStatus()->getStatusIcon();
130  $tpl->setVariable("IMG_STATUS", ilUtil::getImagePath($pic));
131  $tpl->setVariable("ALT_STATUS", $lng->txt("exc_" . $stat));
132 
133  return $tpl->get();
134  }
135 
139  public function getOverviewBody(ilExAssignment $a_ass)
140  {
141  global $DIC;
142 
143  $ilUser = $DIC->user();
144 
145  $this->current_ass_id = $a_ass->getId();
146 
147  $tpl = new ilTemplate("tpl.assignment_body.html", true, true, "Modules/Exercise");
148 
149  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
151 
152  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
153  include_once("./Services/UIComponent/Button/classes/class.ilLinkButton.php");
154 
155  $info = new ilInfoScreenGUI(null);
156  $info->setTableClass("");
157 
158  if ($state->areInstructionsVisible()) {
159  $this->addInstructions($info, $a_ass);
160  $this->addFiles($info, $a_ass);
161  }
162 
163  $this->addSchedule($info, $a_ass);
164 
165  if ($state->hasSubmissionStarted()) {
166  $this->addSubmission($info, $a_ass);
167  }
168 
169  $tpl->setVariable("CONTENT", $info->getHTML());
170 
171  return $tpl->get();
172  }
173 
174 
175  protected function addInstructions(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
176  {
178  $lng = $this->lng;
179 
180  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
182 
183  if ($state->areInstructionsVisible()) {
184  $inst = $a_ass->getInstruction();
185  if (trim($inst)) {
186  $a_info->addSection($lng->txt("exc_instruction"));
187 
188  $is_html = (strlen($inst) != strlen(strip_tags($inst)));
189  if (!$is_html) {
190  $inst = nl2br(ilUtil::makeClickable($inst, true));
191  }
192  $a_info->addProperty("", $inst);
193  }
194  }
195  }
196 
197  protected function addSchedule(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
198  {
199  $lng = $this->lng;
202 
203  $idl = $a_ass->getPersonalDeadline($ilUser->getId());
204 
205  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
207 
208  $a_info->addSection($lng->txt("exc_schedule"));
209  if ($state->getGeneralStart() > 0) {
210  if ($state->getRelativeDeadline()) {
211  $a_info->addProperty($lng->txt("exc_earliest_start_time"), $state->getGeneralStartPresentation());
212  } else {
213  $a_info->addProperty($lng->txt("exc_start_time"), $state->getGeneralStartPresentation());
214  }
215  }
216 
217  // extended deadline info/warning
218  $late_dl = "";
219  //if ($idl &&
220  // $idl < time() &&
221  // $a_ass->beforeDeadline()) // ext dl is last deadline
222  if ($state->inLateSubmissionPhase()) {
223  // extended deadline date should not be presented anywhere
224  $late_dl = $state->getOfficialDeadlinePresentation();
225  $late_dl = "<br />" . sprintf($lng->txt("exc_late_submission_warning"), $late_dl);
226  $late_dl = '<span class="warning">' . $late_dl . '</span>';
227  }
228 
229  if ($state->getCommonDeadline()) { // if we have a common deadline (target timestamp)
230  $until = $state->getCommonDeadlinePresentation();
231 
232  // add late info if no idl
233  if ($late_dl &&
234  $state->getOfficialDeadline() == $state->getCommonDeadline()) {
235  $until .= $late_dl;
236  }
237 
238  $prop = $lng->txt("exc_edit_until");
239  if ($state->exceededOfficialDeadline()) {
240  $prop = $lng->txt("exc_ended_on");
241  }
242 
243  $a_info->addProperty($prop, $until);
244  } elseif ($state->getRelativeDeadline()) { // if we only have a relative deadline (not started yet)
245  $but = "";
246  if ($state->hasGenerallyStarted()) {
247  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $a_ass->getId());
248  $but = $this->ui->factory()->button()->primary($lng->txt("exc_start_assignment"), $ilCtrl->getLinkTargetByClass("ilobjexercisegui", "startAssignment"));
249  $ilCtrl->setParameterByClass("ilobjexercisegui", "ass_id", $_GET["ass_id"]);
250  $but = $this->ui->renderer()->render($but);
251  }
252  $a_info->addProperty($lng->txt("exc_rem_time_after_start"), $state->getRelativeDeadlinePresentation() .
253  " " . $but);
254  }
255 
256  if ($state->getOfficialDeadline() > $state->getCommonDeadline()) {
257  $until = $state->getOfficialDeadlinePresentation();
258 
259  // add late info?
260  if ($late_dl) {
261  $until .= $late_dl;
262  }
263 
264  $a_info->addProperty($lng->txt("exc_individual_deadline"), $until);
265  }
266 
267  if ($state->hasSubmissionStarted()) {
268  $a_info->addProperty(
269  $lng->txt("exc_time_to_send"),
270  "<b>" . $state->getRemainingTimePresentation() . "</b>"
271  );
272  }
273  }
274 
275  protected function addPublicSubmissions(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
276  {
277  $lng = $this->lng;
279 
280 
281  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
283 
284  // submissions are visible, even if other users may still have a larger individual deadline
285  if ($state->hasSubmissionEnded()) {
286  $button = ilLinkButton::getInstance();
287  $button->setCaption("exc_list_submission");
288  $button->setUrl($this->getSubmissionLink("listPublicSubmissions"));
289 
290  $a_info->addProperty($lng->txt("exc_public_submission"), $button->render());
291  } else {
292  $a_info->addProperty(
293  $lng->txt("exc_public_submission"),
294  $lng->txt("exc_msg_public_submission")
295  );
296  }
297  }
298 
299  protected function addFiles(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
300  {
301  $lng = $this->lng;
303 
304  $files = $a_ass->getFiles();
305 
306  if (count($files) > 0) {
307  $a_info->addSection($lng->txt("exc_files"));
308 
309  global $DIC;
310 
311  //file has -> name,fullpath,size,ctime
312  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
313  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
314  include_once "./Services/UIComponent/Modal/classes/class.ilModalGUI.php";
315 
316  $cnt = 0;
317  foreach ($files as $file) {
318  $cnt++;
319  // get mime type
320  $mime = ilObjMediaObject::getMimeType($file['fullpath']);
321 
322  list($format, $type) = explode("/", $mime);
323 
324  $ui_factory = $DIC->ui()->factory();
325  $ui_renderer = $DIC->ui()->renderer();
326 
327  if (in_array($mime, array("image/jpeg", "image/svg+xml", "image/gif", "image/png"))) {
328  $item_id = "il-ex-modal-img-" . $a_ass->getId() . "-" . $cnt;
329 
330 
331  $image = $ui_renderer->render($ui_factory->image()->responsive($file['fullpath'], $file['name']));
332  $image_lens = ilUtil::getImagePath("enlarge.svg");
333 
334  $modal = ilModalGUI::getInstance();
335  $modal->setId($item_id);
336  $modal->setType(ilModalGUI::TYPE_LARGE);
337  $modal->setBody($image);
338  $modal->setHeading($file["name"]);
339  $modal = $modal->getHTML();
340 
341  $img_tpl = new ilTemplate("tpl.image_file.html", true, true, "Modules/Exercise");
342  $img_tpl->setCurrentBlock("image_content");
343  $img_tpl->setVariable("MODAL", $modal);
344  $img_tpl->setVariable("ITEM_ID", $item_id);
345  $img_tpl->setVariable("IMAGE", $image);
346  $img_tpl->setvariable("IMAGE_LENS", $image_lens);
347  $img_tpl->parseCurrentBlock();
348 
349  $a_info->addProperty($file["name"], $img_tpl->get());
350  } elseif (in_array($mime, array("audio/mpeg", "audio/ogg", "video/mp4", "video/x-flv", "video/webm"))) {
351  $media_tpl = new ilTemplate("tpl.media_file.html", true, true, "Modules/Exercise");
352  $mp = new ilMediaPlayerGUI();
353  $mp->setFile($file['fullpath']);
354  $media_tpl->setVariable("MEDIA", $mp->getMediaPlayerHtml());
355 
356  $but = $ui_factory->button()->shy(
357  $lng->txt("download"),
358  $this->getSubmissionLink("downloadFile", array("file" => urlencode($file["name"])))
359  );
360  $media_tpl->setVariable("DOWNLOAD_BUTTON", $ui_renderer->render($but));
361  $a_info->addProperty($file["name"], $media_tpl->get());
362  } else {
363  $a_info->addProperty($file["name"], $lng->txt("download"), $this->getSubmissionLink("downloadFile", array("file" => urlencode($file["name"]))));
364  }
365  }
366  }
367  }
368 
369  protected function addSubmission(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
370  {
371  $lng = $this->lng;
374 
375  include_once("./Modules/Exercise/classes/class.ilExcAssMemberState.php");
377 
378  $a_info->addSection($lng->txt("exc_your_submission"));
379 
380  include_once "Modules/Exercise/classes/class.ilExSubmission.php";
381  $submission = new ilExSubmission($a_ass, $ilUser->getId());
382 
383  include_once "Modules/Exercise/classes/class.ilExSubmissionGUI.php";
384  ilExSubmissionGUI::getOverviewContent($a_info, $submission, $this->exc);
385 
386  $last_sub = null;
387  if ($submission->hasSubmitted()) {
388  $last_sub = $submission->getLastSubmission();
389  if ($last_sub) {
390  $last_sub = ilDatePresentation::formatDate(new ilDateTime($last_sub, IL_CAL_DATETIME));
391  $a_info->addProperty($lng->txt("exc_last_submission"), $last_sub);
392  }
393  }
394 
395  if ($this->exc->getShowSubmissions()) {
396  $this->addPublicSubmissions($a_info, $a_ass);
397  }
398 
399  include_once "Modules/Exercise/classes/class.ilExPeerReviewGUI.php";
400  ilExPeerReviewGUI::getOverviewContent($a_info, $submission);
401 
402  // global feedback / sample solution
404  $show_global_feedback = ($state->hasSubmissionEndedForAllUsers() && $a_ass->getFeedbackFile());
405  }
406  //If it is not well configured...(e.g. show solution before deadline)
407  //the user can get the solution before he summit it.
408  //we can check in the elseif $submission->hasSubmitted()
410  $show_global_feedback = ($a_ass->afterCustomDate() && $a_ass->getFeedbackFile());
411  } else {
412  $show_global_feedback = ($last_sub && $a_ass->getFeedbackFile());
413  }
414 
415  $this->addSubmissionFeedback($a_info, $a_ass, $submission->getFeedbackId(), $show_global_feedback);
416  }
417 
418  protected function addSubmissionFeedback(ilInfoScreenGUI $a_info, ilExAssignment $a_ass, $a_feedback_id, $a_show_global_feedback)
419  {
420  $lng = $this->lng;
421 
422  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
423 
424  $storage = new ilFSStorageExercise($a_ass->getExerciseId(), $a_ass->getId());
425  $cnt_files = $storage->countFeedbackFiles($a_feedback_id);
426 
427  $lpcomment = $a_ass->getMemberStatus()->getComment();
428  $mark = $a_ass->getMemberStatus()->getMark();
429  $status = $a_ass->getMemberStatus()->getStatus();
430 
431  if ($lpcomment != "" ||
432  $mark != "" ||
433  $status != "notgraded" ||
434  $cnt_files > 0 ||
435  $a_show_global_feedback) {
436  $a_info->addSection($lng->txt("exc_feedback_from_tutor"));
437  if ($lpcomment != "") {
438  $a_info->addProperty(
439  $lng->txt("exc_comment"),
440  nl2br($lpcomment)
441  );
442  }
443  if ($mark != "") {
444  $a_info->addProperty(
445  $lng->txt("exc_mark"),
446  $mark
447  );
448  }
449 
450  if ($status == "") {
451  // $a_info->addProperty($lng->txt("status"),
452 // $lng->txt("message_no_delivered_files"));
453  } elseif ($status != "notgraded") {
454  $img = '<img src="' . ilUtil::getImagePath("scorm/" . $status . ".svg") . '" ' .
455  ' alt="' . $lng->txt("exc_" . $status) . '" title="' . $lng->txt("exc_" . $status) .
456  '" />';
457  $a_info->addProperty(
458  $lng->txt("status"),
459  $img . " " . $lng->txt("exc_" . $status)
460  );
461  }
462 
463  if ($cnt_files > 0) {
464  $a_info->addSection($lng->txt("exc_fb_files") .
465  '<a name="fb' . $a_ass->getId() . '"></a>');
466 
467  if ($cnt_files > 0) {
468  $files = $storage->getFeedbackFiles($a_feedback_id);
469  foreach ($files as $file) {
470  $a_info->addProperty(
471  $file,
472  $lng->txt("download"),
473  $this->getSubmissionLink("downloadFeedbackFile", array("file" => urlencode($file)))
474  );
475  }
476  }
477  }
478 
479  // #15002 - global feedback
480  if ($a_show_global_feedback) {
481  $a_info->addSection($lng->txt("exc_global_feedback_file"));
482 
483  $a_info->addProperty(
484  $a_ass->getFeedbackFile(),
485  $lng->txt("download"),
486  $this->getSubmissionLink("downloadGlobalFeedbackFile")
487  );
488  }
489  }
490  }
491 
495  public function getTimeString($a_deadline)
496  {
497  $lng = $this->lng;
498 
499  if ($a_deadline == 0) {
500  return $lng->txt("exc_submit_convenience_no_deadline");
501  }
502 
503  if ($a_deadline - time() <= 0) {
504  $time_str = $lng->txt("exc_time_over_short");
505  } else {
506  $time_str = ilUtil::period2String(new ilDateTime($a_deadline, IL_CAL_UNIX));
507  }
508 
509  return $time_str;
510  }
511 
512  protected function getSubmissionLink($a_cmd, array $a_params = null)
513  {
515 
516  if (is_array($a_params)) {
517  foreach ($a_params as $name => $value) {
518  $ilCtrl->setParameterByClass("ilexsubmissiongui", $name, $value);
519  }
520  }
521 
522  $ilCtrl->setParameterByClass("ilexsubmissiongui", "ass_id", $this->current_ass_id);
523  $url = $ilCtrl->getLinkTargetByClass("ilexsubmissiongui", $a_cmd);
524  $ilCtrl->setParameterByClass("ilexsubmissiongui", "ass_id", "");
525 
526  if (is_array($a_params)) {
527  foreach ($a_params as $name => $value) {
528  $ilCtrl->setParameterByClass("ilexsubmissiongui", $name, "");
529  }
530  }
531 
532  return $url;
533  }
534 }
addSubmissionFeedback(ilInfoScreenGUI $a_info, ilExAssignment $a_ass, $a_feedback_id, $a_show_global_feedback)
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
getMemberStatus($a_user_id=null)
getPersonalDeadline($a_user_id)
Get individual deadline (max of common or idl (team) deadline = Official Deadline) ...
static getMimeType($a_file, $a_external=null)
get mime type for file
Class ilInfoScreenGUI.
Exercise assignment.
$format
Definition: metadata.php:141
$files
Definition: metarefresh.php:49
const IL_CAL_DATETIME
addPublicSubmissions(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
getFeedbackDate()
Get (global) feedback file availability date.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tpl
Definition: ilias.php:10
getId()
Get assignment id.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission, ilObjExercise $a_exc)
getDeadline()
Get deadline (timestamp)
addInstructions(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
addSection($a_title)
add a new section
addSchedule(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
const IL_CAL_UNIX
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 getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
global $ilCtrl
Definition: ilias.php:18
GUI class for exercise assignments.
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
getExerciseId()
Get exercise id.
Class ilObjExercise.
getOverviewBody(ilExAssignment $a_ass)
Get assignment body for overview.
getTimeString($a_deadline)
Get time string for deadline.
addFiles(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static makeClickable($a_text, $detectGotoLinks=false)
makeClickable In Texten enthaltene URLs und Mail-Adressen klickbar machen
special template class to simplify handling of ITX/PEAR
static period2String(ilDateTime $a_from, $a_to=null)
Return a string of time period.
Date and time handling
$ilUser
Definition: imgupload.php:18
getFeedbackFile()
Get (global) feedback file.
__construct(ilObjExercise $a_exc)
Constructor.
getMandatory()
Get mandatory.
getOverviewHeader(ilExAssignment $a_ass)
Get assignment header for overview.
static getInstance()
Get instance.
User interface for media player.
addProperty($a_name, $a_value, $a_link="")
add a property to current section
getInstruction()
Get instruction.
addSubmission(ilInfoScreenGUI $a_info, ilExAssignment $a_ass)
Exercise submission //TODO: This class has to much static methods related to delivered "files"...
$url
countFeedbackFiles($a_user_id)
Count number of feedback files for a user.
$info
Definition: index.php:5
getSubmissionLink($a_cmd, array $a_params=null)