ILIAS  release_8 Revision v8.24
class.ilWikiPageTemplateGUI.php
Go to the documentation of this file.
1<?php
2
20
27{
29 protected ilObjWiki $wiki;
31 protected ilLanguage $lng;
33 protected ilCtrl $ctrl;
35
36 public function __construct(
37 ilObjWikiGUI $a_wiki_gui
38 ) {
39 global $DIC;
40
41 $ilCtrl = $DIC->ctrl();
42 $tpl = $DIC["tpl"];
43 $ilToolbar = $DIC->toolbar();
44 $lng = $DIC->language();
45
46 $this->wiki_gui = $a_wiki_gui;
48 $wiki = $this->wiki_gui->getObject();
49 $this->wiki = $wiki;
50 $this->ctrl = $ilCtrl;
51 $this->tpl = $tpl;
52 $this->lng = $lng;
53 $this->toolbar = $ilToolbar;
54
55 $this->request = $DIC
56 ->wiki()
57 ->internal()
58 ->gui()
59 ->editing()
60 ->request();
61 }
62
63 public function executeCommand(): void
64 {
65 $nc = $this->ctrl->getNextClass();
66
67 switch ($nc) {
68 default:
69 $cmd = $this->ctrl->getCmd("listTemplates");
70 if (in_array($cmd, array("listTemplates", "add", "remove", "saveTemplateSettings", "addPageTemplateFromPageAction", "removePageTemplateFromPageAction"))) {
71 $this->$cmd();
72 }
73 break;
74 }
75 }
76
77 public function listTemplates(): void
78 {
79 // list pages
80 $pages = ilWikiPage::getAllWikiPages($this->wiki->getId());
81 $options = array("" => $this->lng->txt("please_select"));
82 foreach ($pages as $p) {
83 //if (!in_array($p["id"], $ipages_ids))
84 //{
85 $options[$p["id"]] = ilStr::shortenTextExtended($p["title"], 60, true);
86 //}
87 }
88
89 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
90 $this->toolbar->setOpenFormTag(true);
91 $this->toolbar->setCloseFormTag(false);
92
93 if (count($options) > 0) {
94 $si = new ilSelectInputGUI($this->lng->txt("wiki_pages"), "templ_page_id");
95 $si->setOptions($options);
96 $this->toolbar->addInputItem($si);
97 $this->toolbar->addFormButton($this->lng->txt("wiki_add_template"), "add");
98 $this->toolbar->addSeparator();
99 }
100
101 // empty page as template?
102 $cb = new ilCheckboxInputGUI($this->lng->txt("wiki_empty_page_template"), "empty_page_templ");
103 $cb->setChecked($this->wiki->getEmptyPageTemplate());
104 $this->toolbar->addInputItem($cb, true);
105 $this->toolbar->addFormButton($this->lng->txt("save"), "saveTemplateSettings");
106
107 $tab = new ilWikiPageTemplatesTableGUI($this, "listTemplates", $this->wiki->getId());
108 $tab->setOpenFormTag(false);
109 $tab->setCloseFormTag(true);
110 $this->tpl->setContent($tab->getHTML());
111 }
112
113 public function add(): void
114 {
115 $wpt = new ilWikiPageTemplate($this->wiki->getId());
116 $wpt->save($this->request->getPageTemplateId());
117 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_added"), true);
118 $this->ctrl->redirect($this, "listTemplates");
119 }
120
121 public function remove(): void
122 {
123 $wpt = new ilWikiPageTemplate($this->wiki->getId());
124
125 $ids = $this->request->getIds();
126 if (count($ids) > 0) {
127 foreach ($ids as $id) {
128 $wpt->remove((int) $id);
129 }
130 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_status_removed"), true);
131 }
132
133 $this->ctrl->redirect($this, "listTemplates");
134 }
135
136 public function saveTemplateSettings(): void
137 {
138 $all_ids = $this->request->getAllIds();
139 $new_pages = $this->request->getNewPages();
140 $add_to_page = $this->request->getAddToPage();
141 foreach ($all_ids as $id) {
142 $wpt = new ilWikiPageTemplate($this->wiki->getId());
143 $wpt->save($id, $new_pages[$id] ?? 0, $add_to_page[$id] ?? 0);
144 }
145
146 $this->wiki->setEmptyPageTemplate($this->request->getEmptyPageTemplate());
147 $this->wiki->update();
148
149 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
150 $this->ctrl->redirect($this, "listTemplates");
151 }
152
153
154 //
155 // PAGE ACTIONS
156 //
157
158 public function removePageTemplateFromPageAction(): void
159 {
160 $page_id = $this->request->getWikiPageId();
161 if ($page_id) {
162 $wpt = new ilWikiPageTemplate($this->wiki->getId());
163 $wpt->remove($page_id);
164 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_status_removed"), true);
165 }
166
167 $this->ctrl->redirect($this, "listTemplates");
168 }
169
170 public function addPageTemplateFromPageAction(): void
171 {
172 $page_id = $this->request->getWikiPageId();
173 if ($page_id) {
174 $wpt = new ilWikiPageTemplate($this->wiki->getId());
175 $wpt->save($page_id);
176 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_added"), true);
177 }
178
179 $this->ctrl->redirect($this, "listTemplates");
180 }
181}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This class represents a checkbox property in a property form.
Class ilCtrl provides processing control methods.
language handling
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 shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
Wiki page template gui class.
ilGlobalTemplateInterface $tpl
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 getAllWikiPages(int $a_wiki_id)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc