ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilPageLayoutAdministrationGUI.php
Go to the documentation of this file.
1<?php
2
21use ILIAS\Export\ExportHandler\Factory as ilExportHandler;
22
30{
31 protected \ILIAS\COPage\Layout\GUIService $gui;
33 protected ?int $pg_id = null;
35 protected ilTabsGUI $tabs;
37 protected ilCtrl $ctrl;
40 protected ilLanguage $lng;
43 protected int $ref_id;
44 protected ilExportHandler $export_handler;
45
46 public function __construct()
47 {
48 global $DIC;
49
50 $this->ctrl = $DIC->ctrl();
51 $this->rbacsystem = $DIC->rbac()->system();
52 $this->toolbar = $DIC->toolbar();
53 $this->lng = $DIC->language();
54 $this->tpl = $DIC["tpl"];
55 $this->tabs = $DIC->tabs();
56 $this->lng->loadLanguageModule("style");
57 $this->gui = $DIC->copage()->internal()->gui()->layout();
58
59 $this->settings = new ilContentStyleSettings();
60 $this->admin_request = $DIC
61 ->copage()
62 ->internal()
63 ->gui()
64 ->layout()
65 ->adminRequest();
66 $this->ref_id = $this->admin_request->getRefId();
67 $this->export_handler = new ilExportHandler();
68 }
69
70 public function executeCommand(): void
71 {
72 $next_class = $this->ctrl->getNextClass($this);
73 $cmd = $this->ctrl->getCmd("listLayouts");
74
75 if ($cmd == "listLayouts") {
76 $this->checkPermission("read");
77 } else {
78 $this->checkPermission("sty_write_page_layout");
79 }
80
81 switch ($next_class) {
82 case 'ilpagelayoutgui':
83 $this->tabs->clearTargets();
84 $this->tabs->setBackTarget(
85 $this->lng->txt("page_layouts"),
86 $this->ctrl->getLinkTarget($this, "listLayouts")
87 );
88
89 $this->ctrl->setReturn($this, "listLayouts");
90 if ($this->pg_id != null) {
91 $layout_gui = new ilPageLayoutGUI("stys", $this->pg_id);
92 } else {
93 $layout_gui = new ilPageLayoutGUI(
94 "stys",
95 $this->admin_request->getObjId()
96 );
97 }
98 $layout_gui->setTabs();
99 $layout_gui->setEditPreview(true);
100 $this->ctrl->saveParameter($this, "obj_id");
101 $ret = $this->ctrl->forwardCommand($layout_gui);
102 if ($ret != "") {
103 $this->tpl->setContent($ret);
104 }
105 break;
106
107 default:
108 if (in_array($cmd, array("listLayouts", "editPg", "addPageLayout", "cancelCreate", "createPg", "exportLayout",
109 "activate", "deactivate", "importPageLayoutForm", "deletePgl", "cancelDeletePg",
110 "confirmedDeletePg", "importPageLayout"))) {
111 $this->$cmd();
112 } else {
113 die("Unknown command " . $cmd);
114 }
115 }
116 }
117
122 public function checkPermission(
123 string $a_perm,
124 bool $a_throw_exc = true
125 ): bool {
126 if (!$this->rbacsystem->checkAccess($a_perm, $this->ref_id)) {
127 if ($a_throw_exc) {
128 throw new ilObjectException($this->lng->txt("permission_denied"));
129 }
130 return false;
131 }
132 return true;
133 }
134
135 protected function getTable(): \ILIAS\Repository\Table\TableAdapterGUI
136 {
137 return $this->gui->pageLayoutTableBuilder(
138 $this,
139 "listLayouts"
140 )->getTable();
141 }
142
143 public function listLayouts(): void
144 {
145 // show toolbar, if write permission is given
146 if ($this->checkPermission("sty_write_page_layout", false)) {
147 $this->toolbar->addButton(
148 $this->lng->txt("sty_add_pgl"),
149 $this->ctrl->getLinkTarget($this, "addPageLayout")
150 );
151 $this->toolbar->addButton(
152 $this->lng->txt("sty_import_page_layout"),
153 $this->ctrl->getLinkTarget($this, "importPageLayoutForm")
154 );
155 }
156
157 $table = $this->getTable();
158 if ($table->handleCommand()) {
159 return;
160 }
161
162 $this->tpl->setContent($table->render());
163 }
164
165 public function activate(
166 array $ids,
167 bool $a_activate = true
168 ): void {
169 if (count($ids) == 0) {
170 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_checkbox"), true);
171 } else {
172 $this->tpl->setOnScreenMessage('success', $this->lng->txt("sty_opt_saved"), true);
173 foreach ($ids as $item) {
174 $pg_layout = new ilPageLayout($item);
175 $pg_layout->activate($a_activate);
176 }
177 }
178 $this->ctrl->redirect($this, "listLayouts");
179 }
180
181 public function deactivate(array $ids): void
182 {
183 $this->activate($ids, false);
184 }
185
189 public function deletePgl(array $ids): void
190 {
191 if (count($ids) == 0) {
192 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
193 $this->ctrl->redirect($this, "listLayouts");
194 }
195
196 $table = $this->getTable();
197
198 $items = [];
199 foreach ($ids as $id) {
200 $pg_obj = new ilPageLayout($id);
201 $pg_obj->readObject();
202 $items[$id] = $pg_obj->getTitle();
203 }
204
205 $table->renderDeletionConfirmation(
206 $this->lng->txt("info_delete_sure"),
207 $this->lng->txt("info_delete_sure"),
208 "confirmedDeletePg",
209 $items
210 );
211 }
212
216 public function cancelDeletePg(): void
217 {
218 $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_cancel"), true);
219 $this->ctrl->redirect($this, "listLayouts");
220 }
221
225 public function confirmedDeletePg(): void
226 {
227 $ids = $this->getTable()->getItemIds();
228 foreach ($ids as $id) {
229 $pg_obj = new ilPageLayout($id);
230 $pg_obj->delete();
231 }
232
233 $this->ctrl->redirect($this, "listLayouts");
234 }
235
236 public function addPageLayout(?ilPropertyFormGUI $a_form = null): void
237 {
238 if (!$a_form) {
239 $a_form = $this->initAddPageLayoutForm();
240 }
241 $this->tpl->setContent($a_form->getHTML());
242 }
243
245 {
246 $this->lng->loadLanguageModule("content");
247 $this->lng->loadLanguageModule("copg");
248
249 $form_gui = new ilPropertyFormGUI();
250 $form_gui->setFormAction($this->ctrl->getFormAction($this));
251 $form_gui->setTitle($this->lng->txt("sty_create_pgl"));
252
253 $title_input = new ilTextInputGUI($this->lng->txt("title"), "pgl_title");
254 $title_input->setSize(50);
255 $title_input->setMaxLength(128);
256 //$title_input->setValue($this->layout_object->title);
257 $title_input->setTitle($this->lng->txt("title"));
258 $title_input->setRequired(true);
259
260 $desc_input = new ilTextAreaInputGUI($this->lng->txt("description"), "pgl_desc");
261 //$desc_input->setValue($this->layout_object->description);
262 $desc_input->setRows(3);
263 $desc_input->setCols(37);
264
265
266 // modules
267 $mods = new ilCheckboxGroupInputGUI($this->lng->txt("copg_obj_types"), "module");
268 // $mods->setRequired(true);
269 foreach (ilPageLayout::getAvailableModules() as $mod_id => $mod_caption) {
270 $mod = new ilCheckboxOption($mod_caption, $mod_id);
271 $mods->addOption($mod);
272 }
273
274 $ttype_input = new ilSelectInputGUI($this->lng->txt("sty_based_on"), "pgl_template");
275
276 $arr_templates = ilPageLayout::getLayouts();
277 $arr_templates1 = ilPageLayout::getLayouts(false, true);
278 foreach ($arr_templates1 as $v) {
279 $arr_templates[] = $v;
280 }
281
282 $options = array();
283 $options['-1'] = $this->lng->txt("none");
284
285 foreach ($arr_templates as $templ) {
286 $templ->readObject();
287 $key = $templ->getId();
288 $value = $templ->getTitle();
289 $options[$key] = $value;
290 }
291
292 $ttype_input->setOptions($options);
293 $ttype_input->setValue(-1);
294 $ttype_input->setRequired(true);
295
296 $desc_input->setTitle($this->lng->txt("description"));
297 $desc_input->setRequired(false);
298
299 $form_gui->addItem($title_input);
300 $form_gui->addItem($desc_input);
301 $form_gui->addItem($mods);
302 $form_gui->addItem($ttype_input);
303
304
305 $form_gui->addCommandButton("createPg", $this->lng->txt("save"));
306 $form_gui->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
307
308 return $form_gui;
309 }
310
311
312 public function createPg(): void
313 {
314 $form_gui = $this->initAddPageLayoutForm();
315 if (!$form_gui->checkInput()) {
316 $form_gui->setValuesByPost();
317 $this->addPageLayout($form_gui);
318 return;
319 }
320
321 //create Page-Layout-Object first
322 $pg_object = new ilPageLayout();
323 $pg_object->setTitle($form_gui->getInput('pgl_title'));
324 $pg_object->setDescription($form_gui->getInput('pgl_desc'));
325 $pg_object->setModules($form_gui->getInput('module'));
326 $pg_object->update();
327
328 //create Page
329 //if (!is_object($pg_content)) {
330 $this->pg_content = new ilPageLayoutPage();
331 //}
332
333 $this->pg_content->setId($pg_object->getId());
334
335 $tmpl = $form_gui->getInput('pgl_template');
336 if ($tmpl != "-1") {
337 $layout_obj = new ilPageLayout($tmpl);
338 $this->pg_content->setXMLContent($layout_obj->getXMLContent());
339 }
340 $this->pg_content->create(false);
341
342 $this->ctrl->setParameterByClass("ilpagelayoutgui", "obj_id", $pg_object->getId());
343 $this->ctrl->redirectByClass("ilpagelayoutgui", "edit");
344 }
345
346 public function cancelCreate(): void
347 {
348 $this->listLayouts();
349 }
350
351 public function editPg(int $id): void
352 {
353 $this->checkPermission("sty_write_page_layout");
354
355 $this->ctrl->setParameterByClass(ilPageLayoutGUI::class, "obj_id", $id);
356 $this->ctrl->redirectByClass(ilPageLayoutGUI::class, "edit");
357 $this->executeCommand();
358 }
359
360
364 public function exportLayout(int $id): void
365 {
366 $exp = new ilExport();
367
368 $tmpdir = ilFileUtils::ilTempnam();
369 ilFileUtils::makeDir($tmpdir);
370 $exp->setExportConfigs($this->export_handler->consumer()->exportConfig()->allExportConfigs());
371 $succ = $exp->exportEntity(
372 "pgtp",
373 $id,
374 "4.2.0",
375 "components/ILIAS/COPage",
376 "Title",
377 $tmpdir
378 );
379
380 if (is_file($succ["directory"] . "/" . $succ["file"])) {
382 $succ["directory"] . "/" . $succ["file"],
383 $succ["file"],
384 "",
385 false,
386 false,
387 false
388 );
389 }
390 if (is_file($succ["directory"] . "/" . $succ["file"])) {
391 unlink($succ["directory"] . "/" . $succ["file"]);
392 }
393 if (is_dir($succ["directory"])) {
394 //unlink($succ["directory"]);
395 }
396 }
397
401 public function importPageLayoutForm(): void
402 {
403 $form = $this->initPageLayoutImportForm();
404 $this->tpl->setContent($form->getHTML());
405 }
406
411 {
412 $form = new ilPropertyFormGUI();
413
414 // template file
415 $fi = new ilFileInputGUI($this->lng->txt("file"), "file");
416 $fi->setSuffixes(array("zip"));
417 $fi->setRequired(true);
418 $form->addItem($fi);
419
420 $form->addCommandButton("importPageLayout", $this->lng->txt("import"));
421 $form->addCommandButton("listLayouts", $this->lng->txt("cancel"));
422
423 $form->setTitle($this->lng->txt("sty_import_page_layout"));
424 $form->setFormAction($this->ctrl->getFormAction($this));
425
426 return $form;
427 }
428
432 public function importPageLayout(): void
433 {
434 $form = $this->initPageLayoutImportForm();
435 if ($form->checkInput()) {
436 ilPageLayout::import($_FILES["file"]["name"], $_FILES["file"]["tmp_name"]);
437 $this->tpl->setOnScreenMessage('success', $this->lng->txt("sty_imported_layout"), true);
438 $this->ctrl->redirect($this, "listLayouts");
439 } else {
440 $form->setValuesByPost();
441 $this->tpl->setContent($form->getHTML());
442 }
443 }
444}
$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.
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.
deletePgl(array $ids)
display deletion confirmation screen
activate(array $ids, bool $a_activate=true)
initPageLayoutImportForm()
Init page layout import form.
cancelDeletePg()
cancel deletion of Page Layout
confirmedDeletePg()
conform deletion of Page Layout
addPageLayout(?ilPropertyFormGUI $a_form=null)
exportLayout(int $id)
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...
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...
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...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))