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