ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ModifyFooter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ilLink;
32 use ilTemplate;
33 use Closure;
35 
36 final class ModifyFooter
37 {
42  public function __construct(
43  private readonly UI $ui,
44  private readonly User $user,
45  private readonly Provide $legal_documents,
46  private readonly Closure $render,
47  private readonly Closure $create_template,
48  private readonly ?Closure $goto_link,
49  ) {
50  }
51 
52  public function __invoke(Closure $footer): Closure
53  {
54  return $this->user->acceptedVersion()->map(
55  fn($document) => $this->footer($footer, $this->renderModal($document))
56  )->except(
57  fn() => new Ok(
58  !$this->goto_link || $this->user->isLoggedIn() ?
59  $footer :
60  $this->footer($footer, ($this->goto_link)())
61  )
62  )->value();
63  }
64 
65  public function renderModal(DocumentContent $content): Modal
66  {
67  return $this->ui->create()->modal()->roundtrip($content->title(), [
68  $this->ui->create()->legacy($this->ui->txt('usr_agreement_footer_intro')),
69  $this->ui->create()->divider()->horizontal(),
70  $this->legal_documents->document()->contentAsComponent($content),
71  $this->ui->create()->divider()->horizontal(),
72  $this->withdrawalButton(),
73  ]);
74  }
75 
76  public function withdrawalButton(): Component
77  {
78  $template = ($this->create_template)('withdrawal-section.html');
79  $template->setVariable('TXT_WITHDRAWAL_HEADLINE', $this->ui->txt('withdraw_consent_header'));
80  $template->setVariable('TXT_WITHDRAWAL', $this->ui->txt('withdraw_consent_description'));
81  $template->setVariable(
82  'BTN_WITHDRAWAL',
83  ($this->render)(
84  $this->ui->create()->button()->standard($this->ui->txt('withdraw_consent'), $this->legal_documents->withdrawal()->beginProcessURL())
85  )
86  );
87 
88  return $this->ui->create()->legacy($template->get());
89  }
90 
94  private function footer(Closure $footer, object $value): Closure
95  {
96  return $footer($this->legal_documents->id(), $this->ui->txt('usr_agreement'), $value);
97  }
98 }
This describes commonalities between the different modals.
Definition: Modal.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16
__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,)