ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SelfRegistration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32use ilObjUser;
35use Closure;
38
40{
41 private readonly Closure $create_input;
42
48 public function __construct(
49 private readonly string $id,
50 private readonly UI $ui,
51 private readonly User $user,
52 private readonly Provide $legal_documents,
53 private readonly Closure $render,
54 private readonly Closure $build_user,
55 ?Closure $create_input = null
56 ) {
57 $this->create_input = $create_input ?? fn(string $class, ...$args) => new $class(...$args);
58 }
59
60 public function legacyInputGUIs(): array
61 {
62 return $this->user->matchingDocument()->map($this->guis(...))->except(fn() => new Ok([]))->value();
63 }
64
65 public function saveLegacyForm(ilPropertyFormGUI $form): bool
66 {
67 if ($this->user->matchingDocument()->isError()) {
68 $this->ui->loadLanguageModule($this->id);
69 $this->ui->loadLanguageModule('ldoc');
70 $this->ui->mainTemplate()->setOnScreenMessage('failure', sprintf(
71 $this->ui->txt('account_reg_not_possible'),
73 ), true);
74 return false;
75 }
76 $input = $form->getItemByPostVar($this->checkboxVariableName());
77 if ($input && !$form->getInput($this->checkboxVariableName())) {
78 $input->setAlert($this->ui->txt('force_accept_usr_agreement'));
79 return false;
80 }
81
82 return true;
83 }
84
85 public function userCreation(ilObjUser $user): void
86 {
87 // This will accept the document as the USER and NOT as anonymous. If the document is different thats not handled.
88 $user = ($this->build_user)($user);
89 try {
90 $user->acceptMatchingDocument();
91 } catch (NotOKException) {
92 $user->acceptAnyDocument();
93 }
94 }
95
99 private function guis(Document $document): array
100 {
101 $header = ($this->create_input)(ilFormSectionHeaderGUI::class);
102 $header->setTitle($this->ui->txt('usr_agreement'));
103
104 $doc = ($this->create_input)(ilCustomInputGUI::class);
105 $document_content = ($this->render)($this->legal_documents->document()->contentAsComponent($document->content()));
106 $doc->setHtml(sprintf('<div id="%s_agreement">%s</div>', htmlentities($this->id), $document_content));
107
108 $checkbox = ($this->create_input)(ilCheckboxInputGUI::class, $this->ui->txt('accept_usr_agreement'), $this->checkboxVariableName());
109 $checkbox->setRequired(true);
110 $checkbox->setValue('1');
111
112 return [$header, $doc, $checkbox];
113 }
114
115 private function checkboxVariableName(): string
116 {
117 return 'accept_' . $this->id;
118 }
119}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Signals that a result contains no value.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
__construct(private readonly string $id, private readonly UI $ui, private readonly User $user, private readonly Provide $legal_documents, private readonly Closure $render, private readonly Closure $build_user, ?Closure $create_input=null)
This class represents a checkbox property in a property form.
This class represents a custom property in a property form.
This class represents a property in a property form.
This class represents a section header in a property form.
static prepareFormOutput($a_str, bool $a_strip=false)
User class.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
static getMailsToAddress()
Get mailto: emails.
A component is the most general form of an entity in the UI.
Definition: Component.php:28