ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
TableGUI class for wiki page templates.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
This class represents a selection list property in a property form.
Wiki page template gui class.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
if(!array_key_exists('StateId', $_REQUEST)) $id
This class represents a checkbox property in a property form.
global $ilCtrl
Definition: ilias.php:18
add()
Add page as template page.
setChecked($a_checked)
Set Checked.
save($a_id, $a_new_pages=0, $a_add_to_page=0)
Add wiki page template.
saveTemplateSettings()
Save template settings.
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
Create styles array
The data for the language used.
__construct(ilObjWikiGUI $a_wiki_gui)
Constructor.
remove($a_id)
Remove template status of a page.
$_POST["username"]
Class ilObjWikiGUI.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20