ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ViewConfiguration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
31use ILIAS\UI\Component\Button\Standard as StandardButton;
32use ILIAS\UI\Factory as UIFactory;
35
37{
38 private const array PARAMETER_NAMESPACE = ['q', 'vc'];
39 private const string CONFIGURATION_TOKEN_STRING = 'c';
40
41 private readonly URLBuilder $url_builder;
43
44 private readonly array $current_configuration;
45
46 public function __construct(
47 private readonly Language $lng,
48 private readonly Refinery $refinery,
49 private readonly UIFactory $ui_factory,
50 RequestWrapper $query_wrapper,
52 private readonly \ilToolbarGUI $toolbar
53 ) {
54 [
58 self::PARAMETER_NAMESPACE,
59 self::CONFIGURATION_TOKEN_STRING
60 );
61
62 $this->current_configuration = $query_wrapper->retrieve(
63 $this->configuration_token->getName(),
64 $this->refinery->custom()->transformation(
65 function (mixed $values): array {
67 DefaultView::getIdentifier()
68 ];
69 if (!is_array($values)) {
71 }
72
73 $available_capabilities = [
74 AsyncView::getIdentifier(),
75 DefaultView::getIdentifier(),
76 TextFeedback::getIdentifier(),
77 SuggestedLearningContent::getIdentifier(),
78 MarkingAllowingPartialPoints::getIdentifier()
79 ];
80
81 return array_reduce(
82 $values,
83 function (array $c, string $v) use ($available_capabilities): array {
84 if ($v === AsyncView::getIdentifier()
85 || $v === DefaultView::getIdentifier()) {
86 $c = array_filter(
87 $c,
88 fn(string $v): bool => $v !== DefaultView::getIdentifier()
89 && $v !== AsyncView::getIdentifier()
90 );
91 }
92
93 if (in_array($v, $available_capabilities)
94 && !in_array($v, $c)) {
95 $c[] = $v;
96 }
97
98 return $c;
99 },
101 );
102 }
103 )
104 );
105 }
106
107 public function isAsync(): bool
108 {
109 return in_array(
110 AsyncView::getIdentifier(),
111 $this->current_configuration
112 );
113 }
114
115 public function getCurrentConfiguration(): array
116 {
118 }
119
122 ): URLBuilder {
123 if ($url_builder !== null) {
124 [
128 self::PARAMETER_NAMESPACE,
129 self::CONFIGURATION_TOKEN_STRING
130 );
131 } else {
134 }
135
138 $this->current_configuration
139 );
140 }
141
142 public function initializeToolbar(): void
143 {
144 $configuration_without_view = array_filter(
145 $this->current_configuration,
146 fn(string $v): bool => $v !== DefaultView::getIdentifier() && $v !== AsyncView::getIdentifier()
147 );
148 $this->toolbar->addComponent(
149 $this->ui_factory->viewControl()->mode(
150 [
151 $this->lng->txt('default_view') => $this->url_builder->withParameter(
152 $this->configuration_token,
153 [...$configuration_without_view, DefaultView::getIdentifier()]
154 )->buildURI()->__toString(),
155 $this->lng->txt('async_view') => $this->url_builder->withParameter(
156 $this->configuration_token,
157 [...$configuration_without_view, AsyncView::getIdentifier()]
158 )->buildURI()->__toString()
159 ],
160 $this->lng->txt('select_view')
161 )->withActive(
162 in_array(DefaultView::getIdentifier(), $this->current_configuration)
163 ? $this->lng->txt('default_view')
164 : $this->lng->txt('async_view')
165 ),
166 );
167
168 $this->toolbar->addComponent(
169 $this->buildToolbarButton(
170 MarkingAllowingPartialPoints::getIdentifier()
171 )
172 );
173
174 $this->toolbar->addComponent(
175 $this->buildToolbarButton(
176 TextFeedback::getIdentifier()
177 )
178 );
179
180 $this->toolbar->addComponent(
181 $this->buildToolbarButton(
182 SuggestedLearningContent::getIdentifier()
183 )
184 );
185 }
186
187 private function buildToolbarButton(
188 string $identifier
189 ): StandardButton {
190 $capability_activated = in_array($identifier, $this->current_configuration);
191 $filtered_configuration = array_filter(
192 $this->current_configuration,
193 fn(string $v): bool => $v !== $identifier
194 );
195
196 return $this->ui_factory->button()->standard(
197 $this->buildButtonLabel($identifier, $capability_activated),
198 $this->url_builder->withParameter(
199 $this->configuration_token,
200 $capability_activated
201 ? $filtered_configuration
202 : [...$filtered_configuration, $identifier]
203 )->buildURI()->__toString()
204 );
205 }
206
207 private function buildButtonLabel(
208 string $identifier,
209 bool $enabled
210 ): string {
211 $identifier_lng_string = strtolower($identifier);
212
213 return $enabled
214 ? $this->lng->txt("disable_{$identifier_lng_string}")
215 : $this->lng->txt("enable_{$identifier_lng_string}");
216 }
217}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
getURLBuilderWithPreservedConfigurationParameter(?URLBuilder $url_builder=null)
__construct(private readonly Language $lng, private readonly Refinery $refinery, private readonly UIFactory $ui_factory, RequestWrapper $query_wrapper, URLBuilder $url_builder, private readonly \ilToolbarGUI $toolbar)
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166
acquireParameter(array $namespace, string $name, ?string $initial_value=null)
Add a new parameter with a namespace and get its token for subsequent changes.
Definition: URLBuilder.php:119
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface RequestWrapper.
retrieve(string $key, Transformation $transformation)
This describes a standard button.
Definition: Standard.php:27
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))