ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCmiXapiRegistrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31{
32 public const CMD_SHOW_FORM = 'showForm';
33 public const CMD_SAVE_FORM = 'saveForm';
34 public const CMD_CANCEL = 'cancel';
35
37
39
41 private \ilGlobalTemplateInterface $main_tpl;
42 private \ILIAS\DI\Container $dic;
43
48 {
49 global $DIC;
50 $this->dic = $DIC;
51 $this->main_tpl = $DIC->ui()->mainTemplate();
52
53 $this->object = $object;
54
55 $this->cmixUser = new ilCmiXapiUser($object->getId(), $DIC->user()->getId(), $object->getPrivacyIdent());
56 }
57
61 public function executeCommand(): void
62 {
63 global $DIC; /* @var \ILIAS\DI\Container $DIC */
64
65 switch ($DIC->ctrl()->getNextClass()) {
66 default:
67 $command = $DIC->ctrl()->getCmd(self::DEFAULT_CMD) . 'Cmd';
68 $this->{$command}();
69 }
70 }
71
75 protected function cancelCmd(): void
76 {
77 $this->dic->ctrl()->redirectByClass(ilObjCmiXapiGUI::class, ilObjCmiXapiGUI::CMD_INFO_SCREEN);
78 }
79
83 protected function showFormCmd(?ilPropertyFormGUI $form = null): void
84 {
85 if ($form === null) {
86 $form = $this->buildForm();
87 }
88
89 $this->main_tpl->setContent($form->getHTML());
90 }
91
95 protected function saveFormCmd(): void
96 {
97 $form = $this->buildForm();
98
99 if (!$form->checkInput()) {
100 $form->setValuesByPost();
101 $this->showFormCmd($form);
102 return;
103 }
104
105 $this->saveRegistration($form);
106
107 $this->main_tpl->setOnScreenMessage('success', $this->dic->language()->txt('registration_saved_successfully'), true);
108 $this->dic->ctrl()->redirectByClass(ilObjCmiXapiGUI::class, ilObjCmiXapiGUI::CMD_INFO_SCREEN);
109 }
110
114 protected function buildForm(): \ilPropertyFormGUI
115 {
116 $form = new ilPropertyFormGUI();
117
118 $form->setFormAction($this->dic->ctrl()->getFormAction($this, self::CMD_SHOW_FORM));
119
120 if (!$this->hasRegistration()) {
121 $form->setTitle($this->dic->language()->txt('form_create_registration'));
122 $form->addCommandButton(self::CMD_SAVE_FORM, $this->dic->language()->txt('btn_create_registration'));
123 } else {
124 $form->setTitle($this->dic->language()->txt('form_change_registration'));
125 $form->addCommandButton(self::CMD_SAVE_FORM, $this->dic->language()->txt('btn_change_registration'));
126 }
127
128 $form->addCommandButton(self::CMD_CANCEL, $this->dic->language()->txt('cancel'));
129
130 $userIdent = new ilEMailInputGUI($this->dic->language()->txt('field_user_ident'), 'user_ident');
131 $userIdent->setInfo($this->dic->language()->txt('field_user_ident_info'));
132 $userIdent->setRequired(true);
133 $userIdent->setValue($this->cmixUser->getUsrIdent());
134 $form->addItem($userIdent);
135
136 return $form;
137 }
138
139 protected function hasRegistration(): int
140 {
141 return strlen($this->cmixUser->getUsrIdent());
142 }
143
144 protected function saveRegistration(ilPropertyFormGUI $form): void
145 {
146 $this->cmixUser->setUsrIdent($form->getInput('user_ident'));
147 $this->cmixUser->save();
148 }
149}
showFormCmd(?ilPropertyFormGUI $form=null)
saveRegistration(ilPropertyFormGUI $form)
__construct(ilObjCmiXapi $object)
ilCmiXapiRegistrationGUI constructor.
This class represents a email property in a property form.
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-...
global $DIC
Definition: shib_login.php:26