ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilGroupRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(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()) {
180  $tpl->setVariable('WARN_WAIT', $waiting_list->getCountUsers());
181  } else {
182  $tpl->setVariable('NUM_WAIT', $waiting_list->getCountUsers());
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 
308  protected function addCommandButtons(): void
309  {
310  parent::addCommandButtons();
311  switch ($this->container->getRegistrationType()) {
313  if ($this->participants->isSubscriber($this->user->getId())) {
314  $this->form->clearCommandButtons();
315  $this->form->addCommandButton('updateSubscriptionRequest', $this->lng->txt('grp_update_subscr_request'));
316  $this->form->addCommandButton('cancelSubscriptionRequest', $this->lng->txt('grp_cancel_subscr_request'));
317  } else {
318  if (!$this->isRegistrationPossible()) {
319  return;
320  }
321  $this->form->clearCommandButtons();
322  $this->form->addCommandButton('join', $this->lng->txt('grp_join_request'));
323  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
324  }
325  break;
326  }
327  }
328 
329 
335  protected function validate(): bool
336  {
337  if ($this->user->getId() == ANONYMOUS_USER_ID) {
338  $this->join_error = $this->lng->txt('permission_denied');
339  return false;
340  }
341 
342  if (!$this->isRegistrationPossible()) {
343  $this->join_error = $this->lng->txt('mem_error_preconditions');
344  return false;
345  }
346  if ($this->container->getRegistrationType() == ilGroupConstants::GRP_REGISTRATION_PASSWORD) {
347  $password = '';
348  if ($this->http->wrapper()->post()->has('grp_passw')) {
349  $password = $this->http->wrapper()->post()->retrieve(
350  'grp_passw',
351  $this->refinery->kindlyTo()->string()
352  );
353  }
354  if (!strlen($password)) {
355  $this->join_error = $this->lng->txt('err_wrong_password');
356  return false;
357  }
358  if (strcmp($password, $this->container->getPassword()) !== 0) {
359  $this->join_error = $this->lng->txt('err_wrong_password');
360  return false;
361  }
362  }
363  if (!$this->validateCustomFields()) {
364  $this->join_error = $this->lng->txt('fill_out_all_required_fields');
365  return false;
366  }
367  if (!$this->validateAgreement()) {
368  $this->join_error = $this->lng->txt($this->type . '_agreement_required');
369  return false;
370  }
371 
372  return true;
373  }
374 
378  protected function add(): void
379  {
380  // set agreement accepted
381  $this->setAccepted(true);
382 
383  $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
384  $waiting_list = new ilGroupWaitingList($this->container->getId());
385  if (
386  $this->container->isMembershipLimited() and
387  $this->container->isWaitingListEnabled() and
388  (!$free or $waiting_list->getCountUsers())) {
389  $waiting_list->addToList($this->user->getId());
390  $info = sprintf(
391  $this->lng->txt('grp_added_to_list'),
392  $this->container->getTitle(),
393  $waiting_list->getPosition($this->user->getId())
394  );
395 
396  $this->participants->sendNotification(
398  $this->user->getId()
399  );
400  $this->tpl->setOnScreenMessage('success', $info, true);
401  $this->ctrl->setParameterByClass(
402  "ilrepositorygui",
403  "ref_id",
404  $this->tree->getParentId($this->container->getRefId())
405  );
406  $this->ctrl->redirectByClass("ilrepositorygui", "");
407  }
408 
409  switch ($this->container->getRegistrationType()) {
411 
412  $this->participants->addSubscriber($this->user->getId());
413  $this->participants->updateSubscriptionTime($this->user->getId(), time());
414  $subject = '';
415  if ($this->http->wrapper()->post()->has('subject')) {
416  $subject = $this->http->wrapper()->post()->retrieve(
417  'subject',
418  $this->refinery->kindlyTo()->string()
419  );
420  }
421  $this->participants->updateSubject($this->user->getId(), $subject);
422  $this->participants->sendNotification(
424  $this->user->getId()
425  );
426 
427  $this->tpl->setOnScreenMessage('success', $this->lng->txt("application_completed"), true);
428  $this->ctrl->setParameterByClass(
429  "ilrepositorygui",
430  "ref_id",
431  $this->tree->getParentId($this->container->getRefId())
432  );
433  $this->ctrl->redirectByClass("ilrepositorygui", "");
434  break;
435 
436  default:
437 
438  $this->participants->add($this->user->getId(), ilParticipants::IL_GRP_MEMBER);
439  $this->participants->sendNotification(
441  $this->user->getId()
442  );
443  $this->participants->sendNotification(
445  $this->user->getId()
446  );
447 
448  ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $this->user->getId());
449 
450  $pending_goto = ilSession::get('pending_goto');
451  if (!$pending_goto) {
452  $this->tpl->setOnScreenMessage('success', $this->lng->txt("grp_registration_completed"), true);
453  $this->ctrl->returnToParent($this);
454  } else {
455  $tgt = $pending_goto;
456  ilSession::clear('pending_goto');
457  ilUtil::redirect($tgt);
458  }
459  break;
460  }
461  }
462 
463 
469  protected function initParticipants(): ilParticipants
470  {
471  $this->participants = ilGroupParticipants::_getInstanceByObjId($this->obj_id);
472  return $this->participants;
473  }
474 
479  protected function initWaitingList(): ilWaitingList
480  {
481  $this->waiting_list = new ilGroupWaitingList($this->container->getId());
482  return $this->waiting_list;
483  }
484 
488  protected function isWaitingListActive(): bool
489  {
490  static $active = null;
491 
492  if ($active !== null) {
493  return $active;
494  }
495  if (!$this->container->getMaxMembers()) {
496  return $active = false;
497  }
498  if (
499  !$this->container->isWaitingListEnabled() or
500  !$this->container->isMembershipLimited()) {
501  return $active = false;
502  }
503 
504  $free = max(0, $this->container->getMaxMembers() - $this->participants->getCountMembers());
505  return $active = (!$free or $this->getWaitingList()->getCountUsers());
506  }
507 }
static get(string $a_var)
static lookupRegistrationInfo(int $a_obj_id)
getPosition(int $a_usr_id)
isOnList(int $a_usr_id)
const ANONYMOUS_USER_ID
Definition: constants.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
getWaitingList()
Get waiting list object.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
addCommandButtons()
Add group specific command buttons.
enableRegistration(bool $a_status)
ilGlobalTemplateInterface $tpl
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.
fillRegistrationPeriod()
show information about the registration period
Waiting list for groups.
$txt
Definition: error.php:14
GUI class for group registrations.
initParticipants()
Init course participants.
static redirect(string $a_script)
fillMaxMembers()
fill max member information protected
Base class for course and group participants.
form( $class_path, string $cmd, string $submit_caption="")
__construct(ilObject $a_container)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
This class represents a text area property in a property form.
validate()
validate join request protected
static makeClickable(string $a_text, bool $detectGotoLinks=false)
static clear(string $a_var)
static checkForumsExistsInsert(int $ref_id, int $user_id)