ILIAS  release_8 Revision v8.24
class.ilObjGroup.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32{
33 public const CAL_REG_START = 1;
34 public const CAL_REG_END = 2;
35 public const CAL_START = 3;
36 public const CAL_END = 4;
37
38 public const GRP_MEMBER = 1;
39 public const GRP_ADMIN = 2;
40
41 public const ERR_MISSING_TITLE = 'msg_no_title';
42 public const ERR_MISSING_GROUP_TYPE = 'grp_missing_grp_type';
43 public const ERR_MISSING_PASSWORD = 'grp_missing_password';
44 public const ERR_WRONG_MAX_MEMBERS = 'grp_wrong_max_members';
45 public const ERR_WRONG_REG_TIME_LIMIT = 'grp_wrong_reg_time_limit';
46 public const ERR_MISSING_MIN_MAX_MEMBERS = 'grp_wrong_min_max_members';
47 public const ERR_WRONG_MIN_MAX_MEMBERS = 'grp_max_and_min_members_invalid';
48 public const ERR_WRONG_REGISTRATION_LIMITED = 'grp_err_registration_limited';
49
50 public const MAIL_ALLOWED_ALL = 1;
51 public const MAIL_ALLOWED_TUTORS = 2;
52
55
56 private string $information = '';
57 private int $group_status = 0;
60 private bool $reg_unlimited = true;
61 private ?ilDateTime $reg_start = null;
62 private ?ilDateTime $reg_end = null;
63 private string $reg_password = '';
64 private bool $reg_membership_limitation = false;
65 private int $reg_min_members = 0;
66 private int $reg_max_members = 0;
67 private bool $waiting_list = false;
68 private bool $auto_fill_from_waiting = false;
69 private ?ilDate $leave_end = null;
70 private bool $show_members = true;
71 private bool $session_limit = false;
72 private int $session_prev = -1;
73 private int $session_next = -1;
74 private bool $start_time_indication = false;
75 private ?ilDateTime $grp_start = null;
76 private ?ilDateTime $grp_end = null;
77 private bool $auto_notification = true;
78 private string $latitude = '';
79 private string $longitude = '';
80 private int $locationzoom = 0;
81 private bool $enablemap = false;
82 private string $reg_access_code = '';
83 private bool $reg_access_code_enabled = false;
86
88
89
91
93
95
96 private string $message = '';
97
98
102 public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
103 {
104 global $DIC;
105
106 $tree = $DIC['tree'];
107
108 $this->tree = &$tree;
109
110 $this->type = "grp";
111 parent::__construct($a_id, $a_call_by_reference);
112
113 $this->logger = $DIC->logger()->grp();
114 }
115
116 public static function lookupGroupTye(int $a_id): int
117 {
118 global $DIC;
119
120 $ilDB = $DIC->database();
121
122 $query = "SELECT grp_type FROM grp_settings " .
123 "WHERE obj_id = " . $ilDB->quote($a_id, 'integer');
124 $res = $ilDB->query($query);
125 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
126 return (int) $row->grp_type;
127 }
129 }
130
131 public function setInformation(string $a_information): void
132 {
133 $this->information = $a_information;
134 }
135
136 public function getInformation(): string
137 {
138 return $this->information;
139 }
140
141 public function setGroupType(int $a_type): void
142 {
143 $this->group_type = $a_type;
144 }
145
146 public function getGroupType(): int
147 {
148 return $this->group_type;
149 }
150
151 public function setRegistrationType(int $a_type): void
152 {
153 $this->reg_type = $a_type;
154 }
155
156 public function getRegistrationType(): int
157 {
158 return $this->reg_type;
159 }
160
161 public function isRegistrationEnabled(): bool
162 {
164 }
165
166 public function enableUnlimitedRegistration(bool $a_status): void
167 {
168 $this->reg_unlimited = $a_status;
169 }
170
171 public function isRegistrationUnlimited(): bool
172 {
174 }
175
176 public function setRegistrationStart(?ilDateTime $a_start): void
177 {
178 $this->reg_start = $a_start;
179 }
180
182 {
183 return $this->reg_start;
184 }
185
186
187 public function setRegistrationEnd(?ilDateTime $a_end): void
188 {
189 $this->reg_end = $a_end;
190 }
191
192 public function getRegistrationEnd(): ?ilDateTime
193 {
194 return $this->reg_end;
195 }
196
197 public function setPassword(string $a_pass): void
198 {
199 $this->reg_password = $a_pass;
200 }
201
202 public function getPassword(): string
203 {
204 return $this->reg_password;
205 }
206
207 public function enableMembershipLimitation(bool $a_status): void
208 {
209 $this->reg_membership_limitation = $a_status;
210 }
211
212 public function isMembershipLimited(): bool
213 {
215 }
216
217 public function setMinMembers(int $a_max): void
218 {
219 $this->reg_min_members = $a_max;
220 }
221
222 public function getMinMembers(): int
223 {
225 }
226
227 public function setMaxMembers(int $a_max): void
228 {
229 $this->reg_max_members = $a_max;
230 }
231
232 public function getMaxMembers(): int
233 {
235 }
236
237 public function enableWaitingList(bool $a_status): void
238 {
239 $this->waiting_list = $a_status;
240 }
241
242 public function isWaitingListEnabled(): bool
243 {
244 return $this->waiting_list;
245 }
246
247 public function setWaitingListAutoFill(bool $a_value): void
248 {
249 $this->auto_fill_from_waiting = $a_value;
250 }
251
252 public function hasWaitingListAutoFill(): bool
253 {
255 }
256
257 public function setLatitude(string $a_latitude): void
258 {
259 $this->latitude = $a_latitude;
260 }
261
262 public function getLatitude(): string
263 {
264 return $this->latitude;
265 }
266
267 public function setLongitude(string $a_longitude): void
268 {
269 $this->longitude = $a_longitude;
270 }
271
272 public function getLongitude(): string
273 {
274 return $this->longitude;
275 }
276
277 public function setLocationZoom(int $a_locationzoom): void
278 {
279 $this->locationzoom = $a_locationzoom;
280 }
281
282 public function getLocationZoom(): int
283 {
284 return $this->locationzoom;
285 }
286
287 public function setEnableGroupMap(bool $a_enablemap): void
288 {
289 $this->enablemap = $a_enablemap;
290 }
291
292 public function getEnableMap(): bool
293 {
294 return $this->getEnableGroupMap();
295 }
296
297 public function getEnableGroupMap(): bool
298 {
299 return $this->enablemap;
300 }
301
302 public function getRegistrationAccessCode(): string
303 {
305 }
306
307 public function setRegistrationAccessCode(string $a_code): void
308 {
309 $this->reg_access_code = $a_code;
310 }
311
312 public function isRegistrationAccessCodeEnabled(): bool
313 {
315 }
316
317 public function enableRegistrationAccessCode(bool $a_status): void
318 {
319 $this->reg_access_code_enabled = $a_status;
320 }
321
322 public function setMailToMembersType(int $a_type): void
323 {
324 $this->mail_members = $a_type;
325 }
326
327 public function getMailToMembersType(): int
328 {
329 return $this->mail_members;
330 }
331
332 public function setCancellationEnd(?ilDate $a_value): void
333 {
334 $this->leave_end = $a_value;
335 }
336
337 public function getCancellationEnd(): ?ilDate
338 {
339 return $this->leave_end;
340 }
341
342 public function setShowMembers(bool $a_status): void
343 {
344 $this->show_members = $a_status;
345 }
346 public function getShowMembers(): bool
347 {
348 return $this->show_members;
349 }
350
351 public function setAutoNotification(bool $a_status): void
352 {
353 $this->auto_notification = $a_status;
354 }
355
356 public function getAutoNotification(): bool
357 {
359 }
360
361 public function setPeriod(?\ilDateTime $start = null, ?\ilDateTime $end = null): void
362 {
363 if (
364 ($start instanceof \ilDate && !$end instanceof ilDate) ||
365 ($end instanceof \ilDate && !$start instanceof ilDate)
366 ) {
367 throw new InvalidArgumentException('Different date types not supported.');
368 }
369
370 if ($start instanceof \ilDate) {
371 $this->toggleStartTimeIndication(false);
372 } else {
373 $this->toggleStartTimeIndication(true);
374 }
375 $this->setStart($start);
376 $this->setEnd($end);
377 }
378
379 protected function toggleStartTimeIndication(bool $time_indication): void
380 {
381 $this->start_time_indication = $time_indication;
382 }
383
384 public function getStartTimeIndication(): bool
385 {
387 }
388
389
390 protected function setStart(ilDateTime $a_value = null): void
391 {
392 $this->grp_start = $a_value;
393 }
394
395 public function getStart(): ?\ilDateTime
396 {
397 return $this->grp_start;
398 }
399
400 protected function setEnd(ilDateTime $a_value = null): void
401 {
402 $this->grp_end = $a_value;
403 }
404
405 public function getEnd(): ?\ilDateTime
406 {
407 return $this->grp_end;
408 }
409
410 public function enableSessionLimit(bool $a_status): void
411 {
412 $this->session_limit = $a_status;
413 }
414
415 public function isSessionLimitEnabled(): bool
416 {
418 }
419
420 public function setNumberOfPreviousSessions(int $a_num): void
421 {
422 $this->session_prev = $a_num;
423 }
424
426 {
427 return $this->session_prev;
428 }
429
430 public function setNumberOfNextSessions(int $a_num): void
431 {
432 $this->session_next = $a_num;
433 }
434
435 public function getNumberOfNextSessions(): int
436 {
437 return $this->session_next;
438 }
439
440
444 public function validate(): bool
445 {
446 if (!$this->getTitle()) {
447 $this->title = '';
448 $this->error->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
449 }
451 $this->error->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
452 }
453 if ($this->isMembershipLimited()) {
454 if ($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0) {
455 $this->error->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
456 }
457 if ($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled()) {
458 $this->error->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
459 }
460 if ($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers()) {
461 $this->error->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
462 }
463 }
464 if (
465 ($this->getRegistrationStart() && !$this->getRegistrationEnd()) ||
466 (!$this->getRegistrationStart() && $this->getRegistrationEnd()) ||
467 $this->getRegistrationEnd() <= $this->getRegistrationStart()
468 ) {
469 $this->error->appendMessage($this->lng->txt((self::ERR_WRONG_REGISTRATION_LIMITED)));
470 }
471 return strlen($this->error->getMessage()) == 0;
472 }
473
474
475
476
480 public function create(): int
481 {
482 if (!parent::create()) {
483 return 0;
484 }
485 $this->createMetaData();
486
487 $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled," .
488 "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit," .
489 "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type," .
490 "leave_end,registration_min_members,auto_wait, grp_start, grp_end, auto_notification, session_limit, session_prev, session_next) " .
491 "VALUES(" .
492 $this->db->quote($this->getId(), 'integer') . ", " .
493 $this->db->quote($this->getInformation(), 'text') . ", " .
494 $this->db->quote($this->getGroupType(), 'integer') . ", " .
495 $this->db->quote($this->getRegistrationType(), 'integer') . ", " .
496 $this->db->quote(($this->isRegistrationEnabled() ? 1 : 0), 'integer') . ", " .
497 $this->db->quote(($this->isRegistrationUnlimited() ? 1 : 0), 'integer') . ", " .
498 $this->db->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
499 $this->db->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
500 $this->db->quote($this->getPassword(), 'text') . ", " .
501 $this->db->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
502 $this->db->quote($this->getMaxMembers(), 'integer') . ", " .
503 $this->db->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
504 $this->db->quote($this->getLatitude(), 'text') . ", " .
505 $this->db->quote($this->getLongitude(), 'text') . ", " .
506 $this->db->quote($this->getLocationZoom(), 'integer') . ", " .
507 $this->db->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
508 $this->db->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
509 $this->db->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
510 $this->db->quote($this->view_mode, 'integer') . ', ' .
511 $this->db->quote($this->getMailToMembersType(), 'integer') . ', ' .
512 $this->db->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
513 $this->db->quote($this->getMinMembers(), 'integer') . ', ' .
514 $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . ', ' .
515 $this->db->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
516 $this->db->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
517 $this->db->quote($this->getAutoNotification(), \ilDBConstants::T_INTEGER) . ', ' .
518 $this->db->quote($this->isSessionLimitEnabled(), ilDBConstants::T_INTEGER) . ', ' .
519 $this->db->quote($this->getNumberOfPreviousSessions(), ilDBConstants::T_INTEGER) . ', ' .
520 $this->db->quote($this->getNumberOfNextSessions(), ilDBConstants::T_INTEGER) .
521 ')';
522 $res = $this->db->manipulate($query);
523
524 $this->app_event_handler->raise(
525 'Modules/Group',
526 'create',
527 array('object' => $this,
528 'obj_id' => $this->getId(),
529 'appointments' => $this->prepareAppointments('create'))
530 );
531 return $this->getId();
532 }
533
537 public function update(): bool
538 {
539 if (!parent::update()) {
540 return false;
541 }
542
543 $this->updateMetaData();
544
545 $query = "UPDATE grp_settings " .
546 "SET information = " . $this->db->quote($this->getInformation(), 'text') . ", " .
547 "grp_type = " . $this->db->quote($this->getGroupType(), 'integer') . ", " .
548 "registration_type = " . $this->db->quote($this->getRegistrationType(), 'integer') . ", " .
549 "registration_enabled = " . $this->db->quote($this->isRegistrationEnabled() ? 1 : 0, 'integer') . ", " .
550 "registration_unlimited = " . $this->db->quote($this->isRegistrationUnlimited() ? 1 : 0, 'integer') . ", " .
551 "registration_start = " . $this->db->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
552 "registration_end = " . $this->db->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
553 "registration_password = " . $this->db->quote($this->getPassword(), 'text') . ", " .
554// "registration_membership_limited = ".$this->db->quote((int) $this->isMembershipLimited() ,'integer').", ".
555 "registration_mem_limit = " . $this->db->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
556 "registration_max_members = " . $this->db->quote($this->getMaxMembers(), 'integer') . ", " .
557 "waiting_list = " . $this->db->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
558 "latitude = " . $this->db->quote($this->getLatitude(), 'text') . ", " .
559 "longitude = " . $this->db->quote($this->getLongitude(), 'text') . ", " .
560 "location_zoom = " . $this->db->quote($this->getLocationZoom(), 'integer') . ", " .
561 "enablemap = " . $this->db->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
562 'reg_ac_enabled = ' . $this->db->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
563 'reg_ac = ' . $this->db->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
564 'view_mode = ' . $this->db->quote($this->view_mode, 'integer') . ', ' .
565 'mail_members_type = ' . $this->db->quote($this->getMailToMembersType(), 'integer') . ', ' .
566 'leave_end = ' . $this->db->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
567 "registration_min_members = " . $this->db->quote($this->getMinMembers(), 'integer') . ", " .
568 "auto_wait = " . $this->db->quote($this->hasWaitingListAutoFill(), 'integer') . ", " .
569 "show_members = " . $this->db->quote((int) $this->getShowMembers(), 'integer') . ", " .
570 'period_start = ' . $this->db->quote(\ilCalendarUtil::convertDateToUtcDBTimestamp($this->getStart()), \ilDBConstants::T_TIMESTAMP) . ', ' .
571 'period_end = ' . $this->db->quote(\ilCalendarUtil::convertDateToUtcDBTimestamp($this->getEnd()), \ilDBConstants::T_TIMESTAMP) . ', ' .
572 'period_time_indication = ' . $this->db->quote($this->getStartTimeIndication() ? 1 : 0, \ilDBConstants::T_INTEGER) . ', ' .
573 'auto_notification = ' . $this->db->quote($this->getAutoNotification(), \ilDBConstants::T_INTEGER) . ', ' .
574 'session_limit = ' . $this->db->quote($this->isSessionLimitEnabled(), ilDBConstants::T_INTEGER) . ', ' .
575 'session_prev = ' . $this->db->quote($this->getNumberOfPreviousSessions(), ilDBConstants::T_INTEGER) . ', ' .
576 'session_next = ' . $this->db->quote($this->getNumberOfNextSessions(), ilDBConstants::T_INTEGER) . ' ' .
577 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer');
578 $res = $this->db->manipulate($query);
579
580 $this->app_event_handler->raise(
581 'Modules/Group',
582 'update',
583 array('object' => $this,
584 'obj_id' => $this->getId(),
585 'appointments' => $this->prepareAppointments('update'))
586 );
587 return true;
588 }
589
593 public function delete(): bool
594 {
595 // always call parent delete function first!!
596 if (!parent::delete()) {
597 return false;
598 }
599
600 $this->deleteMetaData();
601
602 $query = "DELETE FROM grp_settings " .
603 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer');
604 $res = $this->db->manipulate($query);
605
607
608 $this->app_event_handler->raise(
609 'Modules/Group',
610 'delete',
611 array('object' => $this,
612 'obj_id' => $this->getId(),
613 'appointments' => $this->prepareAppointments('delete'))
614 );
615 return true;
616 }
617
618
622 public function read(): void
623 {
624 parent::read();
625
626 $query = "SELECT * FROM grp_settings " .
627 "WHERE obj_id = " . $this->db->quote($this->getId(), 'integer');
628
629 $res = $this->db->query($query);
630 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
631 $this->setInformation((string) $row->information);
632 $this->setGroupType((int) $row->grp_type);
633 $this->setRegistrationType((int) $row->registration_type);
634 $this->enableUnlimitedRegistration((bool) $row->registration_unlimited);
635 $this->setRegistrationStart(new ilDateTime($row->registration_start, IL_CAL_DATETIME));
636 $this->setRegistrationEnd(new ilDateTime($row->registration_end, IL_CAL_DATETIME));
637 $this->setPassword((string) $row->registration_password);
638 $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
639 $this->setMaxMembers((int) $row->registration_max_members);
640 $this->enableWaitingList((bool) $row->waiting_list);
641 $this->setLatitude((string) $row->latitude);
642 $this->setLongitude((string) $row->longitude);
643 $this->setLocationZoom((int) $row->location_zoom);
644 $this->setEnableGroupMap((bool) $row->enablemap);
645 $this->enableRegistrationAccessCode((bool) $row->reg_ac_enabled);
646 $this->setRegistrationAccessCode((string) $row->reg_ac);
647 $this->setViewMode((int) $row->view_mode);
648 $this->setMailToMembersType((int) $row->mail_members_type);
649 $this->setCancellationEnd($row->leave_end ? new ilDate((int) $row->leave_end, IL_CAL_UNIX) : null);
650 $this->setMinMembers((int) $row->registration_min_members);
651 $this->setWaitingListAutoFill((bool) $row->auto_wait);
652 $this->setShowMembers((bool) $row->show_members);
653 $this->setAutoNotification((bool) $row->auto_notification);
654 if ($row->period_time_indication) {
655 $this->setPeriod(
656 new \ilDateTime($row->period_start, IL_CAL_DATETIME, \ilTimeZone::UTC),
657 new \ilDateTime($row->period_end, IL_CAL_DATETIME, \ilTimeZone::UTC)
658 );
659 } elseif (!is_null($row->period_start) && !is_null($row->period_end)) {
660 $this->setPeriod(
661 new \ilDate($row->period_start, IL_CAL_DATE),
662 new \ilDate($row->period_end, IL_CAL_DATE)
663 );
664 }
665 $this->toggleStartTimeIndication((bool) $row->period_time_indication);
666 $this->enableSessionLimit((bool) $row->session_limit);
667 $this->setNumberOfPreviousSessions((int) $row->session_prev);
668 $this->setNumberOfNextSessions((int) $row->session_next);
669 }
670 $this->initParticipants();
671
672 // Inherit order type from parent course (if exists)
674 }
675
679 public function cloneObject(int $a_target_id, int $a_copy_id = 0, bool $a_omit_tree = false): ?ilObject
680 {
684 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
685
686 // current template
687 $current_template = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId());
688 $new_obj->applyDidacticTemplate($current_template);
689 $this->cloneAutoGeneratedRoles($new_obj);
690 $this->cloneMetaData($new_obj);
691
692 $new_obj->setRegistrationType($this->getRegistrationType());
693 $new_obj->setInformation($this->getInformation());
694 $new_obj->setRegistrationStart($this->getRegistrationStart());
695 $new_obj->setRegistrationEnd($this->getRegistrationEnd());
696 $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
697 $new_obj->setPassword($this->getPassword());
698 $new_obj->enableMembershipLimitation($this->isMembershipLimited());
699 $new_obj->setMaxMembers($this->getMaxMembers());
700 $new_obj->enableWaitingList($this->isWaitingListEnabled());
701 $new_obj->setShowMembers($this->getShowMembers());
702
703 // map
704 $new_obj->setLatitude($this->getLatitude());
705 $new_obj->setLongitude($this->getLongitude());
706 $new_obj->setLocationZoom($this->getLocationZoom());
707 $new_obj->setEnableGroupMap($this->getEnableGroupMap());
708 $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
709 $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
710
711 $new_obj->setViewMode($this->view_mode);
712 $new_obj->setMailToMembersType($this->getMailToMembersType());
713
714 $new_obj->setCancellationEnd($this->getCancellationEnd());
715 $new_obj->setMinMembers($this->getMinMembers());
716 $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
717 $new_obj->setPeriod($this->getStart(), $this->getEnd());
718 $new_obj->setAutoNotification($this->getAutoNotification());
719 $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
720 $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
721 $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
722 $new_obj->update();
723
724 // #13008 - Group Defined Fields
725 ilCourseDefinedFieldDefinition::_clone($this->getId(), $new_obj->getId());
726
727 // Assign user as admin
728 $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
729 $part->add($this->user->getId(), ilParticipants::IL_GRP_ADMIN);
730 $part->updateNotification($this->user->getId(), (bool) $this->setting->get('mail_grp_admin_notification', "1"));
731 $part->updateContact($this->user->getId(), true);
732
733 // Copy learning progress settings
734 $obj_settings = new ilLPObjSettings($this->getId());
735 $obj_settings->cloneSettings($new_obj->getId());
736 unset($obj_settings);
737 return $new_obj;
738 }
739
743 public function cloneDependencies(int $a_target_id, int $a_copy_id): bool
744 {
745 parent::cloneDependencies($a_target_id, $a_copy_id);
746
747 ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
748
749 // clone membership limitation
750 foreach (\ilObjCourseGrouping::_getGroupings($this->getId()) as $grouping_id) {
751 $this->logger->info('Handling grouping id: ' . $grouping_id);
752 $grouping = new \ilObjCourseGrouping($grouping_id);
753 $grouping->cloneGrouping($a_target_id, $a_copy_id);
754 }
755 return true;
756 }
757
761 public function cloneAutoGeneratedRoles(ilObjGroup $new_obj): void
762 {
763 $admin = $this->getDefaultAdminRole();
764 $new_admin = $new_obj->getDefaultAdminRole();
765 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
766 $this->logger->warning('Error cloning auto generated rol: il_grp_admin');
767 }
768 $this->rbac_admin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
769 $this->logger->info('Finished copying of role il_grp_admin.');
770
771 $member = $this->getDefaultMemberRole();
772 $new_member = $new_obj->getDefaultMemberRole();
773 if (!$member || !$new_member) {
774 $this->logger->warning('Error cloning auto generated rol: il_grp_member');
775 }
776 $this->rbac_admin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
777 $this->logger->info('Finished copying of role il_grp_member.');
778 }
779
780
784 public function getDefaultMemberRole(): int
785 {
786 $local_group_Roles = $this->getLocalGroupRoles();
787 return $local_group_Roles["il_grp_member_" . $this->getRefId()];
788 }
789
793 public function getDefaultAdminRole(): int
794 {
795 $local_group_Roles = $this->getLocalGroupRoles();
796 return $local_group_Roles["il_grp_admin_" . $this->getRefId()];
797 }
798
799 public function leaveGroup(): int
800 {
801 $member_ids = $this->getGroupMemberIds();
802 if (count($member_ids) <= 1 || !in_array($this->user->getId(), $member_ids)) {
803 return 2;
804 } elseif (!$this->isAdmin($this->user->getId())) {
805 $this->leave($this->user->getId());
806 $this->recommended_content_manager->removeObjectRecommendation($this->user->getId(), $this->getRefId());
807 return 0;
808 } elseif (count($this->getGroupAdminIds()) == 1) {
809 return 1;
810 }
811 return 1;
812 }
813
817 public function leave(int $a_user_id): bool
818 {
819 $arr_groupRoles = $this->getMemberRoles($a_user_id);
820 foreach ($arr_groupRoles as $groupRole) {
821 $this->rbac_admin->deassignUser($groupRole, $a_user_id);
822 }
823 return true;
824 }
825
831 public function getGroupMemberIds(): array
832 {
833 $usr_arr = array();
834 $rol = $this->getLocalGroupRoles();
835 $mem_arr = [];
836 foreach ($rol as $value) {
837 foreach ($this->rbac_review->assignedUsers($value) as $member_id) {
838 array_push($usr_arr, $member_id);
839 }
840 }
841 return array_unique($usr_arr);
842 }
843
848 public function getGroupMemberData(array $a_mem_ids, int $active = 1): array
849 {
850 $usr_arr = array();
851 $q = "SELECT login,firstname,lastname,title,usr_id,last_login " .
852 "FROM usr_data " .
853 "WHERE usr_id IN (" . implode(',', ilArrayUtil::quoteArray($a_mem_ids)) . ") ";
854
855 if (is_numeric($active) && $active > -1) {
856 $q .= "AND active = '$active'";
857 }
858
859 $q .= 'ORDER BY lastname,firstname';
860
861 $r = $this->db->query($q);
862 $mem_arr = [];
863 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
864 $mem_arr[] = array("id" => (int) $row->usr_id,
865 "login" => $row->login,
866 "firstname" => $row->firstname,
867 "lastname" => $row->lastname,
868 "last_login" => $row->last_login
869 );
870 }
871
872 return $mem_arr;
873 }
874
875 public function getCountMembers(): int
876 {
877 return count($this->getGroupMemberIds());
878 }
879
880 public function getGroupAdminIds(int $a_grpId = 0): array
881 {
882 if (!empty($a_grpId)) {
883 $grp_id = $a_grpId;
884 } else {
885 $grp_id = $this->getRefId();
886 }
887
888 $usr_arr = array();
889 $roles = $this->getDefaultGroupRoles();
890
891 foreach ($this->rbac_review->assignedUsers($this->getDefaultAdminRole()) as $member_id) {
892 array_push($usr_arr, $member_id);
893 }
894 return $usr_arr;
895 }
896
901 protected function getDefaultGroupRoles(): array
902 {
903 $grp_id = $this->getRefId();
904 $role_arr = $this->rbac_review->getRolesOfRoleFolder($grp_id);
905 $arr_grpDefaultRoles = [];
906 foreach ($role_arr as $role_id) {
907 $role = ilObjectFactory::getInstanceByObjId($role_id, false);
908 $grp_Member = "il_grp_member_" . $grp_id;
909 $grp_Admin = "il_grp_admin_" . $grp_id;
910
911 if (strcmp($role->getTitle(), $grp_Member) == 0) {
912 $arr_grpDefaultRoles["grp_member_role"] = $role->getId();
913 }
914
915 if (strcmp($role->getTitle(), $grp_Admin) == 0) {
916 $arr_grpDefaultRoles["grp_admin_role"] = $role->getId();
917 }
918 }
919 return $arr_grpDefaultRoles;
920 }
921
927 public function getLocalGroupRoles(bool $a_translate = false): array
928 {
929 if (empty($this->local_roles)) {
930 $this->local_roles = array();
931 $role_arr = $this->rbac_review->getRolesOfRoleFolder($this->getRefId());
932
933 foreach ($role_arr as $role_id) {
934 if ($this->rbac_review->isAssignable($role_id, $this->getRefId()) == true) {
935 $role = ilObjectFactory::getInstanceByObjId($role_id, false);
936 if ($a_translate) {
937 $role_name = ilObjRole::_getTranslation($role->getTitle());
938 } else {
939 $role_name = $role->getTitle();
940 }
941 $this->local_roles[$role_name] = $role->getId();
942 }
943 }
944 }
945 return $this->local_roles;
946 }
947
952 {
953 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
954 $res = $this->ilias->db->query($q);
955 $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
956
957 return (int) $row["obj_id"];
958 }
959
964 {
965 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
966 $res = $this->ilias->db->query($q);
967 $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
968
969 return (int) $row["obj_id"];
970 }
971
972 public static function lookupGroupStatusTemplateId(int $a_obj_id): int
973 {
974 global $DIC;
975
976 $ilDB = $DIC['ilDB'];
977
978 $type = self::lookupGroupTye($a_obj_id);
980 $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_closed', 'text');
981 } else {
982 $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_open', 'text');
983 }
984 $res = $ilDB->query($query);
985 $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
986 return $row['obj_id'] ? (int) $row['obj_id'] : 0;
987 }
988
989
990
996 public function updateGroupType(
997 int $a_group_type = ilGroupConstants::GRP_TYPE_OPEN
998 ): void {
999 if ($a_group_type == ilGroupConstants::GRP_TYPE_OPEN) {
1000 $this->applyDidacticTemplate(0);
1001 return;
1002 }
1003 $templates = ilDidacticTemplateSettings::getInstanceByObjectType($this->getType())->getTemplates();
1004 foreach ($templates as $template) {
1005 // the closed template
1006 if ($template->isAutoGenerated()) {
1007 $this->logger->info('Appying default closed template');
1008 $this->applyDidacticTemplate($template->getId());
1009 return;
1010 }
1011 }
1012 $this->logger->warning('No closed didactic template available.');
1013 }
1014
1015
1016 public function setGroupStatus(int $a_status): void
1017 {
1018 $this->group_status = $a_status;
1019 }
1020
1024 public function getGroupStatus(): int
1025 {
1026 return $this->group_status;
1027 }
1028
1033 public function readGroupStatus(): int
1034 {
1035 $tpl_id = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId());
1036 if (!$tpl_id) {
1038 }
1040 }
1041
1042 public function getMemberRoles(int $a_user_id): array
1043 {
1044 return array_intersect(
1045 $this->rbac_review->assignedRoles($a_user_id),
1046 $this->getLocalGroupRoles()
1047 );
1048 }
1049
1050 public function isAdmin(int $a_userId): bool
1051 {
1052 $grp_Roles = $this->getDefaultGroupRoles();
1053 if (in_array($a_userId, $this->rbac_review->assignedUsers($grp_Roles["grp_admin_role"]))) {
1054 return true;
1055 } else {
1056 return false;
1057 }
1058 }
1062 public function initDefaultRoles(): void
1063 {
1065 'il_grp_admin_' . $this->getRefId(),
1066 "Groupadmin group obj_no." . $this->getId(),
1067 'il_grp_admin',
1068 $this->getRefId()
1069 );
1070 $this->m_roleAdminId = $role->getId();
1071
1073 'il_grp_member_' . $this->getRefId(),
1074 "Groupmember of group obj_no." . $this->getId(),
1075 'il_grp_member',
1076 $this->getRefId()
1077 );
1078 $this->m_roleMemberId = $role->getId();
1079 }
1080
1089 public function setParentRolePermissions(int $a_parent_ref): bool
1090 {
1091 $parent_roles = $this->rbac_review->getParentRoleIds($a_parent_ref);
1092 foreach ($parent_roles as $parent_role) {
1093 if ($parent_role['parent'] == $this->getRefId()) {
1094 continue;
1095 }
1096 if ($this->rbac_review->isProtected((int) $parent_role['parent'], (int) $parent_role['rol_id'])) {
1097 $operations = $this->rbac_review->getOperationsOfRole(
1098 (int) $parent_role['obj_id'],
1099 $this->getType(),
1100 (int) $parent_role['parent']
1101 );
1102 $this->rbac_admin->grantPermission(
1103 (int) $parent_role['obj_id'],
1104 $operations,
1105 $this->getRefId()
1106 );
1107 continue;
1108 }
1109
1110 $this->rbac_admin->initIntersectionPermissions(
1111 $this->getRefId(),
1112 (int) $parent_role['obj_id'],
1113 (int) $parent_role['parent'],
1114 $this->getGrpStatusOpenTemplateId(),
1116 );
1117 }
1118 return true;
1119 }
1120
1121
1125 public function applyDidacticTemplate(int $a_tpl_id): void
1126 {
1127 parent::applyDidacticTemplate($a_tpl_id);
1128
1129 if (!$a_tpl_id) {
1130 // init default type
1131 $this->setParentRolePermissions($this->getRefId());
1132 }
1133 }
1134
1135
1136 public static function _lookupIdByTitle(string $a_title): int
1137 {
1138 global $DIC;
1139
1140 $ilDB = $DIC['ilDB'];
1141 $query = "SELECT * FROM object_data WHERE title = " .
1142 $ilDB->quote($a_title, 'text') . " AND type = 'grp'";
1143 $res = $ilDB->query($query);
1144 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1145 return $row->obj_id;
1146 }
1147 return 0;
1148 }
1149
1150
1151 public function _isMember(int $a_user_id, int $a_ref_id, string $a_field = ''): bool
1152 {
1153 $local_roles = $this->rbac_review->getRolesOfRoleFolder($a_ref_id, false);
1154 $user_roles = $this->rbac_review->assignedRoles($a_user_id);
1155
1156 // Used for membership limitations -> check membership by given field
1157 if ($a_field) {
1158 $tmp_user = ilObjectFactory::getInstanceByObjId($a_user_id);
1159 if (!$tmp_user instanceof ilObjUser) {
1160 throw new DomainException('Invalid user id given: ' . $a_user_id);
1161 }
1162 switch ($a_field) {
1163 case 'login':
1164 $and = "AND login = '" . $tmp_user->getLogin() . "' ";
1165 break;
1166 case 'email':
1167 $and = "AND email = '" . $tmp_user->getEmail() . "' ";
1168 break;
1169 case 'matriculation':
1170 $and = "AND matriculation = '" . $tmp_user->getMatriculation() . "' ";
1171 break;
1172
1173 default:
1174 $and = "AND usr_id = '" . $a_user_id . "'";
1175 break;
1176 }
1177 if (!$members = ilObjGroup::_getMembers(ilObject::_lookupObjId($a_ref_id))) {
1178 return false;
1179 }
1180 $query = "SELECT * FROM usr_data as ud " .
1181 "WHERE usr_id IN (" . implode(",", ilArrayUtil::quoteArray($members)) . ") " .
1182 $and;
1183 $res = $this->db->query($query);
1184 return (bool) $res->numRows();
1185 }
1186
1187 if (!array_intersect($local_roles, $user_roles)) {
1188 return false;
1189 }
1190
1191 return true;
1192 }
1193
1194 public function _getMembers(int $a_obj_id): array
1195 {
1196 // get reference
1197 $ref_ids = ilObject::_getAllReferences($a_obj_id);
1198 $ref_id = current($ref_ids);
1199
1200 $local_roles = $this->rbac_review->getRolesOfRoleFolder($ref_id, false);
1201
1202 $users = array();
1203 foreach ($local_roles as $role_id) {
1204 $users = array_merge($users, $this->rbac_review->assignedUsers($role_id));
1205 }
1206 return array_unique($users);
1207 }
1208
1213 public function getViewMode(): int
1214 {
1215 $tree = $this->tree;
1216
1217 // default: by type
1218 $view = self::lookupViewMode($this->getId());
1219
1220 if ($view != ilContainer::VIEW_INHERIT) {
1221 return $view;
1222 }
1223
1224 $container_ref_id = $tree->checkForParentType($this->ref_id, 'crs');
1225 if ($container_ref_id) {
1226 $view_mode = ilObjCourseAccess::_lookupViewMode(ilObject::_lookupObjId($container_ref_id));
1227 // these three are available...
1228 if (
1229 $view_mode == ilContainer::VIEW_SESSIONS ||
1230 $view_mode == ilContainer::VIEW_BY_TYPE ||
1231 $view_mode == ilContainer::VIEW_SIMPLE) {
1232 return $view_mode;
1233 }
1234 }
1236 }
1237
1238
1239 public function setViewMode(int $a_view_mode): void
1240 {
1241 $this->view_mode = $a_view_mode;
1242 }
1243
1244 public static function lookupViewMode($a_obj_id): int
1245 {
1246 global $DIC;
1247
1248 $ilDB = $DIC->database();
1249
1250 $query = 'SELECT view_mode FROM grp_settings ' .
1251 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1252 $res = $ilDB->query($query);
1253
1254 $view_mode = null;
1255 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1256 $view_mode = (int) $row->view_mode;
1257 }
1258 return $view_mode;
1259 }
1260
1261 public static function translateViewMode(int $a_obj_id, int $a_view_mode, ?int $a_ref_id = null): int
1262 {
1263 global $DIC;
1264
1265 $tree = $DIC['tree'];
1266
1267 if (!$a_view_mode) {
1268 $a_view_mode = ilContainer::VIEW_DEFAULT;
1269 }
1270
1271 // view mode is inherit => check for parent course
1272 if ($a_view_mode == ilContainer::VIEW_INHERIT) {
1273 if (!$a_ref_id) {
1274 $ref = ilObject::_getAllReferences($a_obj_id);
1275 $a_ref_id = end($ref);
1276 }
1277
1278 $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1279 if (!$crs_ref) {
1281 }
1282
1284
1285 // validate course view mode
1286 if (!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1289 }
1290
1291 return $view_mode;
1292 }
1293
1294 return $a_view_mode;
1295 }
1296
1301 public function addAdditionalSubItemInformation(array &$object): void
1302 {
1304 }
1305
1306 public function getMessage(): string
1307 {
1308 return $this->message;
1309 }
1310
1311 public function setMessage(string $a_message): void
1312 {
1313 $this->message = $a_message;
1314 }
1315 public function appendMessage(string $a_message): void
1316 {
1317 if ($this->getMessage()) {
1318 $this->message .= "<br /> ";
1319 }
1320 $this->message .= $a_message;
1321 }
1322
1327 protected function prepareAppointments($a_mode = 'create'): array
1328 {
1329 switch ($a_mode) {
1330 case 'create':
1331 case 'update':
1332
1333 $apps = array();
1334 if ($this->getStart() && $this->getEnd()) {
1335 $app = new ilCalendarAppointmentTemplate(self::CAL_START);
1336 $app->setTitle($this->getTitle());
1337 $app->setSubtitle('grp_cal_start');
1338 $app->setTranslationType(ilCalendarEntry::TRANSLATION_SYSTEM);
1339 $app->setDescription($this->getLongDescription());
1340 $app->setStart($this->getStart());
1341 $app->setFullday(!$this->getStartTimeIndication());
1342 $apps[] = $app;
1343
1344 $app = new ilCalendarAppointmentTemplate(self::CAL_END);
1345 $app->setTitle($this->getTitle());
1346 $app->setSubtitle('grp_cal_end');
1347 $app->setTranslationType(ilCalendarEntry::TRANSLATION_SYSTEM);
1348 $app->setDescription($this->getLongDescription());
1349 $app->setStart($this->getEnd());
1350 $app->setFullday(!$this->getStartTimeIndication());
1351 $apps[] = $app;
1352 }
1353 if ($this->isRegistrationUnlimited()) {
1354 return $apps;
1355 }
1356
1357 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1358 $app->setTitle($this->getTitle());
1359 $app->setSubtitle('grp_cal_reg_start');
1360 $app->setTranslationType(ilCalendarEntry::TRANSLATION_SYSTEM);
1361 $app->setDescription($this->getLongDescription());
1362 $app->setStart($this->getRegistrationStart());
1363 $apps[] = $app;
1364
1365 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1366 $app->setTitle($this->getTitle());
1367 $app->setSubtitle('grp_cal_reg_end');
1368 $app->setTranslationType(ilCalendarEntry::TRANSLATION_SYSTEM);
1369 $app->setDescription($this->getLongDescription());
1370 $app->setStart($this->getRegistrationEnd());
1371 $apps[] = $app;
1372
1373
1374 return $apps;
1375
1376 case 'delete':
1377 // Nothing to do: The category and all assigned appointments will be deleted.
1378 return array();
1379 }
1380 return [];
1381 }
1382
1383
1384 protected function initParticipants(): void
1385 {
1386 $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1387 }
1388
1390 {
1391 // #17886
1392 if (!$this->members_obj instanceof ilGroupParticipants) {
1393 $this->initParticipants();
1394 }
1395 return $this->members_obj;
1396 }
1397
1402 public static function lookupObjectsByCode(string $a_code): array
1403 {
1404 global $DIC;
1405
1406 $ilDB = $DIC->database();
1407
1408 $query = "SELECT obj_id FROM grp_settings " .
1409 "WHERE reg_ac_enabled = " . $ilDB->quote(1, 'integer') . " " .
1410 "AND reg_ac = " . $ilDB->quote($a_code, 'text');
1411 $res = $ilDB->query($query);
1412
1413 $obj_ids = array();
1414 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1415 $obj_ids[] = (int) $row->obj_id;
1416 }
1417 return $obj_ids;
1418 }
1419
1424 public function register(
1425 int $a_user_id,
1426 int $a_role = ilParticipants::IL_GRP_MEMBER,
1427 bool $a_force_registration = false
1428 ): void {
1430
1431 if ($part->isAssigned($a_user_id)) {
1432 return;
1433 }
1434
1435 if (!$a_force_registration) {
1436 // Availability
1437 if (!$this->isRegistrationEnabled()) {
1439 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
1440 ', group subscription is deactivated.', ilMembershipRegistrationException::REGISTRATION_CODE_DISABLED);
1441 }
1442 }
1443
1444 // Time Limitation
1445 if (!$this->isRegistrationUnlimited()) {
1446 $start = $this->getRegistrationStart();
1447 $end = $this->getRegistrationEnd();
1448 $time = new ilDateTime(time(), IL_CAL_UNIX);
1449
1450 if (!(ilDateTime::_after($time, $start) and ilDateTime::_before($time, $end))) {
1451 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
1452 ', group is out of registration time.', ilMembershipRegistrationException::OUT_OF_REGISTRATION_PERIOD);
1453 }
1454 }
1455
1456 // Max members
1457 if ($this->isMembershipLimited()) {
1458 $free = max(0, $this->getMaxMembers() - $part->getCountMembers());
1459 $waiting_list = new ilGroupWaitingList($this->getId());
1460 if ($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
1461 $this->lng->loadLanguageModule("grp");
1462 $waiting_list->addToList($a_user_id);
1463
1464 $info = sprintf(
1465 $this->lng->txt('grp_added_to_list'),
1466 $this->getTitle(),
1467 $waiting_list->getPosition($a_user_id)
1468 );
1469
1470 $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
1471 $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $a_user_id);
1472
1474 }
1475
1476 if (!$free or $waiting_list->getCountUsers()) {
1477 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
1478 ', membership is limited.', ilMembershipRegistrationException::OBJECT_IS_FULL);
1479 }
1480 }
1481 }
1482
1483 $part->add($a_user_id, $a_role);
1484 $part->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $a_user_id);
1485 $part->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
1486 }
1487
1488 public function handleAutoFill(): void
1489 {
1490 if ($this->isWaitingListEnabled() &&
1491 $this->hasWaitingListAutoFill()) {
1492 $max = $this->getMaxMembers();
1493 $now = ilGroupParticipants::lookupNumberOfMembers($this->getRefId());
1494 if ($max > $now) {
1495 // see assignFromWaitingListObject()
1496 $waiting_list = new ilGroupWaitingList($this->getId());
1497
1498 foreach ($waiting_list->getUserIds() as $user_id) {
1499 if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
1500 continue;
1501 }
1502 if ($this->getMembersObject()->isAssigned($user_id)) {
1503 continue;
1504 }
1505 $this->getMembersObject()->add($user_id, ilParticipants::IL_GRP_MEMBER); // #18213
1506 $this->getMembersObject()->sendNotification(ilGroupMembershipMailNotification::TYPE_ACCEPTED_SUBSCRIPTION_MEMBER, $user_id, true);
1507 $waiting_list->removeFromList($user_id);
1508
1509 $now++;
1510 if ($now >= $max) {
1511 break;
1512 }
1513 }
1514 }
1515 }
1516 }
1517
1518 public static function mayLeave(int $a_group_id, int $a_user_id = null, ?ilDate &$a_date = null): bool
1519 {
1520 global $DIC;
1521
1522 $ilUser = $DIC->user();
1523 $ilDB = $DIC->database();
1524
1525 if (!$a_user_id) {
1526 $a_user_id = $ilUser->getId();
1527 }
1528
1529 $set = $ilDB->query("SELECT leave_end" .
1530 " FROM grp_settings" .
1531 " WHERE obj_id = " . $ilDB->quote($a_group_id, "integer"));
1532 $row = $ilDB->fetchAssoc($set);
1533 if ($row && isset($row["leave_end"]) && is_numeric($row["leave_end"])) {
1534 // timestamp to date
1535 $limit = date("Ymd", (int) $row["leave_end"]);
1536 if ($limit < date("Ymd")) {
1537 $a_date = new ilDate(date("Y-m-d", (int) $row["leave_end"]), IL_CAL_DATE);
1538 return false;
1539 }
1540 }
1541 return true;
1542 }
1543
1544 public static function findGroupsWithNotEnoughMembers(): array
1545 {
1546 global $DIC;
1547 $ilDB = $DIC->database();
1548 $tree = $DIC->repositoryTree();
1549
1550 $res = array();
1551 $before = new ilDateTime(time(), IL_CAL_UNIX);
1552 $now_date = $before->get(IL_CAL_DATETIME, '', ilTimeZone::UTC);
1553 $now = $before->get(IL_CAL_UNIX);
1554
1555 $set = $ilDB->query($q = "SELECT obj_id, registration_min_members" .
1556 " FROM grp_settings" .
1557 " WHERE registration_min_members > " . $ilDB->quote(0, "integer") .
1558 " AND registration_mem_limit = " . $ilDB->quote(1, "integer") . // #17206
1559 " AND ((leave_end IS NOT NULL" .
1560 " AND leave_end < " . $ilDB->quote($now, "integer") . ")" .
1561 " OR (leave_end IS NULL" .
1562 " AND registration_end IS NOT NULL" .
1563 " AND registration_end < " . $ilDB->quote($now_date, "text") . "))" .
1564 " AND (period_start IS NULL OR period_start > " . $ilDB->quote($now_date, ilDBConstants::T_TEXT) . ")");
1565 while ($row = $ilDB->fetchAssoc($set)) {
1566 $refs = ilObject::_getAllReferences((int) $row['obj_id']);
1567 $ref = end($refs);
1568
1569 if ($tree->isDeleted($ref)) {
1570 continue;
1571 }
1572
1573 $part = new ilGroupParticipants((int) $row["obj_id"]);
1574 $reci = $part->getNotificationRecipients();
1575 if (sizeof($reci)) {
1576 $missing = (int) $row["registration_min_members"] - $part->getCountMembers();
1577 if ($missing > 0) {
1578 $res[(int) $row["obj_id"]] = array($missing, $reci);
1579 }
1580 }
1581 }
1582 return $res;
1583 }
1584
1585 public static function lookupShowMembersEnabled(int $a_obj_id): bool
1586 {
1587 global $DIC;
1588 $ilDB = $DIC->database();
1589
1590 $query = 'SELECT show_members FROM grp_settings'
1591 . ' WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1592 $res = $ilDB->query($query);
1593 if ($ilDB->numRows($res) == 0) {
1594 return false;
1595 }
1596 $row = $ilDB->fetchAssoc($res);
1597 return (bool) $row['show_members'];
1598 }
1599
1600
1604 public function getSubItems(
1605 bool $a_admin_panel_enabled = false,
1606 bool $a_include_side_block = false,
1607 int $a_get_single = 0,
1608 \ilContainerUserFilter $container_user_filter = null
1609 ): array {
1610 // Caching
1611 if (
1612 isset($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
1613 is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block])
1614 ) {
1615 return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
1616 }
1617 // Results are stored in $this->items
1618 parent::getSubItems($a_admin_panel_enabled, $a_include_side_block, $a_get_single);
1619 $this->items = ilContainerSessionsContentGUI::prepareSessionPresentationLimitation(
1620 $this->items,
1621 $this,
1622 $a_admin_panel_enabled,
1623 $a_include_side_block
1624 );
1625 return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
1626 }
1627} //END class.ilObjGroup
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
error(string $a_errmsg)
static quoteArray(array $a_array)
Quotes all members of an array for usage in DB query statement.
Apointment templates are used for automatic generated apointments.
static convertDateToUtcDBTimestamp(\ilDateTime $date=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOrderType(int $a_value)
static _clone(int $a_source_id, int $a_target_id)
@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.
Class for single dates.
static getInstanceByObjectType(string $a_obj_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
Waiting list for groups.
Component logger with individual log levels by component id.
static generateCode()
Generate new registration key.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupViewMode(int $a_id)
static _getGroupings(int $a_course_id)
static _lookupViewMode(int $a_id)
Class ilObjGroup.
getLocalGroupRoles(bool $a_translate=false)
get ALL local roles of group, also those created and defined afterwards only fetch data once from dat...
setEnd(ilDateTime $a_value=null)
enableMembershipLimitation(bool $a_status)
static lookupViewMode($a_obj_id)
applyDidacticTemplate(int $a_tpl_id)
@inheritDoc
appendMessage(string $a_message)
setRegistrationAccessCode(string $a_code)
static _lookupIdByTitle(string $a_title)
const ERR_MISSING_TITLE
getDefaultAdminRole()
returns object id of created default adminstrator role
getGroupMemberIds()
get all group Member ids regardless of role
ilDateTime $reg_end
getDefaultMemberRole()
returns object id of created default member role
string $information
enableWaitingList(bool $a_status)
static lookupShowMembersEnabled(int $a_obj_id)
setRegistrationEnd(?ilDateTime $a_end)
setPassword(string $a_pass)
setMessage(string $a_message)
__construct(int $a_id=0, bool $a_call_by_reference=true)
@inheritDoc
const MAIL_ALLOWED_TUTORS
getSubItems(bool $a_admin_panel_enabled=false, bool $a_include_side_block=false, int $a_get_single=0, \ilContainerUserFilter $container_user_filter=null)
@inheritDoc
string $reg_password
getMemberRoles(int $a_user_id)
bool $auto_notification
setAutoNotification(bool $a_status)
updateGroupType(int $a_group_type=ilGroupConstants::GRP_TYPE_OPEN)
Change group type Revokes permissions of all parent non-protected roles and initiates these roles wit...
readGroupStatus()
Read group type.
setEnableGroupMap(bool $a_enablemap)
setGroupType(int $a_type)
ilDateTime $grp_end
cloneAutoGeneratedRoles(ilObjGroup $new_obj)
Clone group admin and member role permissions.
getGrpStatusClosedTemplateId()
get group status closed template
create()
@inheritDoc
const ERR_WRONG_REG_TIME_LIMIT
static lookupGroupStatusTemplateId(int $a_obj_id)
addAdditionalSubItemInformation(array &$object)
Add additional information to sub item, e.g.
static lookupGroupTye(int $a_id)
const ERR_MISSING_MIN_MAX_MEMBERS
setLocationZoom(int $a_locationzoom)
setParentRolePermissions(int $a_parent_ref)
This method is called before "initDefaultRoles".
bool $auto_fill_from_waiting
getGroupAdminIds(int $a_grpId=0)
static lookupObjectsByCode(string $a_code)
setCancellationEnd(?ilDate $a_value)
bool $start_time_indication
read()
@inheritDoc
bool $reg_membership_limitation
setRegistrationType(int $a_type)
setGroupStatus(int $a_status)
update()
@inheritDoc
setInformation(string $a_information)
_getMembers(int $a_obj_id)
const ERR_WRONG_REGISTRATION_LIMITED
_isMember(int $a_user_id, int $a_ref_id, string $a_field='')
validate()
validate group settings
enableRegistrationAccessCode(bool $a_status)
setStart(ilDateTime $a_value=null)
getViewMode()
Get effective container view mode.
getGroupMemberData(array $a_mem_ids, int $active=1)
get all group Members regardless of group role.
getGroupStatus()
get group status
const ERR_MISSING_GROUP_TYPE
setLongitude(string $a_longitude)
const ERR_MISSING_PASSWORD
setMinMembers(int $a_max)
setNumberOfNextSessions(int $a_num)
const ERR_WRONG_MIN_MAX_MEMBERS
static mayLeave(int $a_group_id, int $a_user_id=null, ?ilDate &$a_date=null)
static translateViewMode(int $a_obj_id, int $a_view_mode, ?int $a_ref_id=null)
setMailToMembersType(int $a_type)
isRegistrationAccessCodeEnabled()
getGrpStatusOpenTemplateId()
get group status open template
setViewMode(int $a_view_mode)
const MAIL_ALLOWED_ALL
ilDateTime $reg_start
static findGroupsWithNotEnoughMembers()
setPeriod(?\ilDateTime $start=null, ?\ilDateTime $end=null)
string $reg_access_code
setWaitingListAutoFill(bool $a_value)
ilDateTime $grp_start
enableSessionLimit(bool $a_status)
prepareAppointments($a_mode='create')
Prepare calendar appointments.
cloneDependencies(int $a_target_id, int $a_copy_id)
@inheritDoc
setShowMembers(bool $a_status)
setNumberOfPreviousSessions(int $a_num)
bool $reg_access_code_enabled
toggleStartTimeIndication(bool $time_indication)
setRegistrationStart(?ilDateTime $a_start)
leave(int $a_user_id)
deassign member from group role
ilGroupParticipants $members_obj
getDefaultGroupRoles()
get default group roles, returns the defaultlike create roles il_grp_member, il_grp_admin
const ERR_WRONG_MAX_MEMBERS
setMaxMembers(int $a_max)
ilLogger $logger
enableUnlimitedRegistration(bool $a_status)
setLatitude(string $a_latitude)
isAdmin(int $a_userId)
initDefaultRoles()
@inheritDoc
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
static _getTranslation(string $a_role_title)
User class.
static cloneDependencies(int $ref_id, int $target_id, int $copy_id)
static addAdditionalSubItemInformation(array &$item)
Parse item data for list entries.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
Copy meta data.
static _getAllReferences(int $id)
get all reference ids for object ID
ilTree $tree
string $type
static _lookupObjId(int $ref_id)
static lookupNumberOfMembers(int $a_ref_id)
Lookup number of members.
static _deleteAllEntries(int $a_obj_id)
Delete all entries Normally called in case of object deletion.
$app
Definition: cli.php:39
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const ROLE_FOLDER_ID
Definition: constants.php:34
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
header include for all ilias files.
$query
$message
Definition: xapiexit.php:32