ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
WithdrawProcess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\LegalDocuments\ConsumerSlots\WithdrawProcess as WithdrawProcessInterface;
32use Closure;
33use ILIAS\Refinery\Factory as Refinery;
36
37final class WithdrawProcess implements WithdrawProcessInterface
38{
43 public function __construct(
44 private readonly User $user,
45 private readonly UI $ui,
46 private readonly Routing $routing,
47 private readonly Settings $settings,
48 private readonly Closure $query_parameter,
49 private readonly Provide $legal_documents,
50 private readonly Closure $after_user_withdrawal
51 ) {
52 }
53
54 public function showValidatePasswordMessage(): array
55 {
56 $status = $this->withdrawalRequested();
57 if ($status === null) {
58 return [];
59 }
60 $lng = 'withdraw_consent_description_' . ($status === 'external' ? 'external' : 'internal');
61
62 return [
63 $this->ui->create()->divider()->horizontal(),
64 $this->ui->create()->legacy()->content($this->ui->txt($lng))
65 ];
66 }
67
68 public function isOnGoing(): bool
69 {
70 return $this->user->withdrawalRequested()->value();
71 }
72
73 private function withdrawalRequested(): ?string
74 {
75 if ($this->user->cannotAgree() || $this->user->neverAgreed()) {
76 return null;
77 }
78
79 $this->user->withdrawalRequested()->update(true);
80
81 $external = $this->user->isExternalAccount();
82
83 return $external ? 'external' : 'internal';
84 }
85
86 public function withdrawalFinished(): void
87 {
88 $type = $this->query('tos_withdrawal_type');
89
90 $this->ui->mainTemplate()->setOnScreenMessage('info', match ($type) {
91 'delete_user' => $this->ui->txt('withdrawal_complete_deleted'),
92 'external' => $this->ui->txt('withdrawal_complete_redirect'),
93 null, 'default' => $this->ui->txt('withdrawal_complete'),
94 });
95 }
96
97 public function showWithdraw(string $gui, string $cmd): PageFragment
98 {
99 return match ($cmd) {
100 'indeed' => $this->withdraw(),
101 'cancel' => $this->cancelWithdrawal(),
102 '' => $this->showWithdrawConfirmation($gui, $cmd),
103 };
104 }
105
106 private function withdraw(): void
107 {
108 $this->user->agreeDate()->update(null);
109 $this->user->withdrawalRequested()->update(false);
110
111 $withdrawal_type = 'default';
112 if ($this->user->isLDAPUser()) {
113 $this->sendMail();
114 $withdrawal_type = 'external';
115 } elseif ($this->settings->deleteUserOnWithdrawal()->value()) {
116 $this->user->raw()->delete();
117 $withdrawal_type = 'delete_user';
118 }
119
120 ($this->after_user_withdrawal)();
121
122 $this->legal_documents->withdrawal()->finishAndLogout(['tos_withdrawal_type' => $withdrawal_type]);
123 }
124
125 private function cancelWithdrawal(): void
126 {
127 $this->user->withdrawalRequested()->update(false);
128 $this->routing->redirectToOriginalTarget();
129 }
130
131 private function showWithdrawConfirmation(string $gui, string $cmd): PageFragment
132 {
133 $title = $this->ui->txt('refuse_acceptance');
134
135 if ($this->user->isLDAPUser()) {
136 return new PageContent($title, [
137 $this->ui->create()->panel()->standard($this->ui->txt('withdraw_usr_agreement'), [
138 $this->confirmation($gui),
139 $this->ui->create()->divider()->horizontal(),
140 $this->ui->create()->legacy()->content(nl2br($this->user->format($this->ui->txt('withdrawal_mail_info') . $this->ui->txt('withdrawal_mail_text'))))
141 ])
142 ]);
143 }
144
145 $deletion = $this->settings->deleteUserOnWithdrawal()->value() ? '_deletion' : '';
146 return new PageContent($title, [$this->confirmation($gui, $deletion)]);
147 }
148
149 private function confirmation(string $gui, string $add_to_question = ''): Component
150 {
151 $lng_suffix = $this->user->neverAgreed() ? '_no_consent_yet' : '';
152 $question = 'withdrawal_sure_account' . $add_to_question . $lng_suffix;
153
154 return $this->ui->create()->messageBox()->confirmation($this->ui->txt($question))->withButtons([
155 $this->ui->create()->button()->standard(
156 $this->ui->txt('confirm'),
157 $this->routing->ctrl()->getLinkTargetByClass($gui, 'indeed')
158 ),
159 $this->ui->create()->button()->standard(
160 $this->ui->txt('cancel'),
161 $this->routing->ctrl()->getLinkTargetByClass($gui, 'cancel')
162 ),
163 ]);
164 }
165
166 private function sendMail(): void
167 {
168 $mail = new Mail();
169 $mail->setRecipients([$this->settings->adminEmail()->value()]);
170 $mail->sendGeneric($this->ui->txt('withdrawal_mail_subject'), $this->user->format($this->ui->txt('withdrawal_mail_text')));
171 }
172
173 private function query(string $query_parameter): ?string
174 {
175 return ($this->query_parameter)($query_parameter, fn(Refinery $r) => $r->byTrying([
176 $r->null(),
177 $r->to()->string(),
178 ]));
179 }
180}
Builds data types.
Definition: Factory.php:36
__construct(private readonly User $user, private readonly UI $ui, private readonly Routing $routing, private readonly Settings $settings, private readonly Closure $query_parameter, private readonly Provide $legal_documents, private readonly Closure $after_user_withdrawal)
A transformation is a function from one datatype to another.
A component is the most general form of an entity in the UI.
Definition: Component.php:28
RFC 822 Email address list validation Utility.
global $lng
Definition: privfeed.php:31