ILIAS  release_8 Revision v8.23
class.ilTermsOfServiceWithdrawalGUIHelper.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
31 {
32  protected ilLanguage $lng;
34  protected ilSetting $setting;
35  protected ilObjUser $user;
36  protected Factory $uiFactory;
37  protected Renderer $uiRenderer;
40 
41  public function __construct(ilObjUser $subjectUser)
42  {
43  global $DIC;
44  $this->main_tpl = $DIC->ui()->mainTemplate();
45 
46  $this->user = $subjectUser;
47 
48  $this->lng = $DIC->language();
49  $this->ctrl = $DIC->ctrl();
50  $this->setting = $DIC->settings();
51  $this->uiFactory = $DIC->ui()->factory();
52  $this->uiRenderer = $DIC->ui()->renderer();
53  $this->tosHelper = new ilTermsOfServiceHelper();
54  }
55 
57  {
58  $template = new ilTemplate('tpl.tos_withdrawal_section.html', true, true, 'Services/TermsOfService');
59  $template->setVariable('TXT_TOS_WITHDRAWAL_HEADLINE', $this->lng->txt('withdraw_consent_header'));
60  $template->setVariable('TXT_TOS_WITHDRAWAL', $this->lng->txt('withdraw_consent_description'));
61  $template->setVariable(
62  'BTN_TOS_WITHDRAWAL',
63  $this->uiRenderer->render(
64  $this->uiFactory->button()->standard($this->lng->txt('withdraw_consent'), ilStartUpGUI::logoutUrl(['withdraw_consent' => '']))
65  )
66  );
67 
68  return $template;
69  }
70 
76  public function modifyFooter(Footer $footer): Footer
77  {
78  if (
79  $this->tosHelper->isGloballyEnabled() &&
80  $this->tosHelper->isIncludedUser($this->user) &&
81  $this->user->getAgreeDate()
82  ) {
83  $entity = $this->tosHelper->getCurrentAcceptanceForUser($this->user);
84  if ($entity->getId()) {
85  $footer = $footer->withAdditionalModalAndTrigger(
86  $this->uiFactory->modal()->roundtrip(
87  $entity->getTitle(),
88  [
89  $this->uiFactory->legacy($this->lng->txt('usr_agreement_footer_intro')),
90  $this->uiFactory->divider()->horizontal(),
91  $this->uiFactory->legacy(
92  implode('', [
93  $entity->getText(),
94  $this->getWithdrawalSectionForModal()->get()
95  ])
96  )
97  ]
98  ),
99  $this->uiFactory->button()->shy($this->lng->txt('usr_agreement'), '#')
100  );
101  }
102  }
103 
104  return $footer;
105  }
106 
108  ServerRequestInterface $httpRequest,
109  object $guiClass
110  ): void {
111  if (!isset($httpRequest->getQueryParams()['withdraw_consent'])) {
112  return;
113  }
114 
115  if (!$this->tosHelper->isGloballyEnabled() || !$this->tosHelper->isIncludedUser($this->user)) {
116  return;
117  }
118 
119  $defaultAuth = ilAuthUtils::AUTH_LOCAL;
120  if ($this->setting->get('auth_mode')) {
121  $defaultAuth = $this->setting->get('auth_mode');
122  }
123 
124  $external = false;
125  if (
126  $this->user->getAuthMode() == ilAuthUtils::AUTH_PROVIDER_LTI ||
127  $this->user->getAuthMode() == ilAuthUtils::AUTH_ECS ||
128  ($this->user->getAuthMode() === 'default' && $defaultAuth == ilAuthUtils::AUTH_PROVIDER_LTI) ||
129  ($this->user->getAuthMode() === 'default' && $defaultAuth == ilAuthUtils::AUTH_ECS)
130  ) {
131  $external = true;
132  }
133 
134  $this->user->writePref('consent_withdrawal_requested', '1');
135 
136  if ($external) {
137  $this->ctrl->setParameter($guiClass, 'withdrawal_relogin_content', 'external');
138  } else {
139  $this->ctrl->setParameter($guiClass, 'withdrawal_relogin_content', 'internal');
140  }
141  }
142 
143  public function getWithdrawalTextForLogoutScreen(ServerRequestInterface $httpRequest): string
144  {
145  $withdrawalStatus = ($httpRequest->getQueryParams()['withdrawal_relogin_content'] ?? 0);
146 
147  $text = '';
148  if ($withdrawalStatus !== 0) {
149  $text = $this->uiRenderer->render($this->uiFactory->divider()->horizontal());
150  if ($withdrawalStatus === 'internal') {
151  $text .= $this->lng->txt('withdraw_consent_description_internal');
152  } else {
153  $text .= $this->lng->txt('withdraw_consent_description_external');
154  }
155  }
156 
157  return $text;
158  }
159 
160  public function getConsentWithdrawalConfirmation(object $parentObject): string
161  {
162  $defaultAuth = ilAuthUtils::AUTH_LOCAL;
163  if ($this->setting->get('auth_mode')) {
164  $defaultAuth = $this->setting->get('auth_mode');
165  }
166 
167  $isLdapUser = (
168  $this->user->getAuthMode() == ilAuthUtils::AUTH_LDAP ||
169  ($this->user->getAuthMode() === 'default' && $defaultAuth == ilAuthUtils::AUTH_LDAP)
170  );
171 
172  $lng_suffix = '';
173  if (!$this->user->getAgreeDate()) {
174  $lng_suffix = '_no_consent_yet';
175  }
176  $question = $this->lng->txt('withdrawal_sure_account' . $lng_suffix);
177  if (!$isLdapUser && $this->setting->get('tos_withdrawal_usr_deletion', '0')) {
178  $question = $this->lng->txt('withdrawal_sure_account_deletion' . $lng_suffix);
179  }
180 
181  $confirmation = $this->uiFactory->messageBox()->confirmation($question)->withButtons([
182  $this->uiFactory->button()->standard(
183  $this->lng->txt('confirm'),
184  $this->ctrl->getFormAction($parentObject, 'withdrawAcceptance')
185  ),
186  $this->uiFactory->button()->standard(
187  $this->lng->txt('cancel'),
188  $this->ctrl->getFormAction($parentObject, 'cancelWithdrawal')
189  ),
190  ]);
191 
192  if ($isLdapUser) {
193  $message = nl2br(str_ireplace('[BR]', "\n", sprintf(
194  $this->lng->txt('withdrawal_mail_info') . $this->lng->txt('withdrawal_mail_text'),
195  $this->user->getFullname(),
196  $this->user->getLogin(),
197  $this->user->getExternalAccount()
198  )));
199 
200  $panelContent = $this->uiFactory->legacy(
201  $this->uiRenderer->render([
202  $confirmation,
203  $this->uiFactory->divider()->horizontal(),
204  $this->uiFactory->legacy($message)
205  ])
206  );
207 
208  $content = $this->uiRenderer->render(
209  $this->uiFactory->panel()->standard($this->lng->txt('withdraw_usr_agreement'), $panelContent)
210  );
211  } else {
212  $content = $this->uiRenderer->render($confirmation);
213  }
214 
215  return $content;
216  }
217 
218  public function setWithdrawalInfoForLoginScreen(ServerRequestInterface $httpRequest): void
219  {
220  if (isset($httpRequest->getQueryParams()['tos_withdrawal_type'])) {
221  $withdrawalType = (int) $httpRequest->getQueryParams()['tos_withdrawal_type'];
222  if (1 === $withdrawalType) {
223  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('withdrawal_complete_deleted'));
224  } elseif (2 === $withdrawalType) {
225  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('withdrawal_complete_redirect'));
226  } else {
227  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('withdrawal_complete'));
228  }
229  }
230  }
231 }
An entity that renders components to a string output.
Definition: Renderer.php:30
withAdditionalModalAndTrigger(Modal\RoundTrip $roundTripModal, Button\Shy $shyButton)
getWithdrawalTextForLogoutScreen(ServerRequestInterface $httpRequest)
handleWithdrawalLogoutRequest(ServerRequestInterface $httpRequest, object $guiClass)
global $DIC
Definition: feed.php:28
static logoutUrl(array $parameters=[])
Return the logout URL with a valid CSRF token.
Class ilTermsOfServiceHelper.
setWithdrawalInfoForLoginScreen(ServerRequestInterface $httpRequest)
$message
Definition: xapiexit.php:32
This describes the Footer.
Definition: Footer.php:32