ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ModifyFooter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilLink;
31use ilTemplate;
32use Closure;
34
35final class ModifyFooter
36{
41 public function __construct(
42 private readonly UI $ui,
43 private readonly User $user,
44 private readonly Provide $legal_documents,
45 private readonly Closure $render,
46 private readonly Closure $create_template,
47 private readonly ?Closure $goto_link,
48 ) {
49 }
50
51 public function __invoke(Closure $footer): Closure
52 {
53 return $this->user->acceptedVersion()->map(
54 fn($document) => $this->footer($footer, $this->renderModal($document))
55 )->except(
56 fn() => new Ok(
57 !$this->goto_link || $this->user->isLoggedIn() ?
58 $footer :
59 $this->footer($footer, ($this->goto_link)())
60 )
61 )->value();
62 }
63
64 public function renderModal(DocumentContent $content): Modal
65 {
66 return $this->ui->create()->modal()->roundtrip($content->title(), [
67 $this->ui->create()->legacy()->content($this->ui->txt('usr_agreement_footer_intro')),
68 $this->ui->create()->divider()->horizontal(),
69 $this->legal_documents->document()->contentAsComponent($content),
70 $this->ui->create()->divider()->horizontal(),
71 $this->withdrawalButton(),
72 ]);
73 }
74
75 public function withdrawalButton(): Component
76 {
77 $template = ($this->create_template)('withdrawal-section.html');
78 $template->setVariable('TXT_WITHDRAWAL_HEADLINE', $this->ui->txt('withdraw_consent_header'));
79 $template->setVariable('TXT_WITHDRAWAL', $this->ui->txt('withdraw_consent_description'));
80 $template->setVariable(
81 'BTN_WITHDRAWAL',
82 ($this->render)(
83 $this->ui->create()->button()->standard($this->ui->txt('withdraw_consent'), $this->legal_documents->withdrawal()->beginProcessURL())
84 )
85 );
86
87 return $this->ui->create()->legacy()->content($template->get());
88 }
89
93 private function footer(Closure $footer, object $value): Closure
94 {
95 return $footer($this->legal_documents->id(), $this->ui->txt('usr_agreement'), $value);
96 }
97}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
__construct(private readonly UI $ui, private readonly User $user, private readonly Provide $legal_documents, private readonly Closure $render, private readonly Closure $create_template, private readonly ?Closure $goto_link,)
special template class to simplify handling of ITX/PEAR
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes commonalities between the different modals.
Definition: Modal.php:35