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