ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilRegistrationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 abstract class ilRegistrationGUI
27 {
28  protected int $ref_id;
29  protected int $obj_id;
30  protected string $type;
31  protected string $join_error = '';
32  protected bool $registration_possible = true;
33  protected \ILIAS\HTTP\GlobalHttpState $http;
34  protected \ILIAS\Refinery\Factory $refinery;
36  protected ilObject $container;
40  protected ilObjUser $user;
41  protected ilTabsGUI $tabs;
42  protected ilTree $tree;
45  protected ilLanguage $lng;
46  protected ilCtrl $ctrl;
48 
49  public function __construct(ilObject $a_container)
50  {
51  global $DIC;
52 
53  $this->user = $DIC->user();
54  $this->tabs = $DIC->tabs();
55  $this->tree = $DIC->repositoryTree();
56  $this->rbacreview = $DIC->rbac()->review();
57 
58  $this->lng = $DIC->language();
59  $this->lng->loadLanguageModule('crs');
60  $this->lng->loadLanguageModule('grp');
61  $this->lng->loadLanguageModule('ps');
62  $this->lng->loadLanguageModule('membership');
63 
64  $this->ctrl = $DIC->ctrl();
65  $this->tpl = $DIC->ui()->mainTemplate();
66  $this->access = $DIC->access();
67 
68  $this->container = $a_container;
69  $this->ref_id = $this->container->getRefId();
70  $this->obj_id = ilObject::_lookupObjId($this->ref_id);
71  $this->type = ilObject::_lookupType($this->obj_id);
72 
73  $this->initParticipants();
74  $this->initWaitingList();
75 
76  $this->privacy = ilPrivacySettings::getInstance();
77  $this->http = $DIC->http();
78  $this->refinery = $DIC->refinery();
79  }
80 
81  public function getContainer(): ilObject
82  {
83  return $this->container;
84  }
85 
86  public function getRefId(): int
87  {
88  return $this->ref_id;
89  }
90 
91  protected function isRegistrationPossible(): bool
92  {
94  }
95 
96  protected function enableRegistration(bool $a_status): void
97  {
98  $this->registration_possible = $a_status;
99  }
100 
104  abstract protected function initParticipants(): ilParticipants;
105 
109  abstract protected function initWaitingList(): ilWaitingList;
110 
116  abstract protected function isWaitingListActive(): bool;
117 
121  protected function getWaitingList(): ilWaitingList
122  {
123  return $this->waiting_list;
124  }
125 
126  protected function leaveWaitingList(): void
127  {
128  $this->getWaitingList()->removeFromList($this->user->getId());
129  $parent = $this->tree->getParentId($this->container->getRefId());
130 
131  $message = sprintf(
132  $this->lng->txt($this->container->getType() . '_removed_from_waiting_list'),
133  $this->container->getTitle()
134  );
135  $this->tpl->setOnScreenMessage('success', $message, true);
136  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
137  $this->ctrl->redirectByClass("ilrepositorygui", "");
138  }
139 
143  abstract protected function getFormTitle(): string;
144 
148  abstract protected function fillInformations(): void;
149 
153  abstract protected function fillRegistrationPeriod(): void;
154 
158  abstract protected function fillMaxMembers(): void;
159 
163  abstract protected function fillRegistrationType(): void;
164 
168  protected function fillMembershipLimitation(): void
169  {
170  if (!$items = ilObjCourseGrouping::_getGroupingItems($this->container)) {
171  return;
172  }
173  $mem = new ilCustomInputGUI($this->lng->txt('groupings'));
174  $tpl = new ilTemplate('tpl.membership_limitation_form.html', true, true, 'components/ILIAS/Membership');
175  $tpl->setVariable('LIMIT_INTRO', $this->lng->txt($this->type . '_grp_info_reg'));
176  foreach ($items as $ref_id) {
177  $obj_id = ilObject::_lookupObjId($ref_id);
178  $type = ilObject::_lookupType($obj_id);
179  $title = ilObject::_lookupTitle($obj_id);
180 
181  if ($this->access->checkAccess('visible', '', $ref_id, $type)) {
182  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
183  $tpl->setVariable(
184  'LINK_ITEM',
185  $this->ctrl->getLinkTargetByClass("ilrepositorygui", "")
186  );
187  $get_ref_id = $this->http->wrapper()->query()->retrieve(
188  'ref_id',
189  $this->refinery->byTrying([
190  $this->refinery->kindlyTo()->int(),
191  $this->refinery->always(0)
192  ])
193  );
194 
195  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $get_ref_id);
196  $tpl->setVariable('ITEM_LINKED_TITLE', $title);
197  } else {
198  $tpl->setVariable('ITEM_TITLE');
199  }
200  $tpl->setCurrentBlock('items');
201  $tpl->setVariable('TYPE_ICON', ilObject::_getIcon($obj_id, 'tiny', $type));
202  $tpl->setVariable('ALT_ICON', $this->lng->txt('obj_' . $type));
203  $tpl->parseCurrentBlock();
204  }
205  $mem->setHtml($tpl->get());
206  if (!ilObjCourseGrouping::_checkGroupingDependencies($this->container)) {
207  $mem->setAlert($this->container->getMessage());
208  $this->enableRegistration(false);
209  }
210  $this->form->addItem($mem);
211  }
212 
213  protected function fillAgreement(): void
214  {
215  if (!$this->isRegistrationPossible()) {
216  return;
217  }
218 
219  if (!$this->privacy->confirmationRequired($this->type) && !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId())) {
220  return;
221  }
222 
223  $this->lng->loadLanguageModule('ps');
224 
225  $fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->container->getId()));
226 
227  if (!count($fields_info->getExportableFields())) {
228  return;
229  }
230  $section = new ilFormSectionHeaderGUI();
231  $section->setTitle($this->lng->txt($this->type . '_usr_agreement'));
232  $this->form->addItem($section);
233 
234  ilMemberAgreementGUI::addExportFieldInfo($this->form, $this->obj_id, $this->type);
235 
236  ilMemberAgreementGUI::addCustomFields($this->form, $this->obj_id, $this->type);
237 
238  // Checkbox agreement
239  if ($this->privacy->confirmationRequired($this->type)) {
240  ilMemberAgreementGUI::addAgreement($this->form, $this->obj_id, $this->type);
241  }
242  }
243 
244  protected function showCustomFields(): void
245  {
246  if (!count($cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->container->getId()))) {
247  return;
248  }
249 
250  $cdf_values = $this->http->wrapper()->post()->retrieve(
251  'cdf',
252  $this->refinery->byTrying([
253  $this->refinery->kindlyTo()->dictOf(
254  $this->refinery->kindlyTo()->string()
255  ),
256  $this->refinery->always([])
257  ])
258  );
259 
260  $cdf = new ilNonEditableValueGUI($this->lng->txt('ps_crs_user_fields'));
261  $cdf->setValue($this->lng->txt($this->type . '_ps_cdf_info'));
262  $cdf->setRequired(true);
263  foreach ($cdf_fields as $field_obj) {
264  switch ($field_obj->getType()) {
266  $select = new ilSelectInputGUI($field_obj->getName(), 'cdf[' . $field_obj->getId() . ']');
267  $select->setValue($cdf_values[$field_obj->getId()] ?? '');
268  $select->setOptions($field_obj->prepareSelectBox());
269  if ($field_obj->isRequired()) {
270  $select->setRequired(true);
271  }
272  $cdf->addSubItem($select);
273  break;
274 
276  $text = new ilTextInputGUI($field_obj->getName(), 'cdf[' . $field_obj->getId() . ']');
277  $text->setValue($cdf_values[$field_obj->getId()] ?? '');
278  $text->setSize(32);
279  $text->setMaxLength(255);
280  if ($field_obj->isRequired()) {
281  $text->setRequired(true);
282  }
283  $cdf->addSubItem($text);
284  break;
285  }
286  }
287  $this->form->addItem($cdf);
288  }
289 
290  protected function validateAgreement(): bool
291  {
292  $agreement = $this->http->wrapper()->post()->retrieve(
293  'agreement',
294  $this->refinery->byTrying([
295  $this->refinery->kindlyTo()->string(),
296  $this->refinery->always(null)
297  ])
298  );
299 
300  if ($agreement) {
301  return true;
302  }
303  if (!$this->privacy->confirmationRequired($this->type)) {
304  return true;
305  }
306  return false;
307  }
308 
309  protected function validateCustomFields(): bool
310  {
311  $required_fullfilled = true;
312  $value = '';
313  foreach (ilCourseDefinedFieldDefinition::_getFields($this->container->getId()) as $field_obj) {
314  switch ($field_obj->getType()) {
316  $cdf_value = $this->http->wrapper()->post()->retrieve(
317  'cdf_' . $field_obj->getId(),
318  $this->refinery->byTrying([
319  $this->refinery->kindlyTo()->string(),
320  $this->refinery->always('')
321  ])
322  );
323 
324  // Split value id from post
325  $cdf_parts = explode('_', $cdf_value);
326  $option_id = (int) ($cdf_parts[1] ?? 0);
327 
328  $open_answer_indexes = $field_obj->getValueOptions();
329  if (in_array($option_id, $open_answer_indexes)) {
330  $value = $this->http->wrapper()->post()->retrieve(
331  'cdf_oa_' . $field_obj->getId() . '_' . $option_id,
332  $this->refinery->byTrying([
333  $this->refinery->kindlyTo()->string(),
334  $this->refinery->always('')
335  ])
336  );
337  } else {
338  $value = $field_obj->getValueById((int) $option_id);
339  }
340  break;
341 
343  $value = $this->http->wrapper()->post()->retrieve(
344  'cdf_' . $field_obj->getId(),
345  $this->refinery->byTrying([
346  $this->refinery->kindlyTo()->string(),
347  $this->refinery->always('')
348  ])
349  );
350  break;
351  }
352 
353  $course_user_data = new ilCourseUserData($this->user->getId(), $field_obj->getId());
354  $course_user_data->setValue($value);
355  $course_user_data->update();
356 
357  // #14220
358  if ($field_obj->isRequired() && $value === "") {
359  $required_fullfilled = false;
360  }
361  }
362  return $required_fullfilled;
363  }
364 
365  protected function setAccepted(bool $a_status): void
366  {
367  if (!$this->privacy->confirmationRequired($this->type) && !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId())) {
368  return;
369  }
370 
371  $agreement = new ilMemberAgreement($this->user->getId(), $this->container->getId());
372  $agreement->setAccepted($a_status);
373  $agreement->setAcceptanceTime(time());
374  $agreement->save();
375  }
376 
380  public function cancel(): void
381  {
382  $this->ctrl->setParameterByClass(
383  "ilrepositorygui",
384  "ref_id",
385  $this->tree->getParentId($this->container->getRefId())
386  );
387  $this->ctrl->redirectByClass("ilrepositorygui", "");
388  }
389 
390  public function show(?ilPropertyFormGUI $form = null): void
391  {
392  if (!$form instanceof ilPropertyFormGUI) {
393  $this->initForm();
394  }
395  $pending_goto = (string) ilSession::get('pending_goto');
396  if ($pending_goto) {
397  $this->tpl->setOnScreenMessage('info', $this->lng->txt("reg_goto_parent_membership_info"));
398  }
399  $this->tpl->setContent($this->form->getHTML());
400  }
401 
402  public function join(): void
403  {
404  $form = $this->initForm();
405  if (!$form->checkInput() || !$this->validate()) {
406  $form->setValuesByPost();
407  if ($this->join_error) {
408  $this->tpl->setOnScreenMessage('failure', $this->join_error);
409  } else {
410  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
411  }
412  $this->show($form);
413  return;
414  }
415  $this->add();
416  }
417 
418  protected function validate(): bool
419  {
420  return true;
421  }
422 
426  protected function initForm(): ilPropertyFormGUI
427  {
428  if (is_object($this->form)) {
429  return $this->form;
430  }
431 
432  $this->form = new ilPropertyFormGUI();
433  $this->form->setFormAction($this->ctrl->getFormAction($this, 'join'));
434  $this->form->setTitle($this->getFormTitle());
435 
436  $this->fillInformations();
437  $this->fillMembershipLimitation();
438  if ($this->isRegistrationPossible()) {
439  $this->fillRegistrationPeriod();
440  }
441  if ($this->isRegistrationPossible() || $this->participants->isSubscriber($this->user->getId())) {
442  $this->fillRegistrationType();
443  }
444  if ($this->isRegistrationPossible()) {
445  $this->fillMaxMembers();
446  }
447  if ($this->isRegistrationPossible()) {
448  $this->fillAgreement();
449  }
450  $this->addCommandButtons();
451  return $this->form;
452  }
453 
457  protected function addCommandButtons(): void
458  {
459  if (
460  $this->isRegistrationPossible() &&
461  $this->isWaitingListActive() &&
462  !$this->getWaitingList()->isOnList($this->user->getId())
463  ) {
464  $this->form->addCommandButton('join', $this->lng->txt('mem_add_to_wl'));
465  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
466  } elseif ($this->isRegistrationPossible() && !$this->getWaitingList()->isOnList($this->user->getId())) {
467  $this->form->addCommandButton('join', $this->lng->txt('join'));
468  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
469  }
470  if ($this->getWaitingList()->isOnList($this->user->getId())) {
471  $this->tpl->setOnScreenMessage('question', sprintf(
472  $this->lng->txt($this->container->getType() . '_cancel_waiting_list'),
473  $this->container->getTitle()
474  ));
475  $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
476  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
477  }
478  }
479 
480  protected function updateSubscriptionRequest(): void
481  {
482  $subject = $this->http->wrapper()->post()->retrieve(
483  'subject',
484  $this->refinery->byTrying([
485  $this->refinery->kindlyTo()->string(),
486  $this->refinery->always('')
487  ])
488  );
489 
490  $this->participants->updateSubject($this->user->getId(), ilUtil::stripSlashes($subject));
491  $this->tpl->setOnScreenMessage('success', $this->lng->txt('sub_request_saved'), true);
492  $this->ctrl->setParameterByClass(
493  "ilrepositorygui",
494  "ref_id",
495  $this->tree->getParentId($this->container->getRefId())
496  );
497  $this->ctrl->redirectByClass("ilrepositorygui", "");
498  }
499 
500  protected function cancelSubscriptionRequest(): void
501  {
502  $this->participants->deleteSubscriber($this->user->getId());
503  $this->tpl->setOnScreenMessage('success', $this->lng->txt('sub_request_deleted'), true);
504 
505  $this->ctrl->setParameterByClass(
506  "ilrepositorygui",
507  "ref_id",
508  $this->tree->getParentId($this->container->getRefId())
509  );
510  $this->ctrl->redirectByClass("ilrepositorygui", "");
511  }
512 }
static get(string $a_var)
add()
description: > Example for rendring an add glyph.
Definition: add.php:41
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
Base class for course and group waiting lists.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValue(string $a_value)
ilPrivacySettings $privacy
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
getWaitingList()
Get waiting list object.
fillRegistrationPeriod()
show informations about the registration period
setAccepted(bool $a_status)
set accepted
static _checkGroupingDependencies(ilObject $container_obj, ?int $a_user_id=null)
fillRegistrationType()
show informations about registration procedure
static _getGroupingItems(ilObject $container_obj)
Get courses/groups that are assigned to the same membership limitation.
isWaitingListActive()
Check if the waiting list is active Maximum of members exceeded or any user on the waiting list...
getFormTitle()
Get title for property form.
Base class for Course and Group registration.
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
static addCustomFields(ilPropertyFormGUI $form, int $a_obj_id, string $a_type, string $a_mode='user')
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
enableRegistration(bool $a_status)
ilGlobalTemplateInterface $tpl
initWaitingList()
Init waiting list (course or group waiting list)
static _lookupTitle(int $obj_id)
setValue($a_value)
Set Value.
Singleton class that stores all privacy settings.
static addExportFieldInfo(ilPropertyFormGUI $form, int $a_obj_id, string $a_type)
__construct(ilObject $a_container)
global $DIC
Definition: shib_login.php:22
ILIAS HTTP GlobalHttpState $http
static addAgreement(ilPropertyFormGUI $form, int $a_obj_id, string $a_type)
Base class for course and group participants.
cancel()
cancel subscription
form( $class_path, string $cmd, string $submit_caption="")
static _getInstanceByType(string $a_type)
Get Singleton Instance.
fillMembershipLimitation()
Show membership limitations.
fillInformations()
fill informations
ILIAS Refinery Factory $refinery
fillMaxMembers()
show informations about the maximum number of user.
$message
Definition: xapiexit.php:31
static _lookupType(int $id, bool $reference=false)
show(?ilPropertyFormGUI $form=null)
static _hasFields(int $a_container_id)
Check if there are any define fields.
initParticipants()
Init participants object (course or group participants)