ILIAS  release_8 Revision v8.24
class.SectionCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
20
23
28{
29 protected \ilCtrlInterface $ctrl;
30 protected \ILIAS\DI\UIServices $ui;
31 protected \ilLanguage $lng;
32 protected \ilPageObjectGUI $page_gui;
33 protected \ilObjUser $user;
35
37 {
38 global $DIC;
39
40 $this->ui = $DIC->ui();
41 $this->lng = $DIC->language();
42 $this->ctrl = $DIC->ctrl();
43 $this->page_gui = $page_gui;
44 $this->user = $DIC->user();
45
46 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
47 }
48
49 public function handle(array $query, array $body): Server\Response
50 {
51 switch ($body["action"]) {
52 case "insert":
53 return $this->insertCommand($body);
54
55 case "update":
56 return $this->updateCommand($body);
57
58 default:
59 throw new Exception("Unknown action " . $body["action"]);
60 }
61 }
62
63 protected function insertCommand(array $body): Server\Response
64 {
65 $page = $this->page_gui->getPageObject();
66
67 $hier_id = "pg";
68 $pc_id = "";
69 if (!in_array($body["after_pcid"], ["", "pg"])) {
70 $hier_ids = $page->getHierIdsForPCIds([$body["after_pcid"]]);
71 $hier_id = $hier_ids[$body["after_pcid"]];
72 $pc_id = $body["after_pcid"];
73 }
74
75 // if ($form->checkInput()) {
76 $sec = new \ilPCSection($page);
77 $sec->create($page, $hier_id, $pc_id);
78 $sec_gui = new \ilPCSectionGUI($page, $sec, "", "");
79 $sec_gui->setPageConfig($page->getPageConfig());
80
81 $form = $sec_gui->initForm(true);
82
83 // note: we have everyting in _POST here, form works the usual way
84 $updated = true;
85 if ($sec_gui->checkInput($form)) {
86 $sec_gui->setValuesFromForm($form);
87 $updated = $page->update();
88 } else {
89 $html = $this->ctrl->getHTML(
90 $sec_gui,
91 [
92 "form" => true,
93 "ui_wrapper" => $this->ui_wrapper,
94 "update_fail" => true,
95 "insert" => true,
96 "buttons" => [["Page", "component.save", $this->lng->txt("insert")],
97 ["Page", "component.cancel", $this->lng->txt("cancel")]]
98 ]
99 );
100 return $this->ui_wrapper->sendFormError($html);
101 }
102
103 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
104 }
105
106 protected function updateCommand(array $body): Server\Response
107 {
108 $page = $this->page_gui->getPageObject();
109 $page->addHierIDs();
110 $hier_id = $page->getHierIdForPcId($body["pcid"]);
111 $sec = $page->getContentObjectForPcId($body["pcid"]);
112 $sec_gui = new \ilPCSectionGUI($page, $sec, $hier_id, $body["pcid"]);
113 $sec_gui->setStyleId($this->page_gui->getStyleId());
114 $sec_gui->setPageConfig($page->getPageConfig());
115
116 $form = $sec_gui->initForm(false);
117
118 // note: we have everyting in _POST here, form works the usual way
119 $updated = true;
120 if ($sec_gui->checkInput($form)) {
121 $sec_gui->setValuesFromForm($form);
122 $updated = $page->update();
123 } else {
124 $html = $this->ctrl->getHTML(
125 $sec_gui,
126 [
127 "form" => true,
128 "ui_wrapper" => $this->ui_wrapper,
129 "update_fail" => true,
130 "buttons" => [["Page", "component.update", $this->lng->txt("save")],
131 ["Page", "component.cancel", $this->lng->txt("cancel")]]
132 ]
133 );
134 return $this->ui_wrapper->sendFormError($html);
135 }
136
137 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
138 }
139}
Page editor json server.
Class ilPageObjectGUI.
global $DIC
Definition: feed.php:28
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...
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
$query