ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjPortfolioBaseGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
27 abstract class ilObjPortfolioBaseGUI extends ilObject2GUI
28 {
29  protected \ILIAS\Notes\Service $notes;
30  protected \ILIAS\Portfolio\InternalGUIService $gui;
32  protected ilHelpGUI $help;
33  protected int $user_id = 0;
34  protected array $additional = array();
35  protected array $perma_link = [];
36  protected int $page_id = 0;
37  protected string $page_mode; // preview|edit
38  protected int $requested_ppage;
39  protected int $requested_user_page;
40  protected string $requested_back_url = "";
41  protected \ILIAS\DI\UIServices $ui;
42  protected \ILIAS\HTTP\Services $http;
43  protected \ILIAS\Style\Content\GUIService $content_style_gui;
44  protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
45 
46  public function __construct(
47  int $a_id = 0,
48  int $a_id_type = self::REPOSITORY_NODE_ID,
49  int $a_parent_node_id = 0
50  ) {
51  global $DIC;
52 
53  $this->user = $DIC->user();
54  $this->locator = $DIC["ilLocator"];
55  $this->toolbar = $DIC->toolbar();
56  $this->settings = $DIC->settings();
57  $this->tree = $DIC->repositoryTree();
58  $this->help = $DIC["ilHelp"];
59  $this->tpl = $DIC["tpl"];
60  $ilUser = $DIC->user();
61  $this->ui = $DIC->ui();
62 
63  $this->port_request = $DIC->portfolio()
64  ->internal()
65  ->gui()
66  ->standardRequest();
67 
68  $this->http = $DIC->http();
69 
70  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
71 
72  $this->user_id = $ilUser->getId();
73 
74  $this->lng->loadLanguageModule("prtf");
75  $this->lng->loadLanguageModule("user");
76  $this->lng->loadLanguageModule("obj");
77 
78  $this->requested_ppage = $this->port_request->getPortfolioPageId();
79  $this->requested_user_page = $this->port_request->getUserPage();
80 
81  // temp sanitization, should be done smarter in the future
82  $back = str_replace("&amp;", ":::", $this->port_request->getBackUrl());
83  $back = preg_replace(
84  "/[^a-zA-Z0-9_\.\?=:\s]/",
85  "",
86  $back
87  );
88  $this->requested_back_url = str_replace(":::", "&amp;", $back);
89 
90  $this->ctrl->setParameterByClass("ilobjportfoliogui", "back_url", rawurlencode($this->requested_back_url));
91  $cs = $DIC->contentStyle();
92  $this->content_style_gui = $cs->gui();
93  if ($this->object) {
94  $this->content_style_domain = $cs->domain()->styleForObjId($this->object->getId());
95  }
96  $this->gui = $DIC->portfolio()->internal()->gui();
97  $this->notes = $DIC->notes();
98  }
99 
100  protected function addLocatorItems(): void
101  {
102  $ilLocator = $this->locator;
103 
104  if ($this->object) {
105  $ilLocator->addItem(
106  strip_tags($this->object->getTitle()),
107  $this->ctrl->getLinkTarget($this, "view")
108  );
109  }
110 
111  if ($this->page_id > 0) {
112  $page = $this->getPageInstance($this->page_id);
113  $title = $page->getTitle();
114  if ($page->getType() === ilPortfolioPage::TYPE_BLOG) {
115  $title = ilObject::_lookupTitle($title);
116  }
117  $this->ctrl->setParameterByClass($this->getPageGUIClassName(), "ppage", $this->page_id);
118  $ilLocator->addItem(
119  $title,
120  $this->ctrl->getLinkTargetByClass($this->getPageGUIClassName(), "edit")
121  );
122  }
123  }
124 
125  protected function determinePageCall(): bool
126  {
127  // edit
128  if ($this->requested_ppage > 0) {
129  if (!$this->checkPermissionBool("write")) {
130  $this->ctrl->redirect($this, "view");
131  }
132 
133  $this->page_id = $this->requested_ppage;
134  $this->page_mode = "edit";
135  $this->ctrl->setParameter($this, "ppage", $this->page_id);
136  return true;
137  }
138 
139  // preview
140  $this->page_id = $this->requested_user_page;
141  $this->page_mode = "preview";
142  $this->ctrl->setParameter($this, "user_page", $this->page_id);
143  return false;
144  }
145 
146  protected function handlePageCall(string $a_cmd): void
147  {
148  if (!$this->page_id) {
149  $this->ctrl->redirect($this, "view");
150  }
151 
152  $page_gui = $this->getPageGUIInstance($this->page_id);
153 
154  $this->tabs_gui->clearTargets();
155  $this->tabs_gui->setBackTarget(
156  $this->lng->txt("back"),
157  $this->ctrl->getLinkTarget($this, "view")
158  );
159 
160  // needed for editor
161  $page_gui->setStyleId($this->content_style_domain->getEffectiveStyleId());
162 
163  $ret = $this->ctrl->forwardCommand($page_gui);
164  if ($ret != "" && $ret !== true) {
165  // preview (fullscreen)
166  if ($this->page_mode === "preview") {
167  // embedded call which did not generate any output (e.g. calendar month navigation)
169  // suppress (portfolio) notes for blog postings
170  $this->preview(false, $ret, ($a_cmd !== "previewEmbedded"));
171  } else {
172  $this->preview(false);
173  }
174  }
175  // edit
176  else {
177  $this->setContentStyleSheet();
178  if (is_string($ret)) {
179  $this->tpl->setContent($ret);
180  }
181  }
182  }
183  }
184 
188  public function setAdditional(array $a_additional): void
189  {
190  $this->additional = $a_additional;
191  }
192 
193  public function getAdditional(): array
194  {
195  return $this->additional;
196  }
197 
201  public function setPermaLink(
202  int $a_obj_id,
203  string $a_type
204  ): void {
205  $this->perma_link = array("obj_id" => $a_obj_id, "type" => $a_type);
206  }
207 
208 
209  //
210  // CREATE/EDIT
211  //
212 
213  protected function setSettingsSubTabs(string $a_active): void
214  {
215  // #17455
216  $this->lng->loadLanguageModule($this->getType());
217 
218  // general properties
219  $this->tabs_gui->addSubTab(
220  "properties",
221  $this->lng->txt($this->getType() . "_properties"),
222  $this->ctrl->getLinkTarget($this, 'edit')
223  );
224 
225  $this->tabs_gui->addSubTab(
226  "style",
227  $this->lng->txt("obj_sty"),
228  $this->ctrl->getLinkTargetByClass("ilobjectcontentstylesettingsgui", "")
229  );
230 
231  $this->tabs_gui->activateSubTab($a_active);
232  }
233 
234  protected function initEditCustomForm(ilPropertyFormGUI $a_form): void
235  {
236  $this->setSettingsSubTabs("properties");
237 
238 
239  // profile picture
240  $ppic = new ilCheckboxInputGUI($this->lng->txt("prtf_profile_picture"), "ppic");
241  $a_form->addItem($ppic);
242 
243  $prfa_set = new ilSetting("prfa");
244  if ($prfa_set->get("banner")) {
245  $dimensions = " (" . $prfa_set->get("banner_width") . "x" .
246  $prfa_set->get("banner_height") . ")";
247 
248  $img = new ilImageFileInputGUI($this->lng->txt("prtf_banner") . $dimensions, "banner");
249  $a_form->addItem($img);
250 
251  // show existing file
252  $file = $this->object->getImageFullPath(true);
253  if ($file) {
254  $img->setImage(ilWACSignedPath::signFile($file));
255  }
256  }
257 
258  $section = new ilFormSectionHeaderGUI();
259  $section->setTitle($this->lng->txt('obj_features'));
260  $a_form->addItem($section);
261 
262  // comments
263  $comments = new ilCheckboxInputGUI($this->lng->txt("prtf_public_comments"), "comments");
264  $a_form->addItem($comments);
265 
266  /* #15000
267  $bg_color = new ilColorPickerInputGUI($this->lng->txt("prtf_background_color"), "bg_color");
268  $a_form->addItem($bg_color);
269 
270  $font_color = new ilColorPickerInputGUI($this->lng->txt("prtf_font_color"), "font_color");
271  $a_form->addItem($font_color);
272  */
273  }
274 
275  protected function getEditFormCustomValues(array &$a_values): void
276  {
277  $a_values["comments"] = $this->object->hasPublicComments();
278  $a_values["ppic"] = $this->object->hasProfilePicture();
279  /*
280  $a_values["bg_color"] = $this->object->getBackgroundColor();
281  $a_values["font_color"] = $this->object->getFontColor();
282  */
283  }
284 
285  protected function updateCustom(ilPropertyFormGUI $form): void
286  {
287  $this->object->setPublicComments($form->getInput("comments"));
288  $this->object->setProfilePicture($form->getInput("ppic"));
289  /*
290  $this->object->setBackgroundColor($a_form->getInput("bg_color"));
291  $this->object->setFontcolor($a_form->getInput("font_color"));
292  */
293 
294  $prfa_set = new ilSetting("prfa");
295 
296  if (isset($_FILES["banner"]) && $_FILES["banner"]["tmp_name"]) {
297  $this->object->uploadImage($_FILES["banner"]);
298  } elseif ($prfa_set->get('banner') && $form->getItemByPostVar("banner")->getDeletionFlag()) {
299  $this->object->deleteImage();
300  }
301  }
302 
303 
304  //
305  // PAGES
306  //
307 
308  abstract protected function getPageInstance(
309  ?int $a_page_id = null,
310  ?int $a_portfolio_id = null
311  ): ilPortfolioPage;
312 
313  abstract protected function getPageGUIInstance(int $a_page_id): ilPortfolioPageGUI;
314 
315  abstract public function getPageGUIClassName(): string;
316 
320  public function view(): void
321  {
322  $ilToolbar = $this->toolbar;
324  $lng = $this->lng;
325 
326  if (!$this->checkPermissionBool("write")) {
327  $this->ctrl->redirect($this, "infoScreen");
328  }
329 
330  $this->tabs_gui->activateTab("pages");
331 
333 
334  $this->gui->button(
335  $this->lng->txt("prtf_add_page"),
336  $this->ctrl->getLinkTarget($this, "addPage")
337  )->toToolbar(true);
338 
339  if (!$ilSetting->get('disable_wsp_blogs')) {
340  $this->gui->button(
341  $this->lng->txt("prtf_add_blog"),
342  $this->ctrl->getLinkTarget($this, "addBlog")
343  )->toToolbar(true);
344  }
345 
346 
347  // #16571
348  $modal_html = "";
349  if ($this->getType() === "prtf" && count($pages) > 0) {
350  $ilToolbar->addSeparator();
351 
352  $ui = $this->ui;
353 
354  if ($this->object->isCommentsExportPossible()) {
355  $this->lng->loadLanguageModule("note");
356  $comment_export_helper = new \ILIAS\Notes\Export\ExportHelperGUI();
357  $comment_modal = $comment_export_helper->getCommentIncludeModalDialog(
358  $this->lng->txt("export_html"),
359  $this->lng->txt("note_html_export_include_comments"),
360  $this->ctrl->getLinkTarget($this, "export"),
361  $this->ctrl->getLinkTarget($this, "exportWithComments")
362  );
363  $button = $ui->factory()->button()->standard($this->lng->txt("export_html"), '')
364  ->withOnClick($comment_modal->getShowSignal());
365  $ilToolbar->addComponent($button);
366  $modal_html = $ui->renderer()->render($comment_modal);
367  } else {
368  $this->gui->button(
369  $this->lng->txt("export_html"),
370  $this->ctrl->getLinkTarget($this, "export")
371  )->toToolbar();
372  }
373 
374  $print_view = $this->getPrintView();
375  $modal_elements = $print_view->getModalElements($this->ctrl->getLinkTarget(
376  $this,
377  "printSelection"
378  ));
379  $modal_html .= $ui->renderer()->render($modal_elements->modal);
380  $ilToolbar->addComponent($modal_elements->button);
381  }
382 
383  $table = new ilPortfolioPageTableGUI($this, "view");
384 
385 
386  $this->tpl->setContent($table->getHTML() . $modal_html);
387  }
388 
389  public function getPrintView(): \ILIAS\Export\PrintProcessGUI
390  {
391  $obj_ids = $this->port_request->getObjIds();
392  $signature = $this->port_request->getSignature();
393  $declaration = $this->port_request->getIncludeDeclaration();
394  if (count($obj_ids) === 0) {
395  $obj_ids = null;
396  }
398  $port = $this->object;
400  $this->lng,
401  $this->ctrl,
402  $port,
403  $signature,
404  $obj_ids,
405  $declaration
406  );
407  $provider = $provider->withDeclarationOfAuthorship(
409  $this->user
410  );
411  return new \ILIAS\Export\PrintProcessGUI(
412  $provider,
413  $this->http,
414  $this->ui,
415  $this->lng
416  );
417  }
418 
422  protected function addPage(): void
423  {
424  $ilHelp = $this->help;
425 
426  $this->tabs_gui->clearTargets();
427  $this->tabs_gui->setBackTarget(
428  $this->lng->txt("back"),
429  $this->ctrl->getLinkTarget($this, "view")
430  );
431 
432  $ilHelp->setScreenIdComponent("prtf");
433  $ilHelp->setScreenId("add_page");
434 
435 
436  $form = $this->initPageForm("create");
437  $this->tpl->setContent($form->getHTML());
438  }
439 
443  public function initPageForm(string $a_mode = "create"): ilPropertyFormGUI
444  {
445  $form = new ilPropertyFormGUI();
446  $form->setFormAction($this->ctrl->getFormAction($this));
447 
448  // title
449  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
450  $ti->setMaxLength(200);
451  $ti->setRequired(true);
452  $form->addItem($ti);
453 
454  // save and cancel commands
455  if ($a_mode === "create") {
457  if ($templates) {
458  $use_template = new ilRadioGroupInputGUI($this->lng->txt("prtf_use_page_layout"), "tmpl");
459  $use_template->setRequired(true);
460  $form->addItem($use_template);
461 
462  $opt = new ilRadioOption($this->lng->txt("none"), 0);
463  $use_template->addOption($opt);
464 
465  foreach ($templates as $templ) {
466  $templ->readObject();
467 
468  $opt = new ilRadioOption($templ->getTitle() . $templ->getPreview(), $templ->getId());
469  $use_template->addOption($opt);
470  }
471  }
472 
473  $form->setTitle($this->lng->txt("prtf_add_page") . ": " .
474  $this->object->getTitle());
475  $form->addCommandButton("savePage", $this->lng->txt("save"));
476  $form->addCommandButton("view", $this->lng->txt("cancel"));
477  }
478 
479  return $form;
480  }
481 
485  public function savePage(): void
486  {
487  $form = $this->initPageForm("create");
488  if ($form->checkInput() && $this->checkPermissionBool("write")) {
489  $page = $this->getPageInstance();
490  $page->setType(ilPortfolioPage::TYPE_PAGE);
491  $page->setTitle($form->getInput("title"));
492 
493  // use template as basis
494  $layout_id = $form->getInput("tmpl");
495  if ($layout_id) {
496  $layout_obj = new ilPageLayout($layout_id);
497  $page->setXMLContent($layout_obj->copyXmlContent(false));
498  }
499 
500  $page->create();
501 
502  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_page_created"), true);
503  $this->ctrl->redirect($this, "view");
504  }
505 
506  $this->tabs_gui->clearTargets();
507  $this->tabs_gui->setBackTarget(
508  $this->lng->txt("back"),
509  $this->ctrl->getLinkTarget($this, "view")
510  );
511 
512  $form->setValuesByPost();
513  $this->tpl->setContent($form->getHTML());
514  }
515 
519  protected function addBlog(): void
520  {
521  $ilHelp = $this->help;
522 
523  $this->tabs_gui->clearTargets();
524  $this->tabs_gui->setBackTarget(
525  $this->lng->txt("back"),
526  $this->ctrl->getLinkTarget($this, "view")
527  );
528 
529  $ilHelp->setScreenIdComponent("prtf");
530  $ilHelp->setScreenId("add_blog");
531 
532  $form = $this->initBlogForm();
533  $this->tpl->setContent($form->getHTML());
534  }
535 
536  abstract protected function initBlogForm(): ilPropertyFormGUI;
537 
538  abstract protected function saveBlog(): void;
539 
543  public function savePortfolioPagesOrdering(): void
544  {
545  if (!$this->checkPermissionBool("write")) {
546  return;
547  }
548 
549  $title_changes = array();
550 
551  $order = $this->port_request->getOrder();
552  $titles = $this->port_request->getTitles();
553  if (count($order) > 0) {
554  foreach ($order as $k => $v) {
555  $page = $this->getPageInstance(ilUtil::stripSlashes($k));
556  if ($titles[$k] ?? "") {
557  $new_title = $titles[$k] ?? "";
558  if ($page->getTitle() != $new_title) {
559  $title_changes[$page->getId()] = array("old" => $page->getTitle(), "new" => $new_title);
560  $page->setTitle($new_title);
561  }
562  }
563  $page->setOrderNr(ilUtil::stripSlashes($v));
564  $page->update();
565  }
566  ilPortfolioPage::fixOrdering($this->object->getId());
567  }
568 
569  $this->object->fixLinksOnTitleChange($title_changes);
570 
571  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
572  $this->ctrl->redirect($this, "view");
573  }
574 
575  public function confirmPortfolioPageDeletion(): void
576  {
577  $prtf_pages = $this->port_request->getPortfolioPageIds();
578 
579  if (count($prtf_pages) === 0) {
580  $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
581  $this->ctrl->redirect($this, "view");
582  } else {
583  $this->tabs_gui->activateTab("pages");
584 
585  $cgui = new ilConfirmationGUI();
586  $cgui->setFormAction($this->ctrl->getFormAction($this));
587  $cgui->setHeaderText($this->lng->txt("prtf_sure_delete_portfolio_pages"));
588  $cgui->setCancel($this->lng->txt("cancel"), "view");
589  $cgui->setConfirm($this->lng->txt("delete"), "deletePortfolioPages");
590 
591  foreach ($prtf_pages as $id) {
592  $page = $this->getPageInstance($id);
593  if ($page->getPortfolioId() !== $this->object->getId()) {
594  continue;
595  }
596 
597  $title = $page->getTitle();
598  if ($page->getType() === ilPortfolioPage::TYPE_BLOG) {
599  $title = $this->lng->txt("obj_blog") . ": " . ilObject::_lookupTitle((int) $title);
600  }
601  $cgui->addItem("prtf_pages[]", $id, $title);
602  }
603 
604  $this->tpl->setContent($cgui->getHTML());
605  }
606  }
607 
608  public function deletePortfolioPages(): void
609  {
610  if (!$this->checkPermissionBool("write")) {
611  return;
612  }
613 
614  $page_ids = $this->port_request->getPortfolioPageIds();
615  foreach ($page_ids as $id) {
616  $page = $this->getPageInstance($id);
617  $page->delete();
618  }
619  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_page_deleted"), true);
620  $this->ctrl->redirect($this, "view");
621  }
622 
626  public function preview(
627  bool $a_return = false,
628  $a_content = false,
629  bool $a_show_notes = true
630  ): string {
632  $ilUser = $this->user;
633  $portfolio_id = $this->object->getId();
634  $user_id = $this->object->getOwner();
635 
636  $content = "";
637 
638  $this->tabs_gui->clearTargets();
639 
640  $pages = ilPortfolioPage::getAllPortfolioPages($portfolio_id);
641  $current_page = $this->getCurrentPage();
642 
643  // #13788 - keep page after login
644  if ($this->user_id === ANONYMOUS_USER_ID &&
645  $this->getType() === "prtf") {
646  $this->tpl->setLoginTargetPar("prtf_" . $this->object->getId() . "_" . $current_page);
647  }
648 
649  $back_caption = "";
650 
651  // public profile
652  if ($this->requested_back_url != "") {
654  } elseif (strtolower($this->port_request->getBaseClass()) !== "ilpublicuserprofilegui" &&
655  $this->user_id && $this->user_id !== ANONYMOUS_USER_ID) {
656  if (!$this->checkPermissionBool("write")) {
657  // shared
658  if ($this->getType() === "prtf") {
659  $this->ctrl->setParameterByClass("ilportfoliorepositorygui", "shr_id", $this->object->getOwner());
660  $back = $this->ctrl->getLinkTargetByClass(array("ildashboardgui", "ilportfoliorepositorygui"), "showOther");
661  $this->ctrl->setParameterByClass("ilportfoliorepositorygui", "shr_id", "");
662  }
663  // listgui / parent container
664  else {
665  // #12819
666  $tree = $this->tree;
667  $parent_id = $tree->getParentId($this->node_id);
669  }
670  }
671  // owner
672  else {
673  $back = $this->ctrl->getLinkTarget($this, "view");
674  if ($this->getType() === "prtf") {
675  $back_caption = $this->lng->txt("prtf_back_to_portfolio_owner");
676  } else {
677  // #19316
678  $this->lng->loadLanguageModule("prtt");
679  $back_caption = $this->lng->txt("prtt_edit");
680  }
681  }
682  }
683 
684  // render tabs
685  $current_blog = null;
686  if (count($pages) > 1) {
687  foreach ($pages as $p) {
688  if ($p["type"] == ilPortfolioPage::TYPE_BLOG) {
689  // needed for blog comments (see below)
690  if ($p["id"] == $current_page) {
691  $current_blog = (int) $p["title"];
692  }
693  $p["title"] = ilObjBlog::_lookupTitle($p["title"]);
694  }
695 
696  $this->ctrl->setParameter($this, "user_page", $p["id"]);
697  $this->tabs_gui->addTab(
698  "user_page_" . $p["id"],
699  $p["title"],
700  $this->ctrl->getLinkTarget($this, "preview")
701  );
702  }
703 
704  $this->tabs_gui->activateTab("user_page_" . $current_page);
705  }
706 
707  $this->ctrl->setParameter($this, "user_page", $current_page);
708 
709 
710  // blog posting comments are handled within the blog
711  // note: notes must be handled before the $this->ctrl->getHTML below, since
712  // this messes up the path since ILIAS 8
713  $notes = "";
714  if ($a_show_notes && $this->object->hasPublicComments() && !$current_blog && $current_page) {
715  $comment_gui = $this->getCommentGUI();
716  $next_class = $this->ctrl->getNextClass($this);
717  if ($next_class === "ilcommentgui") {
718  $notes = $this->ctrl->forwardCommand($comment_gui);
719  } else {
720  $notes = $comment_gui->getListHTML();
721  }
722  }
723 
724  if (!$a_content) {
725  // #18291
726  if ($current_page) {
727  // get current page content
728  $page_gui = $this->getPageGUIInstance($current_page);
729  $page_gui->setEmbedded(true);
730 
731  $content = $this->ctrl->getHTML($page_gui);
732  }
733  } else {
734  $content = $a_content;
735  }
736 
737  if ($a_return && $this->checkPermissionBool("write")) {
738  return $content;
739  }
740 
741 
742  if (count($this->perma_link) === 0) {
743  if ($this->getType() === "prtf") {
744  $this->tpl->setPermanentLink($this->getType(), $this->object->getId(), "_" . $current_page);
745  } else {
746  $this->tpl->setPermanentLink($this->getType(), $this->object->getRefId());
747  }
748  } else {
749  $this->tpl->setPermanentLink($this->perma_link["type"] ?? "", $this->perma_link["obj_id"] ?? 0);
750  }
751 
752  // #18208 - see ilPortfolioTemplatePageGUI::getPageContentUserId()
753  if ($this->getType() === "prtt" && !$this->checkPermissionBool("write")) {
754  $user_id = $ilUser->getId();
755  }
756 
758  $obj = $this->object;
759  self::renderFullscreenHeader($obj, $this->tpl, $user_id);
760 
761  // #13564
762  $this->ctrl->setParameter($this, "user_page", "");
763  //$this->tpl->setTitleUrl($this->ctrl->getLinkTarget($this, "preview"));
764  $this->ctrl->setParameter($this, "user_page", $this->page_id);
765 
766  // blog pages do their own (page) style handling
767  if (!$current_blog) {
768  $content = '<div id="ilCOPageContent" class="ilc_page_cont_PageContainer">' .
769  '<div class="ilc_page_Page">' .
770  $content .
771  '</div></div>';
772 
773  $this->setContentStyleSheet($this->tpl);
774  }
775 
776  $this->showEditButton($current_page);
777 
778  // #10717
779  $this->tpl->setContent($content .
780  '<div class="ilClearFloat">' . $notes . '</div>');
781  return "";
782  }
783 
784  protected function getCurrentPage(): ?int
785  {
786  $pages = ilPortfolioPage::getAllPortfolioPages($this->object->getId());
787  $current_page = (int) $this->requested_user_page;
788 
789  // validate current page
790  if ($pages && $current_page) {
791  $found = false;
792  foreach ($pages as $page) {
793  if ((int) $page["id"] === $current_page) {
794  $found = true;
795  break;
796  }
797  }
798  if (!$found) {
799  $current_page = null;
800  }
801  }
802 
803  // display first page of portfolio if none given
804  if (!$current_page && $pages) {
805  $current_page = $pages;
806  $current_page = array_shift($current_page);
807  $current_page = (int) $current_page["id"];
808  }
809  return $current_page;
810  }
811 
812  protected function getCommentGUI(): ilCommentGUI
813  {
814  $gui = $this->notes->gui()->getCommentsGUI(
815  $this->object->getId(),
816  $this->getCurrentPage(),
817  "pfpg"
818  );
819  $gui->setRepositoryMode(false);
820  $gui->enablePublicNotesDeletion(($this->user_id === $this->object->getOwner()) &&
821  $this->settings->get("comments_del_tutor", '1'));
822  return $gui;
823  }
824 
825  protected function showEditButton(
826  int $page_id
827  ): void {
828  $page_class = ($this->getType() === "prtt")
829  ? "ilPortfolioTemplatePageGUI"
830  : "ilportfoliopagegui";
831  $button = null;
832  if ($this->checkPermissionBool("write") &&
833  ($page_id === 0 || ilPortfolioPage::lookupType($page_id) === ilPortfolioPage::TYPE_PAGE)) {
834  if ($this->getType() === "prtt") {
835  $button = $this->ui->factory()->button()->standard(
836  $this->lng->txt("prtt_edit"),
837  $this->ctrl->getLinkTargetByClass(["ilobjportfoliotemplategui"], "view")
838  );
839  } else {
840  $button = $this->ui->factory()->button()->standard(
841  $this->lng->txt("prtf_edit_portfolio"),
842  $this->ctrl->getLinkTargetByClass(["ilobjportfoliogui"], "view")
843  );
844  }
845  $this->toolbar->addComponent($button);
846  $button = null;
847  }
848  if ($page_id > 0 && ilPortfolioPage::lookupType($page_id) === ilPortfolioPage::TYPE_PAGE) {
849  $this->ctrl->setParameterByClass($page_class, "ppage", $page_id);
850  $button = $this->ui->factory()->button()->standard(
851  $this->lng->txt("edit_page"),
852  $this->ctrl->getLinkTargetByClass($page_class, "edit")
853  );
854  if ($this->checkPermissionBool("write")) {
855  $this->toolbar->addComponent($button);
856  }
857  $button = null;
858  }
859  if ($button && $this->checkPermissionBool("write")) {
860  $this->tpl->setHeaderActionMenu($this->ui->renderer()->render($button));
861  }
862  }
863 
867  public static function renderFullscreenHeader(
868  ilObjPortfolioBase $a_portfolio,
870  int $a_user_id,
871  bool $a_export = false
872  ): void {
873  global $DIC;
874 
875  $ilUser = $DIC->user();
876 
877  if (!$a_export) {
879  $a_portfolio->getType(),
880  ($a_portfolio->getType() === "prtt")
881  ? $a_portfolio->getRefId()
882  : $a_portfolio->getId(),
883  $a_portfolio->getId(),
884  $ilUser->getId()
885  );
886  }
887 
888  $name = ilObjUser::_lookupName($a_user_id);
889  $name = $name["lastname"] . ", " . (($t = $name["title"]) ? $t . " " : "") . $name["firstname"];
890 
891  // show banner?
892  $banner = $banner_width = $banner_height = false;
893  $prfa_set = new ilSetting("prfa");
894  if ($prfa_set->get("banner")) {
895  $banner = ilWACSignedPath::signFile($a_portfolio->getImageFullPath());
896  $banner_width = $prfa_set->get("banner_width");
897  $banner_height = $prfa_set->get("banner_height");
898  if ($a_export) {
899  $banner = basename($banner);
900  }
901  }
902 
903  // profile picture
904  $ppic = null;
905  if ($a_portfolio->hasProfilePicture()) {
906  $ppic = ilObjUser::_getPersonalPicturePath($a_user_id, "xsmall", true, true);
907  if ($a_export) {
908  $ppic = basename($ppic);
909  }
910  }
911 
912  $a_tpl->resetHeaderBlock(false);
913  // $a_tpl->setBackgroundColor($a_portfolio->getBackgroundColor());
914  // @todo fix this
915  $a_tpl->setBanner($banner);
916  $a_tpl->setTitleIcon((string) $ppic);
917  $a_tpl->setTitle($a_portfolio->getTitle());
918  // $a_tpl->setTitleColor($a_portfolio->getFontColor());
919  $a_tpl->setDescription($name);
920 
921  // to get rid of locator in portfolio template preview
922  $a_tpl->setVariable("LOCATOR", "");
923 
924  // :TODO: obsolete?
925  // $a_tpl->setBodyClass("std ilExternal ilPortfolio");
926  }
927 
928  public function export(
929  bool $a_with_comments = false
930  ): void {
931  $port_export = new \ILIAS\Portfolio\Export\PortfolioHtmlExport($this);
932  $port_export->includeComments($a_with_comments);
933  $zip = $port_export->exportHtml();
934 
935  ilFileDelivery::deliverFileLegacy($zip, $this->object->getTitle() . ".zip", '', false, true);
936  }
937 
938  public function exportWithComments(): void
939  {
940  $this->export(true);
941  }
942 
946  public function copyPageForm(
947  ilPropertyFormGUI $a_form = null
948  ): void {
949  $prtf_pages = $this->port_request->getPortfolioPageIds();
950 
951  if (count($prtf_pages) === 0) {
952  $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
953  $this->ctrl->redirect($this, "view");
954  } else {
955  $this->tabs_gui->activateTab("pages");
956 
957  if (!$a_form) {
958  $a_form = $this->initCopyPageForm();
959  }
960 
961  foreach ($prtf_pages as $page_id) {
962  $item = new ilHiddenInputGUI("prtf_pages[]");
963  $item->setValue($page_id);
964  $a_form->addItem($item);
965  }
966 
967  $this->tpl->setContent($a_form->getHTML());
968  }
969  }
970 
971  public function copyPage(): void
972  {
973  $form = $this->initCopyPageForm();
974  if ($form->checkInput()) {
975  // existing
976  if ($form->getInput("target") === "old") {
977  $portfolio_id = $form->getInput("prtf");
978  }
979  // new
980  else {
981  $portfolio = new ilObjPortfolio();
982  $portfolio->setTitle($form->getInput("title"));
983  $portfolio->create();
984  $portfolio_id = $portfolio->getId();
985  }
986 
987  // copy page(s)
988  $page_ids = $this->port_request->getPortfolioPageIds();
989  foreach ($page_ids as $page_id) {
990  $source = $this->getPageInstance($page_id);
991  $target = $this->getPageInstance(null, $portfolio_id);
992  $target->setXMLContent($source->copyXmlContent(true)); // copy mobs
993  $target->setType($source->getType());
994  $target->setTitle($source->getTitle());
995  $target->create();
996  }
997 
998  $this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_pages_copied"), true);
999  $this->ctrl->redirect($this, "view");
1000  }
1001 
1002  $form->setValuesByPost();
1003  $this->copyPageForm($form);
1004  }
1005 
1006  abstract protected function initCopyPageFormOptions(ilPropertyFormGUI $a_form): void;
1007 
1009  {
1010  $form = new ilPropertyFormGUI();
1011  $form->setFormAction($this->ctrl->getFormAction($this));
1012  $form->setTitle($this->lng->txt("prtf_copy_page"));
1013 
1014  $this->initCopyPageFormOptions($form);
1015 
1016  $form->addCommandButton("copyPage", $this->lng->txt("save"));
1017  $form->addCommandButton("view", $this->lng->txt("cancel"));
1018 
1019  return $form;
1020  }
1021 
1022 
1026 
1027  public function setContentStyleSheet(
1028  ilGlobalTemplateInterface $a_tpl = null
1029  ): void {
1030  $tpl = $this->tpl;
1031 
1032  if ($a_tpl) {
1033  $ctpl = $a_tpl;
1034  } else {
1035  $ctpl = $tpl;
1036  }
1037 
1038  $this->content_style_gui->addCss(
1039  $ctpl,
1040  $this->object->getRefId(),
1041  $this->object->getId()
1042  );
1043  }
1044 }
updateCustom(ilPropertyFormGUI $form)
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...
getPageInstance(?int $a_page_id=null, ?int $a_portfolio_id=null)
ILIAS Portfolio InternalGUIService $gui
const ANONYMOUS_USER_ID
Definition: constants.php:27
New implementation of ilObjectGUI.
view()
Show list of portfolio pages.
getItemByPostVar(string $a_post_var)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Help GUI class.
setPermaLink(int $a_obj_id, string $a_type)
Set custom perma link (used in public profile?)
resetHeaderBlock(bool $a_reset_header_action=true)
Reset all header properties: title, icon, description, alerts, action menu.
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static renderFullscreenHeader(ilObjPortfolioBase $a_portfolio, ilGlobalTemplateInterface $a_tpl, int $a_user_id, bool $a_export=false)
Render banner, user name.
addPage()
Show portfolio page creation form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
savePage()
Create new portfolio page.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static lookupType($a_page_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
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-...
export(bool $a_with_comments=false)
copyPageForm(ilPropertyFormGUI $a_form=null)
Select target portfolio for page(s) copy.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPageGUIInstance(int $a_page_id)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static activeLayouts(int $a_module=0)
Get active layouts.
global $DIC
Definition: feed.php:28
ilToolbarGUI $toolbar
savePortfolioPagesOrdering()
Save ordering of portfolio pages.
$provider
Definition: ltitoken.php:83
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static _lookupTitle(int $obj_id)
getType()
Functions that must be overwritten.
setRepositoryMode(bool $a_value)
setScreenIdComponent(string $a_comp)
ILIAS Style Content GUIService $content_style_gui
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
initCopyPageFormOptions(ilPropertyFormGUI $a_form)
ilGlobalTemplateInterface $tpl
$comments
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getParentId(int $a_node_id)
get parent id of given node
setAdditional(array $a_additional)
Set Additonal Information (used in public profile?)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
addBlog()
Show portfolio blog page creation form.
setRequired(bool $a_required)
Portfolio view gui base class.
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents an image file property in a property form.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
global $ilSetting
Definition: privfeed.php:18
setDescription(string $a_descr)
Sets description below title in standard template.
Comment GUI.
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
static signFile(string $path_to_file)
ilLocatorGUI $locator
ILIAS Style Content Object ObjectFacade $content_style_domain
static fixOrdering(int $a_portfolio_id)
initEditCustomForm(ilPropertyFormGUI $a_form)
getImageFullPath(bool $a_as_thumb=false)
Get banner image incl.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilSetting $settings
setContentStyleSheet(ilGlobalTemplateInterface $a_tpl=null)
initPageForm(string $a_mode="create")
Init portfolio page form.
setTitle(string $a_title)
addCss(string $a_css_file, string $media="screen")
Add a css file that should be included in the header.