ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGroupRegistrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
30{
31 public function __construct(ilObject $a_container)
32 {
33 parent::__construct($a_container);
34 }
35
36 public function executeCommand(): void
37 {
38 $next_class = $this->ctrl->getNextClass($this);
39
40 if (!$this->access->checkAccess('join', '', $this->getRefId())) {
41 $this->ctrl->redirectByClass(ilObjGroupGUI::class, 'infoScreen');
42 }
43
44 if ($this->getWaitingList()->isOnList($this->user->getId())) {
45 $this->tabs->activateTab('leave');
46 }
47
48 switch ($next_class) {
49 default:
50 $cmd = $this->ctrl->getCmd("show");
51 $this->$cmd();
52 break;
53 }
54 }
55
56
57 protected function getFormTitle(): string
58 {
59 if ($this->getWaitingList()->isOnList($this->user->getId())) {
60 return $this->lng->txt('member_status');
61 }
62 return $this->lng->txt('grp_registration');
63 }
64
65 protected function fillInformations(): void
66 {
67 if ($this->container->getInformation()) {
68 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), '', true);
69 $value = nl2br(ilUtil::makeClickable($this->container->getInformation(), true));
70 $imp->setValue($value);
71 $this->form->addItem($imp);
72 }
73 }
74
78 protected function fillRegistrationPeriod(): void
79 {
80 $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
81
82 if ($this->container->isRegistrationUnlimited()) {
83 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
84 $reg->setValue($this->lng->txt('mem_unlimited'));
85 $this->form->addItem($reg);
86 return;
87 }
88
89 $start = $this->container->getRegistrationStart();
90 $end = $this->container->getRegistrationEnd();
91
92 $warning = '';
93 if (ilDateTime::_before($now, $start)) {
94 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'components/ILIAS/Membership');
95 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
97
98 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
100
101 $warning = $this->lng->txt('mem_reg_not_started');
102 } elseif (ilDateTime::_after($now, $end)) {
103 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'components/ILIAS/Membership');
104 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
106
107 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
109
110 $warning = $this->lng->txt('mem_reg_expired');
111 } else {
112 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'components/ILIAS/Membership');
113 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
115 }
116
117 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
118 $reg->setHtml($tpl->get());
119 if (strlen($warning)) {
120 // Disable registration
121 $this->enableRegistration(false);
122 #$reg->setAlert($warning);
123 $this->tpl->setOnScreenMessage('failure', $warning);
124 }
125 $this->form->addItem($reg);
126 }
127
133 protected function fillMaxMembers(): void
134 {
135 $alert = '';
136 if (!$this->container->isMembershipLimited()) {
137 return;
138 }
139
140 $tpl = new ilTemplate('tpl.max_members_form.html', true, true, 'components/ILIAS/Membership');
141
142 if ($this->container->getMinMembers()) {
143 $tpl->setVariable('TXT_MIN', $this->lng->txt('mem_min_users'));
144 $tpl->setVariable('NUM_MIN', $this->container->getMinMembers());
145 }
146
147 if ($this->container->getMaxMembers()) {
148 $tpl->setVariable('TXT_MAX', $this->lng->txt('mem_max_users'));
149 $tpl->setVariable('NUM_MAX', $this->container->getMaxMembers());
150 $tpl->setVariable('TXT_FREE', $this->lng->txt('mem_free_places') . ":");
151
153 $free = $reg_info['reg_info_free_places'];
154
155
156 if ($free) {
157 $tpl->setVariable('NUM_FREE', $free);
158 } else {
159 $tpl->setVariable('WARN_FREE', $free);
160 }
161
162 $waiting_list = new ilGroupWaitingList($this->container->getId());
163
164 if (
165 $this->container->isWaitingListEnabled() and
166 $this->container->isMembershipLimited() and
167 (!$free or $waiting_list->getCountUsers())) {
168 if ($waiting_list->isOnList($this->user->getId())) {
169 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list_position'));
170 $tpl->setVariable('NUM_WAIT', $waiting_list->getPosition($this->user->getId()));
171 } else {
172 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list'));
173 if ($free and $waiting_list->getCountUsers()) {
175 } else {
177 }
178 }
179 }
180
181 if (
182 !$free and
183 !$this->container->isWaitingListEnabled()) {
184 // Disable registration
185 $this->enableRegistration(false);
186 $alert = $this->lng->txt('mem_alert_no_places');
187 } elseif (
188 $this->container->isWaitingListEnabled() and
189 $this->container->isMembershipLimited() and
190 $waiting_list->isOnList($this->user->getId())) {
191 // Disable registration
192 $this->enableRegistration(false);
193 } elseif (
194 !$free and
195 $this->container->isWaitingListEnabled() and
196 $this->container->isMembershipLimited()) {
197 $alert = $this->lng->txt('grp_warn_no_max_set_on_waiting_list');
198 } elseif (
199 $free and
200 $this->container->isWaitingListEnabled() and
201 $this->container->isMembershipLimited() and
202 $this->getWaitingList()->getCountUsers()) {
203 $alert = $this->lng->txt('grp_warn_wl_set_on_waiting_list');
204 }
205 }
206
207 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
208 $max->setHtml($tpl->get());
209 if (strlen($alert)) {
210 #$max->setAlert($alert);
211 $this->tpl->setOnScreenMessage('failure', $alert);
212 }
213 $this->form->addItem($max);
214 }
215
216 protected function fillRegistrationType(): void
217 {
218 if ($this->getWaitingList()->isOnList($this->user->getId())) {
219 return;
220 }
221
222 switch ($this->container->getRegistrationType()) {
224 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
225 $reg->setValue($this->lng->txt('grp_reg_disabled'));
226 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
227 $this->form->addItem($reg);
228
229 // Disable registration
230 $this->enableRegistration(false);
231
232 break;
233
235 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
236 $txt->setValue($this->lng->txt('grp_pass_request'));
237
238
239 $pass = new ilTextInputGUI($this->lng->txt('passwd'), 'grp_passw');
240 $pass->setInputType('password');
241 $pass->setSize(12);
242 $pass->setMaxLength(32);
243 #$pass->setRequired(true);
244 $pass->setInfo($this->lng->txt('group_password_registration_msg'));
245
246 $txt->addSubItem($pass);
247 $this->form->addItem($txt);
248 break;
249
251
252 // no "request" info if waiting list is active
253 if ($this->isWaitingListActive()) {
254 return;
255 }
256
257 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
258 $txt->setValue($this->lng->txt('grp_reg_request'));
259
260 $sub = new ilTextAreaInputGUI($this->lng->txt('grp_reg_subject'), 'subject');
261 $subject = '';
262 if ($this->http->wrapper()->post()->has('subject')) {
263 $subject = $this->http->wrapper()->post()->retrieve(
264 'subject',
265 $this->refinery->kindlyTo()->string()
266 );
267 }
268 $sub->setValue($subject);
269 $sub->setInfo($this->lng->txt('group_req_registration_msg'));
270 $sub->setCols(40);
271 $sub->setRows(5);
272 if ($this->participants->isSubscriber($this->user->getId())) {
273 $sub_data = $this->participants->getSubscriberData($this->user->getId());
274 $sub->setValue($sub_data['subject']);
275 $sub->setInfo('');
276 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('grp_already_assigned'));
277 $this->enableRegistration(false);
278 }
279 $txt->addSubItem($sub);
280 $this->form->addItem($txt);
281 break;
282
284
285 // no "direct registration" info if waiting list is active
286 if ($this->isWaitingListActive()) {
287 return;
288 }
289
290 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
291 $txt->setValue($this->lng->txt('group_req_direct'));
292
293 $this->form->addItem($txt);
294 break;
295 }
296 }
297
302 protected function addCommandButtons(): void
303 {
304 parent::addCommandButtons();
305 switch ($this->container->getRegistrationType()) {
307 if ($this->participants->isSubscriber($this->user->getId())) {
308 $this->form->clearCommandButtons();
309 $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
310 $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
311 } else {
312 if (!$this->isRegistrationPossible()) {
313 return;
314 }
315 $this->form->clearCommandButtons();
316 $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
317 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
318 }
319 break;
320 }
321 }
322
323
329 protected function validate(): bool
330 {
331 if ($this->user->getId() == ANONYMOUS_USER_ID) {
332 $this->join_error = $this->lng->txt('permission_denied');
333 return false;
334 }
335
336 if (!$this->isRegistrationPossible()) {
337 $this->join_error = $this->lng->txt('mem_error_preconditions');
338 return false;
339 }
340 if ($this->container->getRegistrationType() == ilGroupConstants::GRP_REGISTRATION_PASSWORD) {
341 $password = '';
342 if ($this->http->wrapper()->post()->has('grp_passw')) {
343 $password = $this->http->wrapper()->post()->retrieve(
344 'grp_passw',
345 $this->refinery->kindlyTo()->string()
346 );
347 }
348 if (!strlen($password)) {
349 $this->join_error = $this->lng->txt('err_wrong_password');
350 return false;
351 }
352 if (strcmp($password, $this->container->getPassword()) !== 0) {
353 $this->join_error = $this->lng->txt('err_wrong_password');
354 return false;
355 }
356 }
357 if (!$this->validateCustomFields()) {
358 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
359 return false;
360 }
361 if (!$this->validateAgreement()) {
362 $this->join_error = $this->lng->txt($this->type . '_agreement_required');
363 return false;
364 }
365
366 return true;
367 }
368
372 protected function add(): void
373 {
374 // set agreement accepted
375 $this->setAccepted(true);
376
377 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
378 $waiting_list = new ilGroupWaitingList($this->container->getId());
379 if (
380 $this->container->isMembershipLimited() and
381 $this->container->isWaitingListEnabled() and
382 (!$free or $waiting_list->getCountUsers())) {
383 $waiting_list->addToList($this->user->getId());
384 $info = sprintf(
385 $this->lng->txt('grp_added_to_list'),
386 $this->container->getTitle(),
387 $waiting_list->getPosition($this->user->getId())
388 );
389
390 $this->participants->sendNotification(
392 $this->user->getId()
393 );
394 $this->tpl->setOnScreenMessage('success', $info, true);
395 $this->ctrl->setParameterByClass(
396 "ilrepositorygui",
397 "ref_id",
398 $this->tree->getParentId($this->container->getRefId())
399 );
400 $this->ctrl->redirectByClass("ilrepositorygui", "");
401 }
402
403 switch ($this->container->getRegistrationType()) {
405
406 $this->participants->addSubscriber($this->user->getId());
407 $this->participants->updateSubscriptionTime($this->user->getId(), time());
408 $subject = '';
409 if ($this->http->wrapper()->post()->has('subject')) {
410 $subject = $this->http->wrapper()->post()->retrieve(
411 'subject',
412 $this->refinery->kindlyTo()->string()
413 );
414 }
415 $this->participants->updateSubject($this->user->getId(), $subject);
416 $this->participants->sendNotification(
418 $this->user->getId()
419 );
420
421 $this->tpl->setOnScreenMessage('success', $this->lng->txt("application_completed"), true);
422 $this->ctrl->setParameterByClass(
423 "ilrepositorygui",
424 "ref_id",
425 $this->tree->getParentId($this->container->getRefId())
426 );
427 $this->ctrl->redirectByClass("ilrepositorygui", "");
428 break;
429
430 default:
431
432 $this->participants->add($this->user->getId(), ilParticipants::IL_GRP_MEMBER);
433 $this->participants->sendNotification(
435 $this->user->getId()
436 );
437 $this->participants->sendNotification(
439 $this->user->getId()
440 );
441
442 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $this->user->getId());
443
444 $pending_goto = ilSession::get('pending_goto');
445 if (!$pending_goto) {
446 $this->tpl->setOnScreenMessage('success', $this->lng->txt("grp_registration_completed"), true);
447 $this->ctrl->returnToParent($this);
448 } else {
449 $tgt = $pending_goto;
450 ilSession::clear('pending_goto');
451 ilUtil::redirect($tgt);
452 }
453 break;
454 }
455 }
456
457
463 protected function initParticipants(): ilParticipants
464 {
465 $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
466 return $this->participants;
467 }
468
473 protected function initWaitingList(): ilWaitingList
474 {
475 $this->waiting_list = new ilGroupWaitingList($this->container->getId());
476 return $this->waiting_list;
477 }
478
482 protected function isWaitingListActive(): bool
483 {
484 static $active = null;
485
486 if ($active !== null) {
487 return $active;
488 }
489 if (!$this->container->getMaxMembers()) {
490 return $active = false;
491 }
492 if (
493 !$this->container->isWaitingListEnabled() or
494 !$this->container->isMembershipLimited()) {
495 return $active = false;
496 }
497
498 $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
499 return $active = (!$free or $this->getWaitingList()->getCountUsers());
500 }
501}
const IL_CAL_UNIX
This class represents a custom property in a property form.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@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 class represents a non editable value in a property form.
static lookupRegistrationInfo(int $a_obj_id)
Class ilObject Basic functions for all objects.
Base class for course and group participants.
Base class for Course and Group registration.
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, ?string $ilias_http_path=null)
static redirect(string $a_script)
Base class for course and group waiting lists.
addToList(int $a_usr_id)
getPosition(int $a_usr_id)
isOnList(int $a_usr_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$info
Definition: entry_point.php:21
$txt
Definition: error.php:31
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, string $submit_caption="")