ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPageLayoutAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
29 {
31  protected ?int $pg_id = null;
33  protected ilTabsGUI $tabs;
35  protected ilCtrl $ctrl;
38  protected ilLanguage $lng;
41  protected int $ref_id;
42 
43  public function __construct()
44  {
45  global $DIC;
46 
47  $this->ctrl = $DIC->ctrl();
48  $this->rbacsystem = $DIC->rbac()->system();
49  $this->toolbar = $DIC->toolbar();
50  $this->lng = $DIC->language();
51  $this->tpl = $DIC["tpl"];
52  $this->tabs = $DIC->tabs();
53 
54  $this->settings = new ilContentStyleSettings();
55  $this->admin_request = $DIC
56  ->copage()
57  ->internal()
58  ->gui()
59  ->layout()
60  ->adminRequest();
61  $this->ref_id = $this->admin_request->getRefId();
62  }
63 
64  public function executeCommand(): void
65  {
66  $next_class = $this->ctrl->getNextClass($this);
67  $cmd = $this->ctrl->getCmd("listLayouts");
68 
69  if ($cmd == "listLayouts") {
70  $this->checkPermission("read");
71  } else {
72  $this->checkPermission("sty_write_page_layout");
73  }
74 
75  switch ($next_class) {
76  case 'ilpagelayoutgui':
77  $this->tabs->clearTargets();
78  $this->tabs->setBackTarget(
79  $this->lng->txt("page_layouts"),
80  $this->ctrl->getLinkTarget($this, "listLayouts")
81  );
82 
83  $this->ctrl->setReturn($this, "listLayouts");
84  if ($this->pg_id != null) {
85  $layout_gui = new ilPageLayoutGUI("stys", $this->pg_id);
86  } else {
87  $layout_gui = new ilPageLayoutGUI(
88  "stys",
89  $this->admin_request->getObjId()
90  );
91  }
92  $layout_gui->setTabs();
93  $layout_gui->setEditPreview(true);
94  $this->ctrl->saveParameter($this, "obj_id");
95  $ret = $this->ctrl->forwardCommand($layout_gui);
96  if ($ret != "") {
97  $this->tpl->setContent($ret);
98  }
99  break;
100 
101  default:
102  if (in_array($cmd, array("listLayouts", "editPg", "addPageLayout", "cancelCreate", "createPg", "exportLayout",
103  "activate", "deactivate", "importPageLayoutForm", "deletePgl", "cancelDeletePg",
104  "confirmedDeletePg", "importPageLayout"))) {
105  $this->$cmd();
106  } else {
107  die("Unknown command " . $cmd);
108  }
109  }
110  }
111 
116  public function checkPermission(
117  string $a_perm,
118  bool $a_throw_exc = true
119  ): bool {
120  if (!$this->rbacsystem->checkAccess($a_perm, $this->ref_id)) {
121  if ($a_throw_exc) {
122  throw new ilObjectException($this->lng->txt("permission_denied"));
123  }
124  return false;
125  }
126  return true;
127  }
128 
129  public function listLayouts(): void
130  {
131  // show toolbar, if write permission is given
132  if ($this->checkPermission("sty_write_page_layout", false)) {
133  $this->toolbar->addButton(
134  $this->lng->txt("sty_add_pgl"),
135  $this->ctrl->getLinkTarget($this, "addPageLayout")
136  );
137  $this->toolbar->addButton(
138  $this->lng->txt("sty_import_page_layout"),
139  $this->ctrl->getLinkTarget($this, "importPageLayoutForm")
140  );
141  }
142 
143  $oa_tpl = new ilTemplate("tpl.stys_pglayout.html", true, true, "Services/COPage/Layout");
144 
145  $pglayout_table = new ilPageLayoutTableGUI($this, "listLayouts");
146  $oa_tpl->setVariable("PGLAYOUT_TABLE", $pglayout_table->getHTML());
147  $this->tpl->setContent($oa_tpl->get());
148  }
149 
150  public function activate(
151  bool $a_activate = true
152  ): void {
153  $ids = $this->admin_request->getLayoutIds();
154  if (count($ids) == 0) {
155  $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
156  } else {
157  $this->tpl->setOnScreenMessage('success', $this->lng->txt("sty_opt_saved"), true);
158  foreach ($ids as $item) {
159  $pg_layout = new ilPageLayout($item);
160  $pg_layout->activate($a_activate);
161  }
162  }
163  $this->ctrl->redirect($this, "listLayouts");
164  }
165 
166  public function deactivate(): void
167  {
168  $this->activate(false);
169  }
170 
174  public function deletePgl(): void
175  {
176  $ids = $this->admin_request->getLayoutIds();
177  if (count($ids) == 0) {
178  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
179  $this->ctrl->redirect($this, "listLayouts");
180  }
181 
182  unset($this->data);
183 
184  // display confirmation message
185  $cgui = new ilConfirmationGUI();
186  $cgui->setFormAction($this->ctrl->getFormAction($this));
187  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
188  $cgui->setCancel($this->lng->txt("cancel"), "cancelDeletePg");
189  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDeletePg");
190 
191  foreach ($ids as $id) {
192  $pg_obj = new ilPageLayout($id);
193  $pg_obj->readObject();
194 
195  $caption = $pg_obj->getTitle();
196 
197  $cgui->addItem("pglayout[]", $id, $caption);
198  }
199 
200  $this->tpl->setContent($cgui->getHTML());
201  }
202 
206  public function cancelDeletePg(): void
207  {
208  $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_cancel"), true);
209  $this->ctrl->redirect($this, "listLayouts");
210  }
211 
215  public function confirmedDeletePg(): void
216  {
217  $ids = $this->admin_request->getLayoutIds();
218  foreach ($ids as $id) {
219  $pg_obj = new ilPageLayout($id);
220  $pg_obj->delete();
221  }
222 
223  $this->ctrl->redirect($this, "listLayouts");
224  }
225 
226  public function addPageLayout(ilPropertyFormGUI $a_form = null): void
227  {
228  if (!$a_form) {
229  $a_form = $this->initAddPageLayoutForm();
230  }
231  $this->tpl->setContent($a_form->getHTML());
232  }
233 
235  {
236  $this->lng->loadLanguageModule("content");
237 
238  $form_gui = new ilPropertyFormGUI();
239  $form_gui->setFormAction($this->ctrl->getFormAction($this));
240  $form_gui->setTitle($this->lng->txt("sty_create_pgl"));
241 
242  $title_input = new ilTextInputGUI($this->lng->txt("title"), "pgl_title");
243  $title_input->setSize(50);
244  $title_input->setMaxLength(128);
245  //$title_input->setValue($this->layout_object->title);
246  $title_input->setTitle($this->lng->txt("title"));
247  $title_input->setRequired(true);
248 
249  $desc_input = new ilTextAreaInputGUI($this->lng->txt("description"), "pgl_desc");
250  //$desc_input->setValue($this->layout_object->description);
251  $desc_input->setRows(3);
252  $desc_input->setCols(37);
253 
254 
255  // modules
256  $mods = new ilCheckboxGroupInputGUI($this->lng->txt("modules"), "module");
257  // $mods->setRequired(true);
258  foreach (ilPageLayout::getAvailableModules() as $mod_id => $mod_caption) {
259  $mod = new ilCheckboxOption($mod_caption, $mod_id);
260  $mods->addOption($mod);
261  }
262 
263  $ttype_input = new ilSelectInputGUI($this->lng->txt("sty_based_on"), "pgl_template");
264 
265  $arr_templates = ilPageLayout::getLayouts();
266  $arr_templates1 = ilPageLayout::getLayouts(false, true);
267  foreach ($arr_templates1 as $v) {
268  $arr_templates[] = $v;
269  }
270 
271  $options = array();
272  $options['-1'] = $this->lng->txt("none");
273 
274  foreach ($arr_templates as $templ) {
275  $templ->readObject();
276  $key = $templ->getId();
277  $value = $templ->getTitle();
278  $options[$key] = $value;
279  }
280 
281  $ttype_input->setOptions($options);
282  $ttype_input->setValue(-1);
283  $ttype_input->setRequired(true);
284 
285  $desc_input->setTitle($this->lng->txt("description"));
286  $desc_input->setRequired(false);
287 
288  $form_gui->addItem($title_input);
289  $form_gui->addItem($desc_input);
290  $form_gui->addItem($mods);
291  $form_gui->addItem($ttype_input);
292 
293 
294  $form_gui->addCommandButton("createPg", $this->lng->txt("save"));
295  $form_gui->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
296 
297  return $form_gui;
298  }
299 
300 
301  public function createPg(): void
302  {
303  $form_gui = $this->initAddPageLayoutForm();
304  if (!$form_gui->checkInput()) {
305  $form_gui->setValuesByPost();
306  $this->addPageLayout($form_gui);
307  return;
308  }
309 
310  //create Page-Layout-Object first
311  $pg_object = new ilPageLayout();
312  $pg_object->setTitle($form_gui->getInput('pgl_title'));
313  $pg_object->setDescription($form_gui->getInput('pgl_desc'));
314  $pg_object->setModules($form_gui->getInput('module'));
315  $pg_object->update();
316 
317  //create Page
318  //if (!is_object($pg_content)) {
319  $this->pg_content = new ilPageLayoutPage();
320  //}
321 
322  $this->pg_content->setId($pg_object->getId());
323 
324  $tmpl = $form_gui->getInput('pgl_template');
325  if ($tmpl != "-1") {
326  $layout_obj = new ilPageLayout($tmpl);
327  $this->pg_content->setXMLContent($layout_obj->getXMLContent());
328  }
329  $this->pg_content->create(false);
330 
331  $this->ctrl->setParameterByClass("ilpagelayoutgui", "obj_id", $pg_object->getId());
332  $this->ctrl->redirectByClass("ilpagelayoutgui", "edit");
333  }
334 
335  public function cancelCreate(): void
336  {
337  $this->listLayouts();
338  }
339 
340  public function editPg(): void
341  {
342  $this->checkPermission("sty_write_page_layout");
343 
344  $this->ctrl->setCmdClass("ilpagelayoutgui");
345  $this->ctrl->setCmd("edit");
346  $this->executeCommand();
347  }
348 
349 
353  public function exportLayout(): void
354  {
355  $exp = new ilExport();
356 
357  $tmpdir = ilFileUtils::ilTempnam();
358  ilFileUtils::makeDir($tmpdir);
359  $succ = $exp->exportEntity(
360  "pgtp",
361  $this->admin_request->getObjId(),
362  "4.2.0",
363  "Services/COPage",
364  "Title",
365  $tmpdir
366  );
367 
368  if (is_file($succ["directory"] . "/" . $succ["file"])) {
370  $succ["directory"] . "/" . $succ["file"],
371  $succ["file"],
372  "",
373  false,
374  false,
375  false
376  );
377  }
378  if (is_file($succ["directory"] . "/" . $succ["file"])) {
379  unlink($succ["directory"] . "/" . $succ["file"]);
380  }
381  if (is_dir($succ["directory"])) {
382  //unlink($succ["directory"]);
383  }
384  }
385 
389  public function importPageLayoutForm(): void
390  {
391  $form = $this->initPageLayoutImportForm();
392  $this->tpl->setContent($form->getHTML());
393  }
394 
399  {
400  $form = new ilPropertyFormGUI();
401 
402  // template file
403  $fi = new ilFileInputGUI($this->lng->txt("file"), "file");
404  $fi->setSuffixes(array("zip"));
405  $fi->setRequired(true);
406  $form->addItem($fi);
407 
408  $form->addCommandButton("importPageLayout", $this->lng->txt("import"));
409  $form->addCommandButton("listLayouts", $this->lng->txt("cancel"));
410 
411  $form->setTitle($this->lng->txt("sty_import_page_layout"));
412  $form->setFormAction($this->ctrl->getFormAction($this));
413 
414  return $form;
415  }
416 
420  public function importPageLayout(): void
421  {
422  $form = $this->initPageLayoutImportForm();
423  if ($form->checkInput()) {
424  ilPageLayout::import($_FILES["file"]["name"], $_FILES["file"]["tmp_name"]);
425  $this->tpl->setOnScreenMessage('success', $this->lng->txt("sty_imported_layout"), true);
426  $this->ctrl->redirect($this, "listLayouts");
427  } else {
428  $form->setValuesByPost();
429  $this->tpl->setContent($form->getHTML());
430  }
431  }
432 }
exportLayout()
Export page layout template object.
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...
Class ilPageLayoutGUI GUI class.
This class represents a file property in a property form.
deletePgl()
display deletion confirmation screen
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTabs(ilTabsGUI $a_tabs=null)
output tabs
setSuffixes(array $a_suffixes)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 import(string $a_filename, string $a_filepath)
Import page layout.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAvailableModules()
string $key
Consumer key/client ID value.
Definition: System.php:193
static getLayouts(bool $a_active=false, int $a_module=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
cancelDeletePg()
cancel deletion of Page Layout
This class represents a text area property in a property form.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
initPageLayoutImportForm()
Init page layout import form.
checkPermission(string $a_perm, bool $a_throw_exc=true)
Check permission.
confirmedDeletePg()
conform deletion of Page Layout
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...