ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjSession.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 public const MAIL_ALLOWED_ALL = 1;
32 public const MAIL_ALLOWED_ADMIN = 2;
33 public const LOCAL_ROLE_PARTICIPANT_PREFIX = 'il_sess_participant';
34 public const CAL_REG_START = 1;
35
39 protected string $location = "";
40 protected string $name = "";
41 protected string $phone = "";
42 protected string $email = "";
43 protected string $details = "";
44 protected int $event_id = 0;
46 protected int $reg_limited = 0;
47 protected int $reg_min_users = 0;
48 protected int $reg_limited_users = 0;
49 protected bool $reg_waiting_list = false;
50 protected bool $reg_waiting_list_autofill = false;
51 protected bool $show_members = false;
52 protected bool $show_cannot_participate_option = true;
54 protected array $appointments = [];
56 protected bool $registrationNotificationEnabled = false;
58
59 public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
60 {
61 global $DIC;
62
63 $this->session_logger = $DIC->logger()->sess();
64 $this->obj_data_cache = $DIC['ilObjDataCache'];
65 $this->event_handler = $DIC->event();
66
67 $this->type = "sess";
68 parent::__construct($a_id, $a_call_by_reference);
69 }
70
71 public static function _lookupRegistrationEnabled(int $a_obj_id): bool
72 {
73 global $DIC;
74
75 $ilDB = $DIC->database();
76
77 $query = "SELECT reg_type FROM event " .
78 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
79 $res = $ilDB->query($query);
80 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
81 return (bool) $row->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
82 }
83 return false;
84 }
85
86 public static function lookupSession(int $a_obj_id): array
87 {
88 global $DIC;
89
90 $ilDB = $DIC->database();
91
92 $query = "SELECT * FROM event " .
93 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
94 $res = $ilDB->query($query);
95 $data = [];
96 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
97 $data['location'] = $row->location ?: '';
98 $data['details'] = $row->details ?: '';
99 $data['name'] = $row->tutor_name ?: '';
100 $data['email'] = $row->tutor_email ?: '';
101 $data['phone'] = $row->tutor_phone ?: '';
102 }
103 return $data;
104 }
105
106 public function getPresentationTitle(): string
107 {
108 $date = new ilDate($this->getFirstAppointment()->getStart()->getUnixTime(), IL_CAL_UNIX);
109 if ($this->getTitle()) {
110 return ilDatePresentation::formatDate($this->getFirstAppointment()->getStart()) . ': ' . $this->getTitle();
111 } else {
112 return ilDatePresentation::formatDate($date);
113 }
114 }
115
117 {
118 $title = '';
119 if ($this->getTitle()) {
120 $title = ': ' . $this->getTitle();
121 }
123 $this->getFirstAppointment()->getStart(),
124 $this->getFirstAppointment()->getEnd()
125 ) . $title;
126 }
127
131 public function initDefaultRoles(): void
132 {
134 self::LOCAL_ROLE_PARTICIPANT_PREFIX . '_' . $this->getRefId(),
135 'Participant of session obj_no.' . $this->getId(),
136 self::LOCAL_ROLE_PARTICIPANT_PREFIX,
137 $this->getRefId()
138 );
139
140 if (!$role instanceof ilObjRole) {
141 $this->session_logger->warning('Could not create default session role.');
142 $this->session_logger->logStack(ilLogLevel::WARNING);
143 }
144 }
145
146 public function getEventId(): int
147 {
148 return $this->event_id;
149 }
150
151 public function setLocation(string $a_location): void
152 {
153 $this->location = $a_location;
154 }
155
156 public function getLocation(): string
157 {
158 return $this->location;
159 }
160
161 public function setName(string $a_name): void
162 {
163 $this->name = $a_name;
164 }
165
166 public function getName(): string
167 {
168 return $this->name;
169 }
170
171 public function setPhone(string $a_phone): void
172 {
173 $this->phone = $a_phone;
174 }
175
176 public function getPhone(): string
177 {
178 return $this->phone;
179 }
180
181 public function setEmail(string $a_email): void
182 {
183 $this->email = $a_email;
184 }
185
186 public function getEmail(): string
187 {
188 return $this->email;
189 }
190
191 public function hasTutorSettings(): bool
192 {
193 return strlen($this->getName()) ||
194 strlen($this->getEmail()) ||
195 strlen($this->getPhone());
196 }
197
198 public function setDetails(string $a_details): void
199 {
200 $this->details = $a_details;
201 }
202
203 public function getDetails(): string
204 {
205 return $this->details;
206 }
207
208 public function setRegistrationType(int $a_type): void
209 {
210 $this->reg_type = $a_type;
211 }
212
213 public function getRegistrationType(): int
214 {
215 return $this->reg_type;
216 }
217
219 {
220 return $this->reg_limited;
221 }
222
223 public function enableRegistrationUserLimit(int $a_limit): void
224 {
225 $this->reg_limited = $a_limit;
226 }
227
228 public function getRegistrationMinUsers(): int
229 {
231 }
232
233 public function setRegistrationMinUsers(int $a_users): void
234 {
235 $this->reg_min_users = $a_users;
236 }
237
238 public function getRegistrationMaxUsers(): int
239 {
241 }
242
243 public function setRegistrationMaxUsers(int $a_users): void
244 {
245 $this->reg_limited_users = $a_users;
246 }
247
248 public function isRegistrationWaitingListEnabled(): bool
249 {
251 }
252
253 public function enableRegistrationWaitingList(bool $a_stat): void
254 {
255 $this->reg_waiting_list = $a_stat;
256 }
257
258 public function setWaitingListAutoFill(bool $a_value): void
259 {
260 $this->reg_waiting_list_autofill = $a_value;
261 }
262
263 public function hasWaitingListAutoFill(): bool
264 {
266 }
267
268 public function setShowMembers(bool $a_status): void
269 {
270 $this->show_members = $a_status;
271 }
272
273 public function getShowMembers(): bool
274 {
275 return $this->show_members;
276 }
277
278 public function isRegistrationNotificationEnabled(): bool
279 {
281 }
282
283 public function setRegistrationNotificationEnabled(bool $value): void
284 {
285 $this->registrationNotificationEnabled = $value;
286 }
287
288 public function getRegistrationNotificationOption(): string
289 {
291 }
292
293 public function setRegistrationNotificationOption(string $value): void
294 {
295 $this->notificationOption = $value;
296 }
297
298 public function enabledRegistration(): bool
299 {
300 return $this->reg_type != ilMembershipRegistrationSettings::TYPE_NONE;
301 }
302
303 public function enabledRegistrationForUsers(): bool
304 {
305 return
308 }
309
310 public function isCannotParticipateOptionEnabled(): bool
311 {
313 }
314
315 public function enableCannotParticipateOption(bool $status): void
316 {
317 $this->show_cannot_participate_option = $status;
318 }
319
320 public function getAppointments(): array
321 {
322 return $this->appointments;
323 }
324
325 public function addAppointment(ilSessionAppointment $appointment): void
326 {
327 $this->appointments[] = $appointment;
328 }
329
333 public function setAppointments(array $appointments): void
334 {
335 $this->appointments = $appointments;
336 }
337
339 {
340 $app = $this->appointments[0] ?? null;
341 return is_object($app) ? $app : ($this->appointments[0] = new ilSessionAppointment());
342 }
343
344 public function setMailToMembersType(int $a_type): void
345 {
346 $this->mail_members = $a_type;
347 }
348
349 public function getMailToMembersType(): int
350 {
351 return $this->mail_members;
352 }
353
354 public function validate(): bool
355 {
357
358 // #17114
359 if ($this->isRegistrationUserLimitEnabled() &&
360 !$this->getRegistrationMaxUsers()) {
361 $ilErr->appendMessage($this->lng->txt("sess_max_members_needed"));
362 return false;
363 }
364
365 return true;
366 }
367
368 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObjSession
369 {
373 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
374
376 $new_obj->applyDidacticTemplate($dtpl);
377
378 $this->read();
379
380 $this->cloneSettings($new_obj);
381 $this->cloneMetaData($new_obj);
382
383
384 // Clone appointment
385 $new_app = $this->getFirstAppointment()->cloneObject($new_obj->getId());
386 $new_obj->setAppointments(array($new_app));
387 $new_obj->update(true);
388
389 // Raise update forn new appointments
390
391
392
393 // Copy learning progress settings
394 $obj_settings = new ilLPObjSettings($this->getId());
395 $obj_settings->cloneSettings($new_obj->getId());
396 unset($obj_settings);
397
398 return $new_obj;
399 }
400
401 public function cloneSettings(ilObjSession $new_obj): bool
402 {
404 $new_obj->getId(),
407 $this->getId(),
409 )
410 );
411
412 $new_obj->setLocation($this->getLocation());
413 $new_obj->setName($this->getName());
414 $new_obj->setPhone($this->getPhone());
415 $new_obj->setEmail($this->getEmail());
416 $new_obj->setDetails($this->getDetails());
417
418 $new_obj->setRegistrationType($this->getRegistrationType());
424 $new_obj->setShowMembers($this->getShowMembers());
425 $new_obj->setMailToMembersType($this->getMailToMembersType());
426
430
431 $new_obj->update(true);
432
433 return true;
434 }
435
436 public function cloneDependencies($target_id, $copy_id): bool
437 {
438 $ilObjDataCache = $this->obj_data_cache;
439
440 parent::cloneDependencies($target_id, $copy_id);
441
442 $target_obj_id = $ilObjDataCache->lookupObjId($target_id);
443
444 $session_materials = new ilEventItems($target_obj_id);
445 $session_materials->cloneItems($this->getId(), $copy_id);
446
447 return true;
448 }
449
450 public function create(bool $a_skip_meta_data = false): int
451 {
453 $ilAppEventHandler = $this->event_handler;
454
455 parent::create();
456
457 if (!$a_skip_meta_data) {
458 $this->createMetaData();
459 }
460
461 $next_id = $ilDB->nextId('event');
462 $query = "INSERT INTO event (event_id,obj_id,location,tutor_name,tutor_phone,tutor_email,details,registration, " .
463 'reg_type, reg_limit_users, reg_limited, reg_waiting_list, reg_min_users, reg_auto_wait,show_members,mail_members,
464 reg_notification, notification_opt, show_cannot_part) ' .
465 "VALUES( " .
466 $ilDB->quote($next_id, 'integer') . ", " .
467 $this->db->quote($this->getId(), 'integer') . ", " .
468 $this->db->quote($this->getLocation(), 'text') . "," .
469 $this->db->quote($this->getName(), 'text') . ", " .
470 $this->db->quote($this->getPhone(), 'text') . ", " .
471 $this->db->quote($this->getEmail(), 'text') . ", " .
472 $this->db->quote($this->getDetails(), 'text') . "," .
473 $this->db->quote((int) $this->enabledRegistrationForUsers(), 'integer') . ", " .
474 $this->db->quote($this->getRegistrationType(), 'integer') . ', ' .
475 $this->db->quote($this->getRegistrationMaxUsers(), 'integer') . ', ' .
476 $this->db->quote($this->isRegistrationUserLimitEnabled(), 'integer') . ', ' .
477 $this->db->quote((int) $this->isRegistrationWaitingListEnabled(), 'integer') . ', ' .
478 $this->db->quote($this->getRegistrationMinUsers(), 'integer') . ', ' .
479 $this->db->quote((int) $this->hasWaitingListAutoFill(), 'integer') . ', ' .
480 $this->db->quote((int) $this->getShowMembers(), 'integer') . ', ' .
481 $this->db->quote($this->getMailToMembersType(), 'integer') . ',' .
482 $this->db->quote((int) $this->isRegistrationNotificationEnabled(), 'integer') . ', ' .
483 $this->db->quote($this->getRegistrationNotificationOption(), 'text') . ', ' .
484 $this->db->quote((int) $this->isCannotParticipateOptionEnabled(), ilDBConstants::T_INTEGER) . ' ' .
485 ")";
486 $res = $ilDB->manipulate($query);
487 $this->event_id = $next_id;
488
489 $ilAppEventHandler->raise(
490 'components/ILIAS/Session',
491 'create',
492 array('object' => $this,
493 'obj_id' => $this->getId(),
494 'appointments' => $this->prepareCalendarAppointments('create'))
495 );
496
497 return $this->getId();
498 }
499
500 public function update(bool $a_skip_meta_update = false): bool
501 {
503 $ilAppEventHandler = $this->event_handler;
504
505 if (!parent::update()) {
506 return false;
507 }
508 if (!$a_skip_meta_update) {
509 $this->updateMetaData();
510 }
511
512 $query = "UPDATE event SET " .
513 "location = " . $this->db->quote($this->getLocation(), 'text') . "," .
514 "tutor_name = " . $this->db->quote($this->getName(), 'text') . ", " .
515 "tutor_phone = " . $this->db->quote($this->getPhone(), 'text') . ", " .
516 "tutor_email = " . $this->db->quote($this->getEmail(), 'text') . ", " .
517 "details = " . $this->db->quote($this->getDetails(), 'text') . ", " .
518 "registration = " . $this->db->quote((int) $this->enabledRegistrationForUsers(), 'integer') . ", " .
519 "reg_type = " . $this->db->quote($this->getRegistrationType(), 'integer') . ", " .
520 "reg_limited = " . $this->db->quote($this->isRegistrationUserLimitEnabled(), 'integer') . ", " .
521 "reg_limit_users = " . $this->db->quote($this->getRegistrationMaxUsers(), 'integer') . ", " .
522 "reg_min_users = " . $this->db->quote($this->getRegistrationMinUsers(), 'integer') . ", " .
523 "reg_waiting_list = " . $this->db->quote((int) $this->isRegistrationWaitingListEnabled(), 'integer') . ", " .
524 "reg_auto_wait = " . $this->db->quote((int) $this->hasWaitingListAutoFill(), 'integer') . ", " .
525 'show_members = ' . $this->db->quote((int) $this->getShowMembers(), 'integer') . ', ' .
526 'mail_members = ' . $this->db->quote($this->getMailToMembersType(), 'integer') . ', ' .
527 "reg_auto_wait = " . $this->db->quote((int) $this->hasWaitingListAutoFill(), 'integer') . ", " .
528 "reg_notification = " . $this->db->quote((int) $this->isRegistrationNotificationEnabled(), 'integer') . ", " .
529 "notification_opt = " . $this->db->quote($this->getRegistrationNotificationOption(), 'text') . ", " .
530 'show_cannot_part = ' . $this->db->quote((int) $this->isCannotParticipateOptionEnabled(), ilDBConstants::T_INTEGER) . ' ' .
531 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer') . " ";
532 $res = $ilDB->manipulate($query);
533
534 $ilAppEventHandler->raise(
535 'components/ILIAS/Session',
536 'update',
537 array('object' => $this,
538 'obj_id' => $this->getId(),
539 'appointments' => $this->prepareCalendarAppointments('update'))
540 );
541 return true;
542 }
543
544 public function delete(): bool
545 {
547 $ilAppEventHandler = $this->event_handler;
548
549 if (!parent::delete()) {
550 return false;
551 }
552
553 // delete meta data
554 $this->deleteMetaData();
555
556 $query = "DELETE FROM event " .
557 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer') . " ";
558 $res = $ilDB->manipulate($query);
559
563
564 $ilAppEventHandler->raise(
565 'components/ILIAS/Session',
566 'delete',
567 array('object' => $this,
568 'obj_id' => $this->getId(),
569 'appointments' => $this->prepareCalendarAppointments('delete'))
570 );
571
572 return true;
573 }
574
575 public function read(): void
576 {
577 parent::read();
578
579 $query = "SELECT * FROM event WHERE " .
580 "obj_id = " . $this->db->quote($this->getId(), 'integer') . " ";
581 $res = $this->db->query($query);
582
583 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
584 $this->setLocation((string) $row->location);
585 $this->setName((string) $row->tutor_name);
586 $this->setPhone((string) $row->tutor_phone);
587 $this->setEmail((string) $row->tutor_email);
588 $this->setDetails((string) $row->details);
589 $this->setRegistrationType((int) $row->reg_type);
590 $this->enableRegistrationUserLimit((int) $row->reg_limited);
591 $this->enableRegistrationWaitingList((bool) $row->reg_waiting_list);
592 $this->setWaitingListAutoFill((bool) $row->reg_auto_wait);
593 $this->setRegistrationMaxUsers((int) $row->reg_limit_users);
594 $this->setRegistrationMinUsers((int) $row->reg_min_users);
595 $this->setShowMembers((bool) $row->show_members);
596 $this->setMailToMembersType((int) $row->mail_members);
597 $this->setRegistrationNotificationEnabled((bool) $row->reg_notification);
598 $this->setRegistrationNotificationOption((string) $row->notification_opt);
599 $this->enableCannotParticipateOption((bool) $row->show_cannot_part);
600 $this->event_id = (int) $row->event_id;
601 }
602
603 $this->initAppointments();
604 }
605
606 protected function initAppointments(): void
607 {
608 // get assigned appointments
609 $this->appointments = ilSessionAppointment::_readAppointmentsBySession($this->getId());
610 }
611
612
617 public function prepareCalendarAppointments(string $a_mode = 'create'): array
618 {
619 switch ($a_mode) {
620 case 'create':
621 case 'update':
622
623 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
624 $app->setTranslationType(ilCalendarEntry::TRANSLATION_NONE);
625 $app->setTitle($this->getTitle() ? $this->getTitle() : $this->lng->txt('obj_sess'));
626 $app->setDescription($this->getLongDescription());
627 $app->setLocation($this->getLocation());
628
629 $sess_app = $this->getFirstAppointment();
630 $app->setFullday($sess_app->isFullday());
631 $app->setStart($sess_app->getStart());
632 $app->setEnd($sess_app->getEnd());
633 $apps[] = $app;
634
635 return $apps;
636
637 case 'delete':
638 // Nothing to do: The category and all assigned appointments will be deleted.
639 return [];
640 }
641
642 return [];
643 }
644
645 public function handleAutoFill(): bool
646 {
647 if (
649 !$this->hasWaitingListAutoFill()
650 ) {
651 $this->session_logger->debug('Waiting list or auto fill is disabled.');
652 return true;
653 }
654
656 $current = $parts->getCountParticipants();
657
658 $refs = ilObject::_getAllReferences($this->getId());
659 $ref_id = current($refs);
660 if ($ref_id === false) {
661 $this->session_logger->warning('No ref_id found for obj_id: ' . $this->getId());
662 return true;
663 }
665 $max = $this->getRegistrationMaxUsers();
666
667 if ($max <= $current) {
668 $this->session_logger->debug('Maximum number of participants not reached.');
669 $this->session_logger->debug('Maximum number of members: ' . $max);
670 $this->session_logger->debug('Current number of members: ' . $current);
671 return true;
672 }
673
674 $session_waiting_list = new ilSessionWaitingList($this->getId());
675 foreach ($session_waiting_list->getUserIds() as $user_id) {
677 if (!$user instanceof ilObjUser) {
678 $this->session_logger->warning('Found invalid user id on waiting list: ' . $user_id);
679 continue;
680 }
681 if (in_array($user_id, $parts->getParticipants())) {
682 $this->session_logger->notice('User on waiting list already session member: ' . $user_id);
683 continue;
684 }
685
686 if ($this->enabledRegistrationForUsers()) {
687 $this->session_logger->debug('Registration enabled: register user');
688 $parts->register($user_id);
689 } else {
690 $this->session_logger->debug('Registration disabled: set user status to participated.');
691 $parts->getEventParticipants()->updateParticipation($user_id, true);
692 }
693 $parts->sendNotification(
696 );
697
698 $session_waiting_list->removeFromList($user_id);
699
700 $current++;
701 if ($current >= $max) {
702 break;
703 }
704 }
705
706 return true;
707 }
708
709 protected function initParticipants(): void
710 {
711 $this->members_obj = ilSessionParticipants::_getInstanceByObjId($this->getId());
712 }
713
715 {
716 if (!$this->members_obj instanceof ilSessionParticipants) {
717 $this->initParticipants();
718 }
719 return $this->members_obj;
720 }
721
722 public function getEnableMap(): bool
723 {
724 return false;
725 }
726}
const IL_CAL_UNIX
Global event handler.
Apointment templates are used for automatic generated apointments.
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
Class for single dates.
class ilEventItems
static _delete(int $a_event_id)
static _deleteByEvent(int $a_event_id)
Component logger with individual log levels by component id.
Class ilObjRole.
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
const LOCAL_ROLE_PARTICIPANT_PREFIX
update(bool $a_skip_meta_update=false)
static _lookupRegistrationEnabled(int $a_obj_id)
enableCannotParticipateOption(bool $status)
bool $show_cannot_participate_option
string $notificationOption
create(bool $a_skip_meta_data=false)
initDefaultRoles()
Create local session participant role.
setRegistrationNotificationEnabled(bool $value)
ilAppEventHandler $event_handler
setRegistrationType(int $a_type)
ilObjectDataCache $obj_data_cache
setWaitingListAutoFill(bool $a_value)
__construct(int $a_id=0, bool $a_call_by_reference=true)
prepareCalendarAppointments(string $a_mode='create')
setDetails(string $a_details)
setPhone(string $a_phone)
enableRegistrationWaitingList(bool $a_stat)
setShowMembers(bool $a_status)
setRegistrationMaxUsers(int $a_users)
setName(string $a_name)
setRegistrationMinUsers(int $a_users)
static lookupSession(int $a_obj_id)
ilSessionParticipants $members_obj
addAppointment(ilSessionAppointment $appointment)
getPresentationTitle()
get presentation title Normally same as title Overwritten for sessions
ilLogger $session_logger
bool $reg_waiting_list_autofill
setEmail(string $a_email)
bool $registrationNotificationEnabled
cloneSettings(ilObjSession $new_obj)
getPresentationTitleAppointmentPeriod()
setAppointments(array $appointments)
setMailToMembersType(int $a_type)
setLocation(string $a_location)
enableRegistrationUserLimit(int $a_limit)
setRegistrationNotificationOption(string $value)
cloneDependencies($target_id, $copy_id)
User class.
class ilObjectDataCache
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObject Basic functions for all objects.
string $title
cloneMetaData(ilObject $target_obj)
Copy meta data.
static _getAllReferences(int $id)
get all reference ids for object ID
ilErrorHandling $error
getLongDescription()
get object long description (stored in object_description)
ilObjUser $user
ilDBInterface $db
static lookupNumberOfMembers(int $a_ref_id)
Lookup number of members.
class ilSessionAppointment
static _deleteBySession(int $a_event_id)
static _readAppointmentsBySession(int $a_event_id)
Session participation handling.
static _getInstanceByObjId(int $a_obj_id)
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ilErr
Definition: raiseError.php:33
global $DIC
Definition: shib_login.php:26