ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceWithdrawalGUIHelper.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
6use Psr\Http\Message\RequestInterface;
7
13{
15 protected $lng;
17 protected $ctrl;
19 protected $setting;
21 protected $tpl;
23 protected $user;
25 protected $uiFactory;
27 protected $uiRenderer;
29 protected $tosHelper;
30
35 public function __construct(ilObjUser $subjectUser)
36 {
37 global $DIC;
38
39 $this->user = $subjectUser;
40
41 $this->lng = $DIC->language();
42 $this->ctrl = $DIC->ctrl();
43 $this->setting = $DIC->settings();
44 $this->tpl = $DIC->ui()->mainTemplate();
45 $this->uiFactory = $DIC->ui()->factory();
46 $this->uiRenderer = $DIC->ui()->renderer();
47 $this->tosHelper = new ilTermsOfServiceHelper();
48 }
49
54 {
55 $template = new ilTemplate('tpl.tos_withdrawal_section.html', true, true, 'Services/TermsOfService');
56 $template->setVariable('TXT_TOS_WITHDRAWAL_HEADLINE', $this->lng->txt('withdraw_consent_header'));
57 $template->setVariable('TXT_TOS_WITHDRAWAL', $this->lng->txt('withdraw_consent_description'));
58 $template->setVariable(
59 'BTN_TOS_WITHDRAWAL',
60 $this->uiRenderer->render(
61 $this->uiFactory->button()->standard($this->lng->txt('withdraw_consent'), 'logout.php?withdraw_consent')
62 )
63 );
64
65 return $template;
66 }
67
73 public function modifyFooter(Footer $footer) : Footer
74 {
75 if (
76 $this->tosHelper->isGloballyEnabled() &&
77 $this->tosHelper->isIncludedUser($this->user) &&
78 $this->user->getAgreeDate()
79 ) {
80 $entity = $this->tosHelper->getCurrentAcceptanceForUser($this->user);
81 if ($entity->getId()) {
82 $footer = $footer->withAdditionalModalAndTrigger(
83 $this->uiFactory->modal()->roundtrip(
84 $entity->getTitle(),
85 [
86 $this->uiFactory->legacy($this->lng->txt('usr_agreement_footer_intro')),
87 $this->uiFactory->divider()->horizontal(),
88 $this->uiFactory->legacy(
89 implode('', [
90 $entity->getText(),
91 $this->getWithdrawalSectionForModal()->get()
92 ])
93 )
94 ]
95 ),
96 $this->uiFactory->button()->shy($this->lng->txt('usr_agreement'), '#')
97 );
98 }
99 }
100
101 return $footer;
102 }
103
109 RequestInterface $httpRequest,
110 object $guiClass
111 ) : void {
112 if (!isset($httpRequest->getQueryParams()['withdraw_consent'])) {
113 return;
114 }
115
116 if (!$this->tosHelper->isGloballyEnabled() || !$this->tosHelper->isIncludedUser($this->user)) {
117 return;
118 }
119
120 $defaultAuth = AUTH_LOCAL;
121 if ($this->setting->get('auth_mode')) {
122 $defaultAuth = $this->setting->get('auth_mode');
123 }
124
125 $external = false;
126 if (
127 $this->user->getAuthMode() == AUTH_PROVIDER_LTI ||
128 $this->user->getAuthMode() == AUTH_ECS ||
129 ($this->user->getAuthMode() === 'default' && $defaultAuth == AUTH_PROVIDER_LTI) ||
130 ($this->user->getAuthMode() === 'default' && $defaultAuth == AUTH_ECS)
131 ) {
132 $external = true;
133 }
134
135 $this->user->writePref('consent_withdrawal_requested', 1);
136
137 if ($external) {
138 $this->ctrl->setParameter($guiClass, 'withdrawal_relogin_content', 'external');
139 } else {
140 $this->ctrl->setParameter($guiClass, 'withdrawal_relogin_content', 'internal');
141 }
142 }
143
148 public function getWithdrawalTextForLogoutScreen(RequestInterface $httpRequest) : string
149 {
150 $withdrawalStatus = ($httpRequest->getQueryParams()['withdrawal_relogin_content'] ?? 0);
151
152 $text = '';
153 if ($withdrawalStatus !== 0) {
154 $text = $this->uiRenderer->render($this->uiFactory->divider()->horizontal());
155 if ($withdrawalStatus === 'internal') {
156 $text .= $this->lng->txt('withdraw_consent_description_internal');
157 } else {
158 $text .= $this->lng->txt('withdraw_consent_description_external');
159 }
160 }
161
162 return $text;
163 }
164
165
170 public function getConsentWithdrawalConfirmation(object $parentObject) : string
171 {
172 $defaultAuth = AUTH_LOCAL;
173 if ($this->setting->get('auth_mode')) {
174 $defaultAuth = $this->setting->get('auth_mode');
175 }
176
177 $isLdapUser = (
178 $this->user->getAuthMode() == AUTH_LDAP ||
179 ($this->user->getAuthMode() === 'default' && $defaultAuth == AUTH_LDAP)
180 );
181
182 $lng_suffix = '';
183 if (!$this->user->getAgreeDate()) {
184 $lng_suffix = '_no_consent_yet';
185 }
186 $question = $this->lng->txt('withdrawal_sure_account' . $lng_suffix);
187 if (!$isLdapUser && (bool) $this->setting->get('tos_withdrawal_usr_deletion', false)) {
188 $question = $this->lng->txt('withdrawal_sure_account_deletion' . $lng_suffix);
189 }
190
191 $confirmation = $this->uiFactory->messageBox()->confirmation($question)->withButtons([
192 $this->uiFactory->button()->standard(
193 $this->lng->txt('confirm'),
194 $this->ctrl->getFormAction($parentObject, 'withdrawAcceptance')
195 ),
196 $this->uiFactory->button()->standard(
197 $this->lng->txt('cancel'),
198 $this->ctrl->getFormAction($parentObject, 'cancelWithdrawal')
199 ),
200 ]);
201
202 if ($isLdapUser) {
203 $message = nl2br(str_ireplace("[BR]", "\n", sprintf(
204 $this->lng->txt('withdrawal_mail_info') . $this->lng->txt('withdrawal_mail_text'),
205 $this->user->getFullname(),
206 $this->user->getLogin(),
207 $this->user->getExternalAccount()
208 )));
209
210 $panelContent = $this->uiFactory->legacy(
211 $this->uiRenderer->render([
212 $confirmation,
213 $this->uiFactory->divider()->horizontal(),
214 $this->uiFactory->legacy($message)
215 ])
216 );
217
218 $content = $this->uiRenderer->render(
219 $this->uiFactory->panel()->standard($this->lng->txt('withdraw_usr_agreement'), $panelContent)
220 );
221 } else {
222 $content = $this->uiRenderer->render($confirmation);
223 }
224
225 return $content;
226 }
227
231 public function setWithdrawalInfoForLoginScreen(RequestInterface $httpRequest) : void
232 {
233 if (isset($httpRequest->getQueryParams()['tos_withdrawal_type'])) {
234 $withdrawalType = (int) $httpRequest->getQueryParams()['tos_withdrawal_type'];
235 if (1 === $withdrawalType) {
236 ilUtil::sendInfo($this->lng->txt('withdrawal_complete_deleted'));
237 } elseif (2 === $withdrawalType) {
238 ilUtil::sendInfo($this->lng->txt('withdrawal_complete_redirect'));
239 } else {
240 ilUtil::sendInfo($this->lng->txt('withdrawal_complete'));
241 }
242 }
243 }
244}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const AUTH_ECS
const AUTH_LDAP
const AUTH_LOCAL
const AUTH_PROVIDER_LTI
special template class to simplify handling of ITX/PEAR
Class ilTermsOfServiceHelper.
__construct(ilObjUser $subjectUser)
ilTermsOfServiceWithdrawalGUIHelper constructor.
handleWithdrawalLogoutRequest(RequestInterface $httpRequest, object $guiClass)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
global $DIC
Definition: goto.php:24
This describes the Footer.
Definition: Footer.php:16
withAdditionalModalAndTrigger(Modal\RoundTrip $roundTripModal, Button\Shy $shyButton)
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
$message
Definition: xapiexit.php:14