ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
WithdrawProcess.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 use ilSession;
34 use Closure;
37 use ilStartUpGUI;
38 
40 {
45  public function __construct(
46  private readonly User $user,
47  private readonly UI $ui,
48  private readonly Routing $routing,
49  private readonly Settings $settings,
50  private readonly Closure $query_parameter,
51  private readonly Provide $legal_documents,
52  private readonly Closure $after_user_withdrawal
53  ) {
54  }
55 
56  public function showValidatePasswordMessage(): array
57  {
58  $status = $this->query('withdrawal_relogin_content');
59  $lng = 'withdraw_consent_description_' . ($status === 'external' ? 'external' : 'internal');
60 
61  return [
62  $this->ui->create()->divider()->horizontal(),
63  $this->ui->create()->legacy($this->ui->txt($lng))
64  ];
65  }
66 
67  public function isOnGoing(): bool
68  {
69  return $this->user->withdrawalRequested()->value();
70  }
71 
72  public function withdrawalRequested(): void
73  {
74  if ($this->user->cannotAgree() || $this->user->neverAgreed()) {
75  return;
76  }
77 
78  $this->user->withdrawalRequested()->update(true);
79 
80  $external = $this->user->isExternalAccount();
81 
82  $this->routing->ctrl()->setParameterByClass(ilStartUpGUI::class, 'withdrawal_relogin_content', $external ? 'external' : 'internal');
83  }
84 
85  public function withdrawalFinished(): void
86  {
87  $type = $this->query('tos_withdrawal_type');
88 
89  $this->ui->mainTemplate()->setOnScreenMessage('info', match ($type) {
90  'delete_user' => $this->ui->txt('withdrawal_complete_deleted'),
91  'external' => $this->ui->txt('withdrawal_complete_redirect'),
92  null, 'default' => $this->ui->txt('withdrawal_complete'),
93  });
94  }
95 
96  public function showWithdraw(string $gui, string $cmd): PageFragment
97  {
98  return match ($cmd) {
99  'indeed' => $this->withdraw(),
100  'cancel' => $this->cancelWithdrawal(),
101  '' => $this->showWithdrawConfirmation($gui, $cmd),
102  };
103  }
104 
105  private function withdraw(): void
106  {
107  $this->user->agreeDate()->update(null);
108  $this->user->withdrawalRequested()->update(false);
109 
110  $withdrawal_type = 'default';
111  if ($this->user->isLDAPUser()) {
112  $this->sendMail();
113  $withdrawal_type = 'external';
114  } elseif ($this->settings->deleteUserOnWithdrawal()->value()) {
115  $this->user->raw()->delete();
116  $withdrawal_type = 'delete_user';
117  }
118 
119  ($this->after_user_withdrawal)();
120 
121  $this->legal_documents->withdrawal()->finishAndLogout(['tos_withdrawal_type' => $withdrawal_type]);
122  }
123 
124  private function cancelWithdrawal(): void
125  {
126  $this->user->withdrawalRequested()->update(false);
127  $this->routing->redirectToOriginalTarget();
128  }
129 
130  private function showWithdrawConfirmation(string $gui, string $cmd): PageFragment
131  {
132  $title = $this->ui->txt('refuse_acceptance');
133 
134  if ($this->user->isLDAPUser()) {
135  return new PageContent($title, [
136  $this->ui->create()->panel()->standard($this->ui->txt('withdraw_usr_agreement'), [
137  $this->confirmation($gui),
138  $this->ui->create()->divider()->horizontal(),
139  $this->ui->create()->legacy(nl2br($this->user->format($this->ui->txt('withdrawal_mail_info') . $this->ui->txt('withdrawal_mail_text'))))
140  ])
141  ]);
142  }
143 
144  $deletion = $this->settings->deleteUserOnWithdrawal()->value() ? '_deletion' : '';
145  return new PageContent($title, [$this->confirmation($gui, $deletion)]);
146  }
147 
148  private function confirmation(string $gui, string $add_to_question = ''): Component
149  {
150  $lng_suffix = $this->user->neverAgreed() ? '_no_consent_yet' : '';
151  $question = 'withdrawal_sure_account' . $add_to_question . $lng_suffix;
152 
153  return $this->ui->create()->messageBox()->confirmation($this->ui->txt($question))->withButtons([
154  $this->ui->create()->button()->standard(
155  $this->ui->txt('confirm'),
156  $this->routing->ctrl()->getLinkTargetByClass($gui, 'indeed')
157  ),
158  $this->ui->create()->button()->standard(
159  $this->ui->txt('cancel'),
160  $this->routing->ctrl()->getLinkTargetByClass($gui, 'cancel')
161  ),
162  ]);
163  }
164 
165  private function sendMail(): void
166  {
167  $mail = new Mail();
168  $mail->setRecipients([$this->settings->adminEmail()->value()]);
169  $mail->sendGeneric($this->ui->txt('withdrawal_mail_subject'), $this->user->format($this->ui->txt('withdrawal_mail_text')));
170  }
171 
172  private function refuseContent($components): PageFragment
173  {
174  return new PageContent($this->ui->txt('refuse_tos_acceptance'), $components);
175  }
176 
177  private function query(string $query_parameter): ?string
178  {
179  return ($this->query_parameter)($query_parameter, fn(Refinery $r) => $r->byTrying([
180  $r->null(),
181  $r->to()->string(),
182  ]));
183  }
184 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
__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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lng
RFC 822 Email address list validation Utility.
$r