ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SectionCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
29class SectionCommandActionHandler implements Server\CommandActionHandler
30{
31 protected \ilCtrlInterface $ctrl;
32 protected \ILIAS\DI\UIServices $ui;
33 protected \ilLanguage $lng;
34 protected \ilPageObjectGUI $page_gui;
35 protected \ilObjUser $user;
36 protected Server\UIWrapper $ui_wrapper;
37
39 {
40 global $DIC;
41
42 $this->ui = $DIC->ui();
43 $this->lng = $DIC->language();
44 $this->ctrl = $DIC->ctrl();
45 $this->page_gui = $page_gui;
46 $this->user = $DIC->user();
47 $this->ctrl = $DIC->ctrl();
48
49 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
50 }
51
52 public function handle(array $query, array $body): Server\Response
53 {
54 switch ($body["action"]) {
55 case "insert":
56 return $this->insertCommand($body);
57
58 case "update":
59 return $this->updateCommand($body);
60
61 default:
62 throw new Exception("Unknown action " . $body["action"]);
63 }
64 }
65
66 protected function insertCommand(array $body): Server\Response
67 {
68 $page = $this->page_gui->getPageObject();
69
70 $hier_id = "pg";
71 $pc_id = "";
72 if (!in_array($body["after_pcid"], ["", "pg"])) {
73 $hier_ids = $page->getHierIdsForPCIds([$body["after_pcid"]]);
74 $hier_id = $hier_ids[$body["after_pcid"]];
75 $pc_id = $body["after_pcid"];
76 }
77
78 // if ($form->checkInput()) {
79 $sec = new \ilPCSection($page);
80 $sec->create($page, $hier_id, $pc_id);
81 $sec_gui = new \ilPCSectionGUI($page, $sec, "", "");
82 $sec_gui->setStyleId($this->page_gui->getStyleId());
83 $sec_gui->getCharacteristicsOfCurrentStyle(["section"]);
84 $sec_gui->setPageConfig($page->getPageConfig());
85
86 $form = $sec_gui->initForm(true);
87
88 // note: we have everyting in _POST here, form works the usual way
89 $updated = true;
90 if ($sec_gui->checkInput($form)) {
91 $sec_gui->setValuesFromForm($form);
92 $updated = $page->update();
93 } else {
94 $rendered_form = $this->ctrl->getHTML(
95 $sec_gui,
96 [
97 "form" => true,
98 "validation" => true,
99 "insert" => true,
100 "ui_wrapper" => $this->ui_wrapper,
101 "buttons" => [["Page", "component.save", $this->lng->txt("insert")],
102 ["Page", "component.cancel", $this->lng->txt("cancel")]]
103 ]
104 );
105 return $this->ui_wrapper->sendFormError($rendered_form);
106 }
107
108 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
109 }
110
111 protected function updateCommand(array $body): Server\Response
112 {
113 $page = $this->page_gui->getPageObject();
114 $page->addHierIDs();
115 $hier_id = $page->getHierIdForPcId($body["pcid"]);
116 $sec = $page->getContentObjectForPcId($body["pcid"]);
117 $sec_gui = new \ilPCSectionGUI($page, $sec, $hier_id, $body["pcid"]);
118 $sec_gui->setStyleId($this->page_gui->getStyleId());
119 $sec_gui->getCharacteristicsOfCurrentStyle(["section"]);
120 $sec_gui->setPageConfig($page->getPageConfig());
121
122 $form = $sec_gui->initForm(false);
123
124 // note: we have everyting in _POST here, form works the usual way
125 $updated = true;
126 if ($sec_gui->checkInput($form)) {
127 $sec_gui->setValuesFromForm($form);
128 $updated = $page->update();
129 } else {
130 $rendered_form = $this->ctrl->getHTML(
131 $sec_gui,
132 [
133 "form" => true,
134 "validation" => true,
135 "ui_wrapper" => $this->ui_wrapper,
136 "buttons" => [["Page", "component.update", $this->lng->txt("save")],
137 ["Page", "component.cancel", $this->lng->txt("cancel")]]
138 ]
139 );
140 return $this->ui_wrapper->sendFormError($rendered_form);
141 }
142
143 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
144 }
145}
Page editor json server.
Class ilPageObjectGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26