ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ->request();
60 }
61
62 public function executeCommand(): void
63 {
64 $nc = $this->ctrl->getNextClass();
65
66 switch ($nc) {
67 default:
68 $cmd = $this->ctrl->getCmd("listTemplates");
69 if (in_array($cmd, array("listTemplates", "add", "remove", "saveTemplateSettings", "addPageTemplateFromPageAction", "removePageTemplateFromPageAction"))) {
70 $this->$cmd();
71 }
72 break;
73 }
74 }
75
76 public function listTemplates(): void
77 {
78 // list pages
79 $pages = ilWikiPage::getAllWikiPages($this->wiki->getId(), "-");
80 $options = array("" => $this->lng->txt("please_select"));
81 foreach ($pages as $p) {
82 //if (!in_array($p["id"], $ipages_ids))
83 //{
84 $options[$p["id"]] = ilStr::shortenTextExtended($p["title"], 60, true);
85 //}
86 }
87
88 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
89 $this->toolbar->setOpenFormTag(true);
90 $this->toolbar->setCloseFormTag(false);
91
92 if (count($options) > 0) {
93 $si = new ilSelectInputGUI($this->lng->txt("wiki_pages"), "templ_page_id");
94 $si->setOptions($options);
95 $this->toolbar->addInputItem($si);
96 $this->toolbar->addFormButton($this->lng->txt("wiki_add_template"), "add");
97 $this->toolbar->addSeparator();
98 }
99
100 // empty page as template?
101 $cb = new ilCheckboxInputGUI($this->lng->txt("wiki_empty_page_template"), "empty_page_templ");
102 $cb->setChecked($this->wiki->getEmptyPageTemplate());
103 $this->toolbar->addInputItem($cb, true);
104 $this->toolbar->addFormButton($this->lng->txt("save"), "saveTemplateSettings");
105
106 $tab = new ilWikiPageTemplatesTableGUI($this, "listTemplates", $this->wiki->getId());
107 $tab->setOpenFormTag(false);
108 $tab->setCloseFormTag(true);
109 $this->tpl->setContent($tab->getHTML());
110 }
111
112 public function add(): void
113 {
114 $wpt = new ilWikiPageTemplate($this->wiki->getId());
115 $wpt->save($this->request->getPageTemplateId());
116 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_added"), true);
117 $this->ctrl->redirect($this, "listTemplates");
118 }
119
120 public function remove(): void
121 {
122 $wpt = new ilWikiPageTemplate($this->wiki->getId());
123
124 $ids = $this->request->getIds();
125 if (count($ids) > 0) {
126 foreach ($ids as $id) {
127 $wpt->remove((int) $id);
128 }
129 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_status_removed"), true);
130 }
131
132 $this->ctrl->redirect($this, "listTemplates");
133 }
134
135 public function saveTemplateSettings(): void
136 {
137 $all_ids = $this->request->getAllIds();
138 $new_pages = $this->request->getNewPages();
139 $add_to_page = $this->request->getAddToPage();
140 foreach ($all_ids as $id) {
141 $wpt = new ilWikiPageTemplate($this->wiki->getId());
142 $wpt->save($id, $new_pages[$id] ?? 0, $add_to_page[$id] ?? 0);
143 }
144
145 $this->wiki->setEmptyPageTemplate($this->request->getEmptyPageTemplate());
146 $this->wiki->update();
147
148 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
149 $this->ctrl->redirect($this, "listTemplates");
150 }
151
152
153 //
154 // PAGE ACTIONS
155 //
156
157 public function removePageTemplateFromPageAction(): void
158 {
159 $page_id = $this->request->getWikiPageId();
160 if ($page_id) {
161 $wpt = new ilWikiPageTemplate($this->wiki->getId());
162 $wpt->remove($page_id);
163 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_status_removed"), true);
164 }
165
166 $this->ctrl->redirect($this, "listTemplates");
167 }
168
169 public function addPageTemplateFromPageAction(): void
170 {
171 $page_id = $this->request->getWikiPageId();
172 if ($page_id) {
173 $wpt = new ilWikiPageTemplate($this->wiki->getId());
174 $wpt->save($page_id);
175 $this->tpl->setOnScreenMessage('success', $this->lng->txt("wiki_template_added"), true);
176 }
177
178 $this->ctrl->redirect($this, "listTemplates");
179 }
180}
$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...
TableGUI class for wiki page templates.
static getAllWikiPages(int $a_wiki_id, string $lang="-")
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26