ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilRegistrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26abstract 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;
39 protected ?ilPropertyFormGUI $form = null;
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) {
180
181 if ($this->access->checkAccess('visible', '', $ref_id, $type)) {
182 $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
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));
204 }
205 $mem->setHtml($tpl->get());
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 = $cdf_parts[1] ?? null;
327
328 $open_answer_indexes = $field_obj->getValueOptions();
329
330 if ($option_id === null) {
331 $value = '';
332 } elseif (in_array($option_id, $open_answer_indexes)) {
333 $value = $this->http->wrapper()->post()->retrieve(
334 'cdf_oa_' . $field_obj->getId() . '_' . $option_id,
335 $this->refinery->byTrying([
336 $this->refinery->kindlyTo()->string(),
337 $this->refinery->always('')
338 ])
339 );
340 } else {
341 $value = $field_obj->getValueById((int) $option_id);
342 }
343 break;
344
346 $value = $this->http->wrapper()->post()->retrieve(
347 'cdf_' . $field_obj->getId(),
348 $this->refinery->byTrying([
349 $this->refinery->kindlyTo()->string(),
350 $this->refinery->always('')
351 ])
352 );
353 break;
354 }
355
356 $course_user_data = new ilCourseUserData($this->user->getId(), $field_obj->getId());
357 $course_user_data->setValue($value);
358 $course_user_data->update();
359
360 // #14220
361 if ($field_obj->isRequired() && $value === "") {
362 $required_fullfilled = false;
363 }
364 }
365 return $required_fullfilled;
366 }
367
368 protected function setAccepted(bool $a_status): void
369 {
370 if (!$this->privacy->confirmationRequired($this->type) && !ilCourseDefinedFieldDefinition::_hasFields($this->container->getId())) {
371 return;
372 }
373
374 $agreement = new ilMemberAgreement($this->user->getId(), $this->container->getId());
375 $agreement->setAccepted($a_status);
376 $agreement->setAcceptanceTime(time());
377 $agreement->save();
378 }
379
383 public function cancel(): void
384 {
385 $this->ctrl->setParameterByClass(
386 "ilrepositorygui",
387 "ref_id",
388 $this->tree->getParentId($this->container->getRefId())
389 );
390 $this->ctrl->redirectByClass("ilrepositorygui", "");
391 }
392
393 public function show(?ilPropertyFormGUI $form = null): void
394 {
395 if (!$form instanceof ilPropertyFormGUI) {
396 $this->initForm();
397 }
398 $pending_goto = (string) ilSession::get('pending_goto');
399 if ($pending_goto) {
400 $this->tpl->setOnScreenMessage('info', $this->lng->txt("reg_goto_parent_membership_info"));
401 }
402 $this->tpl->setContent($this->form->getHTML());
403 }
404
405 public function join(): void
406 {
407 $form = $this->initForm();
408 if (!$form->checkInput() || !$this->validate()) {
410 if ($this->join_error) {
411 $this->tpl->setOnScreenMessage('failure', $this->join_error);
412 } else {
413 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
414 }
415 $this->show($form);
416 return;
417 }
418 $this->add();
419 }
420
421 protected function validate(): bool
422 {
423 return true;
424 }
425
429 protected function initForm(): ilPropertyFormGUI
430 {
431 if (is_object($this->form)) {
432 return $this->form;
433 }
434
435 $this->form = new ilPropertyFormGUI();
436 $this->form->setFormAction($this->ctrl->getFormAction($this, 'join'));
437 $this->form->setTitle($this->getFormTitle());
438
439 $this->fillInformations();
441 if ($this->isRegistrationPossible()) {
442 $this->fillRegistrationPeriod();
443 }
444 if ($this->isRegistrationPossible() || $this->participants->isSubscriber($this->user->getId())) {
445 $this->fillRegistrationType();
446 }
447 if ($this->isRegistrationPossible()) {
448 $this->fillMaxMembers();
449 }
450 if ($this->isRegistrationPossible()) {
451 $this->fillAgreement();
452 }
453 $this->addCommandButtons();
454 return $this->form;
455 }
456
460 protected function addCommandButtons(): void
461 {
462 if (
463 $this->isRegistrationPossible() &&
464 $this->isWaitingListActive() &&
465 !$this->getWaitingList()->isOnList($this->user->getId())
466 ) {
467 $this->form->addCommandButton('join', $this->lng->txt('mem_add_to_wl'));
468 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
469 } elseif ($this->isRegistrationPossible() && !$this->getWaitingList()->isOnList($this->user->getId())) {
470 $this->form->addCommandButton('join', $this->lng->txt('join'));
471 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
472 }
473 if ($this->getWaitingList()->isOnList($this->user->getId())) {
474 $this->tpl->setOnScreenMessage('question', sprintf(
475 $this->lng->txt($this->container->getType() . '_cancel_waiting_list'),
476 $this->container->getTitle()
477 ));
478 $this->form->addCommandButton('leaveWaitingList', $this->lng->txt('leave_waiting_list'));
479 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
480 }
481 }
482
483 protected function updateSubscriptionRequest(): void
484 {
485 $subject = $this->http->wrapper()->post()->retrieve(
486 'subject',
487 $this->refinery->byTrying([
488 $this->refinery->kindlyTo()->string(),
489 $this->refinery->always('')
490 ])
491 );
492
493 $this->participants->updateSubject($this->user->getId(), ilUtil::stripSlashes($subject));
494 $this->tpl->setOnScreenMessage('success', $this->lng->txt('sub_request_saved'), true);
495 $this->ctrl->setParameterByClass(
496 "ilrepositorygui",
497 "ref_id",
498 $this->tree->getParentId($this->container->getRefId())
499 );
500 $this->ctrl->redirectByClass("ilrepositorygui", "");
501 }
502
503 protected function cancelSubscriptionRequest(): void
504 {
505 $this->participants->deleteSubscriber($this->user->getId());
506 $this->tpl->setOnScreenMessage('success', $this->lng->txt('sub_request_deleted'), true);
507
508 $this->ctrl->setParameterByClass(
509 "ilrepositorygui",
510 "ref_id",
511 $this->tree->getParentId($this->container->getRefId())
512 );
513 $this->ctrl->redirectByClass("ilrepositorygui", "");
514 }
515}
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
static _hasFields(int $a_container_id)
Check if there are any define fields.
Class ilCtrl provides processing control methods.
This class represents a custom property in a property form.
static _getInstanceByType(string $a_type)
Get Singleton Instance.
This class represents a section header in a property form.
language handling
static addCustomFields(ilPropertyFormGUI $form, int $a_obj_id, string $a_type, string $a_mode='user')
static addAgreement(ilPropertyFormGUI $form, int $a_obj_id, string $a_type)
static addExportFieldInfo(ilPropertyFormGUI $form, int $a_obj_id, string $a_type)
This class represents a non editable value in a property form.
static _getGroupingItems(ilObject $container_obj)
Get courses/groups that are assigned to the same membership limitation.
static _checkGroupingDependencies(ilObject $container_obj, ?int $a_user_id=null)
User class.
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Base class for course and group participants.
Singleton class that stores all privacy settings.
This class represents a property form user interface.
class ilRbacReview Contains Review functions of core Rbac.
Base class for Course and Group registration.
fillRegistrationType()
show informations about registration procedure
ilGlobalTemplateInterface $tpl
initParticipants()
Init participants object (course or group participants)
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.
fillRegistrationPeriod()
show informations about the registration period
ILIAS Refinery Factory $refinery
ilPrivacySettings $privacy
__construct(ilObject $a_container)
cancel()
cancel subscription
fillInformations()
fill informations
fillMembershipLimitation()
Show membership limitations.
ILIAS HTTP GlobalHttpState $http
show(?ilPropertyFormGUI $form=null)
getWaitingList()
Get waiting list object.
initWaitingList()
Init waiting list (course or group waiting list)
enableRegistration(bool $a_status)
fillMaxMembers()
show informations about the maximum number of user.
This class represents a selection list property in a property form.
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Base class for course and group waiting lists.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
static http()
Fetches the global http state from ILIAS.
form(?array $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26
$text
Definition: xapiexit.php:21