ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilCmiXapiRegistrationGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
16{
17 const CMD_SHOW_FORM = 'showForm';
18 const CMD_SAVE_FORM = 'saveForm';
19 const CMD_CANCEL = 'cancel';
20
22
26 protected $object;
27
31 protected $cmixUser;
32
38 {
39 global $DIC; /* @var \ILIAS\DI\Container $DIC */
40
41 $this->object = $object;
42
43 $this->cmixUser = new ilCmiXapiUser($object->getId(), $DIC->user()->getId(), $object->getPrivacyIdent());
44 }
45
46 public function executeCommand()
47 {
48 global $DIC; /* @var \ILIAS\DI\Container $DIC */
49
50 switch ($DIC->ctrl()->getNextClass()) {
51 default:
52 $command = $DIC->ctrl()->getCmd(self::DEFAULT_CMD) . 'Cmd';
53 $this->{$command}();
54 }
55 }
56
57 protected function cancelCmd()
58 {
59 global $DIC; /* @var \ILIAS\DI\Container $DIC */
60
61 $DIC->ctrl()->redirectByClass(ilObjCmiXapiGUI::class, ilObjCmiXapiGUI::CMD_INFO_SCREEN);
62 }
63
64 protected function showFormCmd(ilPropertyFormGUI $form = null)
65 {
66 global $DIC; /* @var \ILIAS\DI\Container $DIC */
67
68 if ($form === null) {
69 $form = $this->buildForm();
70 }
71
72 $DIC->ui()->mainTemplate()->setContent($form->getHTML());
73 }
74
75 protected function saveFormCmd()
76 {
77 global $DIC; /* @var \ILIAS\DI\Container $DIC */
78
79 $form = $this->buildForm();
80
81 if (!$form->checkInput()) {
82 $form->setValuesByPost();
83 $this->showFormCmd($form);
84 return;
85 }
86
87 $this->saveRegistration($form);
88
89 ilUtil::sendSuccess($DIC->language()->txt('registration_saved_successfully'), true);
90 $DIC->ctrl()->redirectByClass(ilObjCmiXapiGUI::class, ilObjCmiXapiGUI::CMD_INFO_SCREEN);
91 }
92
96 protected function buildForm()
97 {
98 global $DIC; /* @var \ILIAS\DI\Container $DIC */
99
100 $form = new ilPropertyFormGUI();
101
102 $form->setFormAction($DIC->ctrl()->getFormAction($this, self::CMD_SHOW_FORM));
103
104 if (!$this->hasRegistration()) {
105 $form->setTitle($DIC->language()->txt('form_create_registration'));
106 $form->addCommandButton(self::CMD_SAVE_FORM, $DIC->language()->txt('btn_create_registration'));
107 } else {
108 $form->setTitle($DIC->language()->txt('form_change_registration'));
109 $form->addCommandButton(self::CMD_SAVE_FORM, $DIC->language()->txt('btn_change_registration'));
110 }
111
112 $form->addCommandButton(self::CMD_CANCEL, $DIC->language()->txt('cancel'));
113
114 $userIdent = new ilEMailInputGUI($DIC->language()->txt('field_user_ident'), 'user_ident');
115 $userIdent->setInfo($DIC->language()->txt('field_user_ident_info'));
116 $userIdent->setRequired(true);
117 $userIdent->setValue($this->cmixUser->getUsrIdent());
118 $form->addItem($userIdent);
119
120 return $form;
121 }
122
123 protected function hasRegistration()
124 {
125 return strlen($this->cmixUser->getUsrIdent());
126 }
127
128 protected function saveRegistration(ilPropertyFormGUI $form)
129 {
130 $this->cmixUser->setUsrIdent($form->getInput('user_ident'));
131 $this->cmixUser->save();
132 }
133}
An exception for terminatinating execution or to throw for unit testing.
saveRegistration(ilPropertyFormGUI $form)
__construct(ilObjCmiXapi $object)
ilCmiXapiRegistrationGUI constructor.
showFormCmd(ilPropertyFormGUI $form=null)
This class represents a email property in a property form.
This class represents a property form user interface.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
$DIC
Definition: xapitoken.php:46