ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Agreement.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
34 use ilSession;
41 use Closure;
42 
43 final class Agreement implements AgreementInterface
44 {
48  public function __construct(
49  private readonly User $user,
50  private readonly Settings $settings,
51  private readonly UI $ui,
52  private readonly Routing $routing,
53  private readonly Closure $with_request
54  ) {
55  }
56 
57  public function showAgreement(string $gui, string $cmd): PageFragment
58  {
59  $title = 'accept_usr_agreement_anonymous';
60  $info = 'accept_usr_agreement_anonymous_intro';
61  if ($this->user->isLoggedIn()) {
62  $title = 'usr_agreement';
63  $info = 'usr_agreement_footer_intro';
64  }
65  return (new PageContent($this->ui->txt($title), [$this->showDocument()]))->withOnScreenMessage('info', $this->ui->txt($info));
66  }
67 
68  public function showAgreementForm(string $gui, string $cmd): PageFragment
69  {
70  $form = $this->user->matchingDocument()->isOk() ?
71  $this->agreementForm($gui, $cmd) :
72  $this->ui->create()->divider()->horizontal();
73 
74  $content = (new PageContent($this->ui->txt('accept_usr_agreement'), [
75  $this->showDocument(),
76  $form,
77  $this->logoutLink(),
78  ]));
79 
80  return $this->user->matchingDocument()->isOk() ?
81  $content->withOnScreenMessage('info', $this->ui->txt('accept_usr_agreement_intro')) :
82  $content;
83  }
84 
85  public function needsToAgree(): bool
86  {
87  return !$this->user->cannotAgree()
88  && $this->user->needsToAcceptNewDocument();
89  }
90 
91  private function showDocument(): Component
92  {
93  return $this->user
94  ->matchingDocument()
95  ->map(fn(Document $document) => $this->ui->create()->legacy($document->content()->value()))
96  ->except(fn() => new Ok($this->ui->create()->legacy(sprintf(
97  $this->ui->txt('no_agreement_description'),
99  ))))->value();
100  }
101 
102  private function agreementForm(string $gui, string $cmd): Component
103  {
104  $url = $this->routing->ctrl()->getFormActionByClass($gui, $cmd);
105  $form = $this->ui->create()->input()->container()->form()->standard($url, [
106  'accept?' => $this->ui->create()->input()->field()->radio($this->ui->txt('accept_usr_agreement'))
107  ->withOption('yes', $this->ui->txt('accept_usr_agreement_btn'))
108  ->withOption('no', $this->ui->txt('deny_usr_agreement_btn'))
109  ]);
110 
111  return ($this->with_request)($form, function (array $data) {
112  $accept = $data['accept?'] ?? '';
113  if ($accept === 'no') {
114  $this->routing->ctrl()->redirectToURL($this->routing->logoutUrl());
115  } elseif ($accept === 'yes') {
116  $this->user->acceptMatchingDocument();
117  $this->routing->redirectToOriginalTarget();
118  }
119  });
120  }
121 
122  private function logoutLink(): Component
123  {
124  return $this->ui->create()->button()->standard($this->ui->txt('logout'), $this->routing->logoutUrl());
125  }
126 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static prepareFormOutput($a_str, bool $a_strip=false)
$accept
Definition: ltiservices.php:66
__construct(private readonly User $user, private readonly Settings $settings, private readonly UI $ui, private readonly Routing $routing, private readonly Closure $with_request)
Definition: Agreement.php:48
static getMailsToAddress()
Get mailto: emails.
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
$url
Definition: ltiregstart.php:35