ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjPortfolioGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
29 {
30  protected \ILIAS\Notes\GUIService $notes_gui;
34  protected \ILIAS\Skill\Service\SkillPersonalService $skill_personal_service;
35 
36  public function __construct(int $a_id = 0)
37  {
38  global $DIC;
39 
40  $this->lng = $DIC->language();
41  $this->help = $DIC["ilHelp"];
42  $this->settings = $DIC->settings();
43  $this->access = $DIC->access();
44  $this->user = $DIC->user();
45  $this->ctrl = $DIC->ctrl();
46  $this->ui = $DIC->ui();
47 
48  $this->tool_context = $DIC->globalScreen()->tool()->context();
49 
50  parent::__construct($a_id, self::PORTFOLIO_OBJECT_ID, 0);
51  $this->declaration_authorship = new ilPortfolioDeclarationOfAuthorship();
52 
53  $this->ctrl->saveParameter($this, "exc_back_ref_id");
54  $this->notes_gui = $DIC->notes()->gui();
55  $this->skill_personal_service = $DIC->skills()->personal();
56  }
57 
58  public function getType(): string
59  {
60  return "prtf";
61  }
62 
63  protected function checkPermissionBool(
64  string $perm,
65  string $cmd = "",
66  string $type = "",
67  ?int $node_id = null
68  ): bool {
69  if ($perm === "create") {
70  return true;
71  }
72  if (!$node_id) {
74  }
75  return $this->access_handler->checkAccess($perm, "", $node_id);
76  }
77 
78  public function executeCommand(): void
79  {
80  $this->checkPermission("read");
81  $this->setTitleAndDescription();
82 
83  $next_class = $this->ctrl->getNextClass($this);
84  $cmd = $this->ctrl->getCmd("view");
85 
86  // we have to init the note js handling here, might go to
87  // a better place in the future
88  /*
89  $this->notes_gui->initJavascript(
90  $this->ctrl->getLinkTargetByClass(
91  array("ilnotegui"),
92  "",
93  "",
94  true,
95  false
96  )
97  );*/
98 
99  // trigger assignment tool
100  $this->triggerAssignmentTool();
101  switch ($next_class) {
102  case "ilworkspaceaccessgui":
103  if ($this->checkPermissionBool("write")) {
104  $this->setTabs();
105  $this->tabs_gui->activateTab("share");
106 
107  $this->tpl->setPermanentLink("prtf", $this->object->getId());
108 
109  $wspacc = new ilWorkspaceAccessGUI($this->object->getId(), $this->access_handler, true);
110  $wspacc->setBlockingMessage($this->getOfflineMessage());
111  $this->ctrl->forwardCommand($wspacc);
112  }
113  break;
114 
115  case 'ilportfoliopagegui':
116  if ($this->determinePageCall()) {
117  // only in edit mode
118  $this->addLocator();
119  }
120  $this->handlePageCall($cmd);
121  break;
122 
123  case "ilcommentgui":
124  $this->preview();
125  break;
126 
127  case "ilcommonactiondispatchergui":
128  //$this->prepareOutput();
130  $this->ctrl->forwardCommand($gui);
131  break;
132 
133  /*
134  case "ilobjstylesheetgui":
135  $this->ctrl->setReturn($this, "editStyleProperties");
136  $style_gui = new ilObjStyleSheetGUI("", $this->object->getStyleSheetId(), false, false);
137  $style_gui->enableWrite(true);
138  $style_gui->omitLocator();
139  if ($cmd == "create" || $this->port_request->getNewType() == "sty") {
140  $style_gui->setCreationMode(true);
141  }
142 
143  if ($cmd == "confirmedDelete") {
144  $this->object->setStyleSheetId(0);
145  $this->object->update();
146  }
147 
148  $ret = $this->ctrl->forwardCommand($style_gui);
149 
150  if ($cmd == "save" || $cmd == "copyStyle" || $cmd == "importStyle") {
151  $style_id = $ret;
152  $this->object->setStyleSheetId($style_id);
153  $this->object->update();
154  $this->ctrl->redirectByClass("ilobjstylesheetgui", "edit");
155  }
156  break;*/
157 
158  case "ilobjectcontentstylesettingsgui":
159  $this->checkPermission("write");
160  $this->addLocator();
161  $this->setTabs();
162  $this->tabs_gui->activateTab("settings");
163  $this->setSettingsSubTabs("style");
164  $settings_gui = $this->content_style_gui
165  ->objectSettingsGUIForObjId(
166  null,
167  $this->object->getId()
168  );
169  $this->ctrl->forwardCommand($settings_gui);
170  break;
171 
172  case "ilportfolioexercisegui":
173  $this->ctrl->setReturn($this, "view");
174  $gui = new ilPortfolioExerciseGUI($this->user_id, $this->object->getId());
175  $this->ctrl->forwardCommand($gui);
176  break;
177 
178  default:
179 
180  if ($cmd !== "preview") {
181  $this->addLocator();
182  $this->setTabs();
183  }
184  $this->$cmd();
185  break;
186  }
187  }
188 
189  protected function triggerAssignmentTool(): void
190  {
191  if (!is_object($this->object) || $this->object->getId() <= 0) {
192  return;
193  }
194  $pe = new ilPortfolioExercise($this->user_id, $this->object->getId());
195  $pe_gui = new ilPortfolioExerciseGUI($this->user_id, $this->object->getId());
196  $assignments = $pe->getAssignmentsOfPortfolio();
197  if (count($assignments) > 0) {
198  $ass_ids = array_map(static function ($i) {
199  return $i["ass_id"];
200  }, $assignments);
201  $this->tool_context->current()->addAdditionalData(ilExerciseGSToolProvider::SHOW_EXC_ASSIGNMENT_INFO, true);
202  $this->tool_context->current()->addAdditionalData(ilExerciseGSToolProvider::EXC_ASS_IDS, $ass_ids);
203  $this->tool_context->current()->addAdditionalData(ilExerciseGSToolProvider::EXC_ASS_BUTTONS, $pe_gui->getActionButtons());
204  }
205  }
206 
207  protected function setTabs(): void
208  {
209  $ilHelp = $this->help;
210 
211  $ilHelp->setScreenIdComponent("prtf");
212 
213  if ($this->checkPermissionBool("write")) {
214  $this->tabs_gui->addTab(
215  "pages",
216  $this->lng->txt("content"),
217  $this->ctrl->getLinkTarget($this, "view")
218  );
219 
220  $this->tabs_gui->addTab(
221  "settings",
222  $this->lng->txt("settings"),
223  $this->ctrl->getLinkTarget($this, "edit")
224  );
225 
226  $this->tabs_gui->addNonTabbedLink(
227  "preview",
228  $this->lng->txt("preview"),
229  $this->ctrl->getLinkTarget($this, "preview")
230  );
231 
232  $this->lng->loadLanguageModule("wsp");
233  $this->tabs_gui->addTab(
234  "share",
235  $this->lng->txt("wsp_permissions"),
236  $this->ctrl->getLinkTargetByClass("ilworkspaceaccessgui", "share")
237  );
238  }
239  }
240 
241  protected function addLocator(): void
242  {
243  if (!$this->creation_mode) {
244  $this->ctrl->setParameter($this, "prt_id", $this->object->getId());
245  }
246 
247  $this->addLocatorItems();
248 
249  $this->tpl->setLocator();
250  }
251 
252  protected function setTitleAndDescription(): void
253  {
254  // parent::setTitleAndDescription();
255 
256  $title = $this->lng->txt("portfolio");
257  if ($this->object) {
258  $title .= ": " . $this->object->getTitle();
259  }
260  $this->tpl->setTitle($title);
261  $this->tpl->setTitleIcon(
262  ilUtil::getImagePath("standard/icon_prtf.svg"),
263  $this->lng->txt("portfolio")
264  );
265 
266  if ($this->object &&
267  !$this->object->isOnline()) {
268  $this->tpl->setAlertProperties(array(
269  array("alert" => true,
270  "property" => $this->lng->txt("status"),
271  "value" => $this->lng->txt("offline"))
272  ));
273  }
274  }
275 
276 
277  //
278  // CREATE/EDIT
279  //
280 
281  public function create(): void
282  {
283  $tpl = $this->tpl;
285 
286  $new_type = $this->port_request->getNewType();
287 
288  // add new object to custom parent container
289  $this->ctrl->saveParameter($this, "crtptrefid");
290  // use forced callback after object creation
291  $this->ctrl->saveParameter($this, "crtcb");
292 
293  if (!$this->checkPermissionBool("create", "", $new_type)) {
294  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
295  } else {
296  $this->lng->loadLanguageModule($new_type);
297  $this->ctrl->setParameter($this, "new_type", $new_type);
298 
299  $forms = $this->initCreationForms($new_type);
300 
301  // copy form validation error: do not show other creation forms
302  if ($this->port_request->getCopyFormProcess() && isset($forms[self::CFORM_CLONE])) {
303  $forms = array(self::CFORM_CLONE => $forms[self::CFORM_CLONE]);
304  }
305  $tpl->setContent($this->getCreationFormsHTML($forms));
306  }
307  }
308 
309  public function createFromTemplate(): void
310  {
311  $tpl = $this->tpl;
313 
314  $new_type = $this->port_request->getNewType();
315 
316  // add new object to custom parent container
317  $this->ctrl->saveParameter($this, "crtptrefid");
318  // use forced callback after object creation
319  $this->ctrl->saveParameter($this, "crtcb");
320 
321  if (!$this->checkPermissionBool("create", "", $new_type)) {
322  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
323  } else {
324  $this->lng->loadLanguageModule($new_type);
325  $this->ctrl->setParameter($this, "new_type", $new_type);
326  $form = $this->initCreateFromTemplateForm();
327  $tpl->setContent($form->getHTML());
328  }
329  }
330 
331  protected function getCreateInfoMessage(): string
332  {
333  global $DIC;
334 
335  $ui = $DIC->ui();
336  $ilSetting = $DIC->settings();
337 
338  $message = "";
339  // page type: blog
340  if (!$ilSetting->get('disable_wsp_blogs')) {
341  $options = array();
342  $tree = new ilWorkspaceTree($this->user_id);
343  $root = $tree->readRootId();
344  if ($root) {
345  $root = $tree->getNodeData($root);
346  foreach ($tree->getSubTree($root) as $node) {
347  if ($node["type"] == "blog") {
348  $options[$node["obj_id"]] = $node["title"];
349  }
350  }
351  asort($options);
352  }
353  if (!count($options)) {
354  // #18147
355  $this->lng->loadLanguageModule('pd');
356  $url = $this->ctrl->getLinkTargetByClass("ilDashboardGUI", "jumpToWorkspace");
357  $text = $this->lng->txt("mm_personal_and_shared_r");
358 
359  $text = sprintf($this->lng->txt("prtf_no_blogs_info"), $text);
360 
361  $mbox = $ui->factory()->messageBox()->info($text)
362  ->withLinks([$ui->factory()->link()->standard(
363  $this->lng->txt("mm_personal_and_shared_r"),
364  $url
365  )]);
366 
367  $message = $ui->renderer()->render($mbox);
368  }
369  }
370  return $message;
371  }
372 
373 
374  protected function initCreationForms(string $new_type): array
375  {
376  return array(self::CFORM_NEW => $this->initCreateForm($new_type));
377  }
378 
379  protected function initCreateForm(string $new_type): ilPropertyFormGUI
380  {
382 
383  $this->ctrl->setParameter($this, "new_type", $this->getType());
384 
385  $form = new ilPropertyFormGUI();
386  $form->setFormAction($this->ctrl->getFormAction($this));
387 
388  // title
389  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
390  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
391  $ti->setMaxLength(ilObject::TITLE_LENGTH);
392  $ti->setRequired(true);
393  $form->addItem($ti);
394 
395  $form->setTitle($this->lng->txt("prtf_create_portfolio"));
396  $form->addCommandButton("save", $this->lng->txt("create"));
397  $form->addCommandButton("toRepository", $this->lng->txt("cancel"));
398 
399  return $form;
400  }
401 
403  {
405 
406  $this->ctrl->setParameter($this, "new_type", $this->getType());
407 
408  $form = new ilPropertyFormGUI();
409  $form->setFormAction($this->ctrl->getFormAction($this));
410 
411  // title
412  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
413  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
414  $ti->setMaxLength(ilObject::TITLE_LENGTH);
415  $ti->setRequired(true);
416  $form->addItem($ti);
417 
418  // portfolio templates
420  if (count($templates)) {
421  $tmpl = new ilSelectInputGUI($this->lng->txt("obj_prtt"), "prtt");
422  $tmpl->setRequired(true);
423  $tmpl->setOptions(array("" => $this->lng->txt("please_select")) + $templates);
424  $form->addItem($tmpl);
425 
426  // incoming from repository
427  $template_id = $this->port_request->getPortfolioTemplateId();
428  if ($template_id > 0) {
429  $tmpl->setValue($template_id);
430  }
431  }
432 
433  $form->setTitle($this->lng->txt("prtf_add_portfolio_from_template"));
434  $form->addCommandButton("saveFromTemplate", $this->lng->txt("create"));
435  $form->addCommandButton("toRepository", $this->lng->txt("cancel"));
436 
437  return $form;
438  }
439 
440  public function save(): void
441  {
442  $form = $this->initCreateForm("prtf");
443  parent::save();
444  }
445 
446  public function saveFromTemplate(): void
447  {
448  $form = $this->initCreateFromTemplateForm();
449  // trigger portfolio template "import" process
450  if ($form->checkInput()) {
452  $form->getInput("title"),
453  $this->port_request->getPortfolioTemplate()
454  );
455  return;
456  } else {
457  $form->setValuesByPost();
458  $this->tpl->setContent($form->getHTML());
459  }
460  }
461 
462  protected function afterSave(ilObject $new_object): void
463  {
464  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_created"), true);
465  $this->ctrl->setParameter($this, "prt_id", $new_object->getId());
466  $this->ctrl->redirect($this, "view");
467  }
468 
469  protected function toRepository(): void
470  {
471  $ilAccess = $this->access;
472 
473  // return to exercise (portfolio assignment)
474  $exc_ref_id = $this->port_request->getExerciseRefId();
475  if ($exc_ref_id &&
476  $ilAccess->checkAccess("read", "", $exc_ref_id)) {
477  ilUtil::redirect(ilLink::_getLink($exc_ref_id, "exc"));
478  }
479 
480  $this->ctrl->redirectByClass("ilportfoliorepositorygui", "show");
481  }
482 
483  protected function initEditForm(): ilPropertyFormGUI
484  {
485  $form = new ilPropertyFormGUI();
486  $form->setFormAction($this->ctrl->getFormAction($this));
487 
488  // title
489  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
490  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
491  $ti->setMaxLength(ilObject::TITLE_LENGTH);
492  $ti->setRequired(true);
493  $ti->setValue($this->object->getTitle());
494  $form->addItem($ti);
495 
496  // :TODO: online
497  $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
498  $online->setChecked($this->object->isOnline());
499  $form->addItem($online);
500 
501  $this->initEditCustomForm($form);
502 
503  $form->setTitle($this->lng->txt("prtf_edit_portfolio"));
504  $form->addCommandButton("update", $this->lng->txt("save"));
505  $form->addCommandButton("view", $this->lng->txt("cancel"));
506 
507  return $form;
508  }
509 
510  protected function getEditFormCustomValues(array &$a_values): void
511  {
512  $a_values["online"] = $this->object->isOnline();
513 
514  parent::getEditFormCustomValues($a_values);
515  }
516 
517  protected function updateCustom(ilPropertyFormGUI $form): void
518  {
519  $this->object->setOnline($form->getInput("online"));
520 
521  // if portfolio is not online, it cannot be default
522  if (!$form->getInput("online")) {
523  ilObjPortfolio::setUserDefault($this->user_id, 0);
524  }
525 
526  parent::updateCustom($form);
527  }
528 
529 
530  //
531  // PAGES
532  //
533 
537  protected function getPageInstance(
538  ?int $a_page_id = null,
539  ?int $a_portfolio_id = null
540  ): ilPortfolioPage {
541  // #11531
542  if (!$a_portfolio_id && $this->object) {
543  $a_portfolio_id = $this->object->getId();
544  }
545  $page = new ilPortfolioPage((int) $a_page_id);
546  $page->setPortfolioId($a_portfolio_id);
547  return $page;
548  }
549 
553  protected function getPageGUIInstance(
554  int $a_page_id
555  ): ilPortfolioPageGUI {
556  $page_gui = new ilPortfolioPageGUI(
557  $this->object->getId(),
558  $a_page_id,
559  0,
560  $this->object->hasPublicComments()
561  );
562  $page_gui->setStyleId($this->content_style_domain->getEffectiveStyleId());
563  $page_gui->setAdditional($this->getAdditional());
564  return $page_gui;
565  }
566 
567  public function getPageGUIClassName(): string
568  {
569  return "ilportfoliopagegui";
570  }
571 
572  protected function initCopyPageFormOptions(ilPropertyFormGUI $a_form): void
573  {
574  $a_tgt = new ilRadioGroupInputGUI($this->lng->txt("target"), "target");
575  $a_tgt->setRequired(true);
576  $a_form->addItem($a_tgt);
577 
578  $old = new ilRadioOption($this->lng->txt("prtf_existing_portfolio"), "old");
579  $a_tgt->addOption($old);
580 
581  $options = array();
582  $all = ilObjPortfolio::getPortfoliosOfUser($this->user_id);
583  foreach ($all as $item) {
584  $options[$item["id"]] = $item["title"];
585  }
586  $prtf = new ilSelectInputGUI($this->lng->txt("portfolio"), "prtf");
587  $prtf->setRequired(true);
588  $prtf->setOptions($options);
589  $old->addSubItem($prtf);
590 
591  $new = new ilRadioOption($this->lng->txt("prtf_new_portfolio"), "new");
592  $a_tgt->addOption($new);
593 
594  $tf = new ilTextInputGUI($this->lng->txt("title"), "title");
595  $tf->setMaxLength(128);
596  $tf->setSize(40);
597  $tf->setRequired(true);
598  $new->addSubItem($tf);
599  }
600 
601 
602  //
603  // BLOG
604  //
605 
606  protected function initBlogForm(): ilPropertyFormGUI
607  {
608  $form = new ilPropertyFormGUI();
609  $form->setFormAction($this->ctrl->getFormAction($this));
610 
611  $options = array();
612  $tree = new ilWorkspaceTree($this->user_id);
613  $root = $tree->readRootId();
614  if ($root) {
615  $root = $tree->getNodeData($root);
616  foreach ($tree->getSubTree($root, true, ["blog"]) as $node) {
617  $options[$node["obj_id"]] = $node["title"];
618  }
619  asort($options);
620  }
621 
622  // add blog
623  $radg = new ilRadioGroupInputGUI($this->lng->txt("obj_blog"), "creation_mode");
624  $radg->setInfo($this->lng->txt(""));
625  $radg->setValue("new");
626  $radg->setInfo($this->lng->txt(""));
627 
628  $op1 = new ilRadioOption($this->lng->txt("prtf_add_new_blog"), "new", $this->lng->txt("prtf_add_new_blog_info"));
629  $radg->addOption($op1);
630  $form->addItem($radg);
631 
632  // Blog title
633  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
634  $ti->setRequired(true);
635  $op1->addSubItem($ti);
636 
637 
638  if (count($options)) {
639  $op2 = new ilRadioOption($this->lng->txt("prtf_add_existing_blog"), "existing");
640  $radg->addOption($op2);
641 
642  $obj = new ilSelectInputGUI($this->lng->txt("obj_blog"), "blog");
643  $obj->setOptions($options);
644  $op2->addSubItem($obj);
645  }
646 
647  $form->setTitle($this->lng->txt("prtf_add_blog") . ": " .
648  $this->object->getTitle());
649  $form->addCommandButton("saveBlog", $this->lng->txt("save"));
650  $form->addCommandButton("view", $this->lng->txt("cancel"));
651 
652  return $form;
653  }
654 
658  protected function saveBlog(): void
659  {
660  global $DIC;
661 
662  $ilUser = $DIC->user();
663 
664  $form = $this->initBlogForm();
665  if ($form->checkInput() && $this->checkPermissionBool("write")) {
666  if ($form->getInput("creation_mode") == "existing") {
667  $page = $this->getPageInstance();
668  $page->setType(ilPortfolioPage::TYPE_BLOG);
669  $page->setTitle($form->getInput("blog"));
670  } else {
671  $blog = new ilObjBlog();
672  $blog->setTitle($form->getInput("title"));
673  $blog->create();
674 
675  $tree = new ilWorkspaceTree($ilUser->getId());
676 
677  // @todo: see also e.g. ilExSubmissionObjectGUI->getOverviewContentBlog, this needs refactoring, consumer should not
678  // be responsibel to handle this
679  if (!$tree->getRootId()) {
680  $tree->createTreeForUser($ilUser->getId());
681  }
682 
684  $node_id = $tree->insertObject($tree->readRootId(), $blog->getId());
685  $access_handler->setPermissions($tree->readRootId(), $node_id);
686 
687  $page = $this->getPageInstance();
688  $page->setType(ilPortfolioPage::TYPE_BLOG);
689  $page->setTitle($blog->getId());
690  }
691  $page->create(false);
692 
693  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_blog_page_created"), true);
694  $this->ctrl->redirect($this, "view");
695  }
696 
697  $this->tabs_gui->clearTargets();
698  $this->tabs_gui->setBackTarget(
699  $this->lng->txt("back"),
700  $this->ctrl->getLinkTarget($this, "view")
701  );
702 
703  $form->setValuesByPost();
704  $this->tpl->setContent($form->getHTML());
705  }
706 
707 
708  //
709  // CREATE FROM TEMPLATE
710  //
711 
712  protected function createPortfolioFromTemplate(
713  ilPropertyFormGUI $a_form = null
714  ): void {
715  $title = $this->port_request->getPortfolioTitle();
716  $prtt_id = $this->port_request->getPortfolioTemplate();
717 
718  // valid template?
720  if (!count($templates) || !in_array($prtt_id, $templates)) {
721  $this->toRepository();
722  }
723  unset($templates);
724 
725  $this->ctrl->setParameter($this, "prtt", $prtt_id);
726 
727  if (!$a_form) {
728  $a_form = $this->initCreatePortfolioFromTemplateForm($prtt_id, $title);
729  }
730  if ($a_form) {
731  $this->tpl->setContent($a_form->getHTML());
732  } else {
734  }
735  }
736 
738  int $a_prtt_id,
739  string $a_title
740  ): ?ilPropertyFormGUI {
742  $ilUser = $this->user;
743 
744  $blog_options = [];
745 
746  $exc_id = $this->port_request->getExerciseRefId();
747  $ass_id = $this->port_request->getExcAssId();
748  if ($exc_id > 0) {
749  $this->ctrl->setParameter($this, "exc_id", $exc_id);
750  $this->ctrl->setParameter($this, "ass_id", $ass_id);
751  }
752 
753  $form = new ilPropertyFormGUI();
754  $form->setFormAction($this->ctrl->getFormAction($this));
755 
756  $tmpl = new ilNonEditableValueGUI($this->lng->txt("obj_prtt"));
757  $tmpl->setValue(ilObject::_lookupTitle($a_prtt_id));
758  $form->addItem($tmpl);
759 
760  $title = new ilNonEditableValueGUI($this->lng->txt("title"), "pt");
761  $title->setValue($a_title);
762  $form->addItem($title);
763 
764  // gather user blogs
765  if (!$ilSetting->get('disable_wsp_blogs')) {
766  $blog_options = array();
767  $tree = new ilWorkspaceTree($this->user_id);
768  $root = $tree->readRootId();
769  if ($root) {
770  $root = $tree->getNodeData($root);
771  foreach ($tree->getSubTree($root, true, ["blog"]) as $node) {
772  $blog_options[$node["obj_id"]] = $node["title"];
773  }
774  asort($blog_options);
775  }
776  }
777 
778  $has_form_content = false;
779 
780  $pskills = array_keys($this->skill_personal_service->getSelectedUserSkills($ilUser->getId()));
781  $skill_ids = array();
782 
783  foreach (ilPortfolioTemplatePage::getAllPortfolioPages($a_prtt_id) as $page) {
784  switch ($page["type"]) {
786  // skills
787  $source_page = new ilPortfolioTemplatePage($page["id"]);
788  $source_page->buildDom(true);
789  $skill_ids = $this->getSkillsToPortfolioAssignment($pskills, $skill_ids, $source_page);
790 
791  if (count($skill_ids)) {
792  $has_form_content = true;
793  }
794  break;
795 
797  if (!$ilSetting->get('disable_wsp_blogs')) {
798  $has_form_content = true;
799 
800  $field_id = "blog_" . $page["id"];
801 
802  $blog = new ilRadioGroupInputGUI($this->lng->txt("obj_blog") . ": " .
803  $page["title"], $field_id);
804  $blog->setRequired(true);
805  $blog->setValue("blog_create");
806  $form->addItem($blog);
807 
808  $new_blog = new ilRadioOption($this->lng->txt("prtf_template_import_blog_create"), "blog_create");
809  $blog->addOption($new_blog);
810 
811  $title = new ilTextInputGUI($this->lng->txt("title"), $field_id . "_create_title");
812  $title->setRequired(true);
813  $new_blog->addSubItem($title);
814 
815  if (count($blog_options)) {
816  $reuse_blog = new ilRadioOption($this->lng->txt("prtf_template_import_blog_reuse"), "blog_resuse");
817  $blog->addOption($reuse_blog);
818 
819  $obj = new ilSelectInputGUI($this->lng->txt("obj_blog"), $field_id . "_reuse_blog");
820  $obj->setRequired(true);
821  $obj->setOptions(array("" => $this->lng->txt("please_select")) + $blog_options);
822  $reuse_blog->addSubItem($obj);
823  }
824 
825  $blog->addOption(new ilRadioOption($this->lng->txt("prtf_template_import_blog_ignore"), "blog_ignore"));
826  }
827  break;
828  }
829  }
830 
831  if ($skill_ids) {
832  $skills = new ilCheckboxGroupInputGUI($this->lng->txt("skills"), "skill_ids");
833  $skills->setInfo($this->lng->txt("prtf_template_import_new_skills"));
834  $skills->setValue($skill_ids);
835  foreach ($skill_ids as $skill_id) {
836  $skills->addOption(new ilCheckboxOption(ilSkillTreeNode::_lookupTitle($skill_id), $skill_id));
837  }
838  $form->addItem($skills);
839  }
840  // no dialog needed, go ahead
841  if (!$has_form_content) {
842  return null;
843  }
844 
845  $form->setTitle($this->lng->txt("prtf_creation_mode") . ": " . $this->lng->txt("prtf_creation_mode_template"));
846  $form->addCommandButton("createPortfolioFromTemplateProcess", $this->lng->txt("continue"));
847  $form->addCommandButton("toRepository", $this->lng->txt("cancel"));
848 
849  return $form;
850  }
851 
853  bool $a_process_form = true
854  ): void {
856 
857  $title = $this->port_request->getPortfolioTitle();
858  $prtt_id = $this->port_request->getPortfolioTemplate();
859 
860  // valid template?
862  if (!count($templates) || !in_array($prtt_id, $templates)) {
863  $this->toRepository();
864  }
865  unset($templates);
866 
867  // build page recipe (aka import form values)
868  $recipe = null;
869  if ($a_process_form) {
870  $this->ctrl->setParameter($this, "prtt", $prtt_id);
871 
872  $form = $this->initCreatePortfolioFromTemplateForm($prtt_id, $title);
873  if ($form->checkInput()) {
874  foreach (ilPortfolioTemplatePage::getAllPortfolioPages($prtt_id) as $page) {
875  if (($page["type"] == ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE) && !$ilSetting->get('disable_wsp_blogs')) {
876  $field_id = "blog_" . $page["id"];
877  switch ($form->getInput($field_id)) {
878  case "blog_create":
879  $recipe[$page["id"]] = array("blog",
880  "create",
881  trim($form->getInput($field_id . "_create_title"))
882  );
883  break;
884 
885  case "blog_resuse":
886  $recipe[$page["id"]] = array("blog",
887  "reuse",
888  (int) $form->getInput($field_id . "_reuse_blog")
889  );
890  break;
891 
892  case "blog_ignore":
893  $recipe[$page["id"]] = array("blog", "ignore");
894  break;
895  }
896  }
897  }
898 
899  $recipe["skills"] = (array) $form->getInput("skill_ids");
900  } else {
901  $form->setValuesByPost();
902  $this->createPortfolioFromTemplate($form);
903  return;
904  }
905  }
906 
907  $source = new ilObjPortfolioTemplate($prtt_id, false);
908 
909  // create portfolio
910  $target = new ilObjPortfolio();
911  $target->setTitle($title);
912  $target->create();
913  $target_id = $target->getId();
914 
915  ilObjPortfolioTemplate::clonePagesAndSettings($source, $target, $recipe);
916 
917  // link portfolio to exercise assignment
918  $this->linkPortfolioToAssignment($target_id);
919 
920  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_created_from_template"), true);
921  $this->ctrl->setParameter($this, "prt_id", $target_id);
922  $this->ctrl->redirect($this, "preview");
923  }
924 
928  protected function createFromTemplateDirect(
929  string $title = "",
930  int $prtt_id = 0
931  ): void {
932  if ($prtt_id === 0) {
933  $prtt_id = $this->port_request->getPortfolioTemplateId();
934  }
935  if ($title === "") {
936  $title = ilObject::_lookupTitle($prtt_id);
937  }
938 
939  // valid template?
941  if (!count($templates) || !in_array($prtt_id, $templates)) {
942  $this->toRepository();
943  }
944  unset($templates);
945 
946  $source = new ilObjPortfolioTemplate($prtt_id, false);
947 
948  // create portfolio
949  $target = new ilObjPortfolio();
950  $target->setTitle($title);
951  $target->create();
952  $target_id = $target->getId();
953 
954  ilObjPortfolioTemplate::clonePagesAndSettings($source, $target, null, true);
955 
956  // link portfolio to exercise assignment
957  //$this->linkPortfolioToAssignment($target_id);
958 
959  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_created_from_template"), true);
960  $this->ctrl->setParameter($this, "prt_id", $target_id);
961  $this->ctrl->redirect($this, "preview");
962  }
963 
964 
965  public static function _goto(string $a_target): void
966  {
967  global $DIC;
968 
969  $ctrl = $DIC->ctrl();
970 
971  $id = explode("_", $a_target);
972 
973  $ctrl->setParameterByClass("ilobjportfoliogui", "prt_id", $id[0]);
974  if (count($id) === 2) {
975  $ctrl->setParameterByClass("ilobjportfoliogui", "user_page", $id[1]);
976  }
977  $ctrl->redirectByClass(["ilsharedresourceGUI", "ilobjportfoliogui"], "preview");
978  }
979 
980  public function createPortfolioFromAssignment(): void
981  {
982  $ilUser = $this->user;
984 
985  $recipe = [];
986 
987  $title = $this->port_request->getPortfolioTitle();
988  $prtt_id = $this->port_request->getPortfolioTemplate();
989 
990  // get assignment template
991  $ass_template_id = 0;
992  $ass_id = $this->port_request->getExcAssId();
993  if ($ass_id > 0) {
994  $ass = new ilExAssignment($ass_id);
995  $ass_template_id = ilObject::_lookupObjectId($ass->getPortfolioTemplateId());
996  }
997 
998  if ($prtt_id > 0) {
1000  if (!count($templates) || !in_array($prtt_id, $templates)) {
1001  if ($ass_template_id !== $prtt_id) {
1002  $this->toRepository();
1003  }
1004  }
1005 
1006  //skills manipulation
1007  $pskills = array_keys($this->skill_personal_service->getSelectedUserSkills($ilUser->getId()));
1008  $skill_ids = array();
1009 
1010  $recipe = array();
1011  foreach (ilPortfolioTemplatePage::getAllPortfolioPages($prtt_id) as $page) {
1012  switch ($page["type"]) {
1014  if (!$ilSetting->get('disable_wsp_blogs')) {
1015  $recipe[$page["id"]] = array("blog", "create", $page['title']);
1016  }
1017  break;
1019  $source_page = new ilPortfolioTemplatePage($page["id"]);
1020  $source_page->buildDom(true);
1021  $skill_ids = $this->getSkillsToPortfolioAssignment($pskills, $skill_ids, $source_page);
1022  break;
1023  }
1024  }
1025 
1026  if ($skill_ids) {
1027  $recipe["skills"] = $skill_ids;
1028  }
1029  }
1030 
1031  // create portfolio
1032  $target = new ilObjPortfolio();
1033  $target->setTitle($title);
1034  $target->create();
1035  $target_id = $target->getId();
1036 
1037  if ($prtt_id) {
1038  $source = new ilObjPortfolioTemplate($prtt_id, false);
1039  ilObjPortfolioTemplate::clonePagesAndSettings($source, $target, $recipe);
1040  }
1041 
1042  // link portfolio to exercise assignment
1043  $this->linkPortfolioToAssignment($target_id);
1044 
1045  $this->ctrl->setParameter($this, "prt_id", $target_id);
1046  if ($prtt_id) {
1047  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_created_from_template"), true);
1048  $this->ctrl->redirect($this, "preview");
1049  } else {
1050  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_created"), true);
1051  $this->ctrl->redirect($this, "view");
1052  }
1053  }
1054 
1055  public function linkPortfolioToAssignment(int $a_target_id): void
1056  {
1057  $ilAccess = $this->access;
1058  $ilUser = $this->user;
1059 
1060  $exc_ref_id = $this->port_request->getExerciseRefId();
1061  $ass_id = $this->port_request->getExcAssId();
1062 
1063  if ($exc_ref_id &&
1064  $ass_id &&
1065  $ilAccess->checkAccess("read", "", $exc_ref_id)) {
1066  $exc = new ilObjExercise($exc_ref_id);
1067  $ass = new ilExAssignment($ass_id);
1068  if ($ass->getExerciseId() === $exc->getId() &&
1069  $ass->getType() === ilExAssignment::TYPE_PORTFOLIO) {
1070  // #16205
1071  $sub = new ilExSubmission($ass, $ilUser->getId());
1072  $sub->addResourceObject($a_target_id);
1073  }
1074  }
1075  }
1076 
1078  array $a_pskills,
1079  array $a_skill_ids,
1080  ilPortfolioTemplatePage $a_source_page
1081  ): array {
1082  $dom = $a_source_page->getDomDoc();
1083  $xpath = new DOMXPath($dom);
1084  $nodes = $xpath->query("//PageContent/Skills");
1085  foreach ($nodes as $node) {
1086  $skill_id = $node->getAttribute("Id");
1087  if (!in_array($skill_id, $a_pskills)) {
1088  $a_skill_ids[] = $skill_id;
1089  }
1090  }
1091  unset($nodes, $xpath, $dom);
1092 
1093  return $a_skill_ids;
1094  }
1095 
1099  public function printSelection(): void
1100  {
1101  $view = $this->getPrintView();
1102  $view->sendForm();
1103  }
1104 
1109  public function showPrintView(
1110  ): void {
1111  $printview = $this->getPrintView();
1112  $printview->sendPrintView();
1113  }
1114 
1118  protected function getOfflineMessage(): string
1119  {
1120  $ui = $this->ui;
1121  $lng = $this->lng;
1122  $ctrl = $this->ctrl;
1123 
1124  if (!$this->object->isOnline()) {
1125  $f = $ui->factory();
1126  $renderer = $ui->renderer();
1127 
1128  $buttons = [$f->button()->standard(
1129  $lng->txt("prtf_set_online"),
1130  $ctrl->getLinkTarget($this, "setOnlineAndShare")
1131  )];
1132 
1133  return $renderer->render($f->messageBox()->info($lng->txt("prtf_no_offline_share_info"))
1134  ->withButtons($buttons));
1135  }
1136  return "";
1137  }
1138 
1142  protected function setOnlineAndShare(): void
1143  {
1144  $ilCtrl = $this->ctrl;
1145  $lng = $this->lng;
1146 
1147  if (ilObjPortfolio::_lookupOwner($this->object->getId()) === $this->user_id) {
1148  $this->object->setOnline(true);
1149  $this->object->update();
1150  $this->tpl->setOnScreenMessage('success', $lng->txt("prtf_has_been_set_online"), true);
1151  }
1152  $ilCtrl->redirectByClass("ilworkspaceaccessgui", "");
1153  }
1154 }
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
createPortfolioFromTemplate(ilPropertyFormGUI $a_form=null)
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
initCopyPageFormOptions(ilPropertyFormGUI $a_form)
Exercise assignment.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
updateCustom(ilPropertyFormGUI $form)
ilErrorHandling $error
getSkillsToPortfolioAssignment(array $a_pskills, array $a_skill_ids, ilPortfolioTemplatePage $a_source_page)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Portfolio InternalGUIService $gui
This class represents a selection list property in a property form.
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...
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
const TITLE_LENGTH
ilPortfolioDeclarationOfAuthorship $declaration_authorship
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
createPortfolioFromTemplateProcess(bool $a_process_form=true)
getCreationFormsHTML(array $forms)
Get HTML for creation forms (accordion)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
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...
getOfflineMessage()
Get offline message for sharing tab.
static _lookupOwner(int $obj_id)
Lookup owner user ID for object ID.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDomDoc()
Get dom doc (DOMDocument)
setOptions(array $a_options)
getEditFormCustomValues(array &$a_values)
setStyleId(int $a_styleid)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
Class ilPortfolioExerciseGUI.
static getAvailablePortfolioTemplates(string $a_permission="read")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ilErr
Definition: raiseError.php:17
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initCreationForms(string $new_type)
linkPortfolioToAssignment(int $a_target_id)
global $DIC
Definition: feed.php:28
saveBlog()
Create new portfolio blog page.
static _goto(string $a_target)
static clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, ?array $a_recipe=null, bool $copy_all=false)
Build template from portfolio and vice versa.
Portfolio view gui class.
Class ilObjExercise.
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
addResourceObject(string $a_wsp_id, string $a_text=null)
Add personal resource or repository object (ref_id) to assigment.
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
setScreenIdComponent(string $a_comp)
static getPortfoliosOfUser(int $a_user_id)
Get portfolios of user.
Class ilObjBlog.
ILIAS Skill Service SkillPersonalService $skill_personal_service
createFromTemplateDirect(string $title="", int $prtt_id=0)
Create portfolio template direct.
ilGlobalTemplateInterface $tpl
static _lookupObjectId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url
Definition: ltiregstart.php:35
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setUserDefault(int $a_user_id, ?int $a_portfolio_id=null)
Set the user default portfolio.
getPageInstance(?int $a_page_id=null, ?int $a_portfolio_id=null)
Get portfolio template page instance.
setRequired(bool $a_required)
afterSave(ilObject $new_object)
Portfolio view gui base class.
ACL access handler GUI.
static redirect(string $a_script)
setOnlineAndShare()
Set online and switch to share screen.
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
initCreateForm(string $new_type)
global $ilSetting
Definition: privfeed.php:18
ContextServices $tool_context
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:32
initEditCustomForm(ilPropertyFormGUI $a_form)
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilWorkspaceAccessHandler $ws_access
ilSetting $settings
ILIAS Notes GUIService $notes_gui
getPageGUIInstance(int $a_page_id)
Get portfolio template page gui instance.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
ilAccessHandler $access
initCreatePortfolioFromTemplateForm(int $a_prtt_id, string $a_title)