ILIAS  release_7 Revision v7.30-3-g800a261c036
class.SectionCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
9
14{
18 protected $ui;
19
23 protected $lng;
24
28 protected $page_gui;
29
33 protected $user;
34
38 protected $ui_wrapper;
39
41 {
42 global $DIC;
43
44 $this->ui = $DIC->ui();
45 $this->lng = $DIC->language();
46 $this->page_gui = $page_gui;
47 $this->user = $DIC->user();
48
49 $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
50 }
51
57 public function handle($query, $body) : Server\Response
58 {
59 switch ($body["action"]) {
60 case "insert":
61 return $this->insertCommand($body);
62 break;
63
64 case "update":
65 return $this->updateCommand($body);
66 break;
67
68 default:
69 throw new Exception("Unknown action " . $body["action"]);
70 break;
71 }
72 }
73
79 protected function insertCommand($body) : Server\Response
80 {
81 $page = $this->page_gui->getPageObject();
82
83 $hier_id = "pg";
84 $pc_id = "";
85 if (!in_array($body["after_pcid"], ["", "pg"])) {
86 $hier_ids = $page->getHierIdsForPCIds([$body["after_pcid"]]);
87 $hier_id = $hier_ids[$body["after_pcid"]];
88 $pc_id = $body["after_pcid"];
89 }
90
91 // if ($form->checkInput()) {
92 $sec = new \ilPCSection($page);
93 $sec->create($page, $hier_id, $pc_id);
94 $sec_gui = new \ilPCSectionGUI($page, $sec, "", "");
95 $sec_gui->setPageConfig($page->getPageConfig());
96
97 $form = $sec_gui->initForm(true);
98
99 // note: we have everyting in _POST here, form works the usual way
100 $updated = true;
101 if ($form->checkInput()) {
102 $sec_gui->setValuesFromForm($form);
103 $updated = $page->update();
104 }
105
106 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
107 }
108
114 protected function updateCommand($body) : Server\Response
115 {
116 $page = $this->page_gui->getPageObject();
117 $page->addHierIDs();
118 $hier_id = $page->getHierIdForPcId($body["pcid"]);
119 $sec = $page->getContentObjectForPcId($body["pcid"]);
120 $sec_gui = new \ilPCSectionGUI($page, $sec, $hier_id, $body["pcid"]);
121 $sec_gui->setPageConfig($page->getPageConfig());
122
123 $form = $sec_gui->initForm(false);
124
125 // note: we have everyting in _POST here, form works the usual way
126 $updated = true;
127 if ($form->checkInput()) {
128 $sec_gui->setValuesFromForm($form);
129 $updated = $page->update();
130 }
131
132 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
133 }
134}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Page editor json server.
Class ilPageObjectGUI.
global $DIC
Definition: goto.php:24
$query
ui()
Definition: ui.php:5