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