ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilExSubmissionObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
30 {
31  protected int $user_id;
33 
37  public function __construct(
38  ilObjExercise $a_exercise,
39  ilExSubmission $a_submission
40  ) {
41  global $DIC;
42 
43  $this->user_id = $DIC->user()->getId();
44 
45  parent::__construct($a_exercise, $a_submission);
46  $this->selected_wsp_obj_id = $this->request->getSelectedWspObjId();
47  }
48 
49  public function executeCommand(): void
50  {
51  $ilCtrl = $this->ctrl;
52 
53  if (!$this->submission->canView()) {
54  $this->returnToParentObject();
55  }
56 
57  $class = $ilCtrl->getNextClass($this);
58  $cmd = $ilCtrl->getCmd();
59 
60  switch ($class) {
61  default:
62  $this->{$cmd . "Object"}();
63  break;
64  }
65  }
66 
67  public static function getOverviewContent(
68  ilInfoScreenGUI $a_info,
69  ilExSubmission $a_submission
70  ): void {
71  switch ($a_submission->getAssignment()->getType()) {
73  self::getOverviewContentBlog($a_info, $a_submission);
74  break;
75 
77  self::getOverviewContentPortfolio($a_info, $a_submission);
78  break;
79  }
80  }
81 
82  protected static function getOverviewContentBlog(
83  ilInfoScreenGUI $a_info,
84  ilExSubmission $a_submission
85  ): void {
86  global $DIC;
87 
88  $lng = $DIC->language();
89  $ilCtrl = $DIC->ctrl();
90  $gui = $DIC->exercise()->internal()->gui();
91 
92  $wsp_tree = new ilWorkspaceTree($a_submission->getUserId());
93 
94  // #12939
95  if (!$wsp_tree->getRootId()) {
96  $wsp_tree->createTreeForUser($a_submission->getUserId());
97  }
98 
99  $files_str = "";
100  $buttons_str = "";
101  $valid_blog = false;
102  $selected_blog = $a_submission->getSelectedObject();
103  if ($selected_blog) {
104  $blog_id = (int) $selected_blog?->getTitle();
105  $node = $wsp_tree->getNodeData($blog_id);
106  if ($node["title"]) {
107  // #10116
108  $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", $blog_id);
109  $blog_link = $ilCtrl->getLinkTargetByClass(array("ildashboardgui", "ilpersonalworkspacegui", "ilobjbloggui"), "");
110  $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", "");
111  $files_str = '<a href="' . $blog_link . '">' .
112  $node["title"] . '</a>';
113  $valid_blog = true;
114  }
115  // remove invalid resource if no upload yet (see download below)
116  elseif (substr($selected_blog["filename"], -1) == "/") {
117  // #16887
118  $a_submission->deleteResourceObject();
119  }
120  }
121  if ($a_submission->canSubmit()) {
122  if (!$valid_blog) {
123  $button = $gui->button(
124  $lng->txt("exc_create_blog"),
125  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionObjectGUI"), "createBlog")
126  );
127  $buttons_str .= $button->render();
128  }
129  // #10462
130  $blogs = count($wsp_tree->getObjectsFromType("blog"));
131  if ((!$valid_blog && $blogs)
132  || ($valid_blog && $blogs > 1)) {
133  $link = $gui->link(
134  $lng->txt("exc_select_blog" . ($valid_blog ? "_change" : "")),
135  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionObjectGUI"), "selectBlog")
136  )->emphasised();
137  $buttons_str .= " " . $link->render();
138  }
139  }
140 
141  // todo: move this to ks somehow
142  if ($buttons_str != "") {
143  $files_str .= "<p>" . $buttons_str . "</p>";
144  }
145 
146 
147  if ($files_str) {
148  $a_info->addProperty($lng->txt("exc_blog_returned"), $files_str);
149  }
150  if ($a_submission->hasSubmitted()) {
151  $ilCtrl->setParameterByClass("ilExSubmissionFileGUI", "delivered", $selected_blog["returned_id"]);
152  $dl_link = $ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionFileGUI"), "download");
153  $ilCtrl->setParameterByClass("ilExSubmissionFileGUI", "delivered", "");
154 
155  $button = $gui->button(
156  $lng->txt("download"),
157  $dl_link
158  );
159 
160  $a_info->addProperty($lng->txt("exc_files_returned"), $button->render());
161  }
162  }
163 
164  protected static function getOverviewContentPortfolio(ilInfoScreenGUI $a_info, ilExSubmission $a_submission): void
165  {
166  global $DIC;
167 
168  $back_ref_id = $DIC->http()->wrapper()->query()->retrieve(
169  "ref_id",
170  $DIC->refinery()->kindlyTo()->int()
171  ) ?? 0;
172 
173  $request = $DIC->exercise()->internal()->gui()->request();
174  $gui = $DIC->exercise()->internal()->gui();
175 
176 
177  $lng = $DIC->language();
178  $ilCtrl = $DIC->ctrl();
179 
180  $files_str = "";
181  $buttons_str = "";
182  $valid_prtf = false;
183  $selected_prtf = $a_submission->getSelectedObject();
184  if ($selected_prtf) {
185  $portfolio_id = (int) $selected_prtf?->getTitle();
186 
187  // #11746
188  if (ilObject::_exists($portfolio_id, false, "prtf")) {
189  $portfolio = new ilObjPortfolio($portfolio_id, false);
190  if ($portfolio->getTitle()) {
191  // #10116 / #12791
192  $ilCtrl->setParameterByClass("ilobjportfoliogui", "prt_id", $portfolio_id);
193 
194  $ref_id = $request->getRefId();
195  $ilCtrl->setParameterByClass("ilobjportfoliogui", "ref_id", $ref_id);
196  $ilCtrl->setParameterByClass("ilobjportfoliogui", "exc_back_ref_id", $back_ref_id);
197 
198  $prtf_link = $ilCtrl->getLinkTargetByClass(array("ildashboardgui", "ilportfoliorepositorygui", "ilobjportfoliogui"), "view");
199  $ilCtrl->setParameterByClass("ilobjportfoliogui", "prt_id", "");
200  $ilCtrl->setParameterByClass("ilobjportfoliogui", "ref_id", "");
201 
202 
203  $files_str = '<a href="' . $prtf_link .
204  '">' . $portfolio->getTitle() . '</a>';
205  $valid_prtf = true;
206  }
207  }
208  // remove invalid resource if no upload yet (see download below)
209  elseif (substr($selected_prtf["filename"], -1) == "/") {
210  // #16887
211  $a_submission->deleteResourceObject();
212  }
213  }
214  if ($a_submission->canSubmit()) {
215  if (!$valid_prtf) {
216  $button = $gui->button(
217  $lng->txt("exc_create_portfolio"),
218  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionObjectGUI"), "createPortfolioFromAssignment")
219  );
220 
221  $buttons_str .= $button->render();
222  }
223  // #10462
224  //selectPortfolio ( remove it? )
225  $prtfs = count(ilObjPortfolio::getPortfoliosOfUser($a_submission->getUserId()));
226  if ((!$valid_prtf && $prtfs)
227  || ($valid_prtf && $prtfs > 1)) {
228  $link = $gui->link(
229  $lng->txt("exc_select_portfolio" . ($valid_prtf ? "_change" : "")),
230  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionObjectGUI"), "selectPortfolio")
231  )->emphasised();
232 
233  $buttons_str .= " " . $link->render();
234  }
235  if ($valid_prtf) {
236  $link = $gui->link(
237  $lng->txt("exc_select_portfolio_unlink"),
238  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionObjectGUI"), "askUnlinkPortfolio")
239  )->emphasised();
240  $buttons_str .= " " . $link->render();
241  }
242  }
243  // todo: move this to ks somehow
244  if ($buttons_str != "") {
245  $files_str .= "<p>" . $buttons_str . "</p>";
246  }
247  if ($files_str) {
248  $a_info->addProperty($lng->txt("exc_portfolio_returned"), $files_str);
249  }
250  if ($a_submission->hasSubmitted()) {
251  $ilCtrl->setParameterByClass("ilExSubmissionFileGUI", "delivered", $selected_prtf["returned_id"]);
252  $dl_link = $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionFileGUI"), "download");
253  $ilCtrl->setParameterByClass("ilExSubmissionFileGUI", "delivered", "");
254 
255  $button = $gui->button(
256  $lng->txt("download"),
257  $dl_link
258  );
259 
260  $a_info->addProperty($lng->txt("exc_files_returned"), $button->render());
261  }
262  }
263 
264  protected function renderResourceSelection(
265  string $a_title,
266  string $a_info,
267  string $a_cmd,
268  string $a_explorer_cmd,
269  ?array $a_items = null
270  ): void {
271  if (!$this->submission->canSubmit()) {
272  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
273  $this->returnToParentObject();
274  }
275 
276  $html = "";
277  $tpl = new ilTemplate("tpl.exc_select_resource.html", true, true, "components/ILIAS/Exercise");
278 
279  if (is_array($a_items)) {
280  $tpl->setCurrentBlock("item");
281  foreach ($a_items as $item_id => $item_title) {
282  $tpl->setVariable("ITEM_ID", $item_id);
283  $tpl->setVariable("ITEM_TITLE", $item_title);
285  }
286  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
287  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
288  $tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
289  $tpl->setVariable("CMD_SUBMIT", $a_cmd);
290  $tpl->setVariable("CMD_CANCEL", "returnToParent");
291  $html = $tpl->get();
292  } elseif ($a_explorer_cmd) {
293  $html = $this->renderWorkspaceExplorer($a_explorer_cmd);
294  }
295 
296 
297  $this->tpl->setOnScreenMessage('info', $this->lng->txt($a_info));
298 
299  $title = $this->lng->txt($a_title) . ": " . $this->assignment->getTitle();
300 
301  $f = $this->gui->ui()->factory();
302  $r = $this->gui->ui()->renderer();
303  $p = $f->panel()->standard(
304  $title,
305  $f->legacy()->content($html)
306  );
307 
308  $this->tpl->setContent($r->render($p));
309  }
310 
311 
312  //
313  // BLOG
314  //
315 
316  protected function createBlogObject(): void
317  {
318  $this->handleTabs();
319 
321  "exc_create_blog",
322  "exc_create_blog_select_info",
323  "saveBlog",
324  "createBlog"
325  );
326  }
327 
328  protected function selectBlogObject(): void
329  {
330  $this->handleTabs();
331 
333  "exc_select_blog",
334  "exc_select_blog_info",
335  "setSelectedBlog",
336  "selectBlog"
337  );
338  }
339 
344  protected function saveBlogObject(): void
345  {
346  if (!$this->submission->canSubmit()) {
347  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
348  $this->returnToParentObject();
349  }
350 
351  if ($this->selected_wsp_obj_id == 0) {
352  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
353  $this->createBlogObject();
354  return;
355  }
356 
357  $parent_node = $this->selected_wsp_obj_id;
358 
359  $blog = new ilObjBlog();
360  $blog->setTitle($this->exercise->getTitle() . " - " . $this->assignment->getTitle());
361  $blog->create();
362 
363  $tree = new ilWorkspaceTree($this->submission->getUserId()); // #15993
364 
365  $node_id = $tree->insertObject($parent_node, $blog->getId());
366 
367  $access_handler = new ilWorkspaceAccessHandler($tree);
368  $access_handler->setPermissions($parent_node, $node_id);
369 
370  $this->submission->deleteAllFiles();
371  $this->handleRemovedUpload();
372 
373  $this->submission->addResourceObject($node_id);
374 
375  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_blog_created"), true);
376  $this->ctrl->setParameterByClass(ilObjBlogGUI::class, "wsp_id", $node_id);
377  $this->ctrl->redirectByClass(
378  [ilDashboardGUI::class, ilPersonalWorkspaceGUI::class, ilObjBlogGUI::class],
379  ""
380  );
381  }
382 
387  protected function setSelectedBlogObject(): void
388  {
389  if (!$this->submission->canSubmit()) {
390  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
391  $this->returnToParentObject();
392  }
393 
394  if ($this->selected_wsp_obj_id > 0) {
395  $tree = new ilWorkspaceTree($this->submission->getUserId());
396  $node = $tree->getNodeData($this->selected_wsp_obj_id);
397  if ($node && $node["type"] == "blog") {
398  $this->submission->deleteAllFiles();
399  $this->handleRemovedUpload();
400 
401  $this->submission->addResourceObject($node["wsp_id"]);
402 
403  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_blog_selected"), true);
404  $this->ctrl->setParameter($this, "blog_id", $node["wsp_id"]);
405  $this->ctrl->redirect($this, "askDirectSubmission");
406  }
407  }
408 
409  $this->selectBlogObject();
410  }
411 
412  protected function renderWorkspaceExplorer(
413  string $a_cmd
414  ): string {
415  $exp2 = null;
416  switch ($a_cmd) {
417  case "selectBlog":
418  $exp2 = new ilWorkspaceExplorerGUI($this->submission->getUserId(), $this, $a_cmd, $this, "setSelectedBlog");
419  $exp2->setTypeWhiteList(array("blog", "wsrt", "wfld"));
420  $exp2->setSelectableTypes(array("blog"));
421  break;
422 
423  case "createBlog":
424  $exp2 = new ilWorkspaceExplorerGUI($this->submission->getUserId(), $this, $a_cmd, $this, "saveBlog");
425  $exp2->setTypeWhiteList(array("wsrt", "wfld"));
426  $exp2->setSelectableTypes(array("wsrt", "wfld"));
427  break;
428  }
429  if (!$exp2->handleCommand()) {
430  return $exp2->getHTML();
431  }
432  exit;
433  }
434 
435 
436  //
437  // PORTFOLIO
438  //
439 
440  protected function selectPortfolioObject(): void
441  {
442  $this->handleTabs();
443 
444  $items = array();
445  $portfolios = ilObjPortfolio::getPortfoliosOfUser($this->submission->getUserId());
446  foreach ($portfolios as $portfolio) {
447  $items[$portfolio["id"]] = $portfolio["title"];
448  }
449 
451  "exc_select_portfolio",
452  "exc_select_portfolio_info",
453  "setSelectedPortfolio",
454  "",
455  $items
456  );
457  }
458 
459  protected function initPortfolioTemplateForm(
460  array $a_templates
461  ): ilPropertyFormGUI {
462  $form = new ilPropertyFormGUI();
463  $form->setTitle($this->lng->txt("exc_create_portfolio") . ": " . $this->assignment->getTitle());
464  $form->setFormAction($this->ctrl->getFormAction($this, "setSelectedPortfolioTemplate"));
465 
466  $prtt = new ilRadioGroupInputGUI($this->lng->txt("obj_prtt"), "prtt");
467  $prtt->setRequired(true);
468  $prtt->addOption(new ilRadioOption($this->lng->txt("exc_create_portfolio_no_template"), -1));
469  foreach ($a_templates as $id => $title) {
470  $prtt->addOption(new ilRadioOption('"' . $title . '"', $id));
471  }
472  $prtt->setValue(-1);
473  $form->addItem($prtt);
474 
475  $form->addCommandButton("setSelectedPortfolioTemplate", $this->lng->txt("save"));
476  $form->addCommandButton("returnToParent", $this->lng->txt("cancel"));
477 
478  return $form;
479  }
480 
481  protected function createPortfolioFromAssignmentObject(): void
482  {
483  global $DIC;
484 
485  $ctrl = $DIC->ctrl();
486 
488 
489  //template id is stored in the DB with the ref_id.
490  $template_id = $this->assignment->getPortfolioTemplateId();
491  //get the object id to compare with a list of template objects.
492  $template_object_id = ilObject::_lookupObjectId($template_id);
493 
494  // select a template, if available
495  if ($templates !== [] && $template_object_id == 0) {
497  return;
498  }
499 
500  $title = $this->exercise->getTitle() . " - " . $this->assignment->getTitle();
501  $ctrl->setParameterByClass("ilObjPortfolioGUI", "exc_id", $this->exercise->getRefId());
502  $ctrl->setParameterByClass("ilObjPortfolioGUI", "ass_id", $this->assignment->getId());
503  $ctrl->setParameterByClass("ilObjPortfolioGUI", "pt", $title);
504 
505  if ($template_object_id > 0) {
506  $ctrl->setParameterByClass("ilObjPortfolioGUI", "prtt", $template_object_id);
507  }
508  $ctrl->setParameterByClass("ilobjportfoliogui", "exc_back_ref_id", $this->requested_ref_id);
509  $ctrl->redirectByClass(array("ildashboardgui", "ilPortfolioRepositoryGUI", "ilObjPortfolioGUI"), "createPortfolioFromAssignment");
510  }
511 
512  protected function createPortfolioTemplateObject(
513  ?ilPropertyFormGUI $a_form = null
514  ): void {
515  if (!$this->submission->canSubmit()) {
516  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
517  $this->returnToParentObject();
518  }
519 
521  if ($templates === []) {
522  $this->returnToParentObject();
523  }
524 
525  if ($a_form === null) {
526  $a_form = $this->initPortfolioTemplateForm($templates);
527  }
528 
529  $this->tpl->setContent($a_form->getHTML());
530  }
531 
536  protected function setSelectedPortfolioTemplateObject(): void
537  {
538  if (!$this->submission->canSubmit()) {
539  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
540  $this->returnToParentObject();
541  }
542 
544  if ($templates === []) {
545  $this->ctrl->redirect($this, "returnToParent");
546  }
547 
548  $form = $this->initPortfolioTemplateForm($templates);
549  if ($form->checkInput()) {
550  $prtt = $form->getInput("prtt");
551  if ($prtt > 0 && array_key_exists($prtt, $templates)) {
552  $title = $this->exercise->getTitle() . " - " . $this->assignment->getTitle();
553  $this->ctrl->setParameterByClass("ilObjPortfolioGUI", "exc_id", $this->exercise->getRefId());
554  $this->ctrl->setParameterByClass("ilObjPortfolioGUI", "ass_id", $this->assignment->getId());
555  $this->ctrl->setParameterByClass("ilObjPortfolioGUI", "pt", $title);
556  $this->ctrl->setParameterByClass("ilObjPortfolioGUI", "prtt", $prtt);
557  $this->ctrl->setParameterByClass("ilobjportfoliogui", "exc_back_ref_id", $this->requested_ref_id);
558  $this->ctrl->redirectByClass(array("ildashboardgui", "ilPortfolioRepositoryGUI", "ilObjPortfolioGUI"), "createPortfolioFromTemplate");
559  } else {
560  // do not use template
561  $this->createPortfolioObject();
562  return;
563  }
564  }
565 
566  $form->setValuesByPost();
567  $this->createPortfolioTemplateObject($form);
568  }
569 
574  protected function createPortfolioObject(): void
575  {
576  if (!$this->submission->canSubmit()) {
577  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
578  $this->returnToParentObject();
579  }
580 
581  $portfolio = new ilObjPortfolio();
582  $portfolio->setTitle($this->exercise->getTitle() . " - " . $this->assignment->getTitle());
583  $portfolio->create();
584 
585  $this->submission->deleteAllFiles();
586  $this->handleRemovedUpload();
587 
588  $this->submission->addResourceObject($portfolio->getId());
589 
590  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_portfolio_created"), true);
591  $this->ctrl->setParameterByClass(ilObjPortfolioGUI::class, "prt_id", $portfolio->getId());
592  $this->ctrl->redirectByClass(array("ildashboardgui", "ilPortfolioRepositoryGUI", "ilObjPortfolioGUI"), "view");
593  }
594 
599  protected function setSelectedPortfolioObject(): void
600  {
601  if (!$this->submission->canSubmit()) {
602  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
603  $this->returnToParentObject();
604  }
605 
606  $prtf_id = $this->request->getResourceObjectId();
607  if ($prtf_id > 0) {
608  $this->submission->deleteAllFiles();
609  $this->handleRemovedUpload();
610 
611  $this->submission->addResourceObject($prtf_id);
612 
613  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_portfolio_selected"), true);
614  $this->ctrl->setParameter($this, "prtf_id", $prtf_id);
615  $this->ctrl->redirect($this, "askDirectSubmission");
616  }
617 
618  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"));
619  $this->selectPortfolioObject();
620  }
621 
622  protected function askUnlinkPortfolioObject(): void
623  {
624  $tpl = $this->tpl;
625 
626  $conf = new ilConfirmationGUI();
627  $conf->setFormAction($this->ctrl->getFormAction($this, "unlinkPortfolio"));
628  $conf->setHeaderText($this->lng->txt("exc_sure_unlink_portfolio", "sure_unlink_portfolio"));
629  $conf->setConfirm($this->lng->txt("confirm"), "unlinkPortfolio");
630  $conf->setCancel($this->lng->txt("cancel"), "returnToParent");
631 
632  $submission = $this->submission->getSelectedObject();
633  $port = new ilObjPortfolio((int) $submission?->getTitle(), false);
634 
635  $conf->addItem("id[]", "", $port->getTitle(), ilUtil::getImagePath("standard/icon_prtf.svg"));
636 
637  $tpl->setContent($conf->getHTML());
638  }
639 
640  protected function unlinkPortfolioObject(): void
641  {
642  global $DIC;
643 
644  $user = $DIC->user();
645 
646  //$portfolio = $this->submission->getSelectedObject();
647  //$port_id = $portfolio["returned_id"];
648 
649  //$ilsub = new ilExSubmission($this->assignment, $user->getId());
650  $this->submission->deleteResourceObject();
651 
652  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_portfolio_unlinked_from_assignment"), true);
653 
654  $this->ctrl->redirect($this, "returnToParent");
655  }
656 
657  protected function askUnlinkBlogObject(): void
658  {
659  $tpl = $this->tpl;
660 
661  $conf = new ilConfirmationGUI();
662  $conf->setFormAction($this->ctrl->getFormAction($this, "unlinkBlog"));
663  $conf->setHeaderText($this->lng->txt("exc_sure_unlink_blog"));
664  $conf->setConfirm($this->lng->txt("confirm"), "unlinkBlog");
665  $conf->setCancel($this->lng->txt("cancel"), "returnToParent");
666 
667  $submission = $this->submission->getSelectedObject();
668  $wstree = new ilWorkspaceTree($this->submission->getUserId());
669  $object_id = $wstree->lookupObjectId((int) $submission?->getTitle());
670  $port = new ilObjBlog($object_id, false);
671 
672  $conf->addItem("id[]", "", $port->getTitle(), ilUtil::getImagePath("standard/icon_blog.svg"));
673 
674  $tpl->setContent($conf->getHTML());
675  }
676 
677  protected function unlinkBlogObject(): void
678  {
679  $this->submission->deleteResourceObject();
680 
681  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_blog_unlinked_from_assignment"), true);
682 
683  $this->ctrl->redirect($this, "returnToParent");
684  }
685 
686  //
687  // SUBMIT BLOG/PORTFOLIO
688  //
689 
690  protected function askDirectSubmissionObject(): void
691  {
692  $tpl = $this->tpl;
693 
694  if (!$this->submission->canSubmit()) {
695  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
696  $this->returnToParentObject();
697  }
698 
699  $conf = new ilConfirmationGUI();
700 
701  if ($this->request->getBlogId() > 0) {
702  $this->ctrl->setParameter($this, "blog_id", $this->request->getBlogId());
703  $txt = $this->lng->txt("exc_direct_submit_blog");
704  } else {
705  $this->ctrl->setParameter($this, "prtf_id", $this->request->getPortfolioId());
706  $txt = $this->lng->txt("exc_direct_submit_portfolio");
707  }
708  $conf->setFormAction($this->ctrl->getFormAction($this, "directSubmit"));
709 
710  $conf->setHeaderText($txt);
711  $conf->setConfirm($this->lng->txt("exc_direct_submit"), "directSubmit");
712  $conf->setCancel($this->lng->txt("exc_direct_no_submit"), "returnToParent");
713 
714  $tpl->setContent($conf->getHTML());
715  }
716 
721  protected function directSubmitObject(): void
722  {
723  if (!$this->submission->canSubmit()) {
724  $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"), true);
725  $this->returnToParentObject();
726  }
727 
728  $success = false;
729 
730  // submit current version of blog
731  if ($this->request->getBlogId() > 0) {
732  $success = $this->submitBlog($this->request->getBlogId());
733  $this->ctrl->setParameter($this, "blog_id", "");
734  }
735  // submit current version of portfolio
736  elseif ($this->request->getPortfolioId() > 0) {
737  $success = $this->submitPortfolio($this->request->getPortfolioId());
738  $this->ctrl->setParameter($this, "prtf_id", "");
739  }
740 
741  if ($success) {
742  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
743  } else {
744  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_failed"), true);
745  }
746  $this->ctrl->redirectByClass([ilExerciseHandlerGUI::class, ilObjExerciseGUI::class, ilAssignmentPresentationGUI::class, ilExSubmissionGUI::class, ilExSubmissionObjectGUI::class], "returnToParent");
747  }
748 
754  public function submitBlog(
755  int $a_blog_id
756  ): bool {
757  if (!$this->submission->canSubmit()) {
758  return false;
759  }
760 
761  $subm = $this->domain->submission($this->submission->getAssignment()->getId());
762 
763  $blog_id = $a_blog_id;
764 
765  $blog_gui = new ilObjBlogGUI($blog_id, ilObject2GUI::WORKSPACE_NODE_ID);
766  if ($blog_gui->getObject()) {
767  $export = $blog_gui->buildExportFile();
768  $file = $export->getFilePath();
769  $size = filesize($file);
770  if ($size) {
771  $this->submission->deleteAllFiles();
772 
773  $subm->addLocalFile(
774  $this->user_id,
775  $file,
776  $blog_id . ".zip"
777  );
778  $export->delete();
779 
780  // print version
781  $export = $blog_gui->buildExportFile(false, true);
782  $file = $export->getFilePath();
783  $size = filesize($file);
784  if ($size) {
785  $subm->addLocalFile(
786  $this->user_id,
787  $file,
788  $blog_id . "print.zip"
789  );
790  $export->delete();
791  }
792 
793  $this->handleNewUpload();
794  return true;
795  }
796  }
797  return false;
798  }
799 
804  public function submitPortfolio(
805  int $a_portfolio_id
806  ): bool {
807  if (!$this->submission->canSubmit()) {
808  return false;
809  }
810 
811  $prtf_id = $a_portfolio_id;
812  $subm = $this->domain->submission($this->submission->getAssignment()->getId());
813 
814  $prtf = new ilObjPortfolio($prtf_id, false);
815  if ($prtf->getTitle()) {
816  $port_gui = new ilObjPortfolioGUI($prtf_id);
817  $port_export = new PortfolioHtmlExport($port_gui);
818  $port_export->exportHtml();
819 
820  $file = $port_export->getFilePath();
821 
822  $size = filesize($file);
823  if ($size) {
824  $this->submission->deleteAllFiles();
825 
826  $subm->addLocalFile(
827  $this->user_id,
828  $file,
829  $prtf_id . ".zip"
830  );
831  $port_export->delete();
832 
833  // print version
834  $port_export = new PortfolioHtmlExport($port_gui);
835  $port_export->setPrintVersion(true);
836  $port_export->exportHtml();
837  $file = $port_export->getFilePath();
838  $size = filesize($file);
839 
840  if ($size) {
841  $subm->addLocalFile(
842  $this->user_id,
843  $file,
844  $prtf_id . "print.zip"
845  );
846  $file = $port_export->delete();
847  }
848 
849  $this->handleNewUpload();
850  return true;
851  }
852  }
853  return false;
854  }
855 
859  public static function initGUIForSubmit(
860  int $a_ass_id,
861  ?int $a_user_id = null
863  global $DIC;
864 
865  $ilUser = $DIC->user();
866 
867  if (!$a_user_id) {
868  $a_user_id = $ilUser->getId();
869  }
870 
871  $ass = new ilExAssignment($a_ass_id);
872  $sub = new ilExSubmission($ass, $a_user_id);
873  $exc_id = $ass->getExerciseId();
874 
875  // #11173 - ref_id is needed for notifications
876  $ref_ids = ilObject::_getAllReferences($exc_id);
877  $exc_ref_id = current($ref_ids);
878  $exc = new ilObjExercise($exc_ref_id, true);
879 
880  return new self($exc, $sub);
881  }
882 }
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
handleNewUpload(bool $a_no_notifications=false)
This class represents an option in a radio group.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
ILIAS Exercise InternalGUIService $gui
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
Exercise assignment.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
setTypeWhiteList(array $a_val)
Set type white list.
static _getAllReferences(int $id)
get all reference ids for object ID
Exercise submission base gui.
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static getOverviewContentPortfolio(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
static getAvailablePortfolioTemplates(string $a_permission="read")
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
submitBlog(int $a_blog_id)
Submit blog for assignment.
renderResourceSelection(string $a_title, string $a_info, string $a_cmd, string $a_explorer_cmd, ?array $a_items=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getOverviewContentBlog(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
ilObjPortfolioGUI: ilPortfolioPageGUI, ilPageObjectGUI ilObjPortfolioGUI: ilWorkspaceAccessGUI, ilCommentGUI, ilCommonActionDispatcherGUI ilObjPortfolioGUI: ilObjectContentStyleSettingsGUI, ilPortfolioExerciseGUI ilObjPortfolioGUI: ILIAS
Class ilObjExercise.
$ref_id
Definition: ltiauth.php:65
This class represents a property in a property form.
ilObjBlogGUI: ilBlogPostingGUI, ilWorkspaceAccessGUI ilObjBlogGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI ilObjBlogGUI: ilPermissionGUI, ilObjectCopyGUI, ilRepositorySearchGUI ilObjBlogGUI: ilExportGUI, ilObjectContentStyleSettingsGUI, ilBlogExerciseGUI, ilObjNotificationSettingsGUI ilObjBlogGUI: ilObjectMetaDataGUI ilObjBlogGUI: ILIAS ilObjBlogGUI: ILIAS
static initGUIForSubmit(int $a_ass_id, ?int $a_user_id=null)
static getPortfoliosOfUser(int $a_user_id)
Get portfolios of user.
global $DIC
Definition: shib_login.php:26
Explorer for selecting a personal workspace item.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static _lookupObjectId(int $ref_id)
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$txt
Definition: error.php:31
setRequired(bool $a_required)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
lookupObjectId(int $a_node_id)
Get object id for node id.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
Exercise submission //TODO: This class has many static methods related to delivered "files"...
createPortfolioTemplateObject(?ilPropertyFormGUI $a_form=null)
submitPortfolio(int $a_portfolio_id)
Submit portfolio for assignment.
createTreeForUser(int $a_user_id)
Create personal workspace tree for user.
insertObject(int $a_parent_node_id, int $a_object_id)
Add object to tree.
Object-based submissions (ends up as static file)
$r