ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseRegistrationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
28{
29 private object $parent_gui;
30
31 public function __construct(ilObject $a_container, object $a_parent_gui)
32 {
33 parent::__construct($a_container);
34 $this->parent_gui = $a_parent_gui;
35 }
36
37 public function executeCommand()
38 {
39 if ($this->getWaitingList()->isOnList($this->user->getId())) {
40 $this->tabs->activateTab('leave');
41 }
42
43 if (!$this->access->checkAccess('join', '', $this->getRefId())) {
44 $this->ctrl->setReturn($this->parent_gui, 'infoScreen');
45 $this->ctrl->returnToParent($this);
46 return;
47 }
48
49 $next_class = $this->ctrl->getNextClass($this);
50 switch ($next_class) {
51 default:
52 $cmd = $this->ctrl->getCmd("show");
53 $this->$cmd();
54 break;
55 }
56 }
57
58 protected function getFormTitle(): string
59 {
60 if ($this->getWaitingList()->isOnList($this->user->getId())) {
61 return $this->lng->txt('member_status');
62 }
63 return $this->lng->txt('crs_registration');
64 }
65
66 protected function fillInformations(): void
67 {
68 if ($this->container->getImportantInformation()) {
69 $imp = new ilNonEditableValueGUI($this->lng->txt('crs_important_info'), "", true);
70 $value = nl2br(ilUtil::makeClickable($this->container->getImportantInformation(), true));
71 $imp->setValue($value);
72 $this->form->addItem($imp);
73 }
74
75 if ($this->container->getSyllabus()) {
76 $syl = new ilNonEditableValueGUI($this->lng->txt('crs_syllabus'), "", true);
77 $value = nl2br(ilUtil::makeClickable($this->container->getSyllabus(), true));
78 $syl->setValue($value);
79 $this->form->addItem($syl);
80 }
81 }
82
83 protected function fillRegistrationPeriod(): void
84 {
85 $now = new ilDateTime(time(), IL_CAL_UNIX, 'UTC');
86
87 if ($this->container->getSubscriptionUnlimitedStatus()) {
88 $reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_period'));
89 $reg->setValue($this->lng->txt('mem_unlimited'));
90 $this->form->addItem($reg);
91 return;
92 } elseif ($this->container->getSubscriptionLimitationType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_DEACTIVATED) {
93 return;
94 }
95
96 $start = new ilDateTime($this->container->getSubscriptionStart(), IL_CAL_UNIX, 'UTC');
97 $end = new ilDateTime($this->container->getSubscriptionEnd(), IL_CAL_UNIX, 'UTC');
98
99 $warning = '';
100 if (ilDateTime::_before($now, $start)) {
101 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'components/ILIAS/Membership');
102 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
104
105 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
107
108 $warning = $this->lng->txt('mem_reg_not_started');
109 } elseif (ilDateTime::_after($now, $end)) {
110 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'components/ILIAS/Membership');
111 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_start'));
113
114 $tpl->setVariable('TXT_END', $this->lng->txt('mem_end'));
116
117 $warning = $this->lng->txt('mem_reg_expired');
118 } else {
119 $tpl = new ilTemplate('tpl.registration_period_form.html', true, true, 'components/ILIAS/Membership');
120 $tpl->setVariable('TXT_FIRST', $this->lng->txt('mem_end'));
122 }
123
124 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_period'));
125 $reg->setHtml($tpl->get());
126 if (strlen($warning)) {
127 // Disable registration
128 $this->enableRegistration(false);
129 $this->tpl->setOnScreenMessage('failure', $warning);
130 #$reg->setAlert($warning);
131 }
132 $this->form->addItem($reg);
133 }
134
135 protected function fillMaxMembers(): void
136 {
137 if (!$this->container->isSubscriptionMembershipLimited()) {
138 return;
139 }
140 $tpl = new ilTemplate('tpl.max_members_form.html', true, true, 'components/ILIAS/Membership');
141
142 $alert = '';
143 if ($this->container->getSubscriptionMinMembers()) {
144 $tpl->setVariable('TXT_MIN', $this->lng->txt('mem_min_users') . ':');
145 $tpl->setVariable('NUM_MIN', $this->container->getSubscriptionMinMembers());
146 }
147
148 if ($this->container->getSubscriptionMaxMembers()) {
149 $tpl->setVariable('TXT_MAX', $this->lng->txt('mem_max_users'));
150 $tpl->setVariable('NUM_MAX', $this->container->getSubscriptionMaxMembers());
151
152 $tpl->setVariable('TXT_FREE', $this->lng->txt('mem_free_places') . ":");
154 $free = $reg_info['reg_info_free_places'];
155
156 if ($free) {
157 $tpl->setVariable('NUM_FREE', $free);
158 } else {
159 $tpl->setVariable('WARN_FREE', $free);
160 }
161
162 $waiting_list = new ilCourseWaitingList($this->container->getId());
163 if (
164 $this->container->isSubscriptionMembershipLimited() && $this->container->enabledWaitingList() && (!$free || $waiting_list->getCountUsers())) {
165 if ($waiting_list->isOnList($this->user->getId())) {
166 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list_position'));
167 $tpl->setVariable('NUM_WAIT', $waiting_list->getPosition($this->user->getId()));
168 } else {
169 $tpl->setVariable('TXT_WAIT', $this->lng->txt('mem_waiting_list'));
170 if ($free && $waiting_list->getCountUsers()) {
172 } else {
174 }
175 }
176 }
177 if (
178 !$free && !$this->container->enabledWaitingList()) {
179 // Disable registration
180 $this->enableRegistration(false);
181 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mem_alert_no_places'));
182 #$alert = $this->lng->txt('mem_alert_no_places');
183 } elseif (
184 $this->container->enabledWaitingList() && $this->container->isSubscriptionMembershipLimited() && $waiting_list->isOnList($this->user->getId())
185 ) {
186 // Disable registration
187 $this->enableRegistration(false);
188 } elseif (
189 !$free && $this->container->enabledWaitingList() && $this->container->isSubscriptionMembershipLimited()) {
190 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_warn_no_max_set_on_waiting_list'));
191 #$alert = $this->lng->txt('crs_warn_no_max_set_on_waiting_list');
192 } elseif (
193 $free && $this->container->enabledWaitingList() && $this->container->isSubscriptionMembershipLimited() && $this->getWaitingList()->getCountUsers()) {
194 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_warn_wl_set_on_waiting_list'));
195 #$alert = $this->lng->txt('crs_warn_wl_set_on_waiting_list');
196 }
197 }
198
199 $max = new ilCustomInputGUI($this->lng->txt('mem_participants'));
200 $max->setHtml($tpl->get());
201 if (strlen($alert)) {
202 $max->setAlert($alert);
203 }
204 $this->form->addItem($max);
205 }
206
207 protected function fillRegistrationType(): void
208 {
209 if ($this->container->getSubscriptionLimitationType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_DEACTIVATED) {
210 $reg = new ilCustomInputGUI($this->lng->txt('mem_reg_type'));
211 #$reg->setHtml($this->lng->txt('crs_info_reg_deactivated'));
212 $reg->setAlert($this->lng->txt('crs_info_reg_deactivated'));
213 #ilUtil::sendFailure($this->lng->txt('crs_info_reg_deactivated'));
214 #$reg = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
215 #$reg->setValue($this->lng->txt('crs_info_reg_deactivated'));
216 #$reg->setAlert($this->lng->txt('grp_reg_deactivated_alert'));
217 $this->form->addItem($reg);
218
219 // Disable registration
220 $this->enableRegistration(false);
221 return;
222 }
223
224 switch ($this->container->getSubscriptionType()) {
226
227 // no "request" info if waiting list is active
228 if ($this->isWaitingListActive()) {
229 return;
230 }
231
232 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
233 $txt->setValue($this->lng->txt('crs_info_reg_direct'));
234
235 $this->form->addItem($txt);
236 break;
237
239 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
240 $txt->setValue($this->lng->txt('crs_subscription_options_password'));
241
242 $pass = new ilTextInputGUI($this->lng->txt('passwd'), 'grp_passw');
243 $pass->setInputType('password');
244 $pass->setSize(12);
245 $pass->setMaxLength(32);
246 #$pass->setRequired(true);
247 $pass->setInfo($this->lng->txt('crs_info_reg_password'));
248
249 $txt->addSubItem($pass);
250 $this->form->addItem($txt);
251 break;
252
254
255 // no "request" info if waiting list is active
256 if ($this->isWaitingListActive()) {
257 return;
258 }
259
260 $txt = new ilNonEditableValueGUI($this->lng->txt('mem_reg_type'));
261 $txt->setValue($this->lng->txt('crs_subscription_options_confirmation'));
262
263 $sub = new ilTextAreaInputGUI($this->lng->txt('crs_reg_subject'), 'subject');
264 $sub->setInfo($this->lng->txt('crs_info_reg_confirmation'));
265 $sub->setCols(40);
266 $sub->setRows(5);
267 if ($this->participants->isSubscriber($this->user->getId())) {
268 $sub_data = $this->participants->getSubscriberData($this->user->getId());
269 $sub->setValue($sub_data['subject']);
270 $sub->setInfo('');
271 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_reg_user_already_subscribed'));
272 $this->enableRegistration(false);
273 }
274 $txt->addSubItem($sub);
275 $this->form->addItem($txt);
276 break;
277
278 default:
279 }
280 }
281
282 protected function addCommandButtons(): void
283 {
284 parent::addCommandButtons();
285 switch ($this->container->getSubscriptionType()) {
287 if ($this->participants->isSubscriber($this->user->getId())) {
288 $this->form->clearCommandButtons();
289 $this->form->addCommandButton(
290 'updateSubscriptionRequest',
291 $this->lng->txt('crs_update_subscr_request')
292 );
293 $this->form->addCommandButton(
294 'cancelSubscriptionRequest',
295 $this->lng->txt('crs_cancel_subscr_request')
296 );
297 } elseif ($this->isRegistrationPossible()) {
298 $this->form->clearCommandButtons();
299 $this->form->addCommandButton('join', $this->lng->txt('crs_join_request'));
300 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
301 }
302 break;
303 }
304 if (!$this->isRegistrationPossible()) {
305 }
306 }
307
308 protected function validate(): bool
309 {
310 if ($this->user->getId() == ANONYMOUS_USER_ID) {
311 $this->join_error = $this->lng->txt('permission_denied');
312 return false;
313 }
314
315 // Set aggrement to not accepted
316 $this->setAccepted(false);
317
318 if (!$this->isRegistrationPossible()) {
319 $this->join_error = $this->lng->txt('mem_error_preconditions');
320 return false;
321 }
322 if ($this->container->getSubscriptionType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_PASSWORD) {
323 $pass = $this->http->wrapper()->post()->retrieve(
324 'grp_passw',
325 $this->refinery->kindlyTo()->string()
326 );
327 if ((string) $pass === '') {
328 $this->join_error = $this->lng->txt('crs_password_required');
329 return false;
330 }
331 if (strcmp($pass, $this->container->getSubscriptionPassword()) !== 0) {
332 $this->join_error = $this->lng->txt('crs_password_not_valid');
333 return false;
334 }
335 }
336 if (!$this->validateCustomFields()) {
337 $this->join_error = $this->lng->txt('fill_out_all_required_fields');
338 return false;
339 }
340 if (!$this->validateAgreement()) {
341 $this->join_error = $this->lng->txt('crs_agreement_required');
342 return false;
343 }
344
345 return true;
346 }
347
348 protected function add()
349 {
350 // set aggreement accepted
351 $this->setAccepted(true);
352
353 $free = max(0, $this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
354 $waiting_list = new ilCourseWaitingList($this->container->getId());
355 if ($this->container->isSubscriptionMembershipLimited() && $this->container->enabledWaitingList() && (!$free || $waiting_list->getCountUsers())) {
356 $waiting_list->addToList($this->user->getId());
357 $info = sprintf(
358 $this->lng->txt('crs_added_to_list'),
359 $waiting_list->getPosition($this->user->getId())
360 );
361 $this->tpl->setOnScreenMessage('success', $info, true);
362
363 $this->participants->sendNotification(
365 $this->user->getId()
366 );
367 $this->participants->sendNotification(
369 $this->user->getId()
370 );
371 $this->ctrl->setParameterByClass(
372 "ilrepositorygui",
373 "ref_id",
374 $this->tree->getParentId($this->container->getRefId())
375 );
376 $this->ctrl->redirectByClass("ilrepositorygui", "");
377 }
378
379 switch ($this->container->getSubscriptionType()) {
381 $this->participants->addSubscriber($this->user->getId());
382 $this->participants->updateSubscriptionTime($this->user->getId(), time());
383
384 $subject = $this->http->wrapper()->post()->retrieve(
385 'subject',
386 $this->refinery->kindlyTo()->string()
387 );
388 $this->participants->updateSubject($this->user->getId(), $subject);
389 $this->participants->sendNotification(
391 $this->user->getId()
392 );
393
394 $this->tpl->setOnScreenMessage('success', $this->lng->txt("application_completed"), true);
395 $this->ctrl->setParameterByClass(
396 "ilrepositorygui",
397 "ref_id",
398 $this->tree->getParentId($this->container->getRefId())
399 );
400 $this->ctrl->redirectByClass("ilrepositorygui", "");
401 break;
402
403 default:
404
405 if ($this->container->isSubscriptionMembershipLimited() && $this->container->getSubscriptionMaxMembers()) {
406 $success = $GLOBALS['DIC']['rbacadmin']->assignUserLimited(
407 ilParticipants::getDefaultMemberRole($this->container->getRefId()),
408 $this->user->getId(),
409 $this->container->getSubscriptionMaxMembers(),
410 array(ilParticipants::getDefaultMemberRole($this->container->getRefId()))
411 );
412 if (!$success) {
413 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_subscription_failed_limit'));
414 $this->show();
415 return;
416 }
417 }
418
419 $this->participants->add($this->user->getId(), ilParticipants::IL_CRS_MEMBER);
420 $this->participants->sendNotification(ilCourseMembershipMailNotification::TYPE_NOTIFICATION_ADMINS, $this->user->getId());
421 $this->participants->sendNotification(ilCourseMembershipMailNotification::TYPE_SUBSCRIBE_MEMBER, $this->user->getId());
422
423 ilForumNotification::checkForumsExistsInsert($this->container->getRefId(), $this->user->getId());
424
425 if ($this->container->getType() == "crs") {
426 $this->container->checkLPStatusSync($this->user->getId());
427 }
428 $pending_goto = ilSession::get('pending_goto');
429 if (!$pending_goto) {
430 $this->tpl->setOnScreenMessage('success', $this->lng->txt("crs_subscription_successful"), true);
431 $this->ctrl->returnToParent($this);
432 } else {
433 $tgt = $pending_goto;
434 ilSession::clear('pending_goto');
435 ilUtil::redirect($tgt);
436 }
437 break;
438 }
439 }
440
441 protected function initParticipants(): ilParticipants
442 {
443 $this->participants = ilCourseParticipants::_getInstanceByObjId($this->obj_id);
444 return $this->participants;
445 }
446
447 protected function initWaitingList(): ilWaitingList
448 {
449 $this->waiting_list = new ilCourseWaitingList($this->container->getId());
450 return $this->waiting_list;
451 }
452
453 protected function isWaitingListActive(): bool
454 {
455 static $active = null;
456
457 if ($active !== null) {
458 return $active;
459 }
460 if (!$this->container->enabledWaitingList() || !$this->container->isSubscriptionMembershipLimited()) {
461 return $active = false;
462 }
463 if (!$this->container->getSubscriptionMaxMembers()) {
464 return $active = false;
465 }
466
467 $free = max(0, $this->container->getSubscriptionMaxMembers() - $this->participants->getCountMembers());
468 return $active = (!$free || $this->getWaitingList()->getCountUsers());
469 }
470}
const IL_CAL_UNIX
static _getInstanceByObjId(int $a_obj_id)
GUI class for course registrations.
getFormTitle()
Get title for property form.
initParticipants()
Init participants object (course or group participants)
__construct(ilObject $a_container, object $a_parent_gui)
fillRegistrationPeriod()
show informations about the registration period
isWaitingListActive()
Check if the waiting list is active Maximum of members exceeded or any user on the waiting list.
initWaitingList()
Init waiting list (course or group waiting list)
fillMaxMembers()
show informations about the maximum number of user.
fillRegistrationType()
show informations about registration procedure
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)
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.
static getDefaultMemberRole(int $a_ref_id)
Base class for Course and Group registration.
ilGlobalTemplateInterface $tpl
show(?ilPropertyFormGUI $form=null)
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="")
$GLOBALS["DIC"]
Definition: wac.php:54