ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ControlCenterGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\UI\Factory as UIFactory;
27use ILIAS\UI\Renderer as UIRenderer;
28use ILIAS\MetaData\Presentation\UtilitiesInterface as PresentationUtilities;
38use ILIAS\StaticURL\Services as StaticURL;
39use ILIAS\Data\Factory as DataFactory;
41
43{
44 protected int $ref_id;
45 protected int $obj_id;
46 protected string $type;
48
49 public function __construct(
50 protected URI $link_to_parent,
51 protected ilCtrlInterface $ctrl,
52 protected ilGlobalTemplateInterface $tpl,
53 protected UIFactory $ui_factory,
54 protected UIRenderer $ui_renderer,
55 protected RequestParserInterface $request_parser,
56 protected ContentFactoryInterface $content_factory,
57 protected PresentationUtilities $presentation_utilities,
58 protected StateInfoFetcherInterface $state_info_fetcher,
59 protected PublisherInterface $state_changer,
60 protected PublishingSettings $publishing_settings,
61 protected StaticURL $static_url,
62 protected DataFactory $data_factory,
63 protected ObjectHandler $object_handler
64 ) {
65 $this->ref_id = $this->request_parser->fetchRefID();
66 $this->obj_id = $this->request_parser->fetchObjID();
67 $this->type = $this->request_parser->fetchType();
68 $this->state_info = $this->state_info_fetcher->getStateInfoForObjectReference(
69 $this->ref_id,
70 $this->obj_id,
71 $this->type
72 );
73 }
74
75 public function executeCommand(): void
76 {
77 $next_class = $this->ctrl->getNextClass($this);
78
79 $cmd = Command::tryFrom($this->ctrl->getCmd());
80 switch ($next_class) {
81 default:
82 if (!$cmd || !$this->isCommandAvailable($cmd)) {
83 throw new ilPermissionException($this->presentation_utilities->txt('permission_denied'));
84 }
85 $cmd_value = $cmd->value;
86 $this->$cmd_value();
87 break;
88 }
89 }
90
94 protected function isCommandAvailable(Command $cmd): bool
95 {
96 if (!$this->state_info->isPublishingRelevant()) {
97 return false;
98 }
99
100 return match ($cmd) {
101 Command::VIEW => true,
102 Command::BLOCK => $this->state_info->isActionAvailable(Action::BLOCK),
103 Command::UNBLOCK => $this->state_info->isActionAvailable(Action::UNBLOCK),
104 Command::PUBLISH => $this->state_info->isActionAvailable(Action::PUBLISH),
105 Command::WITHDRAW, Command::CONFIRM_WITHDRAW => $this->state_info->isActionAvailable(Action::WITHDRAW),
106 Command::SUBMIT => $this->state_info->isActionAvailable(Action::SUBMIT),
107 Command::ACCEPT, Command::CONFIRM_ACCEPT => $this->state_info->isActionAvailable(Action::ACCEPT),
108 Command::REJECT, Command::CONFIRM_REJECT => $this->state_info->isActionAvailable(Action::REJECT)
109 };
110 }
111
112 protected function view(): void
113 {
114 $content = $this->content_factory->getInfoContent($this->ref_id, $this->obj_id, $this->type, $this->state_info);
115 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->show($content));
116 exit;
117 }
118
119 protected function block(): void
120 {
121 $this->state_changer->block($this->obj_id);
122 $this->showSuccessMessageAfterRedirect(Action::BLOCK);
123 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($this->link_to_parent));
124 exit;
125 }
126
127 protected function unblock(): void
128 {
129 $this->state_changer->unblock($this->obj_id);
130 $this->showSuccessMessageAfterRedirect(Action::UNBLOCK);
131 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($this->link_to_parent));
132 exit;
133 }
134
135 protected function publish(): void
136 {
137 $this->state_changer->publish($this->obj_id, $this->type);
138 $this->showSuccessMessageAfterRedirect(Action::PUBLISH);
139 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($this->link_to_parent));
140 exit;
141 }
142
143 protected function withdraw(): void
144 {
145 $content = $this->content_factory->getConfirmationContent(
146 $this->ref_id,
147 $this->obj_id,
148 $this->type,
149 Action::WITHDRAW,
150 $this->object_handler->isOnlyReference($this->ref_id)
151 );
152 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->show($content));
153 exit;
154 }
155
156 protected function confirmWithdraw(): void
157 {
158 $this->state_changer->withdraw($this->obj_id);
159
160 $this->showSuccessMessageAfterRedirect(Action::WITHDRAW);
161 $link = $this->getRedirectTargetAfterDeletion($this->publishing_settings->getContainerRefIDForPublishing());
162 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($link));
163 exit;
164 }
165
166 protected function submit(): void
167 {
168 $this->state_changer->submit($this->obj_id);
169 $this->showSuccessMessageAfterRedirect(Action::SUBMIT);
170 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($this->link_to_parent));
171 exit;
172 }
173
174 protected function accept(): void
175 {
176 $content = $this->content_factory->getConfirmationContent(
177 $this->ref_id,
178 $this->obj_id,
179 $this->type,
180 Action::ACCEPT,
181 $this->object_handler->isOnlyReference($this->ref_id)
182 );
183 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->show($content));
184 exit;
185 }
186
187 protected function confirmAccept(): void
188 {
189 $this->state_changer->accept($this->obj_id, $this->type);
190
191 $this->showSuccessMessageAfterRedirect(Action::ACCEPT);
192 $link = $this->getRedirectTargetAfterDeletion($this->publishing_settings->getContainerRefIDForEditorialStep());
193 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($link));
194 exit;
195 }
196
197 protected function reject(): void
198 {
199 $content = $this->content_factory->getConfirmationContent(
200 $this->ref_id,
201 $this->obj_id,
202 $this->type,
204 $this->object_handler->isOnlyReference($this->ref_id)
205 );
206 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->show($content));
207 exit;
208 }
209
210 protected function confirmReject(): void
211 {
212 $this->state_changer->reject($this->obj_id);
213
215 $link = $this->getRedirectTargetAfterDeletion($this->publishing_settings->getContainerRefIDForEditorialStep());
216 echo $this->ui_renderer->renderAsync($this->ui_factory->prompt()->state()->redirect($link));
217 exit;
218 }
219
220 protected function getRedirectTargetAfterDeletion(int $fallback_ref_id): URI
221 {
222 if ($this->object_handler->doesReferenceExist($this->ref_id)) {
223 return $this->link_to_parent;
224 }
225 return $this->static_url->builder()->build('cat', $this->data_factory->refId($fallback_ref_id));
226 }
227
228 protected function showSuccessMessageAfterRedirect(Action $action): void
229 {
230 $this->tpl->setOnScreenMessage(
232 $this->content_factory->getSuccessMessage($action),
233 true
234 );
235 }
236}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Class Services.
Definition: Services.php:38
__construct(protected URI $link_to_parent, protected ilCtrlInterface $ctrl, protected ilGlobalTemplateInterface $tpl, protected UIFactory $ui_factory, protected UIRenderer $ui_renderer, protected RequestParserInterface $request_parser, protected ContentFactoryInterface $content_factory, protected PresentationUtilities $presentation_utilities, protected StateInfoFetcherInterface $state_info_fetcher, protected PublisherInterface $state_changer, protected PublishingSettings $publishing_settings, protected StaticURL $static_url, protected DataFactory $data_factory, protected ObjectHandler $object_handler)
isCommandAvailable(Command $cmd)
Includes access checks via StateInfo.
exit
$static_url
Definition: goto.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...