ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
38 const GRP_MEMBER = 1;
39 const GRP_ADMIN = 2;
40
41 const ERR_MISSING_TITLE = 'msg_no_title';
42 const ERR_MISSING_GROUP_TYPE = 'grp_missing_grp_type';
43 const ERR_MISSING_PASSWORD = 'grp_missing_password';
44 const ERR_WRONG_MAX_MEMBERS = 'grp_wrong_max_members';
45 const ERR_WRONG_REG_TIME_LIMIT = 'grp_wrong_reg_time_limit';
46 const ERR_MISSING_MIN_MAX_MEMBERS = 'grp_wrong_min_max_members';
47 const ERR_WRONG_MIN_MAX_MEMBERS = 'grp_max_and_min_members_invalid';
48 const ERR_WRONG_REGISTRATION_LIMITED = 'grp_err_registration_limited';
49
52
55
56 protected $information;
57 protected $group_type = null;
59 protected $reg_enabled = true;
60 protected $reg_unlimited = true;
61 protected $reg_start = null;
62 protected $reg_end = null;
63 protected $reg_password = '';
64 protected $reg_membership_limitation = false;
65 protected $reg_min_members = 0;
66 protected $reg_max_members = 0;
67 protected $waiting_list = false;
68 protected $auto_fill_from_waiting; // [bool]
69 protected $leave_end; // [ilDate]
70 protected $show_members = 1;
71
72
73 // Map
74 private $latitude = '';
75 private $longitude = '';
76 private $locationzoom = 0;
77 private $enablemap = 0;
78
79 private $reg_access_code = '';
80 private $reg_access_code_enabled = false;
81
82 private $view_mode = NULL;
83
85
86
88
89
93 var $file_obj = null;
94
96
98
100
107 public function __construct($a_id = 0,$a_call_by_reference = true)
108 {
109 global $tree;
110
111 $this->tree =& $tree;
112
113 $this->type = "grp";
114 parent::__construct($a_id,$a_call_by_reference);
115 $this->setRegisterMode(true); // ???
116 }
117
123 public static function lookupGroupTye($a_id)
124 {
125 global $ilDB;
126
127 $query = "SELECT grp_type FROM grp_settings ".
128 "WHERE obj_id = ".$ilDB->quote($a_id,'integer');
129 $res = $ilDB->query($query);
130 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
131 {
132 return $row->grp_type;
133 }
134 return GRP_TYPE_UNKNOWN;
135 }
136
137 // Setter/Getter
145 public function setInformation($a_information)
146 {
147 $this->information = $a_information;
148 }
149
157 public function getInformation()
158 {
159 return $this->information;
160 }
161
168 public function setGroupType($a_type)
169 {
170 $this->group_type = $a_type;
171 }
172
179 public function getGroupType()
180 {
181 return $this->group_type;
182 }
183
192 {
193 $this->reg_type = $a_type;
194 }
195
202 public function getRegistrationType()
203 {
204 return $this->reg_type;
205 }
206
213 public function isRegistrationEnabled()
214 {
216 }
217
225 public function enableUnlimitedRegistration($a_status)
226 {
227 $this->reg_unlimited = $a_status;
228 }
229
236 public function isRegistrationUnlimited()
237 {
239 }
240
248 public function setRegistrationStart($a_start)
249 {
250 $this->reg_start = $a_start;
251 }
252
259 public function getRegistrationStart()
260 {
261 return $this->reg_start;
262 }
263
264
272 public function setRegistrationEnd($a_end)
273 {
274 $this->reg_end = $a_end;
275 }
276
283 public function getRegistrationEnd()
284 {
285 return $this->reg_end;
286 }
287
294 public function setPassword($a_pass)
295 {
296 $this->reg_password = $a_pass;
297 }
298
305 public function getPassword()
306 {
307 return $this->reg_password;
308 }
309
317 public function enableMembershipLimitation($a_status)
318 {
319 $this->reg_membership_limitation = $a_status;
320 }
321
328 public function isMembershipLimited()
329 {
331 }
332
339 public function setMinMembers($a_max)
340 {
341 $this->reg_min_members = $a_max;
342 }
343
350 public function getMinMembers()
351 {
353 }
354
361 public function setMaxMembers($a_max)
362 {
363 $this->reg_max_members = $a_max;
364 }
365
372 public function getMaxMembers()
373 {
375 }
376
384 public function enableWaitingList($a_status)
385 {
386 $this->waiting_list = $a_status;
387 }
388
396 public function isWaitingListEnabled()
397 {
398 return $this->waiting_list;
399 }
400
401 function setWaitingListAutoFill($a_value)
402 {
403 $this->auto_fill_from_waiting = (bool)$a_value;
404 }
405
407 {
409 }
410
416 function setLatitude($a_latitude)
417 {
418 $this->latitude = $a_latitude;
419 }
420
426 function getLatitude()
427 {
428 return $this->latitude;
429 }
430
436 function setLongitude($a_longitude)
437 {
438 $this->longitude = $a_longitude;
439 }
440
446 function getLongitude()
447 {
448 return $this->longitude;
449 }
450
456 function setLocationZoom($a_locationzoom)
457 {
458 $this->locationzoom = $a_locationzoom;
459 }
460
467 {
468 return $this->locationzoom;
469 }
470
476 function setEnableGroupMap($a_enablemap)
477 {
478 $this->enablemap = $a_enablemap;
479 }
480
485 public function getEnableMap()
486 {
487 return $this->getEnableGroupMap();
488 }
489
496 {
497 return (bool) $this->enablemap;
498 }
499
505 {
507 }
508
514 public function setRegistrationAccessCode($a_code)
515 {
516 $this->reg_access_code = $a_code;
517 }
518
524 {
525 return (bool) $this->reg_access_code_enabled;
526 }
527
533 public function enableRegistrationAccessCode($a_status)
534 {
535 $this->reg_access_code_enabled = $a_status;
536 }
537
544 {
545 $this->mail_members = $a_type;
546 }
547
552 public function getMailToMembersType()
553 {
554 return $this->mail_members;
555 }
556
557 function setCancellationEnd(ilDate $a_value = null)
558 {
559 $this->leave_end = $a_value;
560 }
561
563 {
564 return $this->leave_end;
565 }
566
567 function setShowMembers($a_status)
568 {
569 $this->show_members = $a_status;
570 }
571 function getShowMembers()
572 {
573 return $this->show_members;
574 }
575
582 public function validate()
583 {
584 global $ilErr;
585
586 if(!$this->getTitle())
587 {
588 $this->title = '';
589 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
590 }
591 if($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword()))
592 {
593 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
594 }
595 /*
596 if(ilDateTime::_before($this->getRegistrationEnd(),$this->getRegistrationStart()))
597 {
598 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
599 }
600 */
601 if($this->isMembershipLimited())
602 {
603 if($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0)
604 {
605 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
606 }
607 if($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled())
608 {
609 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
610 }
611 if($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers())
612 {
613 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
614 }
615 }
616 if(
617 ($this->getRegistrationStart() && !$this->getRegistrationEnd()) ||
618 (!$this->getRegistrationStart() && $this->getRegistrationEnd()) ||
619 $this->getRegistrationEnd() <= $this->getRegistrationStart()
620 )
621 {
622 $ilErr->appendMessage($this->lng->txt((self::ERR_WRONG_REGISTRATION_LIMITED)));
623 }
624
625 return strlen($ilErr->getMessage()) == 0;
626 }
627
628
629
630
634 function create()
635 {
636 global $ilDB,$ilAppEventHandler;
637
638 if(!parent::create())
639 {
640 return false;
641 }
642
643 $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled,".
644 "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit,".
645 "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type,".
646 "leave_end,registration_min_members,auto_wait) ".
647 "VALUES(".
648 $ilDB->quote($this->getId() ,'integer').", ".
649 $ilDB->quote($this->getInformation() ,'text').", ".
650 $ilDB->quote((int) $this->getGroupType() ,'integer').", ".
651 $ilDB->quote($this->getRegistrationType() ,'integer').", ".
652 $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0) ,'integer').", ".
653 $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0) ,'integer').", ".
654 $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME,'') : null,'timestamp').", ".
655 $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') : null,'timestamp').", ".
656 $ilDB->quote($this->getPassword() ,'text').", ".
657 $ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
658 $ilDB->quote($this->getMaxMembers() ,'integer').", ".
659 $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
660 $ilDB->quote($this->getLatitude() ,'text').", ".
661 $ilDB->quote($this->getLongitude() ,'text').", ".
662 $ilDB->quote($this->getLocationZoom() ,'integer').", ".
663 $ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
664 $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
665 $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
666 $ilDB->quote($this->getViewMode(),'integer').', '.
667 $ilDB->quote($this->getMailToMembersType(),'integer').', '.
668 $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer').', '.
669 $ilDB->quote($this->getMinMembers(),'integer').', '.
670 $ilDB->quote($this->hasWaitingListAutoFill(),'integer').' '.
671 ")";
672 $res = $ilDB->manipulate($query);
673
674 $ilAppEventHandler->raise('Modules/Group',
675 'create',
676 array('object' => $this,
677 'obj_id' => $this->getId(),
678 'appointments' => $this->prepareAppointments('create')));
679
680 return $this->getId();
681 }
682
686 function update()
687 {
688 global $ilDB,$ilAppEventHandler;
689
690 if (!parent::update())
691 {
692 return false;
693 }
694
695 $query = "UPDATE grp_settings ".
696 "SET information = ".$ilDB->quote($this->getInformation() ,'text').", ".
697 "grp_type = ".$ilDB->quote((int) $this->getGroupType() ,'integer').", ".
698 "registration_type = ".$ilDB->quote($this->getRegistrationType() ,'integer').", ".
699 "registration_enabled = ".$ilDB->quote($this->isRegistrationEnabled() ? 1 : 0 ,'integer').", ".
700 "registration_unlimited = ".$ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0 ,'integer').", ".
701 "registration_start = ".$ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME,'') : null,'timestamp').", ".
702 "registration_end = ".$ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') : null,'timestamp').", ".
703 "registration_password = ".$ilDB->quote($this->getPassword() ,'text').", ".
704// "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
705 "registration_mem_limit = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
706 "registration_max_members = ".$ilDB->quote($this->getMaxMembers() ,'integer').", ".
707 "waiting_list = ".$ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
708 "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
709 "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
710 "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
711 "enablemap = ".$ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
712 'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
713 'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
714 'view_mode = '.$ilDB->quote($this->getViewMode(),'integer').', '.
715 'mail_members_type = '.$ilDB->quote($this->getMailToMembersType(),'integer').', '.
716 'leave_end = '.$ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer').', '.
717 "registration_min_members = ".$ilDB->quote($this->getMinMembers() ,'integer').", ".
718 "auto_wait = ".$ilDB->quote($this->hasWaitingListAutoFill() ,'integer').", ".
719 "show_members = ".$ilDB->quote((int) $this->getShowMembers() ,'integer')." ".
720 "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
721 $res = $ilDB->manipulate($query);
722
723 $ilAppEventHandler->raise('Modules/Group',
724 'update',
725 array('object' => $this,
726 'obj_id' => $this->getId(),
727 'appointments' => $this->prepareAppointments('update')));
728
729
730 return true;
731 }
732
739 public function delete()
740 {
741 global $ilDB,$ilAppEventHandler;
742
743 // always call parent delete function first!!
744 if (!parent::delete())
745 {
746 return false;
747 }
748
749 $query = "DELETE FROM grp_settings ".
750 "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
751 $res = $ilDB->manipulate($query);
752
753 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
755
756 $ilAppEventHandler->raise('Modules/Group',
757 'delete',
758 array('object' => $this,
759 'obj_id' => $this->getId(),
760 'appointments' => $this->prepareAppointments('delete')));
761
762
763 return true;
764 }
765
766
770 function read()
771 {
772 global $ilDB;
773
774 parent::read();
775
776 $query = "SELECT * FROM grp_settings ".
777 "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
778
779 $res = $ilDB->query($query);
780 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
781 {
782 $this->setInformation($row->information);
783 $this->setGroupType($row->grp_type);
784 $this->setRegistrationType($row->registration_type);
785 $this->enableUnlimitedRegistration($row->registration_unlimited);
786 $this->setRegistrationStart(new ilDateTime($row->registration_start,IL_CAL_DATETIME));
787 $this->setRegistrationEnd(new ilDateTime($row->registration_end,IL_CAL_DATETIME));
788 $this->setPassword($row->registration_password);
789 $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
790 $this->setMaxMembers($row->registration_max_members);
791 $this->enableWaitingList($row->waiting_list);
792 $this->setLatitude($row->latitude);
793 $this->setLongitude($row->longitude);
794 $this->setLocationZoom($row->location_zoom);
795 $this->setEnableGroupMap($row->enablemap);
796 $this->enableRegistrationAccessCode($row->reg_ac_enabled);
797 $this->setRegistrationAccessCode($row->reg_ac);
798 $this->setViewMode($row->view_mode);
799 $this->setMailToMembersType($row->mail_members_type);
800 $this->setCancellationEnd($row->leave_end ? new ilDate($row->leave_end, IL_CAL_UNIX) : null);
801 $this->setMinMembers($row->registration_min_members);
802 $this->setWaitingListAutoFill($row->auto_wait);
803 $this->setShowMembers($row->show_members);
804 }
805 $this->initParticipants();
806
807 // Inherit order type from parent course (if exists)
808 include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
810 }
811
820 public function cloneObject($a_target_id,$a_copy_id = 0, $a_omit_tree = false)
821 {
822 global $ilDB,$ilUser, $ilSetting;
823
824 $new_obj = parent::cloneObject($a_target_id,$a_copy_id, $a_omit_tree);
825 $new_obj->setGroupType($this->getGroupType());
826 $new_obj->initGroupStatus($this->getGroupType() ? $this->getGroupType() : $this->readGroupStatus());
827
828 $this->cloneAutoGeneratedRoles($new_obj);
829
830 $new_obj->setRegistrationType($this->getRegistrationType());
831 $new_obj->setInformation($this->getInformation());
832 $new_obj->setRegistrationStart($this->getRegistrationStart());
833 $new_obj->setRegistrationEnd($this->getRegistrationEnd());
834 $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
835 $new_obj->setPassword($this->getPassword());
836 $new_obj->enableMembershipLimitation($this->isMembershipLimited());
837 $new_obj->setMaxMembers($this->getMaxMembers());
838 $new_obj->enableWaitingList($this->isWaitingListEnabled());
839 $new_obj->setShowMembers($this->getShowMembers());
840
841 // map
842 $new_obj->setLatitude($this->getLatitude());
843 $new_obj->setLongitude($this->getLongitude());
844 $new_obj->setLocationZoom($this->getLocationZoom());
845 $new_obj->setEnableGroupMap($this->getEnableGroupMap());
846 $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
847 include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
848 $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
849
850 $new_obj->setViewMode($this->getViewMode());
851 $new_obj->setMailToMembersType($this->getMailToMembersType());
852
853 $new_obj->setCancellationEnd($this->getCancellationEnd());
854 $new_obj->setMinMembers($this->getMinMembers());
855 $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
856
857 $new_obj->update();
858
859 // #13008 - Group Defined Fields
860 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
861 ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
862
863 ilLoggerFactory::getLogger('grp')->debug('Starting add user');
864
865 // Assign user as admin
866 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
867 $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
868 $part->add($ilUser->getId(),IL_GRP_ADMIN);
869 $part->updateNotification($ilUser->getId(),$ilSetting->get('mail_grp_admin_notification', true));
870
871 // Copy learning progress settings
872 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
873 $obj_settings = new ilLPObjSettings($this->getId());
874 $obj_settings->cloneSettings($new_obj->getId());
875 unset($obj_settings);
876
877 // clone icons
878 $new_obj->saveIcons($this->getBigIconPath(),
879 $this->getSmallIconPath(),
880 $this->getTinyIconPath());
881
882 return $new_obj;
883 }
884
893 public function cloneDependencies($a_target_id,$a_copy_id)
894 {
895 global $tree;
896
897 parent::cloneDependencies($a_target_id,$a_copy_id);
898
899 include_once('Services/Object/classes/class.ilObjectActivation.php');
900 ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
901
902 return true;
903 }
904
912 public function cloneAutoGeneratedRoles($new_obj)
913 {
914 global $rbacadmin,$rbacreview;
915
916 $admin = $this->getDefaultAdminRole();
917 $new_admin = $new_obj->getDefaultAdminRole();
918 if(!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId())
919 {
920 ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_admin');
921 }
922 $rbacadmin->copyRolePermissions($admin,$this->getRefId(),$new_obj->getRefId(),$new_admin,true);
923 ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_admin.');
924
925 $member = $this->getDefaultMemberRole();
926 $new_member = $new_obj->getDefaultMemberRole();
927 if(!$member || !$new_member)
928 {
929 ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_member');
930 }
931 $rbacadmin->copyRolePermissions($member,$this->getRefId(),$new_obj->getRefId(),$new_member,true);
932 ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_member.');
933 }
934
935
941 function join($a_user_id, $a_mem_role="")
942 {
943 global $rbacadmin;
944
945 if (is_array($a_mem_role))
946 {
947 foreach ($a_mem_role as $role)
948 {
949 $rbacadmin->assignUser($role,$a_user_id, false);
950 }
951 }
952 else
953 {
954 $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
955 }
956
957 return true;
958 }
959
964 public function getDefaultMemberRole()
965 {
966 $local_group_Roles = $this->getLocalGroupRoles();
967
968 return $local_group_Roles["il_grp_member_".$this->getRefId()];
969 }
970
975 public function getDefaultAdminRole()
976 {
977 $local_group_Roles = $this->getLocalGroupRoles();
978
979 return $local_group_Roles["il_grp_admin_".$this->getRefId()];
980 }
981
988 function addMember($a_user_id, $a_mem_role)
989 {
990 global $rbacadmin;
991
992 if (isset($a_user_id) && isset($a_mem_role) )
993 {
994 $this->join($a_user_id,$a_mem_role);
995 return true;
996 }
997 else
998 {
999 $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
1000 return false;
1001 }
1002 }
1003
1004
1011 function leaveGroup()
1012 {
1013 global $rbacadmin, $rbacreview;
1014
1015 $member_ids = $this->getGroupMemberIds();
1016
1017 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
1018 {
1019 return 2;
1020 }
1021 else
1022 {
1023 if (!$this->isAdmin($this->ilias->account->getId()))
1024 {
1025 $this->leave($this->ilias->account->getId());
1026 $member = new ilObjUser($this->ilias->account->getId());
1027 $member->dropDesktopItem($this->getRefId(), "grp");
1028
1029 return 0;
1030 }
1031 else if (count($this->getGroupAdminIds()) == 1)
1032 {
1033 return 1;
1034 }
1035 }
1036 }
1037
1042 function leave($a_user_id)
1043 {
1044 global $rbacadmin;
1045
1046 $arr_groupRoles = $this->getMemberRoles($a_user_id);
1047
1048 if (is_array($arr_groupRoles))
1049 {
1050 foreach ($arr_groupRoles as $groupRole)
1051 {
1052 $rbacadmin->deassignUser($groupRole, $a_user_id);
1053 }
1054 }
1055 else
1056 {
1057 $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
1058 }
1059
1060 return true;
1061 }
1062
1070 {
1071 global $rbacadmin, $rbacreview;
1072
1073 $usr_arr= array();
1074
1075 $rol = $this->getLocalGroupRoles();
1076
1077 foreach ($rol as $value)
1078 {
1079 foreach ($rbacreview->assignedUsers($value) as $member_id)
1080 {
1081 array_push($usr_arr,$member_id);
1082 }
1083 }
1084
1085 $mem_arr = array_unique($usr_arr);
1086
1087 return $mem_arr ? $mem_arr : array();
1088 }
1089
1097 function getGroupMemberData($a_mem_ids, $active = 1)
1098 {
1099 global $rbacadmin, $rbacreview, $ilBench, $ilDB;
1100
1101 $usr_arr= array();
1102
1103 $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
1104 "FROM usr_data ".
1105 "WHERE usr_id IN (".implode(',',ilUtil::quoteArray($a_mem_ids)).") ";
1106
1107 if (is_numeric($active) && $active > -1)
1108 $q .= "AND active = '$active'";
1109
1110 $q .= 'ORDER BY lastname,firstname';
1111
1112 $r = $ilDB->query($q);
1113
1114 while($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1115 {
1116 $mem_arr[] = array("id" => $row->usr_id,
1117 "login" => $row->login,
1118 "firstname" => $row->firstname,
1119 "lastname" => $row->lastname,
1120 "last_login" => $row->last_login
1121 );
1122 }
1123
1124 return $mem_arr ? $mem_arr : array();
1125 }
1126
1128 {
1129 return count($this->getGroupMemberIds());
1130 }
1131
1138 function getGroupAdminIds($a_grpId = "")
1139 {
1140 global $rbacreview;
1141
1142 if (!empty($a_grpId))
1143 {
1144 $grp_id = $a_grpId;
1145 }
1146 else
1147 {
1148 $grp_id = $this->getRefId();
1149 }
1150
1151 $usr_arr = array();
1152 $roles = $this->getDefaultGroupRoles($this->getRefId());
1153
1154 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
1155 {
1156 array_push($usr_arr,$member_id);
1157 }
1158
1159 return $usr_arr;
1160 }
1161
1167 function getDefaultGroupRoles($a_grp_id="")
1168 {
1169 global $rbacadmin, $rbacreview;
1170
1171 if (strlen($a_grp_id) > 0)
1172 {
1173 $grp_id = $a_grp_id;
1174 }
1175 else
1176 {
1177 $grp_id = $this->getRefId();
1178 }
1179
1180 $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1181
1182 foreach ($role_arr as $role_id)
1183 {
1184 $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1185
1186 $grp_Member ="il_grp_member_".$grp_id;
1187 $grp_Admin ="il_grp_admin_".$grp_id;
1188
1189 if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1190 {
1191 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1192 }
1193
1194 if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1195 {
1196 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1197 }
1198 }
1199
1200 return $arr_grpDefaultRoles;
1201 }
1202
1209 function getLocalGroupRoles($a_translate = false)
1210 {
1211 global $rbacadmin,$rbacreview;
1212
1213 if (empty($this->local_roles))
1214 {
1215 $this->local_roles = array();
1216 $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1217
1218 foreach ($role_arr as $role_id)
1219 {
1220 if ($rbacreview->isAssignable($role_id,$this->getRefId()) == true)
1221 {
1222 $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1223
1224 if ($a_translate)
1225 {
1226 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1227 }
1228 else
1229 {
1230 $role_name = $role_Obj->getTitle();
1231 }
1232
1233 $this->local_roles[$role_name] = $role_Obj->getId();
1234 }
1235 }
1236 }
1237
1238 return $this->local_roles;
1239 }
1240
1247 {
1248 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1249 $res = $this->ilias->db->query($q);
1251
1252 return $row["obj_id"];
1253 }
1254
1261 {
1262 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1263 $res = $this->ilias->db->query($q);
1265
1266 return $row["obj_id"];
1267 }
1268
1275 public static function lookupGroupStatusTemplateId($a_obj_id)
1276 {
1277 global $ilDB;
1278
1279 $type = self::lookupGroupTye($a_obj_id);
1280 if($type == GRP_TYPE_CLOSED)
1281 {
1282 $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_grp_status_closed','text');
1283 }
1284 else
1285 {
1286 $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_grp_status_open','text');
1287 }
1288 $res = $ilDB->query($query);
1290
1291 return isset($row['obj_id']) ? $row['obj_id'] : 0;
1292 }
1293
1294
1295
1305 public function updateGroupType()
1306 {
1307 global $tree,$rbacreview,$rbacadmin;
1308
1309 $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1310 $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1311
1312 // Delete parent roles with stopped inheritance
1313 foreach($real_parent_roles as $role_id)
1314 {
1315 // Delete local role
1316 $rbacadmin->deleteLocalRole($role_id,$this->getRefId());
1317 }
1318 $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1319 $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1320
1321 switch($this->getGroupType())
1322 {
1323 case GRP_TYPE_PUBLIC:
1325 break;
1326
1327 case GRP_TYPE_CLOSED:
1329 break;
1330 }
1331
1332 $first = true;
1333 foreach($tree->getFilteredSubTree($this->getRefId(),array('grp')) as $subnode)
1334 {
1335 // Read template operations
1336 $template_ops = $rbacreview->getOperationsOfRole($template_id,$subnode['type'], ROLE_FOLDER_ID);
1337
1338 // for all parent roles
1339 foreach($real_parent_roles as $role_id)
1340 {
1341 if($rbacreview->isProtected($parent_roles[$role_id]['parent'],$role_id))
1342 {
1343 continue;
1344 }
1345
1346 $rbacadmin->deleteLocalRole($role_id,$subnode['child']);
1347
1348 // Store current operations
1349 $current_ops = $rbacreview->getOperationsOfRole($role_id,$subnode['type'],$parent_roles[$role_id]['parent']);
1350
1351 // Revoke permissions
1352 $rbacadmin->revokePermission($subnode['child'],$role_id);
1353
1354 // Grant permissions
1355 $granted = array();
1356 foreach($template_ops as $operation)
1357 {
1358 if(in_array($operation,$current_ops))
1359 {
1360 $granted[] = $operation;
1361 }
1362 }
1363 if($granted)
1364 {
1365 $rbacadmin->grantPermission($role_id, $granted,$subnode['child']);
1366 }
1367
1368 if($first)
1369 {
1370 // This is the group itself
1371 $rbacadmin->copyRolePermissionIntersection(
1372 $template_id, ROLE_FOLDER_ID,
1373 $role_id, $parent_roles[$role_id]['parent'],
1374 $subnode["child"],$role_id);
1375 $rbacadmin->assignRoleToFolder($role_id,$subnode['child'],"n");
1376
1377 }
1378 }
1379 $first = false;
1380 }
1381 }
1382
1400 function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1401 {
1402 global $rbacadmin, $rbacreview, $rbacsystem;
1403
1404 //define all relevant roles that rights are needed to be changed
1405 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1406
1407 $real_local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId(),false);
1408 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$real_local_roles);
1409
1410 //group status open (aka public) or group status closed
1411 if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED)
1412 {
1413 if ($a_grpStatus == GRP_TYPE_PUBLIC)
1414 {
1416 }
1417 else
1418 {
1420 }
1421 //get defined operations from template
1422 $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1423
1424 foreach ($arr_relevantParentRoleIds as $parentRole)
1425 {
1426 if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1427 {
1428 continue;
1429 }
1430
1431 $granted_permissions = array();
1432
1433 // Delete the linked role for the parent role
1434 // (just in case if it already exists).
1435
1436 // Added additional check, since this operation is very dangerous.
1437 // If there is no role folder ALL parent roles are deleted.
1438
1439 // @todo refactor rolf
1440 $rbacadmin->deleteLocalRole($parentRole,$this->getRefId());
1441
1442 // Grant permissions on the group object for
1443 // the parent role. In the foreach loop we
1444 // compute the intersection of the role
1445 // template il_grp_status_open/_closed and the
1446 // permission template of the parent role.
1447 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1448 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1449 foreach ($template_ops as $template_op)
1450 {
1451 if (in_array($template_op,$current_ops))
1452 {
1453 array_push($granted_permissions,$template_op);
1454 }
1455 }
1456 if (!empty($granted_permissions))
1457 {
1458 $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1459 }
1460
1461 // Create a linked role for the parent role and
1462 // initialize it with the intersection of
1463 // il_grp_status_open/_closed and the permission
1464 // template of the parent role
1465
1466 $rbacadmin->copyRolePermissionIntersection(
1467 $template_id, ROLE_FOLDER_ID,
1468 $parentRole, $arr_parentRoles[$parentRole]['parent'],
1469 $this->getRefId(), $parentRole
1470 );
1471 $rbacadmin->assignRoleToFolder($parentRole,$this->getRefId(),"false");
1472 }//END foreach
1473 }
1474 }
1475
1483 public function setGroupStatus($a_status)
1484 {
1485 $this->group_status = $a_status;
1486 }
1487
1495 public function getGroupStatus()
1496 {
1497 return $this->group_status;
1498 }
1499
1506 {
1507 global $rbacsystem,$rbacreview;
1508
1509 $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1510
1511 //get all relevant roles
1512 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1513
1514 //if one global role has no permission to join the group is officially closed !
1515 foreach ($arr_globalRoles as $globalRole)
1516 {
1517 if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
1518 {
1519 return $this->group_status = GRP_TYPE_PUBLIC;
1520 }
1521 }
1522
1523 return $this->group_status = GRP_TYPE_CLOSED;
1524 }
1525
1532 function getMemberRoles($a_user_id)
1533 {
1534 global $rbacadmin, $rbacreview,$ilBench;
1535
1536 $ilBench->start("Group", "getMemberRoles");
1537
1538 $arr_assignedRoles = array();
1539
1540 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
1541
1542 $ilBench->stop("Group", "getMemberRoles");
1543
1544 return $arr_assignedRoles;
1545 }
1546
1553 function isAdmin($a_userId)
1554 {
1555 global $rbacreview;
1556
1557 $grp_Roles = $this->getDefaultGroupRoles();
1558
1559 if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
1560 {
1561 return true;
1562 }
1563 else
1564 {
1565 return false;
1566 }
1567 }
1574 {
1575 include_once './Services/AccessControl/classes/class.ilObjRole.php';
1577 'il_grp_admin_'.$this->getRefId(),
1578 "Groupadmin group obj_no.".$this->getId(),
1579 'il_grp_admin',
1580 $this->getRefId()
1581 );
1582 $this->m_roleAdminId = $role->getId();
1583
1585 'il_grp_member_'.$this->getRefId(),
1586 "Groupmember of group obj_no.".$this->getId(),
1587 'il_grp_member',
1588 $this->getRefId()
1589 );
1590 $this->m_roleMemberId = $role->getId();
1591
1592 return array();
1593 }
1594
1604 public function setParentRolePermissions($a_parent_ref)
1605 {
1606 $rbacadmin = $GLOBALS['DIC']->rbac()->admin();
1607 $rbacreview = $GLOBALS['DIC']->rbac()->review();
1608
1609 $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1610 foreach((array) $parent_roles as $parent_role)
1611 {
1612 if($parent_role['parent'] == $this->getRefId())
1613 {
1614 continue;
1615 }
1616 if($rbacreview->isProtected($parent_role['parent'], $parent_role['rol_id']))
1617 {
1618 $operations = $rbacreview->getOperationsOfRole(
1619 $parent_role['obj_id'],
1620 $this->getType(),
1621 $parent_role['parent']
1622 );
1623 $rbacadmin->grantPermission(
1624 $parent_role['obj_id'],
1625 $operations,
1626 $this->getRefId()
1627 );
1628 continue;
1629 }
1630
1631 $rbacadmin->initIntersectionPermissions(
1632 $this->getRefId(),
1633 $parent_role['obj_id'],
1634 $parent_role['parent'],
1636 ROLE_FOLDER_ID
1637 );
1638 }
1639 }
1640
1641
1646 public function applyDidacticTemplate($a_tpl_id)
1647 {
1648 parent::applyDidacticTemplate($a_tpl_id);
1649
1650 if(!$a_tpl_id)
1651 {
1652 // init default type
1653 $this->setParentRolePermissions($this->getRefId());
1654 }
1655
1656 }
1657
1658
1659 public static function _lookupIdByTitle($a_title)
1660 {
1661 global $ilDB;
1662
1663 $query = "SELECT * FROM object_data WHERE title = ".
1664 $ilDB->quote($a_title ,'text')." AND type = 'grp'";
1665 $res = $ilDB->query($query);
1666 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1667 {
1668 return $row->obj_id;
1669 }
1670 return 0;
1671 }
1672
1673
1674 function _isMember($a_user_id,$a_ref_id,$a_field = '')
1675 {
1676 global $rbacreview,$ilObjDataCache,$ilDB;
1677
1678 $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
1679 $user_roles = $rbacreview->assignedRoles($a_user_id);
1680
1681 // Used for membership limitations -> check membership by given field
1682 if($a_field)
1683 {
1684 include_once './Services/User/classes/class.ilObjUser.php';
1685
1686 $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
1687 switch($a_field)
1688 {
1689 case 'login':
1690 $and = "AND login = '".$tmp_user->getLogin()."' ";
1691 break;
1692 case 'email':
1693 $and = "AND email = '".$tmp_user->getEmail()."' ";
1694 break;
1695 case 'matriculation':
1696 $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
1697 break;
1698
1699 default:
1700 $and = "AND usr_id = '".$a_user_id."'";
1701 break;
1702 }
1703 if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
1704 {
1705 return false;
1706 }
1707 $query = "SELECT * FROM usr_data as ud ".
1708 "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
1709 $and;
1710 $res = $ilDB->query($query);
1711
1712 return $res->numRows() ? true : false;
1713 }
1714
1715 if (!array_intersect($local_roles,$user_roles))
1716 {
1717 return false;
1718 }
1719
1720 return true;
1721 }
1722
1723 function _getMembers($a_obj_id)
1724 {
1725 global $rbacreview;
1726
1727 // get reference
1728 $ref_ids = ilObject::_getAllReferences($a_obj_id);
1729 $ref_id = current($ref_ids);
1730
1731 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
1732
1733 $users = array();
1734 foreach($local_roles as $role_id)
1735 {
1736 $users = array_merge($users,$rbacreview->assignedUsers($role_id));
1737 }
1738
1739 return array_unique($users);
1740 }
1741
1748 public function getViewMode($a_translate_inherit = true)
1749 {
1750 $view = (int) $this->view_mode;
1751
1752 if(!$view)
1753 {
1755 }
1756 return $view;
1757 }
1758
1763 public function setViewMode($a_view_mode)
1764 {
1765 $this->view_mode = $a_view_mode;
1766 }
1767
1772 public static function lookupViewMode($a_obj_id)
1773 {
1774 global $ilDB;
1775
1776 $query = 'SELECT view_mode FROM grp_settings '.
1777 'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1778 $res = $ilDB->query($query);
1779
1780 $view_mode = NULL;
1781 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1782 {
1783 $view_mode = $row->view_mode;
1784 }
1785 return self::translateViewMode($a_obj_id,$view_mode);
1786 }
1787
1795 public static function translateViewMode($a_obj_id,$a_view_mode,$a_ref_id = null)
1796 {
1797 global $tree;
1798
1799 if(!$a_view_mode)
1800 {
1801 $a_view_mode = ilContainer::VIEW_DEFAULT;
1802 }
1803
1804 // view mode is inherit => check for parent course
1805 if($a_view_mode == ilContainer::VIEW_INHERIT)
1806 {
1807 if(!$a_ref_id)
1808 {
1809 $ref = ilObject::_getAllReferences($a_obj_id);
1810 $a_ref_id = end($ref);
1811 }
1812
1813 $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1814 if(!$crs_ref)
1815 {
1817 }
1818
1819 include_once './Modules/Course/classes/class.ilObjCourse.php';
1821
1822 // validate course view mode
1823 if(!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1825 {
1827 }
1828
1829 return $view_mode;
1830 }
1831
1832 return $a_view_mode;
1833 }
1834
1839 function addAdditionalSubItemInformation(&$a_item_data)
1840 {
1841 include_once './Services/Object/classes/class.ilObjectActivation.php';
1843 }
1844
1845 function getMessage()
1846 {
1847 return $this->message;
1848 }
1849 function setMessage($a_message)
1850 {
1851 $this->message = $a_message;
1852 }
1853 function appendMessage($a_message)
1854 {
1855 if($this->getMessage())
1856 {
1857 $this->message .= "<br /> ";
1858 }
1859 $this->message .= $a_message;
1860 }
1861
1869 protected function prepareAppointments($a_mode = 'create')
1870 {
1871 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1872
1873 switch($a_mode)
1874 {
1875 case 'create':
1876 case 'update':
1877 if($this->isRegistrationUnlimited())
1878 {
1879 return array();
1880 }
1881 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1882 $app->setTitle($this->getTitle());
1883 $app->setSubtitle('grp_cal_reg_start');
1884 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1885 $app->setDescription($this->getLongDescription());
1886 $app->setStart($this->getRegistrationStart());
1887 $apps[] = $app;
1888
1889 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1890 $app->setTitle($this->getTitle());
1891 $app->setSubtitle('grp_cal_reg_end');
1892 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1893 $app->setDescription($this->getLongDescription());
1894 $app->setStart($this->getRegistrationEnd());
1895 $apps[] = $app;
1896
1897 return $apps;
1898
1899 case 'delete':
1900 // Nothing to do: The category and all assigned appointments will be deleted.
1901 return array();
1902 }
1903 }
1904
1912 protected function initParticipants()
1913 {
1914 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1915 $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1916 }
1917
1923 public function getMembersObject()
1924 {
1925 // #17886
1926 if(!$this->members_obj instanceof ilGroupParticipants)
1927 {
1928 $this->initParticipants();
1929 }
1930 return $this->members_obj;
1931 }
1932
1937 public static function lookupObjectsByCode($a_code)
1938 {
1939 global $ilDB;
1940
1941 $query = "SELECT obj_id FROM grp_settings ".
1942 "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1943 "AND reg_ac = ".$ilDB->quote($a_code,'text');
1944 $res = $ilDB->query($query);
1945
1946 $obj_ids = array();
1947 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1948 {
1949 $obj_ids[] = $row->obj_id;
1950 }
1951 return $obj_ids;
1952 }
1953
1960 public function register($a_user_id,$a_role = IL_GRP_MEMBER, $a_force_registration = false)
1961 {
1962 include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1963 include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1965
1966 if($part->isAssigned($a_user_id))
1967 {
1968 return true;
1969 }
1970
1971 if(!$a_force_registration)
1972 {
1973 // Availability
1974 if(!$this->isRegistrationEnabled())
1975 {
1976 include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1977
1979 {
1980 throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
1981 ', group subscription is deactivated.', ilMembershipRegistrationException::REGISTRATION_CODE_DISABLED);
1982 }
1983 }
1984
1985 // Time Limitation
1986 if(!$this->isRegistrationUnlimited())
1987 {
1988 $start = $this->getRegistrationStart();
1989 $end = $this->getRegistrationEnd();
1990 $time = new ilDateTime(time(),IL_CAL_UNIX);
1991
1992 if( !(ilDateTime::_after($time, $start) and ilDateTime::_before($time,$end)) )
1993 {
1994 throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
1995 ', group is out of registration time.', ilMembershipRegistrationException::OUT_OF_REGISTRATION_PERIOD);
1996 }
1997 }
1998
1999 // Max members
2000 if($this->isMembershipLimited())
2001 {
2002 $free = max(0,$this->getMaxMembers() - $part->getCountMembers());
2003 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2004 $waiting_list = new ilGroupWaitingList($this->getId());
2005 if($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
2006 {
2007 $this->lng->loadLanguageModule("grp");
2008 $waiting_list->addToList($a_user_id);
2009
2010 $info = sprintf($this->lng->txt('grp_added_to_list'),
2011 $this->getTitle(),
2012 $waiting_list->getPosition($a_user_id));
2013
2014 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2015 include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
2016 $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
2017 $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER,$a_user_id);
2018
2020 }
2021
2022 if(!$free or $waiting_list->getCountUsers())
2023 {
2024 throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2025 ', membership is limited.', ilMembershipRegistrationException::OBJECT_IS_FULL);
2026 }
2027 }
2028 }
2029
2030 $part->add($a_user_id,$a_role);
2031 $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2032 return true;
2033 }
2034
2035 public function handleAutoFill()
2036 {
2037 if($this->isWaitingListEnabled() &&
2038 $this->hasWaitingListAutoFill())
2039 {
2040 $max = $this->getMaxMembers();
2042 if($max > $now)
2043 {
2044 // see assignFromWaitingListObject()
2045 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2046 $waiting_list = new ilGroupWaitingList($this->getId());
2047
2048 foreach($waiting_list->getUserIds() as $user_id)
2049 {
2050 if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id,false))
2051 {
2052 continue;
2053 }
2054 if($this->getMembersObject()->isAssigned($user_id))
2055 {
2056 continue;
2057 }
2058 $this->getMembersObject()->add($user_id,IL_GRP_MEMBER); // #18213
2059 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
2061 $waiting_list->removeFromList($user_id);
2062
2063 $now++;
2064 if($now >= $max)
2065 {
2066 break;
2067 }
2068 }
2069 }
2070 }
2071 }
2072
2073 public static function mayLeave($a_group_id, $a_user_id = null, &$a_date = null)
2074 {
2075 global $ilUser, $ilDB;
2076
2077 if(!$a_user_id)
2078 {
2079 $a_user_id = $ilUser->getId();
2080 }
2081
2082 $set = $ilDB->query("SELECT leave_end".
2083 " FROM grp_settings".
2084 " WHERE obj_id = ".$ilDB->quote($a_group_id, "integer"));
2085 $row = $ilDB->fetchAssoc($set);
2086 if($row && $row["leave_end"])
2087 {
2088 // timestamp to date
2089 $limit = date("Ymd", $row["leave_end"]);
2090 if($limit < date("Ymd"))
2091 {
2092 $a_date = new ilDate(date("Y-m-d", $row["leave_end"]), IL_CAL_DATE);
2093 return false;
2094 }
2095 }
2096 return true;
2097 }
2098
2104 public static function findGroupsWithNotEnoughMembers()
2105 {
2106 $ilDB = $GLOBALS['DIC']->database();
2107 $tree = $GLOBALS['DIC']->repositoryTree();
2108
2109 $res = array();
2110
2111 $now = date("Y-m-d H:i:s");
2112
2113 include_once "Modules/Group/classes/class.ilGroupParticipants.php";
2114
2115 $set = $ilDB->query("SELECT obj_id, registration_min_members".
2116 " FROM grp_settings".
2117 " WHERE registration_min_members > ".$ilDB->quote(0, "integer").
2118 " AND registration_mem_limit = ".$ilDB->quote(1, "integer"). // #17206
2119 " AND ((leave_end IS NOT NULL".
2120 " AND leave_end < ".$ilDB->quote($now, "text").")".
2121 " OR (leave_end IS NULL".
2122 " AND registration_end IS NOT NULL".
2123 " AND registration_end < ".$ilDB->quote($now, "text")."))"
2124 // :TODO: there is no group start ?!
2125 /* " AND (grp_start IS NULL OR grp_start > ".$ilDB->quote($now, "integer").")" */);
2126 while($row = $ilDB->fetchAssoc($set))
2127 {
2128 $refs = ilObject::_getAllReferences($row['obj_id']);
2129 $ref = end($refs);
2130
2131 if($tree->isDeleted($ref))
2132 {
2133 continue;
2134 }
2135
2136 $part = new ilGroupParticipants($row["obj_id"]);
2137 $reci = $part->getNotificationRecipients();
2138 if(sizeof($reci))
2139 {
2140 $missing = (int)$row["registration_min_members"]-$part->getCountMembers();
2141 if($missing > 0)
2142 {
2143 $res[$row["obj_id"]] = array($missing, $reci);
2144 }
2145 }
2146 }
2147
2148 return $res;
2149 }
2150
2151} //END class.ilObjGroup
2152?>
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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_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.
getBigIconPath()
Get path for big icon.
setOrderType($a_value)
getSmallIconPath()
Get path for small icon.
getViewMode()
Get container view mode.
getTinyIconPath()
Get path for tiny icon.
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 _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.
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)
updateGroupType()
Change group type.
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
getRegistrationType()
get registration type
setMaxMembers($a_max)
set max members
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)
static mayLeave($a_group_id, $a_user_id=null, &$a_date=null)
prepareAppointments($a_mode='create')
Prepare calendar appointments.
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.
$r
Definition: example_031.php:79
$info
Definition: example_052.php:80
$template_id
Definition: example_062.php:89
$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.
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
global $ilErr
Definition: raiseError.php:16
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93