ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ResourcesCommandActionHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
29class ResourcesCommandActionHandler implements Server\CommandActionHandler
30{
31 protected \ILIAS\DI\UIServices $ui;
32 protected \ilLanguage $lng;
33 protected \ilPageObjectGUI $page_gui;
34 protected \ilObjUser $user;
35 protected Server\UIWrapper $ui_wrapper;
36
38 {
39 global $DIC;
40
41 $this->ui = $DIC->ui();
42 $this->lng = $DIC->language();
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 $res = new \ilPCResources($page);
77 $res->create($page, $hier_id, $pc_id);
78
79 $res_type = $body["res_type"];
80
81 $invalid = false;
82 if ($res_type === "_other") {
83 $res->setResourceListType("_other");
84 } elseif ($res_type === "_lobj") {
85 $res->setResourceListType("_lobj");
86 } elseif ($res_type !== "itgr") {
87 if (isset($body["type"])) {
88 $res->setResourceListType(
89 $body["type"]
90 );
91 } else {
92 $invalid = true;
93 }
94 } else {
95 $res->setItemGroupRefId(
96 (int) $body["itgr"]
97 );
98 }
99
100 if (!$invalid) {
101 $updated = $page->update();
102 } else {
103 $page->buildDom(true); // rebuild dom (remove changes)
104 $updated = true;
105 }
106
107 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
108 }
109
110 protected function updateCommand(array $body): Server\Response
111 {
112 $page = $this->page_gui->getPageObject();
113
115 $res = $page->getContentObjectForPcId($body["pcid"]);
116
117 $res_type = $body["res_type"];
118
119 if ($res_type === "_other") {
120 $res->setResourceListType("_other");
121 } elseif ($res_type === "_lobj") {
122 $res->setResourceListType("_lobj");
123 } elseif ($res_type !== "itgr") {
124 $res->setResourceListType(
125 $body["type"]
126 );
127 } else {
128 $res->setItemGroupRefId(
129 (int) $body["itgr"]
130 );
131 }
132
133 $updated = $page->update();
134 if ($page instanceof \ilContainerPage) {
135 $page->addMissingContainerBlocks($this->page_gui->getItemPresentationManager());
136 }
137
138 return $this->ui_wrapper->sendPage($this->page_gui, $updated);
139 }
140}
Page editor json server.
Container page object.
Class ilPageObjectGUI.
$res
Definition: ltiservices.php:69
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