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