ILIAS  release_8 Revision v8.24
class.ilGroupRegistrationGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
36{
37 public function __construct(ilObject $a_container)
38 {
39 parent::__construct($a_container);
40 }
41
42 public function executeCommand(): void
43 {
44 $next_class = $this->ctrl->getNextClass($this);
45
46 if (!$this->access->checkAccess('join', '', $this->getRefId())) {
47 $this->ctrl->redirectByClass(ilObjGroupGUI::class, 'infoScreen');
48 }
49
50 if ($this->getWaitingList()->isOnList($this->user->getId())) {
51 $this->tabs->activateTab('leave');
52 }
53
54 switch ($next_class) {
55 default:
56 $cmd = $this->ctrl->getCmd("show");
57 $this->$cmd();
58 break;
59 }
60 }
61
62
63 protected function getFormTitle(): string
64 {
65 if ($this->getWaitingList()->isOnList($this->user->getId())) {
66 return $this->lng->txt('member_status');
67 }
68 return $this->lng->txt('grp_registration');
69 }
70
71 protected function fillInformations(): void
72 {
73 if ($this->container->getInformation()) {
74 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), '', true);
75 $value = nl2br(ilUtil::makeClickable($this->container->getInformation(), true));
76 $imp->setValue($value);
77 $this->form->addItem($imp);
78 }
79 }
80
84 protected function fillRegistrationPeriod(): void
85 {
86 $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
87
88 if ($this->container->isRegistrationUnlimited()) {
89 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
90 $reg->setValue($this->lng->txt('mem_unlimited'));
91 $this->form->addItem($reg);
92 return;
93 }
94
95 $start = $this->container->getRegistrationStart();
96 $end = $this->container->getRegistrationEnd();
97
98 $warning = '';
99 if (ilDateTime::_before($now, $start)) {
100 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
101 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
103
104 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
106
107 $warning = $this->lng->txt('mem_reg_not_started');
108 } elseif (ilDateTime::_after($now, $end)) {
109 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
110 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
112
113 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
115
116 $warning = $this->lng->txt('mem_reg_expired');
117 } else {
118 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'Services/Membership');
119 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
121 }
122
123 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
124 $reg->setHtml($tpl->get());
125 if (strlen($warning)) {
126 // Disable registration
127 $this->enableRegistration(false);
128 #$reg->setAlert($warning);
129 $this->tpl->setOnScreenMessage('failure', $warning);
130 }
131 $this->form->addItem($reg);
132 }
133
139 protected function fillMaxMembers(): void
140 {
141 $alert = '';
142 if (!$this->container->isMembershipLimited()) {
143 return;
144 }
145
146 $tpl = new ilTemplate('tpl.max_members_form.html', true, true, 'Services/Membership');
147
148 if ($this->container->getMinMembers()) {
149 $tpl->setVariable('TXT_MIN', $this->lng->txt('mem_min_users'));
150 $tpl->setVariable('NUM_MIN', $this->container->getMinMembers());
151 }
152
153 if ($this->container->getMaxMembers()) {
154 $tpl->setVariable('TXT_MAX', $this->lng->txt('mem_max_users'));
155 $tpl->setVariable('NUM_MAX', $this->container->getMaxMembers());
156 $tpl->setVariable('TXT_FREE', $this->lng->txt('mem_free_places') . ":");
157
159 $free = $reg_info['reg_info_free_places'];
160
161
162 if ($free) {
163 $tpl->setVariable('NUM_FREE', $free);
164 } else {
165 $tpl->setVariable('WARN_FREE', $free);
166 }
167
168 $waiting_list = new ilGroupWaitingList($this->container->getId());
169
170 if (
171 $this->container->isWaitingListEnabled() and
172 $this->container->isMembershipLimited() and
173 (!$free or $waiting_list->getCountUsers())) {
174 if ($waiting_list->isOnList($this->user->getId())) {
175 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list_position'));
176 $tpl->setVariable('NUM_WAIT', $waiting_list->getPosition($this->user->getId()));
177 } else {
178 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list'));
179 if ($free and $waiting_list->getCountUsers()) {
181 } else {
183 }
184 }
185 }
186
187 if (
188 !$free and
189 !$this->container->isWaitingListEnabled()) {
190 // Disable registration
191 $this->enableRegistration(false);
192 $alert = $this->lng->txt('mem_alert_no_places');
193 } elseif (
194 $this->container->isWaitingListEnabled() and
195 $this->container->isMembershipLimited() and
196 $waiting_list->isOnList($this->user->getId())) {
197 // Disable registration
198 $this->enableRegistration(false);
199 } elseif (
200 !$free and
201 $this->container->isWaitingListEnabled() and
202 $this->container->isMembershipLimited()) {
203 $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
204 } elseif (
205 $free and
206 $this->container->isWaitingListEnabled() and
207 $this->container->isMembershipLimited() and
208 $this->getWaitingList()->getCountUsers()) {
209 $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
210 }
211 }
212
213 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
214 $max->setHtml($tpl->get());
215 if (strlen($alert)) {
216 #$max->setAlert($alert);
217 $this->tpl->setOnScreenMessage('failure', $alert);
218 }
219 $this->form->addItem($max);
220 }
221
222 protected function fillRegistrationType(): void
223 {
224 if ($this->getWaitingList()->isOnList($this->user->getId())) {
225 return;
226 }
227
228 switch ($this->container->getRegistrationType()) {
230 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
231 $reg->setValue($this->lng->txt('grp_reg_disabled'));
232 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
233 $this->form->addItem($reg);
234
235 // Disable registration
236 $this->enableRegistration(false);
237
238 break;
239
241 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
242 $txt->setValue($this->lng->txt('grp_pass_request'));
243
244
245 $pass = new ilTextInputGUI($this->lng->txt('passwd'), 'grp_passw');
246 $pass->setInputType('password');
247 $pass->setSize(12);
248 $pass->setMaxLength(32);
249 #$pass->setRequired(true);
250 $pass->setInfo($this->lng->txt('group_password_registration_msg'));
251
252 $txt->addSubItem($pass);
253 $this->form->addItem($txt);
254 break;
255
257
258 // no "request" info if waiting list is active
259 if ($this->isWaitingListActive()) {
260 return;
261 }
262
263 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
264 $txt->setValue($this->lng->txt('grp_reg_request'));
265
266 $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'), 'subject');
267 $subject = '';
268 if ($this->http->wrapper()->post()->has('subject')) {
269 $subject = $this->http->wrapper()->post()->retrieve(
270 'subject',
271 $this->refinery->kindlyTo()->string()
272 );
273 }
274 $sub->setValue($subject);
275 $sub->setInfo($this->lng->txt('group_req_registration_msg'));
276 $sub->setCols(40);
277 $sub->setRows(5);
278 if ($this->participants->isSubscriber($this->user->getId())) {
279 $sub_data = $this->participants->getSubscriberData($this->user->getId());
280 $sub->setValue($sub_data['subject']);
281 $sub->setInfo('');
282 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('grp_already_assigned'));
283 $this->enableRegistration(false);
284 }
285 $txt->addSubItem($sub);
286 $this->form->addItem($txt);
287 break;
288
290
291 // no "direct registration" info if waiting list is active
292 if ($this->isWaitingListActive()) {
293 return;
294 }
295
296 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
297 $txt->setValue($this->lng->txt('group_req_direct'));
298
299 $this->form->addItem($txt);
300 break;
301
302 }
303 }
304
309 protected function addCommandButtons(): void
310 {
311 parent::addCommandButtons();
312 switch ($this->container->getRegistrationType()) {
314 if ($this->participants->isSubscriber($this->user->getId())) {
315 $this->form->clearCommandButtons();
316 $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
317 $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
318 } else {
319 if (!$this->isRegistrationPossible()) {
320 return;
321 }
322 $this->form->clearCommandButtons();
323 $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
324 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
325 }
326 break;
327 }
328 }
329
330
336 protected function validate(): bool
337 {
338 if ($this->user->getId() == ANONYMOUS_USER_ID) {
339 $this->join_error = $this->lng->txt('permission_denied');
340 return false;
341 }
342
343 if (!$this->isRegistrationPossible()) {
344 $this->join_error = $this->lng->txt('mem_error_preconditions');
345 return false;
346 }
347 if ($this->container->getRegistrationType() == ilGroupConstants::GRP_REGISTRATION_PASSWORD) {
348 $password = '';
349 if ($this->http->wrapper()->post()->has('grp_passw')) {
350 $password = $this->http->wrapper()->post()->retrieve(
351 'grp_passw',
352 $this->refinery->kindlyTo()->string()
353 );
354 }
355 if (!strlen($password)) {
356 $this->join_error = $this->lng->txt('err_wrong_password');
357 return false;
358 }
359 if (strcmp($password, $this->container->getPassword()) !== 0) {
360 $this->join_error = $this->lng->txt('err_wrong_password');
361 return false;
362 }
363 }
364 if (!$this->validateCustomFields()) {
365 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
366 return false;
367 }
368 if (!$this->validateAgreement()) {
369 $this->join_error = $this->lng->txt($this->type . '_agreement_required');
370 return false;
371 }
372
373 return true;
374 }
375
379 protected function add(): void
380 {
381 // set agreement accepted
382 $this->setAccepted(true);
383
384 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
385 $waiting_list = new ilGroupWaitingList($this->container->getId());
386 if (
387 $this->container->isMembershipLimited() and
388 $this->container->isWaitingListEnabled() and
389 (!$free or $waiting_list->getCountUsers())) {
390 $waiting_list->addToList($this->user->getId());
391 $info = sprintf(
392 $this->lng->txt('grp_added_to_list'),
393 $this->container->getTitle(),
394 $waiting_list->getPosition($this->user->getId())
395 );
396
397 $this->participants->sendNotification(
399 $this->user->getId()
400 );
401 $this->tpl->setOnScreenMessage('success', $info, true);
402 $this->ctrl->setParameterByClass(
403 "ilrepositorygui",
404 "ref_id",
405 $this->tree->getParentId($this->container->getRefId())
406 );
407 $this->ctrl->redirectByClass("ilrepositorygui", "");
408 }
409
410 switch ($this->container->getRegistrationType()) {
412
413 $this->participants->addSubscriber($this->user->getId());
414 $this->participants->updateSubscriptionTime($this->user->getId(), time());
415 $subject = '';
416 if ($this->http->wrapper()->post()->has('subject')) {
417 $subject = $this->http->wrapper()->post()->retrieve(
418 'subject',
419 $this->refinery->kindlyTo()->string()
420 );
421 }
422 $this->participants->updateSubject($this->user->getId(), $subject);
423 $this->participants->sendNotification(
425 $this->user->getId()
426 );
427
428 $this->tpl->setOnScreenMessage('success', $this->lng->txt("application_completed"), true);
429 $this->ctrl->setParameterByClass(
430 "ilrepositorygui",
431 "ref_id",
432 $this->tree->getParentId($this->container->getRefId())
433 );
434 $this->ctrl->redirectByClass("ilrepositorygui", "");
435 break;
436
437 default:
438
439 $this->participants->add($this->user->getId(), ilParticipants::IL_GRP_MEMBER);
440 $this->participants->sendNotification(
442 $this->user->getId()
443 );
444 $this->participants->sendNotification(
446 $this->user->getId()
447 );
448
449 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $this->user->getId());
450
451 $pending_goto = ilSession::get('pending_goto');
452 if (!$pending_goto) {
453 $this->tpl->setOnScreenMessage('success', $this->lng->txt("grp_registration_completed"), true);
454 $this->ctrl->returnToParent($this);
455 } else {
456 $tgt = $pending_goto;
457 ilSession::clear('pending_goto');
458 ilUtil::redirect($tgt);
459 }
460 break;
461 }
462 }
463
464
470 protected function initParticipants(): ilParticipants
471 {
472 $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
473 return $this->participants;
474 }
475
480 protected function initWaitingList(): ilWaitingList
481 {
482 $this->waiting_list = new ilGroupWaitingList($this->container->getId());
483 return $this->waiting_list;
484 }
485
489 protected function isWaitingListActive(): bool
490 {
491 static $active = null;
492
493 if ($active !== null) {
494 return $active;
495 }
496 if (!$this->container->getMaxMembers()) {
497 return $active = false;
498 }
499 if (
500 !$this->container->isWaitingListEnabled() or
501 !$this->container->isMembershipLimited()) {
502 return $active = false;
503 }
504
505 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
506 return $active = (!$free or $this->getWaitingList()->getCountUsers());
507 }
508}
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static checkForumsExistsInsert(int $ref_id, int $user_id)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
GUI class for group registrations.
__construct(ilObject $a_container)
fillRegistrationType()
show informations about registration procedure
fillMaxMembers()
fill max member information @access protected
getFormTitle()
Get title for property form.
validate()
validate join request @access protected
addCommandButtons()
Add group specific command buttons.
fillRegistrationPeriod()
show information about the registration period
initParticipants()
Init course participants.
Waiting list for groups.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupRegistrationInfo(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Base class for course and group participants.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
getWaitingList()
Get waiting list object.
enableRegistration(bool $a_status)
static get(string $a_var)
static clear(string $a_var)
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static makeClickable(string $a_text, bool $detectGotoLinks=false)
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addToList(int $a_usr_id)
getPosition(int $a_usr_id)
isOnList(int $a_usr_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$txt
Definition: error.php:13
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)