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