ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Blocks.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
37use Closure;
38use ilObjUser;
39use ilDateTime;
41use DateTimeImmutable;
42use ILIAS\Data\Factory as DataFactory;
43use ilStartUpGUI;
47
48class Blocks
49{
51 private readonly Closure $format_date;
53 private readonly Closure $mail_contact;
54
59 public function __construct(
60 private readonly string $id,
61 private readonly Container $container,
62 private readonly Provide $provide,
63 ?Closure $format_date = null,
64 ?Closure $mail_contact = null
65 ) {
66 $this->format_date = $format_date ?? fn(DateTimeImmutable $date): string => ilDatePresentation::formatDate(
67 new ilDateTime($date->getTimestamp(), IL_CAL_UNIX)
68 );
70 }
71
72 public function slot(): Slot
73 {
74 return new Slot(
75 $this->id,
76 $this,
77 $this->provide,
78 $this->container
79 );
80 }
81
83 {
84 return new DefaultMappings($this->id, $this->container);
85 }
86
87 public function marshal(): Marshal
88 {
89 return new Marshal($this->container->refinery());
90 }
91
93 {
94 return new SelectSetting($store, $this->marshal());
95 }
96
97 public function readOnlyStore(KeyValueStore $store): KeyValueStore
98 {
99 return new ReadOnlyStore($store);
100 }
101
102 public function globalStore(): KeyValueStore
103 {
104 return new ILIASSettingStore($this->container->settings());
105 }
106
107 public function userStore(ilObjUser $user): KeyValueStore
108 {
109 return new UserPreferenceStore($user);
110 }
111
112 public function sessionStore(): KeyValueStore
113 {
114 return new SessionStore();
115 }
116
117 public function ui(): UI
118 {
119 return new UI($this->id, $this->container->ui(), $this->container->language());
120 }
121
122 public function user(Settings $global_settings, UserSettings $user_settings, ilObjUser $user): User
123 {
124 return new User($user, $global_settings, $user_settings, $this->provide, (new DataFactory())->clock()->system());
125 }
126
127 public function routing(): Routing
128 {
129 return new Routing(
130 $this->container->ctrl(),
131 $this->selectSettingsFrom($this->sessionStore()),
134 );
135 }
136
140 public function retrieveQueryParameter(string $key, Closure $select)
141 {
142 return $this->container->http()->wrapper()->query()->retrieve($key, $select($this->container->refinery()));
143 }
144
145 public function userManagementAgreeDateField(callable $build_user, string $lang_key, ?string $module = null): Closure
146 {
147 return function (ilObjUser $user) use ($build_user, $lang_key, $module) {
148 if ($module) {
149 $this->container->language()->loadLanguageModule($module);
150 }
151 $this->container->language()->loadLanguageModule('ldoc');
152 $user = $build_user($user);
153
154 $value = $user->acceptedVersion()->map(function (DocumentContent $content) use ($lang_key, $user): array {
155 $input = new ilNonEditableValueGUI($this->ui()->txt($lang_key), $lang_key);
156 $input->setValue($this->formatDate($user->agreeDate()->value()));
157 $modal = $this->ui()->create()->modal()->lightbox([
158 $this->ui()->create()->modal()->lightboxTextPage($content->value(), $content->title())
159 ]);
160
161 $titleLink = $this->ui()->create()->button()->shy($content->title(), '#')->withOnClick($modal->getShowSignal());
162 $sub = new ilNonEditableValueGUI($this->ui()->txt('agreement_document'), '', true);
163 $sub->setValue($this->container->ui()->renderer()->render($titleLink));
164 $input->addSubItem($sub);
165
166 return [$input, $modal];
167 })->except(fn() => new Ok($this->ui()->txt('never')))->value();
168
169 return [$lang_key => $value];
170 };
171 }
172
176 public function withRequest(Form $form, Closure $then): Form
177 {
178 if ($this->container->http()->request()->getMethod() !== 'POST') {
179 return $form;
180 }
181
182 $form = $form->withRequest($this->container->http()->request());
183 $data = $form->getData();
184
185 if ($data) {
186 $then($data);
187 }
188
189 return $form;
190 }
191
192 public function notAvailable(): PageFragment
193 {
194 return new PageContent($this->ui()->txt('accept_usr_agreement_anonymous'), [
195 $this->container->ui()->factory()->legacy()->content(sprintf(
196 $this->ui()->txt('no_agreement_description'),
197 'mailto:' . htmlspecialchars(($this->mail_contact)(), ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8')
198 )),
199 ]);
200 }
201
202 private function formatDate(?DateTimeImmutable $date): string
203 {
204 return $date ? ($this->format_date)($date) : '';
205 }
206}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Builds data types.
Definition: Factory.php:36
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
readOnlyStore(KeyValueStore $store)
Definition: Blocks.php:97
selectSettingsFrom(KeyValueStore $store)
Definition: Blocks.php:92
userManagementAgreeDateField(callable $build_user, string $lang_key, ?string $module=null)
Definition: Blocks.php:145
__construct(private readonly string $id, private readonly Container $container, private readonly Provide $provide, ?Closure $format_date=null, ?Closure $mail_contact=null)
Definition: Blocks.php:59
formatDate(?DateTimeImmutable $date)
Definition: Blocks.php:202
withRequest(Form $form, Closure $then)
Definition: Blocks.php:176
retrieveQueryParameter(string $key, Closure $select)
Definition: Blocks.php:140
user(Settings $global_settings, UserSettings $user_settings, ilObjUser $user)
Definition: Blocks.php:122
const IL_CAL_UNIX
Class for date presentation.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
ILIAS Initialisation Utility Class perform basic setup: init database handler, load configuration fil...
static redirectToStartingPage(string $target='')
This class represents a non editable value in a property form.
User class.
@ilCtrl_Calls ilStartUpGUI: ilAccountRegistrationGUI, ilPasswordAssistanceGUI, ilLoginPageGUI,...
static logoutUrl(array $parameters=[])
Return the logout URL with a valid CSRF token.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getMailsToAddress()
Get mailto: emails.
A transformation is a function from one datatype to another.
withRequest(ServerRequestInterface $request)
Get a form like this where data from the request is attached.
getData()
Get the data in the form if all inputs are ok, where the transformation is applied if one was added.
This describes commonalities between all forms.
Definition: Form.php:33
modal(string $title="", string $cancel_label="")
$container
@noRector
Definition: wac.php:37