ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BaseCommands.php
Go to the documentation of this file.
1<?php
2
20
23use ILIAS\Data\Factory as DataFactory;
26use Psr\Http\Message\ServerRequestInterface;
27use ILIAS\UI\Factory as UIFactory;
28use ILIAS\UI\Renderer as UIRenderer;
29
34abstract class BaseCommands
35{
36 public const CMD_INDEX = "index";
37 public const CMD_DEFAULT_PERMISSIONS = "defaultPermissions";
38 public const CMD_ADD = "add";
39 public const CMD_CREATE = "create";
40 public const CMD_EDIT = "edit";
41 public const CMD_UPDATE = "update";
42 public const CMD_CONFIRM = "confirm";
43 public const CMD_DELETE = "delete";
44 public const CMD_CANCEL = "cancel";
45 public const AR_ID = "arid";
46
47 protected \ilLanguage $lng;
48 protected \ilCtrl $ctrl;
49 private \ilTabsGUI $tabsGUI;
50 protected \ilAccess $access;
51 protected \ILIAS\HTTP\Services $http;
52 protected \ilGlobalTemplateInterface $tpl;
53 protected ?BaseCommands $parent_gui = null;
54
56 protected ?URLBuilderToken $action_token = null;
58 protected DataFactory $data_factory;
60 protected ServerRequestInterface $request;
61 protected \ILIAS\HTTP\Wrapper\ArrayBasedRequestWrapper $query;
62
63 protected UIFactory $ui_factory;
64 protected UIRenderer $ui_renderer;
65
66 protected function __construct(
67 protected array $query_namespace = ['orgu', 'posedit']
68 ) {
69 global $DIC;
70
71 $this->lng = $DIC->language();
72 $this->lng->loadLanguageModule("orgu");
73 $this->ctrl = $DIC->ctrl();
74 $this->tabsGUI = $DIC->tabs();
75 $this->access = $DIC->access();
76 $this->http = $DIC->http();
77 $this->tpl = $DIC->ui()->mainTemplate();
78 $this->refinery = $DIC['refinery'];
79 $this->query = $DIC->http()->wrapper()->query();
80 $this->request = $DIC->http()->request();
81 $this->data_factory = new DataFactory();
82
83 $here_uri = $this->data_factory->uri(
84 $this->request->getUri()->__toString()
85 );
86 $this->url_builder = new URLBuilder($here_uri);
88 $this->url_builder->acquireParameters($this->query_namespace, "action", "rowid");
89 $this->url_builder = $url_builder;
90 $this->action_token = $action_token;
91 $this->row_id_token = $row_id_token;
92
93 $this->ui_factory = $DIC['ui.factory'];
94 $this->ui_renderer = $DIC['ui.renderer'];
95 }
96
97 public function getParentGui(): ?BaseCommands
98 {
99 return $this->parent_gui;
100 }
101
103 {
104 $this->parent_gui = $parent_gui;
105 }
106
107 abstract protected function index(): void;
108
109 protected function getPossibleNextClasses(): array
110 {
111 return array();
112 }
113
114 protected function getActiveTabId(): ?string
115 {
116 return null;
117 }
118
122 protected function cancel(): void
123 {
124 $this->ctrl->redirect($this, self::CMD_INDEX);
125 }
126
127 protected function setContent(string $html)
128 {
129 $this->tpl->setContent($html);
130 }
131
135 public function executeCommand()
136 {
137 global $DIC;
138 $this->ctrl = $DIC->ctrl();
139 $this->http = $DIC->http();
140 $this->access = $DIC->access();
141 $this->tabsGUI = $DIC->tabs();
142 $this->lng = $DIC->language();
143 $this->tpl = $DIC->ui()->mainTemplate();
144 $this->lng->loadLanguageModule("orgu");
145
146 $cmd = $this->ctrl->getCmd(self::CMD_INDEX);
147
148 if ($this->action_token &&
149 $this->query->has($this->action_token->getName())
150 ) {
151 $cmd = $this->query->retrieve(
152 $this->action_token->getName(),
153 $this->refinery->to()->string()
154 );
155 }
156
157 $next_class = $this->ctrl->getNextClass();
158 if ($next_class) {
159 foreach ($this->getPossibleNextClasses() as $class) {
160 if (strtolower($class) === $next_class) {
161 $instance = new $class();
162 if ($instance instanceof BaseCommands) {
163 $instance->setParentGui($this);
164 $this->ctrl->forwardCommand($instance);
165 }
166
167 return;
168 }
169 }
170 }
171
172 if ($this->getActiveTabId()) {
173 $this->tabsGUI->activateTab($this->getActiveTabId());
174 }
175
176 switch ($cmd) {
177 default:
178 if ($this->checkRequestReferenceId()) {
179 $this->{$cmd}();
180 }
181 break;
182 }
183 }
184
185 protected function pushSubTab(string $subtab_id, string $url)
186 {
187 $this->tabsGUI->addSubTab($subtab_id, $this->lng->txt($subtab_id), $url);
188 }
189
190 protected function activeSubTab(string $subtab_id)
191 {
192 $this->tabsGUI->activateSubTab($subtab_id);
193 }
194
195 protected function checkRequestReferenceId()
196 {
200 $ref_id = $this->getParentRefId();
201 if ($ref_id) {
202 return $this->access->checkAccess("read", "", $ref_id);
203 }
204
205 return true;
206 }
207
208 protected function getParentRefId(): ?int
209 {
210 $ref_id = $this->http->request()->getQueryParams()["ref_id"];
211
212 return $ref_id;
213 }
214
215 public function addSubTabs(): void
216 {
217 }
218
219 protected function getRowIdFromQuery(): int
220 {
221 if ($this->query->has($this->row_id_token->getName())) {
222 return $this->query->retrieve(
223 $this->row_id_token->getName(),
224 $this->refinery->custom()->transformation(fn($v) => (int) array_shift($v))
225 );
226 }
227 throw new \Exception('no position-id in query');
228 }
229}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
pushSubTab(string $subtab_id, string $url)
__construct(protected array $query_namespace=['orgu', 'posedit'])
ILIAS HTTP Wrapper ArrayBasedRequestWrapper $query
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
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
$url
Definition: shib_logout.php:68