ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjGroup.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4//TODO: function getRoleId($groupRole) returns the object-id of grouprole
5
6require_once "./Services/Container/classes/class.ilContainer.php";
7include_once('./Services/Calendar/classes/class.ilDateTime.php');
8include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
9
10define('GRP_REGISTRATION_DEACTIVATED', -1);
11define('GRP_REGISTRATION_DIRECT', 0);
12define('GRP_REGISTRATION_REQUEST', 1);
13define('GRP_REGISTRATION_PASSWORD', 2);
14
15define('GRP_REGISTRATION_LIMITED', 1);
16define('GRP_REGISTRATION_UNLIMITED', 2);
17
18define('GRP_TYPE_UNKNOWN', 0);
19define('GRP_TYPE_CLOSED', 1);
20define('GRP_TYPE_OPEN', 2);
21define('GRP_TYPE_PUBLIC', 3);
22
34{
35 const CAL_REG_START = 1;
36 const CAL_REG_END = 2;
37 const CAL_START = 3;
38 const CAL_END = 4;
39
40 const GRP_MEMBER = 1;
41 const GRP_ADMIN = 2;
42
43 const ERR_MISSING_TITLE = 'msg_no_title';
44 const ERR_MISSING_GROUP_TYPE = 'grp_missing_grp_type';
45 const ERR_MISSING_PASSWORD = 'grp_missing_password';
46 const ERR_WRONG_MAX_MEMBERS = 'grp_wrong_max_members';
47 const ERR_WRONG_REG_TIME_LIMIT = 'grp_wrong_reg_time_limit';
48 const ERR_MISSING_MIN_MAX_MEMBERS = 'grp_wrong_min_max_members';
49 const ERR_WRONG_MIN_MAX_MEMBERS = 'grp_max_and_min_members_invalid';
50 const ERR_WRONG_REGISTRATION_LIMITED = 'grp_err_registration_limited';
51
54
57
58 protected $information;
59 protected $group_type = null;
61 protected $reg_enabled = true;
62 protected $reg_unlimited = true;
63 protected $reg_start = null;
64 protected $reg_end = null;
65 protected $reg_password = '';
66 protected $reg_membership_limitation = false;
67 protected $reg_min_members = 0;
68 protected $reg_max_members = 0;
69 protected $waiting_list = false;
70 protected $auto_fill_from_waiting; // [bool]
71 protected $leave_end; // [ilDate]
72 protected $show_members = 1;
73
74
75 protected $start = null;
76 protected $end = null;
77
78
79 // Map
80 private $latitude = '';
81 private $longitude = '';
82 private $locationzoom = 0;
83 private $enablemap = 0;
84
85 private $reg_access_code = '';
86 private $reg_access_code_enabled = false;
87
88 private $view_mode = null;
89
91
92
94
95
99 public $file_obj = null;
100
102
104
106
113 public function __construct($a_id = 0, $a_call_by_reference = true)
114 {
115 global $tree;
116
117 $this->tree =&$tree;
118
119 $this->type = "grp";
120 parent::__construct($a_id, $a_call_by_reference);
121 $this->setRegisterMode(true); // ???
122 }
123
129 public static function lookupGroupTye($a_id)
130 {
131 global $ilDB;
132
133 $query = "SELECT grp_type FROM grp_settings " .
134 "WHERE obj_id = " . $ilDB->quote($a_id, 'integer');
135 $res = $ilDB->query($query);
136 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
137 return $row->grp_type;
138 }
139 return GRP_TYPE_UNKNOWN;
140 }
141
142 // Setter/Getter
150 public function setInformation($a_information)
151 {
152 $this->information = $a_information;
153 }
154
162 public function getInformation()
163 {
164 return $this->information;
165 }
166
173 public function setGroupType($a_type)
174 {
175 $this->group_type = $a_type;
176 }
177
184 public function getGroupType()
185 {
186 return $this->group_type;
187 }
188
197 {
198 $this->reg_type = $a_type;
199 }
200
207 public function getRegistrationType()
208 {
209 return $this->reg_type;
210 }
211
218 public function isRegistrationEnabled()
219 {
221 }
222
230 public function enableUnlimitedRegistration($a_status)
231 {
232 $this->reg_unlimited = $a_status;
233 }
234
241 public function isRegistrationUnlimited()
242 {
244 }
245
253 public function setRegistrationStart($a_start)
254 {
255 $this->reg_start = $a_start;
256 }
257
264 public function getRegistrationStart()
265 {
266 return $this->reg_start;
267 }
268
269
277 public function setRegistrationEnd($a_end)
278 {
279 $this->reg_end = $a_end;
280 }
281
288 public function getRegistrationEnd()
289 {
290 return $this->reg_end;
291 }
292
299 public function setPassword($a_pass)
300 {
301 $this->reg_password = $a_pass;
302 }
303
310 public function getPassword()
311 {
312 return $this->reg_password;
313 }
314
322 public function enableMembershipLimitation($a_status)
323 {
324 $this->reg_membership_limitation = $a_status;
325 }
326
333 public function isMembershipLimited()
334 {
336 }
337
344 public function setMinMembers($a_max)
345 {
346 $this->reg_min_members = $a_max;
347 }
348
355 public function getMinMembers()
356 {
358 }
359
366 public function setMaxMembers($a_max)
367 {
368 $this->reg_max_members = $a_max;
369 }
370
377 public function getMaxMembers()
378 {
380 }
381
389 public function enableWaitingList($a_status)
390 {
391 $this->waiting_list = $a_status;
392 }
393
401 public function isWaitingListEnabled()
402 {
403 return $this->waiting_list;
404 }
405
406 public function setWaitingListAutoFill($a_value)
407 {
408 $this->auto_fill_from_waiting = (bool) $a_value;
409 }
410
411 public function hasWaitingListAutoFill()
412 {
413 return (bool) $this->auto_fill_from_waiting;
414 }
415
421 public function setLatitude($a_latitude)
422 {
423 $this->latitude = $a_latitude;
424 }
425
431 public function getLatitude()
432 {
433 return $this->latitude;
434 }
435
441 public function setLongitude($a_longitude)
442 {
443 $this->longitude = $a_longitude;
444 }
445
451 public function getLongitude()
452 {
453 return $this->longitude;
454 }
455
461 public function setLocationZoom($a_locationzoom)
462 {
463 $this->locationzoom = $a_locationzoom;
464 }
465
471 public function getLocationZoom()
472 {
473 return $this->locationzoom;
474 }
475
481 public function setEnableGroupMap($a_enablemap)
482 {
483 $this->enablemap = $a_enablemap;
484 }
485
490 public function getEnableMap()
491 {
492 return $this->getEnableGroupMap();
493 }
494
500 public function getEnableGroupMap()
501 {
502 return (bool) $this->enablemap;
503 }
504
510 {
512 }
513
519 public function setRegistrationAccessCode($a_code)
520 {
521 $this->reg_access_code = $a_code;
522 }
523
529 {
530 return (bool) $this->reg_access_code_enabled;
531 }
532
538 public function enableRegistrationAccessCode($a_status)
539 {
540 $this->reg_access_code_enabled = $a_status;
541 }
542
549 {
550 $this->mail_members = $a_type;
551 }
552
557 public function getMailToMembersType()
558 {
559 return $this->mail_members;
560 }
561
562 public function setCancellationEnd(ilDate $a_value = null)
563 {
564 $this->leave_end = $a_value;
565 }
566
567 public function getCancellationEnd()
568 {
569 return $this->leave_end;
570 }
571
572 public function setShowMembers($a_status)
573 {
574 $this->show_members = $a_status;
575 }
576 public function getShowMembers()
577 {
578 return $this->show_members;
579 }
580
585 public function getStart()
586 {
587 return $this->start;
588 }
589
594 public function setStart(ilDate $start = null)
595 {
596 $this->start = $start;
597 }
598
603 public function getEnd()
604 {
605 return $this->end;
606 }
607
612 public function setEnd(ilDate $end = null)
613 {
614 $this->end = $end;
615 }
616
623 public function validate()
624 {
625 global $ilErr;
626
627 if (!$this->getTitle()) {
628 $this->title = '';
629 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
630 }
631 if ($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword())) {
632 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
633 }
634 /*
635 if(ilDateTime::_before($this->getRegistrationEnd(),$this->getRegistrationStart()))
636 {
637 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
638 }
639 */
640 if ($this->isMembershipLimited()) {
641 if ($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0) {
642 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
643 }
644 if ($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled()) {
645 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
646 }
647 if ($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers()) {
648 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
649 }
650 }
651 if (
652 ($this->getRegistrationStart() && !$this->getRegistrationEnd()) ||
653 (!$this->getRegistrationStart() && $this->getRegistrationEnd()) ||
654 $this->getRegistrationEnd() <= $this->getRegistrationStart()
655 ) {
656 $ilErr->appendMessage($this->lng->txt((self::ERR_WRONG_REGISTRATION_LIMITED)));
657 }
658
659 return strlen($ilErr->getMessage()) == 0;
660 }
661
662
663
664
668 public function create()
669 {
670 global $ilDB,$ilAppEventHandler;
671
672 if (!parent::create()) {
673 return false;
674 }
675
676 $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled," .
677 "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit," .
678 "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type," .
679 "leave_end,registration_min_members,auto_wait, grp_start, grp_end) " .
680 "VALUES(" .
681 $ilDB->quote($this->getId(), 'integer') . ", " .
682 $ilDB->quote($this->getInformation(), 'text') . ", " .
683 $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
684 $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
685 $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0), 'integer') . ", " .
686 $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0), 'integer') . ", " .
687 $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
688 $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
689 $ilDB->quote($this->getPassword(), 'text') . ", " .
690 $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
691 $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
692 $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
693 $ilDB->quote($this->getLatitude(), 'text') . ", " .
694 $ilDB->quote($this->getLongitude(), 'text') . ", " .
695 $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
696 $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
697 $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
698 $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
699 $ilDB->quote($this->getViewMode(), 'integer') . ', ' .
700 $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
701 $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
702 $ilDB->quote($this->getMinMembers(), 'integer') . ', ' .
703 $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ', ' .
704 $ilDB->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
705 $ilDB->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null, 'integer') . ' ' .
706 ")";
707 $res = $ilDB->manipulate($query);
708
709 $ilAppEventHandler->raise(
710 'Modules/Group',
711 'create',
712 array('object' => $this,
713 'obj_id' => $this->getId(),
714 'appointments' => $this->prepareAppointments('create'))
715 );
716
717 return $this->getId();
718 }
719
723 public function update()
724 {
725 global $ilDB,$ilAppEventHandler;
726
727 if (!parent::update()) {
728 return false;
729 }
730
731 $query = "UPDATE grp_settings " .
732 "SET information = " . $ilDB->quote($this->getInformation(), 'text') . ", " .
733 "grp_type = " . $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
734 "registration_type = " . $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
735 "registration_enabled = " . $ilDB->quote($this->isRegistrationEnabled() ? 1 : 0, 'integer') . ", " .
736 "registration_unlimited = " . $ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0, 'integer') . ", " .
737 "registration_start = " . $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
738 "registration_end = " . $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
739 "registration_password = " . $ilDB->quote($this->getPassword(), 'text') . ", " .
740// "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
741 "registration_mem_limit = " . $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
742 "registration_max_members = " . $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
743 "waiting_list = " . $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
744 "latitude = " . $ilDB->quote($this->getLatitude(), 'text') . ", " .
745 "longitude = " . $ilDB->quote($this->getLongitude(), 'text') . ", " .
746 "location_zoom = " . $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
747 "enablemap = " . $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
748 'reg_ac_enabled = ' . $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
749 'reg_ac = ' . $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
750 'view_mode = ' . $ilDB->quote($this->getViewMode(), 'integer') . ', ' .
751 'mail_members_type = ' . $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
752 'leave_end = ' . $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
753 "registration_min_members = " . $ilDB->quote($this->getMinMembers(), 'integer') . ", " .
754 "auto_wait = " . $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ", " .
755 "show_members = " . $ilDB->quote((int) $this->getShowMembers(), 'integer') . ", " .
756 'grp_start = ' . $ilDB->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null) . ', ' .
757 'grp_end = ' . $ilDB->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null) . ' ' .
758 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
759 $res = $ilDB->manipulate($query);
760
761 $ilAppEventHandler->raise(
762 'Modules/Group',
763 'update',
764 array('object' => $this,
765 'obj_id' => $this->getId(),
766 'appointments' => $this->prepareAppointments('update'))
767 );
768
769
770 return true;
771 }
772
779 public function delete()
780 {
781 global $ilDB,$ilAppEventHandler;
782
783 // always call parent delete function first!!
784 if (!parent::delete()) {
785 return false;
786 }
787
788 $query = "DELETE FROM grp_settings " .
789 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
790 $res = $ilDB->manipulate($query);
791
792 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
794
795 $ilAppEventHandler->raise(
796 'Modules/Group',
797 'delete',
798 array('object' => $this,
799 'obj_id' => $this->getId(),
800 'appointments' => $this->prepareAppointments('delete'))
801 );
802
803
804 return true;
805 }
806
807
811 public function read()
812 {
813 global $ilDB;
814
815 parent::read();
816
817 $query = "SELECT * FROM grp_settings " .
818 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
819
820 $res = $ilDB->query($query);
821 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
822 $this->setInformation($row->information);
823 $this->setGroupType($row->grp_type);
824 $this->setRegistrationType($row->registration_type);
825 $this->enableUnlimitedRegistration($row->registration_unlimited);
826 $this->setRegistrationStart(new ilDateTime($row->registration_start, IL_CAL_DATETIME));
827 $this->setRegistrationEnd(new ilDateTime($row->registration_end, IL_CAL_DATETIME));
828 $this->setPassword($row->registration_password);
829 $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
830 $this->setMaxMembers($row->registration_max_members);
831 $this->enableWaitingList($row->waiting_list);
832 $this->setLatitude($row->latitude);
833 $this->setLongitude($row->longitude);
834 $this->setLocationZoom($row->location_zoom);
835 $this->setEnableGroupMap($row->enablemap);
836 $this->enableRegistrationAccessCode($row->reg_ac_enabled);
837 $this->setRegistrationAccessCode($row->reg_ac);
838 $this->setViewMode($row->view_mode);
839 $this->setMailToMembersType($row->mail_members_type);
840 $this->setCancellationEnd($row->leave_end ? new ilDate($row->leave_end, IL_CAL_UNIX) : null);
841 $this->setMinMembers($row->registration_min_members);
842 $this->setWaitingListAutoFill($row->auto_wait);
843 $this->setShowMembers($row->show_members);
844 $this->setStart($row->grp_start ? new ilDate($row->grp_start, IL_CAL_UNIX) : null);
845 $this->setEnd($row->grp_end ? new ilDate($row->grp_end, IL_CAL_UNIX) : null);
846 }
847 $this->initParticipants();
848
849 // Inherit order type from parent course (if exists)
850 include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
852 }
853
862 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
863 {
864 global $ilDB,$ilUser, $ilSetting;
865
866 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
867
868 // current template
869 $current_template = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId());
870 $new_obj->applyDidacticTemplate($current_template);
871 $this->cloneAutoGeneratedRoles($new_obj);
872
873 $new_obj->setRegistrationType($this->getRegistrationType());
874 $new_obj->setInformation($this->getInformation());
875 $new_obj->setRegistrationStart($this->getRegistrationStart());
876 $new_obj->setRegistrationEnd($this->getRegistrationEnd());
877 $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
878 $new_obj->setPassword($this->getPassword());
879 $new_obj->enableMembershipLimitation($this->isMembershipLimited());
880 $new_obj->setMaxMembers($this->getMaxMembers());
881 $new_obj->enableWaitingList($this->isWaitingListEnabled());
882 $new_obj->setShowMembers($this->getShowMembers());
883
884 // map
885 $new_obj->setLatitude($this->getLatitude());
886 $new_obj->setLongitude($this->getLongitude());
887 $new_obj->setLocationZoom($this->getLocationZoom());
888 $new_obj->setEnableGroupMap($this->getEnableGroupMap());
889 $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
890 include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
891 $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
892
893 $new_obj->setViewMode($this->getViewMode());
894 $new_obj->setMailToMembersType($this->getMailToMembersType());
895
896 $new_obj->setCancellationEnd($this->getCancellationEnd());
897 $new_obj->setMinMembers($this->getMinMembers());
898 $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
899
900 $new_obj->setStart($this->getStart());
901 $new_obj->setEnd($this->getEnd());
902
903 $new_obj->update();
904
905 // #13008 - Group Defined Fields
906 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
907 ilCourseDefinedFieldDefinition::_clone($this->getId(), $new_obj->getId());
908
909 // Assign user as admin
910 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
911 $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
912 $part->add($ilUser->getId(), IL_GRP_ADMIN);
913 $part->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
914
915 // Copy learning progress settings
916 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
917 $obj_settings = new ilLPObjSettings($this->getId());
918 $obj_settings->cloneSettings($new_obj->getId());
919 unset($obj_settings);
920
921 return $new_obj;
922 }
923
932 public function cloneDependencies($a_target_id, $a_copy_id)
933 {
934 global $tree;
935
936 parent::cloneDependencies($a_target_id, $a_copy_id);
937
938 include_once('Services/Object/classes/class.ilObjectActivation.php');
939 ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
940
941 return true;
942 }
943
951 public function cloneAutoGeneratedRoles($new_obj)
952 {
953 global $rbacadmin,$rbacreview;
954
955 $admin = $this->getDefaultAdminRole();
956 $new_admin = $new_obj->getDefaultAdminRole();
957 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
958 ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_admin');
959 }
960 $rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
961 ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_admin.');
962
963 $member = $this->getDefaultMemberRole();
964 $new_member = $new_obj->getDefaultMemberRole();
965 if (!$member || !$new_member) {
966 ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_member');
967 }
968 $rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
969 ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_member.');
970 }
971
972
978 public function join($a_user_id, $a_mem_role="")
979 {
980 global $rbacadmin;
981
982 if (is_array($a_mem_role)) {
983 foreach ($a_mem_role as $role) {
984 $rbacadmin->assignUser($role, $a_user_id, false);
985 }
986 } else {
987 $rbacadmin->assignUser($a_mem_role, $a_user_id, false);
988 }
989
990 return true;
991 }
992
997 public function getDefaultMemberRole()
998 {
999 $local_group_Roles = $this->getLocalGroupRoles();
1000
1001 return $local_group_Roles["il_grp_member_" . $this->getRefId()];
1002 }
1003
1008 public function getDefaultAdminRole()
1009 {
1010 $local_group_Roles = $this->getLocalGroupRoles();
1011
1012 return $local_group_Roles["il_grp_admin_" . $this->getRefId()];
1013 }
1014
1021 public function addMember($a_user_id, $a_mem_role)
1022 {
1023 global $rbacadmin;
1024
1025 if (isset($a_user_id) && isset($a_mem_role)) {
1026 $this->join($a_user_id, $a_mem_role);
1027 return true;
1028 } else {
1029 $this->ilias->raiseError(get_class($this) . "::addMember(): Missing parameters !", $this->ilias->error_obj->WARNING);
1030 return false;
1031 }
1032 }
1033
1034
1041 public function leaveGroup()
1042 {
1043 global $rbacadmin, $rbacreview;
1044
1045 $member_ids = $this->getGroupMemberIds();
1046
1047 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids)) {
1048 return 2;
1049 } else {
1050 if (!$this->isAdmin($this->ilias->account->getId())) {
1051 $this->leave($this->ilias->account->getId());
1052 $member = new ilObjUser($this->ilias->account->getId());
1053 $member->dropDesktopItem($this->getRefId(), "grp");
1054
1055 return 0;
1056 } elseif (count($this->getGroupAdminIds()) == 1) {
1057 return 1;
1058 }
1059 }
1060 }
1061
1066 public function leave($a_user_id)
1067 {
1068 global $rbacadmin;
1069
1070 $arr_groupRoles = $this->getMemberRoles($a_user_id);
1071
1072 if (is_array($arr_groupRoles)) {
1073 foreach ($arr_groupRoles as $groupRole) {
1074 $rbacadmin->deassignUser($groupRole, $a_user_id);
1075 }
1076 } else {
1077 $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
1078 }
1079
1080 return true;
1081 }
1082
1089 public function getGroupMemberIds()
1090 {
1091 global $rbacadmin, $rbacreview;
1092
1093 $usr_arr= array();
1094
1095 $rol = $this->getLocalGroupRoles();
1096
1097 foreach ($rol as $value) {
1098 foreach ($rbacreview->assignedUsers($value) as $member_id) {
1099 array_push($usr_arr, $member_id);
1100 }
1101 }
1102
1103 $mem_arr = array_unique($usr_arr);
1104
1105 return $mem_arr ? $mem_arr : array();
1106 }
1107
1115 public function getGroupMemberData($a_mem_ids, $active = 1)
1116 {
1118
1119 $usr_arr= array();
1120
1121 $q = "SELECT login,firstname,lastname,title,usr_id,last_login " .
1122 "FROM usr_data " .
1123 "WHERE usr_id IN (" . implode(',', ilUtil::quoteArray($a_mem_ids)) . ") ";
1124
1125 if (is_numeric($active) && $active > -1) {
1126 $q .= "AND active = '$active'";
1127 }
1128
1129 $q .= 'ORDER BY lastname,firstname';
1130
1131 $r = $ilDB->query($q);
1132
1133 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1134 $mem_arr[] = array("id" => $row->usr_id,
1135 "login" => $row->login,
1136 "firstname" => $row->firstname,
1137 "lastname" => $row->lastname,
1138 "last_login" => $row->last_login
1139 );
1140 }
1141
1142 return $mem_arr ? $mem_arr : array();
1143 }
1144
1145 public function getCountMembers()
1146 {
1147 return count($this->getGroupMemberIds());
1148 }
1149
1156 public function getGroupAdminIds($a_grpId = "")
1157 {
1158 global $rbacreview;
1159
1160 if (!empty($a_grpId)) {
1161 $grp_id = $a_grpId;
1162 } else {
1163 $grp_id = $this->getRefId();
1164 }
1165
1166 $usr_arr = array();
1167 $roles = $this->getDefaultGroupRoles($this->getRefId());
1168
1169 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id) {
1170 array_push($usr_arr, $member_id);
1171 }
1172
1173 return $usr_arr;
1174 }
1175
1181 public function getDefaultGroupRoles($a_grp_id="")
1182 {
1183 global $rbacadmin, $rbacreview;
1184
1185 if (strlen($a_grp_id) > 0) {
1186 $grp_id = $a_grp_id;
1187 } else {
1188 $grp_id = $this->getRefId();
1189 }
1190
1191 $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1192
1193 foreach ($role_arr as $role_id) {
1194 $role_Obj =&$this->ilias->obj_factory->getInstanceByObjId($role_id);
1195
1196 $grp_Member ="il_grp_member_" . $grp_id;
1197 $grp_Admin ="il_grp_admin_" . $grp_id;
1198
1199 if (strcmp($role_Obj->getTitle(), $grp_Member) == 0) {
1200 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1201 }
1202
1203 if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0) {
1204 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1205 }
1206 }
1207
1208 return $arr_grpDefaultRoles;
1209 }
1210
1217 public function getLocalGroupRoles($a_translate = false)
1218 {
1219 global $rbacadmin,$rbacreview;
1220
1221 if (empty($this->local_roles)) {
1222 $this->local_roles = array();
1223 $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1224
1225 foreach ($role_arr as $role_id) {
1226 if ($rbacreview->isAssignable($role_id, $this->getRefId()) == true) {
1227 $role_Obj =&$this->ilias->obj_factory->getInstanceByObjId($role_id);
1228
1229 if ($a_translate) {
1230 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1231 } else {
1232 $role_name = $role_Obj->getTitle();
1233 }
1234
1235 $this->local_roles[$role_name] = $role_Obj->getId();
1236 }
1237 }
1238 }
1239
1240 return $this->local_roles;
1241 }
1242
1249 {
1250 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1251 $res = $this->ilias->db->query($q);
1253
1254 return $row["obj_id"];
1255 }
1256
1263 {
1264 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1265 $res = $this->ilias->db->query($q);
1267
1268 return $row["obj_id"];
1269 }
1270
1277 public static function lookupGroupStatusTemplateId($a_obj_id)
1278 {
1279 global $ilDB;
1280
1281 $type = self::lookupGroupTye($a_obj_id);
1282 if ($type == GRP_TYPE_CLOSED) {
1283 $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_closed', 'text');
1284 } else {
1285 $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_open', 'text');
1286 }
1287 $res = $ilDB->query($query);
1289
1290 return isset($row['obj_id']) ? $row['obj_id'] : 0;
1291 }
1292
1293
1294
1304 public function updateGroupType($a_group_type = GRP_TYPE_OPEN)
1305 {
1306 global $DIC;
1307
1308 $logger = $DIC->logger()->grp();
1309
1310 if ($a_group_type == GRP_TYPE_OPEN) {
1311 $this->applyDidacticTemplate(0);
1312 return;
1313 }
1314
1315 $templates = ilDidacticTemplateSettings::getInstanceByObjectType($this->getType())->getTemplates();
1316 foreach ($templates as $template) {
1317 // the closed template
1318 if ($template->isAutoGenerated()) {
1319 $logger->info('Appying default closed template');
1320 $this->applyDidacticTemplate($template->getId());
1321 return;
1322 }
1323 }
1324 $logger->warning('No closed didactic template available.');
1325 }
1326
1346 public function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1347 {
1349
1350 //define all relevant roles that rights are needed to be changed
1351 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1352
1353 $real_local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId(), false);
1354 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles), $real_local_roles);
1355
1356 //group status open (aka public) or group status closed
1357 if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED) {
1358 if ($a_grpStatus == GRP_TYPE_PUBLIC) {
1360 } else {
1362 }
1363 //get defined operations from template
1364 $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1365
1366 foreach ($arr_relevantParentRoleIds as $parentRole) {
1367 if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'], $parentRole)) {
1368 continue;
1369 }
1370
1371 $granted_permissions = array();
1372
1373 // Delete the linked role for the parent role
1374 // (just in case if it already exists).
1375
1376 // Added additional check, since this operation is very dangerous.
1377 // If there is no role folder ALL parent roles are deleted.
1378
1379 // @todo refactor rolf
1380 $rbacadmin->deleteLocalRole($parentRole, $this->getRefId());
1381
1382 // Grant permissions on the group object for
1383 // the parent role. In the foreach loop we
1384 // compute the intersection of the role
1385 // template il_grp_status_open/_closed and the
1386 // permission template of the parent role.
1387 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1388 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1389 foreach ($template_ops as $template_op) {
1390 if (in_array($template_op, $current_ops)) {
1391 array_push($granted_permissions, $template_op);
1392 }
1393 }
1394 if (!empty($granted_permissions)) {
1395 $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1396 }
1397
1398 // Create a linked role for the parent role and
1399 // initialize it with the intersection of
1400 // il_grp_status_open/_closed and the permission
1401 // template of the parent role
1402
1403 $rbacadmin->copyRolePermissionIntersection(
1405 ROLE_FOLDER_ID,
1406 $parentRole,
1407 $arr_parentRoles[$parentRole]['parent'],
1408 $this->getRefId(),
1409 $parentRole
1410 );
1411 $rbacadmin->assignRoleToFolder($parentRole, $this->getRefId(), "false");
1412 }//END foreach
1413 }
1414 }
1415
1423 public function setGroupStatus($a_status)
1424 {
1425 $this->group_status = $a_status;
1426 }
1427
1435 public function getGroupStatus()
1436 {
1437 return $this->group_status;
1438 }
1439
1445 public function readGroupStatus()
1446 {
1447 global $rbacsystem,$rbacreview;
1448
1449 $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1450
1451 //get all relevant roles
1452 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1453
1454 //if one global role has no permission to join the group is officially closed !
1455 foreach ($arr_globalRoles as $globalRole) {
1456 if ($rbacsystem->checkPermission($this->getRefId(), $globalRole, "join")) {
1457 return $this->group_status = GRP_TYPE_PUBLIC;
1458 }
1459 }
1460
1461 return $this->group_status = GRP_TYPE_CLOSED;
1462 }
1463
1470 public function getMemberRoles($a_user_id)
1471 {
1473
1474 $ilBench->start("Group", "getMemberRoles");
1475
1476 $arr_assignedRoles = array();
1477
1478 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id), $this->getLocalGroupRoles());
1479
1480 $ilBench->stop("Group", "getMemberRoles");
1481
1482 return $arr_assignedRoles;
1483 }
1484
1491 public function isAdmin($a_userId)
1492 {
1493 global $rbacreview;
1494
1495 $grp_Roles = $this->getDefaultGroupRoles();
1496
1497 if (in_array($a_userId, $rbacreview->assignedUsers($grp_Roles["grp_admin_role"]))) {
1498 return true;
1499 } else {
1500 return false;
1501 }
1502 }
1508 public function initDefaultRoles()
1509 {
1510 include_once './Services/AccessControl/classes/class.ilObjRole.php';
1512 'il_grp_admin_' . $this->getRefId(),
1513 "Groupadmin group obj_no." . $this->getId(),
1514 'il_grp_admin',
1515 $this->getRefId()
1516 );
1517 $this->m_roleAdminId = $role->getId();
1518
1520 'il_grp_member_' . $this->getRefId(),
1521 "Groupmember of group obj_no." . $this->getId(),
1522 'il_grp_member',
1523 $this->getRefId()
1524 );
1525 $this->m_roleMemberId = $role->getId();
1526
1527 return array();
1528 }
1529
1539 public function setParentRolePermissions($a_parent_ref)
1540 {
1541 $rbacadmin = $GLOBALS['DIC']->rbac()->admin();
1542 $rbacreview = $GLOBALS['DIC']->rbac()->review();
1543
1544 $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1545 foreach ((array) $parent_roles as $parent_role) {
1546 if ($parent_role['parent'] == $this->getRefId()) {
1547 continue;
1548 }
1549 if ($rbacreview->isProtected($parent_role['parent'], $parent_role['rol_id'])) {
1550 $operations = $rbacreview->getOperationsOfRole(
1551 $parent_role['obj_id'],
1552 $this->getType(),
1553 $parent_role['parent']
1554 );
1555 $rbacadmin->grantPermission(
1556 $parent_role['obj_id'],
1557 $operations,
1558 $this->getRefId()
1559 );
1560 continue;
1561 }
1562
1563 $rbacadmin->initIntersectionPermissions(
1564 $this->getRefId(),
1565 $parent_role['obj_id'],
1566 $parent_role['parent'],
1568 ROLE_FOLDER_ID
1569 );
1570 }
1571 }
1572
1573
1578 public function applyDidacticTemplate($a_tpl_id)
1579 {
1580 parent::applyDidacticTemplate($a_tpl_id);
1581
1582 if (!$a_tpl_id) {
1583 // init default type
1584 $this->setParentRolePermissions($this->getRefId());
1585 }
1586 }
1587
1588
1589 public static function _lookupIdByTitle($a_title)
1590 {
1591 global $ilDB;
1592
1593 $query = "SELECT * FROM object_data WHERE title = " .
1594 $ilDB->quote($a_title, 'text') . " AND type = 'grp'";
1595 $res = $ilDB->query($query);
1596 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1597 return $row->obj_id;
1598 }
1599 return 0;
1600 }
1601
1602
1603 public function _isMember($a_user_id, $a_ref_id, $a_field = '')
1604 {
1605 global $rbacreview,$ilObjDataCache,$ilDB;
1606
1607 $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
1608 $user_roles = $rbacreview->assignedRoles($a_user_id);
1609
1610 // Used for membership limitations -> check membership by given field
1611 if ($a_field) {
1612 include_once './Services/User/classes/class.ilObjUser.php';
1613
1614 $tmp_user =&ilObjectFactory::getInstanceByObjId($a_user_id);
1615 switch ($a_field) {
1616 case 'login':
1617 $and = "AND login = '" . $tmp_user->getLogin() . "' ";
1618 break;
1619 case 'email':
1620 $and = "AND email = '" . $tmp_user->getEmail() . "' ";
1621 break;
1622 case 'matriculation':
1623 $and = "AND matriculation = '" . $tmp_user->getMatriculation() . "' ";
1624 break;
1625
1626 default:
1627 $and = "AND usr_id = '" . $a_user_id . "'";
1628 break;
1629 }
1630 if (!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id))) {
1631 return false;
1632 }
1633 $query = "SELECT * FROM usr_data as ud " .
1634 "WHERE usr_id IN (" . implode(",", ilUtil::quoteArray($members)) . ") " .
1635 $and;
1636 $res = $ilDB->query($query);
1637
1638 return $res->numRows() ? true : false;
1639 }
1640
1641 if (!array_intersect($local_roles, $user_roles)) {
1642 return false;
1643 }
1644
1645 return true;
1646 }
1647
1648 public function _getMembers($a_obj_id)
1649 {
1650 global $rbacreview;
1651
1652 // get reference
1653 $ref_ids = ilObject::_getAllReferences($a_obj_id);
1654 $ref_id = current($ref_ids);
1655
1656 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
1657
1658 $users = array();
1659 foreach ($local_roles as $role_id) {
1660 $users = array_merge($users, $rbacreview->assignedUsers($role_id));
1661 }
1662
1663 return array_unique($users);
1664 }
1665
1672 public function getViewMode($a_translate_inherit = true)
1673 {
1674 $view = (int) $this->view_mode;
1675
1676 if (!$view) {
1678 }
1679 return $view;
1680 }
1681
1686 public function setViewMode($a_view_mode)
1687 {
1688 $this->view_mode = $a_view_mode;
1689 }
1690
1695 public static function lookupViewMode($a_obj_id)
1696 {
1697 global $ilDB;
1698
1699 $query = 'SELECT view_mode FROM grp_settings ' .
1700 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1701 $res = $ilDB->query($query);
1702
1703 $view_mode = null;
1704 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1705 $view_mode = $row->view_mode;
1706 }
1707 return self::translateViewMode($a_obj_id, $view_mode);
1708 }
1709
1717 public static function translateViewMode($a_obj_id, $a_view_mode, $a_ref_id = null)
1718 {
1719 global $tree;
1720
1721 if (!$a_view_mode) {
1722 $a_view_mode = ilContainer::VIEW_DEFAULT;
1723 }
1724
1725 // view mode is inherit => check for parent course
1726 if ($a_view_mode == ilContainer::VIEW_INHERIT) {
1727 if (!$a_ref_id) {
1728 $ref = ilObject::_getAllReferences($a_obj_id);
1729 $a_ref_id = end($ref);
1730 }
1731
1732 $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1733 if (!$crs_ref) {
1735 }
1736
1737 include_once './Modules/Course/classes/class.ilObjCourse.php';
1739
1740 // validate course view mode
1741 if (!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1744 }
1745
1746 return $view_mode;
1747 }
1748
1749 return $a_view_mode;
1750 }
1751
1756 public function addAdditionalSubItemInformation(&$a_item_data)
1757 {
1758 include_once './Services/Object/classes/class.ilObjectActivation.php';
1760 }
1761
1762 public function getMessage()
1763 {
1764 return $this->message;
1765 }
1766 public function setMessage($a_message)
1767 {
1768 $this->message = $a_message;
1769 }
1770 public function appendMessage($a_message)
1771 {
1772 if ($this->getMessage()) {
1773 $this->message .= "<br /> ";
1774 }
1775 $this->message .= $a_message;
1776 }
1777
1785 protected function prepareAppointments($a_mode = 'create')
1786 {
1787 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1788
1789 switch ($a_mode) {
1790 case 'create':
1791 case 'update':
1792
1793 $apps = array();
1794 if ($this->getStart() && $this->getEnd()) {
1795 $app = new ilCalendarAppointmentTemplate(self::CAL_START);
1796 $app->setTitle($this->getTitle());
1797 $app->setSubtitle('grp_cal_start');
1798 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1799 $app->setDescription($this->getLongDescription());
1800 $app->setStart($this->getStart());
1801 $app->setFullday(true);
1802 $apps[] = $app;
1803
1804 $app = new ilCalendarAppointmentTemplate(self::CAL_END);
1805 $app->setTitle($this->getTitle());
1806 $app->setSubtitle('grp_cal_end');
1807 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1808 $app->setDescription($this->getLongDescription());
1809 $app->setStart($this->getEnd());
1810 $app->setFullday(true);
1811 $apps[] = $app;
1812 }
1813 if ($this->isRegistrationUnlimited()) {
1814 return $apps;
1815 }
1816
1817 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1818 $app->setTitle($this->getTitle());
1819 $app->setSubtitle('grp_cal_reg_start');
1820 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1821 $app->setDescription($this->getLongDescription());
1822 $app->setStart($this->getRegistrationStart());
1823 $apps[] = $app;
1824
1825 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1826 $app->setTitle($this->getTitle());
1827 $app->setSubtitle('grp_cal_reg_end');
1828 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1829 $app->setDescription($this->getLongDescription());
1830 $app->setStart($this->getRegistrationEnd());
1831 $apps[] = $app;
1832
1833
1834 return $apps;
1835
1836 case 'delete':
1837 // Nothing to do: The category and all assigned appointments will be deleted.
1838 return array();
1839 }
1840 }
1841
1849 protected function initParticipants()
1850 {
1851 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1852 $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1853 }
1854
1860 public function getMembersObject()
1861 {
1862 // #17886
1863 if (!$this->members_obj instanceof ilGroupParticipants) {
1864 $this->initParticipants();
1865 }
1866 return $this->members_obj;
1867 }
1868
1873 public static function lookupObjectsByCode($a_code)
1874 {
1875 global $ilDB;
1876
1877 $query = "SELECT obj_id FROM grp_settings " .
1878 "WHERE reg_ac_enabled = " . $ilDB->quote(1, 'integer') . " " .
1879 "AND reg_ac = " . $ilDB->quote($a_code, 'text');
1880 $res = $ilDB->query($query);
1881
1882 $obj_ids = array();
1883 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1884 $obj_ids[] = $row->obj_id;
1885 }
1886 return $obj_ids;
1887 }
1888
1895 public function register($a_user_id, $a_role = IL_GRP_MEMBER, $a_force_registration = false)
1896 {
1897 include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1898 include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1900
1901 if ($part->isAssigned($a_user_id)) {
1902 return true;
1903 }
1904
1905 if (!$a_force_registration) {
1906 // Availability
1907 if (!$this->isRegistrationEnabled()) {
1908 include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1909
1911 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
1912 ', group subscription is deactivated.', ilMembershipRegistrationException::REGISTRATION_CODE_DISABLED);
1913 }
1914 }
1915
1916 // Time Limitation
1917 if (!$this->isRegistrationUnlimited()) {
1918 $start = $this->getRegistrationStart();
1919 $end = $this->getRegistrationEnd();
1920 $time = new ilDateTime(time(), IL_CAL_UNIX);
1921
1923 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
1924 ', group is out of registration time.', ilMembershipRegistrationException::OUT_OF_REGISTRATION_PERIOD);
1925 }
1926 }
1927
1928 // Max members
1929 if ($this->isMembershipLimited()) {
1930 $free = max(0, $this->getMaxMembers() - $part->getCountMembers());
1931 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
1932 $waiting_list = new ilGroupWaitingList($this->getId());
1933 if ($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
1934 $this->lng->loadLanguageModule("grp");
1935 $waiting_list->addToList($a_user_id);
1936
1937 $info = sprintf(
1938 $this->lng->txt('grp_added_to_list'),
1939 $this->getTitle(),
1940 $waiting_list->getPosition($a_user_id)
1941 );
1942
1943 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1944 include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
1945 $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
1946 $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $a_user_id);
1947
1949 }
1950
1951 if (!$free or $waiting_list->getCountUsers()) {
1952 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
1953 ', membership is limited.', ilMembershipRegistrationException::OBJECT_IS_FULL);
1954 }
1955 }
1956 }
1957
1958 $part->add($a_user_id, $a_role);
1959 $part->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $a_user_id);
1960 $part->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
1961 return true;
1962 }
1963
1964 public function handleAutoFill()
1965 {
1966 if ($this->isWaitingListEnabled() &&
1967 $this->hasWaitingListAutoFill()) {
1968 $max = $this->getMaxMembers();
1970 if ($max > $now) {
1971 // see assignFromWaitingListObject()
1972 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
1973 $waiting_list = new ilGroupWaitingList($this->getId());
1974
1975 foreach ($waiting_list->getUserIds() as $user_id) {
1976 if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
1977 continue;
1978 }
1979 if ($this->getMembersObject()->isAssigned($user_id)) {
1980 continue;
1981 }
1982 $this->getMembersObject()->add($user_id, IL_GRP_MEMBER); // #18213
1983 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
1985 $waiting_list->removeFromList($user_id);
1986
1987 $now++;
1988 if ($now >= $max) {
1989 break;
1990 }
1991 }
1992 }
1993 }
1994 }
1995
1996 public static function mayLeave($a_group_id, $a_user_id = null, &$a_date = null)
1997 {
1998 global $ilUser, $ilDB;
1999
2000 if (!$a_user_id) {
2001 $a_user_id = $ilUser->getId();
2002 }
2003
2004 $set = $ilDB->query("SELECT leave_end" .
2005 " FROM grp_settings" .
2006 " WHERE obj_id = " . $ilDB->quote($a_group_id, "integer"));
2007 $row = $ilDB->fetchAssoc($set);
2008 if ($row && $row["leave_end"]) {
2009 // timestamp to date
2010 $limit = date("Ymd", $row["leave_end"]);
2011 if ($limit < date("Ymd")) {
2012 $a_date = new ilDate(date("Y-m-d", $row["leave_end"]), IL_CAL_DATE);
2013 return false;
2014 }
2015 }
2016 return true;
2017 }
2018
2024 public static function findGroupsWithNotEnoughMembers()
2025 {
2026 $ilDB = $GLOBALS['DIC']->database();
2027 $tree = $GLOBALS['DIC']->repositoryTree();
2028
2029 $res = array();
2030
2031 $now = date("Y-m-d H:i:s");
2032
2033 include_once "Modules/Group/classes/class.ilGroupParticipants.php";
2034
2035 $set = $ilDB->query("SELECT obj_id, registration_min_members" .
2036 " FROM grp_settings" .
2037 " WHERE registration_min_members > " . $ilDB->quote(0, "integer") .
2038 " AND registration_mem_limit = " . $ilDB->quote(1, "integer") . // #17206
2039 " AND ((leave_end IS NOT NULL" .
2040 " AND leave_end < " . $ilDB->quote($now, "text") . ")" .
2041 " OR (leave_end IS NULL" .
2042 " AND registration_end IS NOT NULL" .
2043 " AND registration_end < " . $ilDB->quote($now, "text") . "))" .
2044 " AND (grp_start IS NULL OR grp_start > " . $ilDB->quote($now, "integer") . ")");
2045 while ($row = $ilDB->fetchAssoc($set)) {
2046 $refs = ilObject::_getAllReferences($row['obj_id']);
2047 $ref = end($refs);
2048
2049 if ($tree->isDeleted($ref)) {
2050 continue;
2051 }
2052
2053 $part = new ilGroupParticipants($row["obj_id"]);
2054 $reci = $part->getNotificationRecipients();
2055 if (sizeof($reci)) {
2056 $missing = (int) $row["registration_min_members"]-$part->getCountMembers();
2057 if ($missing > 0) {
2058 $res[$row["obj_id"]] = array($missing, $reci);
2059 }
2060 }
2061 }
2062
2063 return $res;
2064 }
2065
2066 public static function lookupShowMembersEnabled(int $a_obj_id)
2067 {
2068 global $DIC;
2069 $ilDB = $DIC["ilDB"];
2070 $query = 'SELECT show_members FROM grp_settings'
2071 .' WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
2072 $res = $ilDB->query($query);
2073 if($ilDB->numRows($res) == 0) {
2074 return false;
2075 }
2076 $row = $ilDB->fetchAssoc($res);
2077 return (bool)$row['show_members'];
2078 }
2079} //END class.ilObjGroup
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$users
Definition: authpage.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_TRANSLATION_SYSTEM
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const GRP_REGISTRATION_DIRECT
const GRP_REGISTRATION_PASSWORD
const GRP_TYPE_OPEN
const GRP_TYPE_CLOSED
const GRP_TYPE_UNKNOWN
const GRP_REGISTRATION_DEACTIVATED
const GRP_TYPE_PUBLIC
const IL_GRP_MEMBER
const IL_GRP_ADMIN
Apointment templates are used for automatic generated apointments.
static _lookupSortMode($a_obj_id)
lookup sort mode
Class ilContainer.
setOrderType($a_value)
getViewMode()
Get container view mode.
static _clone($a_source_id, $a_target_id)
Clone fields.
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
static lookupTemplateId($a_ref_id)
Lookup template id @global ilDB $ilDB.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Waiting list for groups.
static getLogger($a_component_id)
Get component logger.
static generateCode()
Generate new registration key.
static _lookupViewMode($a_id)
lookup view mode of container
static _usingRegistrationCode()
Using Registration code.
Class ilObjGroup.
getGroupMemberData($a_mem_ids, $active=1)
get all group Members regardless of group role.
setGroupStatus($a_status)
Set group status.
getInformation()
get Information
static lookupViewMode($a_obj_id)
lookup view mode @global $ilDB
getGroupType()
get group type
getLocationZoom()
Get LocationZoom.
getLongitude()
Get Longitude.
getLocalGroupRoles($a_translate=false)
get ALL local roles of group, also those created and defined afterwards only fetch data once from dat...
const ERR_MISSING_TITLE
getDefaultAdminRole()
returns object id of created default adminstrator role @access public
getPassword()
get password
getEnableMap()
Type independent wrapper.
getGroupMemberIds()
get all group Member ids regardless of role @access public
appendMessage($a_message)
enableRegistrationAccessCode($a_status)
En/disable registration access code.
getDefaultMemberRole()
returns object id of created default member role @access public
getMinMembers()
get min members
getMembersObject()
Get members objects.
static lookupShowMembersEnabled(int $a_obj_id)
getEnd()
Get end.
setPassword($a_pass)
set password
enableWaitingList($a_status)
enable waiting list
const MAIL_ALLOWED_TUTORS
applyDidacticTemplate($a_tpl_id)
Apply template.
static lookupObjectsByCode($a_code)
getRegistrationStart()
get registration start
readGroupStatus()
get group status, redundant method because @access public
initParticipants()
init participants object
setRegistrationAccessCode($a_code)
Set refistration access code.
setRegistrationStart($a_start)
set registration start
setInformation($a_information)
set information
setEnd(ilDate $end=null)
Set end.
getRegistrationType()
get registration type
setMaxMembers($a_max)
set max members
setStart(ilDate $start=null)
Set start.
getGrpStatusClosedTemplateId()
get group status closed template @access public
create()
Create group.
getMaxMembers()
get max members
const ERR_WRONG_REG_TIME_LIMIT
isMembershipLimited()
is max member limited
getDefaultGroupRoles($a_grp_id="")
get default group roles, returns the defaultlike create roles il_grp_member, il_grp_admin @access pub...
setEnableGroupMap($a_enablemap)
Set Enable Group Map.
setCancellationEnd(ilDate $a_value=null)
cloneAutoGeneratedRoles($new_obj)
Clone group admin and member role permissions.
setWaitingListAutoFill($a_value)
leave($a_user_id)
deassign member from group role @access private
const ERR_MISSING_MIN_MAX_MEMBERS
static lookupGroupTye($a_id)
Lookup group type.
_isMember($a_user_id, $a_ref_id, $a_field='')
setLongitude($a_longitude)
Set Longitude.
static _lookupIdByTitle($a_title)
addMember($a_user_id, $a_mem_role)
add Member to Group @access public
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies (crs items, preconditions)
setRegistrationEnd($a_end)
set registration end
getRegistrationAccessCode()
get access code
$file_obj
Group file object for handling of export files.
isAdmin($a_userId)
is Admin @access public
read()
Read group.
setGroupType($a_type)
set group type
getRegistrationEnd()
get registration end
update()
Update group.
initGroupStatus($a_grpStatus=GRP_TYPE_PUBLIC)
set group status
setMinMembers($a_max)
set min members
setMailToMembersType($a_type)
Set mail to members type.
setLatitude($a_latitude)
Set Latitude.
setLocationZoom($a_locationzoom)
Set LocationZoom.
join($a_user_id, $a_mem_role="")
join Group, assigns user to role @access private
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
const ERR_WRONG_REGISTRATION_LIMITED
setViewMode($a_view_mode)
Set group view mode.
validate()
validate group settings
setRegistrationType($a_type)
set registration type
getGroupStatus()
get group status
const ERR_MISSING_GROUP_TYPE
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone group (no member data)
addAdditionalSubItemInformation(&$a_item_data)
Add additional information to sub item, e.g.
leaveGroup()
is called when a member decides to leave group @access public
enableMembershipLimitation($a_status)
enable max member limitation
const ERR_MISSING_PASSWORD
isRegistrationUnlimited()
is registration unlimited
setShowMembers($a_status)
isRegistrationEnabled()
is registration enabled
const ERR_WRONG_MIN_MAX_MEMBERS
isRegistrationAccessCodeEnabled()
Check if access code is enabled.
getLatitude()
Get Latitude.
getGrpStatusOpenTemplateId()
get group status open template @access public
const MAIL_ALLOWED_ALL
getMailToMembersType()
Get mail to members type.
static findGroupsWithNotEnoughMembers()
Minimum members check @global $ilDB $ilDB.
enableUnlimitedRegistration($a_status)
enable unlimited registration
getViewMode($a_translate_inherit=true)
get view mode
getEnableGroupMap()
Get Enable Group Map.
static lookupGroupStatusTemplateId($a_obj_id)
@global $ilDB $ilDB
_getMembers($a_obj_id)
getStart()
Get group start.
static mayLeave($a_group_id, $a_user_id=null, &$a_date=null)
prepareAppointments($a_mode='create')
Prepare calendar appointments.
updateGroupType($a_group_type=GRP_TYPE_OPEN)
Change group type.
getGroupAdminIds($a_grpId="")
get Group Admin Id @access public
setParentRolePermissions($a_parent_ref)
This method is called before "initDefaultRoles".
const ERR_WRONG_MAX_MEMBERS
setMessage($a_message)
static translateViewMode($a_obj_id, $a_view_mode, $a_ref_id=null)
translate view mode
getMemberRoles($a_user_id)
get group member status @access public
initDefaultRoles()
init default roles settings @access public
isWaitingListEnabled()
is waiting list enabled
static _getTranslation($a_role_title)
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
static cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
Clone dependencies.
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getType()
get object type @access public
static _lookupObjId($a_id)
setRegisterMode($a_bool)
getRefId()
get reference id @access public
getLongDescription()
get object long description (stored in object_description)
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id @access public
getTitle()
get object title @access public
static lookupNumberOfMembers($a_ref_id)
Lookup number of members @global ilRbacReview $rbacreview @global <type> $ilObjDataCache.
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.
$template
$r
Definition: example_031.php:79
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilBench
Definition: ilias.php:18
Interface for all objects that offer registration with access codes.
$time
Definition: cron.php:21
catch(Exception $e) $message
$info
Definition: index.php:5
update($pash, $contents, Config $config)
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$query
global $ilErr
Definition: raiseError.php:16
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$template_id