ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilWikiPageTemplateGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $toolbar;
18
22 protected $lng;
23
24 protected $wiki_gui;
25 protected $ctrl;
26 protected $tpl;
27
33 public function __construct(ilObjWikiGUI $a_wiki_gui)
34 {
35 global $DIC;
36
37 $ilCtrl = $DIC->ctrl();
38 $tpl = $DIC["tpl"];
39 $ilToolbar = $DIC->toolbar();
40 $lng = $DIC->language();
41
42 $this->wiki_gui = $a_wiki_gui;
43 $this->wiki = $this->wiki_gui->object;
44 $this->ctrl = $ilCtrl;
45 $this->tpl = $tpl;
46 $this->lng = $lng;
47 $this->toolbar = $ilToolbar;
48 }
49
53 public function executeCommand()
54 {
55 $nc = $this->ctrl->getNextClass();
56
57 switch ($nc) {
58 default:
59 $cmd = $this->ctrl->getCmd("listTemplates");
60 if (in_array($cmd, array("listTemplates", "add", "remove", "saveTemplateSettings", "addPageTemplateFromPageAction", "removePageTemplateFromPageAction"))) {
61 $this->$cmd();
62 }
63 break;
64 }
65 }
66
70 public function listTemplates()
71 {
72 // list pages
73 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
74 $pages = ilWikiPage::getAllWikiPages($this->wiki->getId());
75 $options = array("" => $this->lng->txt("please_select"));
76 foreach ($pages as $p) {
77 //if (!in_array($p["id"], $ipages_ids))
78 //{
79 $options[$p["id"]] = ilUtil::shortenText($p["title"], 60, true);
80 //}
81 }
82
83 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
84 $this->toolbar->setOpenFormTag(true);
85 $this->toolbar->setCloseFormTag(false);
86
87 if (count($options) > 0) {
88 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
89 $si = new ilSelectInputGUI($this->lng->txt("wiki_pages"), "templ_page_id");
90 $si->setOptions($options);
91 $this->toolbar->addInputItem($si);
92 $this->toolbar->addFormButton($this->lng->txt("wiki_add_template"), "add");
93 $this->toolbar->addSeparator();
94 }
95
96 // empty page as template?
97 include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
98 $cb = new ilCheckboxInputGUI($this->lng->txt("wiki_empty_page_template"), "empty_page_templ");
99 $cb->setChecked($this->wiki->getEmptyPageTemplate());
100 $this->toolbar->addInputItem($cb, true);
101 $this->toolbar->addFormButton($this->lng->txt("save"), "saveTemplateSettings");
102
103
104 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplatesTableGUI.php");
105 $tab = new ilWikiPageTemplatesTableGUI($this, "listTemplates", $this->wiki->getId());
106 $tab->setOpenFormTag(false);
107 $tab->setCloseFormTag(true);
108 $this->tpl->setContent($tab->getHTML());
109 }
110
114 public function add()
115 {
116 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
117 $wpt = new ilWikiPageTemplate($this->wiki->getId());
118 $wpt->save((int) $_POST["templ_page_id"]);
119 ilUtil::sendSuccess($this->lng->txt("wiki_template_added"), true);
120 $this->ctrl->redirect($this, "listTemplates");
121 }
122
126 public function remove()
127 {
128 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
129 $wpt = new ilWikiPageTemplate($this->wiki->getId());
130
131 if (is_array($_POST["id"])) {
132 foreach ($_POST["id"] as $id) {
133 $wpt->remove((int) $id);
134 }
135 ilUtil::sendSuccess($this->lng->txt("wiki_template_status_removed"), true);
136 }
137
138 $this->ctrl->redirect($this, "listTemplates");
139 }
140
144 public function saveTemplateSettings()
145 {
146 if (is_array($_POST["all_ids"])) {
147 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
148 foreach ($_POST["all_ids"] as $id) {
149 $wpt = new ilWikiPageTemplate($this->wiki->getId());
150 $wpt->save((int) $id, (int) $_POST["new_pages"][$id], (int) $_POST["add_to_page"][$id]);
151 }
152 }
153
154 $this->wiki->setEmptyPageTemplate((int) $_POST["empty_page_templ"]);
155 $this->wiki->update();
156
157 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
158 $this->ctrl->redirect($this, "listTemplates");
159 }
160
161
162 //
163 // PAGE ACTIONS
164 //
165
167 {
168 $page_id = (int) $_GET["wpg_id"];
169 if ($page_id) {
170 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
171 $wpt = new ilWikiPageTemplate($this->wiki->getId());
172 $wpt->remove($page_id);
173 ilUtil::sendSuccess($this->lng->txt("wiki_template_status_removed"), true);
174 }
175
176 $this->ctrl->redirect($this, "listTemplates");
177 }
178
180 {
181 $page_id = (int) $_GET["wpg_id"];
182 if ($page_id) {
183 include_once("./Modules/Wiki/classes/class.ilWikiPageTemplate.php");
184 $wpt = new ilWikiPageTemplate($this->wiki->getId());
185 $wpt->save($page_id);
186 ilUtil::sendSuccess($this->lng->txt("wiki_template_added"), true);
187 }
188
189 $this->ctrl->redirect($this, "listTemplates");
190 }
191}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
Class ilObjWikiGUI.
This class represents a selection list property in a property form.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
Wiki page template gui class.
__construct(ilObjWikiGUI $a_wiki_gui)
Constructor.
saveTemplateSettings()
Save template settings.
add()
Add page as template page.
TableGUI class for wiki page templates.
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
global $DIC
Definition: goto.php:24