ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.SectionCommandActionHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
29 class 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 
38  public function __construct(\ilPageObjectGUI $page_gui)
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->setPageConfig($page->getPageConfig());
83 
84  $form = $sec_gui->initForm(true);
85 
86  // note: we have everyting in _POST here, form works the usual way
87  $updated = true;
88  if ($sec_gui->checkInput($form)) {
89  $sec_gui->setValuesFromForm($form);
90  $updated = $page->update();
91  } else {
92  $rendered_form = $this->ctrl->getHTML(
93  $sec_gui,
94  [
95  "form" => true,
96  "validation" => true,
97  "insert" => true,
98  "ui_wrapper" => $this->ui_wrapper,
99  "buttons" => [["Page", "component.save", $this->lng->txt("insert")],
100  ["Page", "component.cancel", $this->lng->txt("cancel")]]
101  ]
102  );
103  return $this->ui_wrapper->sendFormError($rendered_form);
104  }
105 
106  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
107  }
108 
109  protected function updateCommand(array $body): Server\Response
110  {
111  $page = $this->page_gui->getPageObject();
112  $page->addHierIDs();
113  $hier_id = $page->getHierIdForPcId($body["pcid"]);
114  $sec = $page->getContentObjectForPcId($body["pcid"]);
115  $sec_gui = new \ilPCSectionGUI($page, $sec, $hier_id, $body["pcid"]);
116  $sec_gui->setStyleId($this->page_gui->getStyleId());
117  $sec_gui->setPageConfig($page->getPageConfig());
118 
119  $form = $sec_gui->initForm(false);
120 
121  // note: we have everyting in _POST here, form works the usual way
122  $updated = true;
123  if ($sec_gui->checkInput($form)) {
124  $sec_gui->setValuesFromForm($form);
125  $updated = $page->update();
126  } else {
127  $rendered_form = $this->ctrl->getHTML(
128  $sec_gui,
129  [
130  "form" => true,
131  "validation" => true,
132  "ui_wrapper" => $this->ui_wrapper,
133  "buttons" => [["Page", "component.update", $this->lng->txt("save")],
134  ["Page", "component.cancel", $this->lng->txt("cancel")]]
135  ]
136  );
137  return $this->ui_wrapper->sendFormError($rendered_form);
138  }
139 
140  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
141  }
142 }
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...
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
Page editor json server.