ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
6 require_once "./Services/Container/classes/class.ilContainer.php";
7 include_once('./Services/Calendar/classes/class.ilDateTime.php');
8 include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
9 
10 define('GRP_REGISTRATION_DEACTIVATED',-1);
11 define('GRP_REGISTRATION_DIRECT',0);
12 define('GRP_REGISTRATION_REQUEST',1);
13 define('GRP_REGISTRATION_PASSWORD',2);
14 
15 define('GRP_REGISTRATION_LIMITED',1);
16 define('GRP_REGISTRATION_UNLIMITED',2);
17 
18 define('GRP_TYPE_UNKNOWN',0);
19 define('GRP_TYPE_CLOSED',1);
20 define('GRP_TYPE_OPEN',2);
21 define('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 
47  const MAIL_ALLOWED_ALL = 1;
49 
50  protected $information;
51  protected $group_type = null;
53  protected $reg_enabled = true;
54  protected $reg_unlimited = true;
55  protected $reg_start = null;
56  protected $reg_end = null;
57  protected $reg_password = '';
58  protected $reg_membership_limitation = false;
59  protected $reg_max_members = 0;
60  protected $waiting_list = false;
61 
62 
63  // Map
64  private $latitude = '';
65  private $longitude = '';
66  private $locationzoom = 0;
67  private $enablemap = 0;
68 
69  private $reg_access_code = '';
70  private $reg_access_code_enabled = false;
71 
72  private $view_mode = NULL;
73 
75 
76 
77  public $members_obj;
78 
79 
83  var $file_obj = null;
84 
86 
88 
90 
97  public function __construct($a_id = 0,$a_call_by_reference = true)
98  {
99  global $tree;
100 
101  $this->tree =& $tree;
102 
103  $this->type = "grp";
104  $this->ilObject($a_id,$a_call_by_reference);
105  $this->setRegisterMode(true); // ???
106  }
107 
113  public static function lookupGroupTye($a_id)
114  {
115  global $ilDB;
116 
117  $query = "SELECT grp_type FROM grp_settings ".
118  "WHERE obj_id = ".$ilDB->quote($a_id,'integer');
119  $res = $ilDB->query($query);
120  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
121  {
122  return $row->grp_type;
123  }
124  return GRP_TYPE_UNKNOWN;
125  }
126 
127  // Setter/Getter
135  public function setInformation($a_information)
136  {
137  $this->information = $a_information;
138  }
139 
147  public function getInformation()
148  {
149  return $this->information;
150  }
151 
158  public function setGroupType($a_type)
159  {
160  $this->group_type = $a_type;
161  }
162 
169  public function getGroupType()
170  {
171  return $this->group_type;
172  }
173 
181  public function isGroupTypeModified($a_old_type)
182  {
183  if($a_old_type == GRP_TYPE_UNKNOWN)
184  {
185  $group_type = $this->readGroupStatus();
186  }
187  else
188  {
189  $group_type = $a_old_type;
190  }
191  return $group_type != $this->getGroupType();
192  }
193 
201  public function setRegistrationType($a_type)
202  {
203  $this->reg_type = $a_type;
204  }
205 
212  public function getRegistrationType()
213  {
214  return $this->reg_type;
215  }
216 
223  public function isRegistrationEnabled()
224  {
226  }
227 
235  public function enableUnlimitedRegistration($a_status)
236  {
237  $this->reg_unlimited = $a_status;
238  }
239 
246  public function isRegistrationUnlimited()
247  {
248  return $this->reg_unlimited;
249  }
250 
258  public function setRegistrationStart($a_start)
259  {
260  $this->reg_start = $a_start;
261  }
262 
269  public function getRegistrationStart()
270  {
271  return $this->reg_start ? $this->reg_start : $this->reg_start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
272  }
273 
274 
282  public function setRegistrationEnd($a_end)
283  {
284  $this->reg_end = $a_end;
285  }
286 
293  public function getRegistrationEnd()
294  {
295  return $this->reg_end ? $this->reg_end : $this->reg_end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
296  }
297 
304  public function setPassword($a_pass)
305  {
306  $this->reg_password = $a_pass;
307  }
308 
315  public function getPassword()
316  {
317  return $this->reg_password;
318  }
319 
327  public function enableMembershipLimitation($a_status)
328  {
329  $this->reg_membership_limitation = $a_status;
330  }
331 
338  public function isMembershipLimited()
339  {
340  return (bool) $this->reg_membership_limitation;
341  }
342 
349  public function setMaxMembers($a_max)
350  {
351  $this->reg_max_members = $a_max;
352  }
353 
360  public function getMaxMembers()
361  {
362  return $this->reg_max_members;
363  }
364 
372  public function enableWaitingList($a_status)
373  {
374  $this->waiting_list = $a_status;
375  }
376 
384  public function isWaitingListEnabled()
385  {
386  return $this->waiting_list;
387  }
388 
394  function setLatitude($a_latitude)
395  {
396  $this->latitude = $a_latitude;
397  }
398 
404  function getLatitude()
405  {
406  return $this->latitude;
407  }
408 
414  function setLongitude($a_longitude)
415  {
416  $this->longitude = $a_longitude;
417  }
418 
424  function getLongitude()
425  {
426  return $this->longitude;
427  }
428 
434  function setLocationZoom($a_locationzoom)
435  {
436  $this->locationzoom = $a_locationzoom;
437  }
438 
444  function getLocationZoom()
445  {
446  return $this->locationzoom;
447  }
448 
454  function setEnableGroupMap($a_enablemap)
455  {
456  $this->enablemap = $a_enablemap;
457  }
458 
464  function getEnableGroupMap()
465  {
466  return (bool) $this->enablemap;
467  }
468 
473  public function getRegistrationAccessCode()
474  {
475  return $this->reg_access_code;
476  }
477 
483  public function setRegistrationAccessCode($a_code)
484  {
485  $this->reg_access_code = $a_code;
486  }
487 
493  {
494  return (bool) $this->reg_access_code_enabled;
495  }
496 
502  public function enableRegistrationAccessCode($a_status)
503  {
504  $this->reg_access_code_enabled = $a_status;
505  }
506 
512  public function setMailToMembersType($a_type)
513  {
514  $this->mail_members = $a_type;
515  }
516 
521  public function getMailToMembersType()
522  {
523  return $this->mail_members;
524  }
525 
526 
527 
528 
535  public function validate()
536  {
537  global $ilErr;
538 
539  if(!$this->getTitle())
540  {
541  $this->title = '';
542  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
543  }
544  if(!$this->getGroupType())
545  {
546  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_GROUP_TYPE));
547  }
548  if($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword()))
549  {
550  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
551  }
553  {
554  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
555  }
556  if($this->isMembershipLimited() and (!is_numeric($this->getMaxMembers()) or $this->getMaxMembers() <= 0))
557  {
558  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
559  }
560  return strlen($ilErr->getMessage()) == 0;
561  }
562 
563 
564 
565 
569  function create()
570  {
571  global $ilDB,$ilAppEventHandler;
572 
573  if(!parent::create())
574  {
575  return false;
576  }
577 
578  $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled,".
579  "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit,".
580  "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type) ".
581  "VALUES(".
582  $ilDB->quote($this->getId() ,'integer').", ".
583  $ilDB->quote($this->getInformation() ,'text').", ".
584  $ilDB->quote((int) $this->getGroupType() ,'integer').", ".
585  $ilDB->quote($this->getRegistrationType() ,'integer').", ".
586  $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0) ,'integer').", ".
587  $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0) ,'integer').", ".
588  $ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
589  $ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
590  $ilDB->quote($this->getPassword() ,'text').", ".
591  $ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
592  $ilDB->quote($this->getMaxMembers() ,'integer').", ".
593  $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
594  $ilDB->quote($this->getLatitude() ,'text').", ".
595  $ilDB->quote($this->getLongitude() ,'text').", ".
596  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
597  $ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
598  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
599  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
600  $ilDB->quote($this->getViewMode(false),'integer').', '.
601  $ilDB->quote($this->getMailToMembersType(),'integer').' '.
602  ")";
603  $res = $ilDB->manipulate($query);
604 
605  $ilAppEventHandler->raise('Modules/Group',
606  'create',
607  array('object' => $this,
608  'obj_id' => $this->getId(),
609  'appointments' => $this->prepareAppointments('create')));
610 
611  return $this->getId();
612  }
613 
617  function update()
618  {
619  global $ilDB,$ilAppEventHandler;
620 
621  if (!parent::update())
622  {
623  return false;
624  }
625 
626  $query = "UPDATE grp_settings ".
627  "SET information = ".$ilDB->quote($this->getInformation() ,'text').", ".
628  "grp_type = ".$ilDB->quote((int) $this->getGroupType() ,'integer').", ".
629  "registration_type = ".$ilDB->quote($this->getRegistrationType() ,'integer').", ".
630  "registration_enabled = ".$ilDB->quote($this->isRegistrationEnabled() ? 1 : 0 ,'integer').", ".
631  "registration_unlimited = ".$ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0 ,'integer').", ".
632  "registration_start = ".$ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
633  "registration_end = ".$ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
634  "registration_password = ".$ilDB->quote($this->getPassword() ,'text').", ".
635 // "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
636  "registration_mem_limit = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
637  "registration_max_members = ".$ilDB->quote($this->getMaxMembers() ,'integer').", ".
638  "waiting_list = ".$ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
639  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
640  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
641  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
642  "enablemap = ".$ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
643  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
644  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
645  'view_mode = '.$ilDB->quote($this->getViewMode(false),'integer').', '.
646  'mail_members_type = '.$ilDB->quote($this->getMailToMembersType(),'integer').' '.
647  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
648  $res = $ilDB->manipulate($query);
649 
650  $ilAppEventHandler->raise('Modules/Group',
651  'update',
652  array('object' => $this,
653  'obj_id' => $this->getId(),
654  'appointments' => $this->prepareAppointments('update')));
655 
656 
657  return true;
658  }
659 
666  public function delete()
667  {
668  global $ilDB,$ilAppEventHandler;
669 
670  // always call parent delete function first!!
671  if (!parent::delete())
672  {
673  return false;
674  }
675 
676  $query = "DELETE FROM grp_settings ".
677  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
678  $res = $ilDB->manipulate($query);
679 
680  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
682 
683  $ilAppEventHandler->raise('Modules/Group',
684  'delete',
685  array('object' => $this,
686  'obj_id' => $this->getId(),
687  'appointments' => $this->prepareAppointments('delete')));
688 
689 
690  return true;
691  }
692 
693 
697  function read()
698  {
699  global $ilDB;
700 
701  parent::read();
702 
703  $query = "SELECT * FROM grp_settings ".
704  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
705 
706  $res = $ilDB->query($query);
707  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
708  {
709  $this->setInformation($row->information);
710  $this->setGroupType($row->grp_type);
711  $this->setRegistrationType($row->registration_type);
712  $this->enableUnlimitedRegistration($row->registration_unlimited);
713  $this->setRegistrationStart(new ilDateTime($row->registration_start,IL_CAL_DATETIME));
714  $this->setRegistrationEnd(new ilDateTime($row->registration_end,IL_CAL_DATETIME));
715  $this->setPassword($row->registration_password);
716  $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
717  $this->setMaxMembers($row->registration_max_members);
718  $this->enableWaitingList($row->waiting_list);
719  $this->setLatitude($row->latitude);
720  $this->setLongitude($row->longitude);
721  $this->setLocationZoom($row->location_zoom);
722  $this->setEnableGroupMap($row->enablemap);
723  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
724  $this->setRegistrationAccessCode($row->reg_ac);
725  $this->setViewMode($row->view_mode);
726  $this->setMailToMembersType($row->mail_members_type);
727  }
728  $this->initParticipants();
729 
730  // Inherit order type from parent course (if exists)
731  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
733  }
734 
743  public function cloneObject($a_target_id,$a_copy_id = 0)
744  {
745  global $ilDB,$ilUser;
746 
747  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
748  $new_obj->setGroupType($this->getGroupType());
749  $new_obj->initGroupStatus($this->getGroupType() ? $this->getGroupType() : $this->readGroupStatus());
750 
751  $this->cloneAutoGeneratedRoles($new_obj);
752 
753  $new_obj->setRegistrationType($this->getRegistrationType());
754  $new_obj->setInformation($this->getInformation());
755  $new_obj->setRegistrationStart($this->getRegistrationStart());
756  $new_obj->setRegistrationEnd($this->getRegistrationEnd());
757  $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
758  $new_obj->setPassword($this->getPassword());
759  $new_obj->enableMembershipLimitation($this->isMembershipLimited());
760  $new_obj->setMaxMembers($this->getMaxMembers());
761  $new_obj->enableWaitingList($this->isWaitingListEnabled());
762 
763  // map
764  $new_obj->setLatitude($this->getLatitude());
765  $new_obj->setLongitude($this->getLongitude());
766  $new_obj->setLocationZoom($this->getLocationZoom());
767  $new_obj->setEnableGroupMap($this->getEnableGroupMap());
768  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
769  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
770  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
771 
772  $new_obj->setViewMode($this->getViewMode());
773  $new_obj->setMailToMembersType($this->getMailToMembersType());
774 
775  $new_obj->update();
776 
777  // #13008 - Group Defined Fields
778  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
779  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
780 
781  global $ilLog;
782  $ilLog->write(__METHOD__.': Starting add user');
783 
784  // Assign user as admin
785  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
786  $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
787  $part->add($ilUser->getId(),IL_GRP_ADMIN);
788  $part->updateNotification($ilUser->getId(),1);
789 
790  // Copy learning progress settings
791  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
792  $obj_settings = new ilLPObjSettings($this->getId());
793  $obj_settings->cloneSettings($new_obj->getId());
794  unset($obj_settings);
795 
796  // clone icons
797  $new_obj->saveIcons($this->getBigIconPath(),
798  $this->getSmallIconPath(),
799  $this->getTinyIconPath());
800 
801  return $new_obj;
802  }
803 
812  public function cloneDependencies($a_target_id,$a_copy_id)
813  {
814  global $tree;
815 
816  parent::cloneDependencies($a_target_id,$a_copy_id);
817 
818  include_once('Services/Object/classes/class.ilObjectActivation.php');
819  ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
820 
821  return true;
822  }
823 
831  public function cloneAutoGeneratedRoles($new_obj)
832  {
833  global $ilLog,$rbacadmin,$rbacreview;
834 
835  $admin = $this->getDefaultAdminRole();
836  $new_admin = $new_obj->getDefaultAdminRole();
837  if(!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId())
838  {
839  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_admin');
840  }
841  $rbacadmin->copyRolePermissions($admin,$this->getRefId(),$new_obj->getRefId(),$new_admin,true);
842  $ilLog->write(__METHOD__.' : Finished copying of role il_grp_admin.');
843 
844  $member = $this->getDefaultMemberRole();
845  $new_member = $new_obj->getDefaultMemberRole();
846  if(!$member || !$new_member)
847  {
848  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_member');
849  }
850  $rbacadmin->copyRolePermissions($member,$this->getRefId(),$new_obj->getRefId(),$new_member,true);
851  $ilLog->write(__METHOD__.' : Finished copying of role grp_member.');
852  }
853 
854 
860  function join($a_user_id, $a_mem_role="")
861  {
862  global $rbacadmin;
863 
864  if (is_array($a_mem_role))
865  {
866  foreach ($a_mem_role as $role)
867  {
868  $rbacadmin->assignUser($role,$a_user_id, false);
869  }
870  }
871  else
872  {
873  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
874  }
875 
876  return true;
877  }
878 
884  {
885  $local_group_Roles = $this->getLocalGroupRoles();
886 
887  return $local_group_Roles["il_grp_member_".$this->getRefId()];
888  }
889 
895  {
896  $local_group_Roles = $this->getLocalGroupRoles();
897 
898  return $local_group_Roles["il_grp_admin_".$this->getRefId()];
899  }
900 
907  function addMember($a_user_id, $a_mem_role)
908  {
909  global $rbacadmin;
910 
911  if (isset($a_user_id) && isset($a_mem_role) )
912  {
913  $this->join($a_user_id,$a_mem_role);
914  return true;
915  }
916  else
917  {
918  $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
919  return false;
920  }
921  }
922 
923 
930  function leaveGroup()
931  {
932  global $rbacadmin, $rbacreview;
933 
934  $member_ids = $this->getGroupMemberIds();
935 
936  if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
937  {
938  return 2;
939  }
940  else
941  {
942  if (!$this->isAdmin($this->ilias->account->getId()))
943  {
944  $this->leave($this->ilias->account->getId());
945  $member = new ilObjUser($this->ilias->account->getId());
946  $member->dropDesktopItem($this->getRefId(), "grp");
947 
948  return 0;
949  }
950  else if (count($this->getGroupAdminIds()) == 1)
951  {
952  return 1;
953  }
954  }
955  }
956 
961  function leave($a_user_id)
962  {
963  global $rbacadmin;
964 
965  $arr_groupRoles = $this->getMemberRoles($a_user_id);
966 
967  if (is_array($arr_groupRoles))
968  {
969  foreach ($arr_groupRoles as $groupRole)
970  {
971  $rbacadmin->deassignUser($groupRole, $a_user_id);
972  }
973  }
974  else
975  {
976  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
977  }
978 
979  return true;
980  }
981 
988  function getGroupMemberIds()
989  {
990  global $rbacadmin, $rbacreview;
991 
992  $usr_arr= array();
993 
994  $rol = $this->getLocalGroupRoles();
995 
996  foreach ($rol as $value)
997  {
998  foreach ($rbacreview->assignedUsers($value) as $member_id)
999  {
1000  array_push($usr_arr,$member_id);
1001  }
1002  }
1003 
1004  $mem_arr = array_unique($usr_arr);
1005 
1006  return $mem_arr ? $mem_arr : array();
1007  }
1008 
1016  function getGroupMemberData($a_mem_ids, $active = 1)
1017  {
1018  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
1019 
1020  $usr_arr= array();
1021 
1022  $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
1023  "FROM usr_data ".
1024  "WHERE usr_id IN (".implode(',',ilUtil::quoteArray($a_mem_ids)).") ";
1025 
1026  if (is_numeric($active) && $active > -1)
1027  $q .= "AND active = '$active'";
1028 
1029  $q .= 'ORDER BY lastname,firstname';
1030 
1031  $r = $ilDB->query($q);
1032 
1033  while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
1034  {
1035  $mem_arr[] = array("id" => $row->usr_id,
1036  "login" => $row->login,
1037  "firstname" => $row->firstname,
1038  "lastname" => $row->lastname,
1039  "last_login" => $row->last_login
1040  );
1041  }
1042 
1043  return $mem_arr ? $mem_arr : array();
1044  }
1045 
1046  function getCountMembers()
1047  {
1048  return count($this->getGroupMemberIds());
1049  }
1050 
1057  function getGroupAdminIds($a_grpId = "")
1058  {
1059  global $rbacreview;
1060 
1061  if (!empty($a_grpId))
1062  {
1063  $grp_id = $a_grpId;
1064  }
1065  else
1066  {
1067  $grp_id = $this->getRefId();
1068  }
1069 
1070  $usr_arr = array();
1071  $roles = $this->getDefaultGroupRoles($this->getRefId());
1072 
1073  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
1074  {
1075  array_push($usr_arr,$member_id);
1076  }
1077 
1078  return $usr_arr;
1079  }
1080 
1086  function getDefaultGroupRoles($a_grp_id="")
1087  {
1088  global $rbacadmin, $rbacreview;
1089 
1090  if (strlen($a_grp_id) > 0)
1091  {
1092  $grp_id = $a_grp_id;
1093  }
1094  else
1095  {
1096  $grp_id = $this->getRefId();
1097  }
1098 
1099  $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1100 
1101  foreach ($role_arr as $role_id)
1102  {
1103  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1104 
1105  $grp_Member ="il_grp_member_".$grp_id;
1106  $grp_Admin ="il_grp_admin_".$grp_id;
1107 
1108  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1109  {
1110  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1111  }
1112 
1113  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1114  {
1115  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1116  }
1117  }
1118 
1119  return $arr_grpDefaultRoles;
1120  }
1121 
1128  function getLocalGroupRoles($a_translate = false)
1129  {
1130  global $rbacadmin,$rbacreview;
1131 
1132  if (empty($this->local_roles))
1133  {
1134  $this->local_roles = array();
1135  $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1136 
1137  foreach ($role_arr as $role_id)
1138  {
1139  if ($rbacreview->isAssignable($role_id,$this->getRefId()) == true)
1140  {
1141  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1142 
1143  if ($a_translate)
1144  {
1145  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1146  }
1147  else
1148  {
1149  $role_name = $role_Obj->getTitle();
1150  }
1151 
1152  $this->local_roles[$role_name] = $role_Obj->getId();
1153  }
1154  }
1155  }
1156 
1157  return $this->local_roles;
1158  }
1159 
1166  {
1167  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1168  $res = $this->ilias->db->query($q);
1169  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1170 
1171  return $row["obj_id"];
1172  }
1173 
1180  {
1181  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1182  $res = $this->ilias->db->query($q);
1183  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1184 
1185  return $row["obj_id"];
1186  }
1187 
1194  public static function lookupGroupStatusTemplateId($a_obj_id)
1195  {
1196  global $ilDB;
1197 
1198  $type = self::lookupGroupTye($a_obj_id);
1199  if($type == GRP_TYPE_CLOSED)
1200  {
1201  $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_grp_status_closed','text');
1202  }
1203  else
1204  {
1205  $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_grp_status_open','text');
1206  }
1207  $res = $ilDB->query($query);
1208  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1209 
1210  return isset($row['obj_id']) ? $row['obj_id'] : 0;
1211  }
1212 
1213 
1214 
1224  public function updateGroupType()
1225  {
1226  global $tree,$rbacreview,$rbacadmin;
1227 
1228  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1229  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1230 
1231  // Delete parent roles with stopped inheritance
1232  foreach($real_parent_roles as $role_id)
1233  {
1234  // Delete local role
1235  $rbacadmin->deleteLocalRole($role_id,$this->getRefId());
1236  }
1237  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1238  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1239 
1240  switch($this->getGroupType())
1241  {
1242  case GRP_TYPE_PUBLIC:
1243  $template_id = $this->getGrpStatusOpenTemplateId();
1244  break;
1245 
1246  case GRP_TYPE_CLOSED:
1247  $template_id = $this->getGrpStatusClosedTemplateId();
1248  break;
1249  }
1250 
1251  $first = true;
1252  foreach($tree->getFilteredSubTree($this->getRefId(),array('grp')) as $subnode)
1253  {
1254  // Read template operations
1255  $template_ops = $rbacreview->getOperationsOfRole($template_id,$subnode['type'], ROLE_FOLDER_ID);
1256 
1257  // for all parent roles
1258  foreach($real_parent_roles as $role_id)
1259  {
1260  if($rbacreview->isProtected($parent_roles[$role_id]['parent'],$role_id))
1261  {
1262  continue;
1263  }
1264 
1265  $rbacadmin->deleteLocalRole($role_id,$subnode['child']);
1266 
1267  // Store current operations
1268  $current_ops = $rbacreview->getOperationsOfRole($role_id,$subnode['type'],$parent_roles[$role_id]['parent']);
1269 
1270  // Revoke permissions
1271  $rbacadmin->revokePermission($subnode['child'],$role_id);
1272 
1273  // Grant permissions
1274  $granted = array();
1275  foreach($template_ops as $operation)
1276  {
1277  if(in_array($operation,$current_ops))
1278  {
1279  $granted[] = $operation;
1280  }
1281  }
1282  if($granted)
1283  {
1284  $rbacadmin->grantPermission($role_id, $granted,$subnode['child']);
1285  }
1286 
1287  if($first)
1288  {
1289  // This is the group itself
1290  $rbacadmin->copyRolePermissionIntersection(
1291  $template_id, ROLE_FOLDER_ID,
1292  $role_id, $parent_roles[$role_id]['parent'],
1293  $subnode["child"],$role_id);
1294  $rbacadmin->assignRoleToFolder($role_id,$subnode['child'],"n");
1295 
1296  }
1297  }
1298  $first = false;
1299  }
1300  }
1301 
1319  function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1320  {
1321  global $rbacadmin, $rbacreview, $rbacsystem;
1322 
1323  //define all relevant roles that rights are needed to be changed
1324  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1325 
1326  $real_local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId(),false);
1327  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$real_local_roles);
1328 
1329  //group status open (aka public) or group status closed
1330  if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED)
1331  {
1332  if ($a_grpStatus == GRP_TYPE_PUBLIC)
1333  {
1334  $template_id = $this->getGrpStatusOpenTemplateId();
1335  }
1336  else
1337  {
1338  $template_id = $this->getGrpStatusClosedTemplateId();
1339  }
1340  //get defined operations from template
1341  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1342 
1343  foreach ($arr_relevantParentRoleIds as $parentRole)
1344  {
1345  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1346  {
1347  continue;
1348  }
1349 
1350  $granted_permissions = array();
1351 
1352  // Delete the linked role for the parent role
1353  // (just in case if it already exists).
1354 
1355  // Added additional check, since this operation is very dangerous.
1356  // If there is no role folder ALL parent roles are deleted.
1357 
1358  // @todo refactor rolf
1359  $rbacadmin->deleteLocalRole($parentRole,$this->getRefId());
1360 
1361  // Grant permissions on the group object for
1362  // the parent role. In the foreach loop we
1363  // compute the intersection of the role
1364  // template il_grp_status_open/_closed and the
1365  // permission template of the parent role.
1366  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1367  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1368  foreach ($template_ops as $template_op)
1369  {
1370  if (in_array($template_op,$current_ops))
1371  {
1372  array_push($granted_permissions,$template_op);
1373  }
1374  }
1375  if (!empty($granted_permissions))
1376  {
1377  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1378  }
1379 
1380  // Create a linked role for the parent role and
1381  // initialize it with the intersection of
1382  // il_grp_status_open/_closed and the permission
1383  // template of the parent role
1384 
1385  $rbacadmin->copyRolePermissionIntersection(
1386  $template_id, ROLE_FOLDER_ID,
1387  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1388  $this->getRefId(), $parentRole
1389  );
1390  $rbacadmin->assignRoleToFolder($parentRole,$this->getRefId(),"false");
1391  }//END foreach
1392  }
1393  }
1394 
1402  public function setGroupStatus($a_status)
1403  {
1404  $this->group_status = $a_status;
1405  }
1406 
1414  public function getGroupStatus()
1415  {
1416  return $this->group_status;
1417  }
1418 
1424  function readGroupStatus()
1425  {
1426  global $rbacsystem,$rbacreview;
1427 
1428  $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1429 
1430  //get all relevant roles
1431  $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1432 
1433  //if one global role has no permission to join the group is officially closed !
1434  foreach ($arr_globalRoles as $globalRole)
1435  {
1436  if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
1437  {
1438  return $this->group_status = GRP_TYPE_PUBLIC;
1439  }
1440  }
1441 
1442  return $this->group_status = GRP_TYPE_CLOSED;
1443  }
1444 
1451  function getMemberRoles($a_user_id)
1452  {
1453  global $rbacadmin, $rbacreview,$ilBench;
1454 
1455  $ilBench->start("Group", "getMemberRoles");
1456 
1457  $arr_assignedRoles = array();
1458 
1459  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
1460 
1461  $ilBench->stop("Group", "getMemberRoles");
1462 
1463  return $arr_assignedRoles;
1464  }
1465 
1472  function isAdmin($a_userId)
1473  {
1474  global $rbacreview;
1475 
1476  $grp_Roles = $this->getDefaultGroupRoles();
1477 
1478  if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
1479  {
1480  return true;
1481  }
1482  else
1483  {
1484  return false;
1485  }
1486  }
1487 
1488 
1489 
1495  function initDefaultRoles()
1496  {
1497  include_once './Services/AccessControl/classes/class.ilObjRole.php';
1499  'il_grp_admin_'.$this->getRefId(),
1500  "Groupadmin group obj_no.".$this->getId(),
1501  'il_grp_admin',
1502  $this->getRefId()
1503  );
1504  $this->m_roleAdminId = $role->getId();
1505 
1507  'il_grp_member_'.$this->getRefId(),
1508  "Groupmember of group obj_no.".$this->getId(),
1509  'il_grp_member',
1510  $this->getRefId()
1511  );
1512  $this->m_roleMemberId = $role->getId();
1513 
1514  return array();
1515  }
1516 
1527  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1528  {
1529  global $tree;
1530 
1531  $parent_id = (int) $tree->getParentId($a_node_id);
1532 
1533  if ($parent_id != 0)
1534  {
1535  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1536  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1537  }
1538 
1539  return true;
1540  }
1541 
1542 
1543  function exportXML()
1544  {
1545  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
1546 
1547  $xml_writer = new ilGroupXMLWriter($this);
1548  $xml_writer->start();
1549 
1550  $xml = $xml_writer->getXML();
1551 
1552  $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
1553 
1554  $this->__initFileObject();
1555 
1556  $this->file_obj->addGroupDirectory();
1557  $this->file_obj->addDirectory($name);
1558  $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
1559  $this->file_obj->zipFile($name,$name.'.zip');
1560  $this->file_obj->deleteDirectory($name);
1561 
1562  return true;
1563  }
1564 
1565  function deleteExportFiles($a_files)
1566  {
1567  $this->__initFileObject();
1568 
1569  foreach($a_files as $file)
1570  {
1571  $this->file_obj->deleteFile($file);
1572  }
1573  return true;
1574  }
1575 
1577  {
1578  $this->__initFileObject();
1579 
1580  if($abs_name = $this->file_obj->getExportFile($file))
1581  {
1582  ilUtil::deliverFile($abs_name,$file);
1583  // Not reached
1584  }
1585  return false;
1586  }
1587 
1596  function _importFromXMLString($xml,$parent_id)
1597  {
1598  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
1599 
1600  $import_parser = new ilGroupXMLParser($xml,$parent_id);
1601 
1602  return $import_parser->startParsing();
1603  }
1604 
1612  function _importFromFile($file,$parent_id)
1613  {
1614  global $lng;
1615 
1616  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1617 
1618  $file_obj = new ilFileDataGroup(null);
1619  $file_obj->addImportDirectory();
1620  $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
1621  $file_obj->unpackImportFile();
1622 
1623  if(!$file_obj->validateImportFile())
1624  {
1625  return false;
1626  }
1627  return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
1628  }
1629 
1630  function _lookupIdByTitle($a_title)
1631  {
1632  global $ilDB;
1633 
1634  $query = "SELECT * FROM object_data WHERE title = ".
1635  $ilDB->quote($a_title ,'text')." AND type = 'grp'";
1636  $res = $ilDB->query($query);
1637  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1638  {
1639  return $row->obj_id;
1640  }
1641  return 0;
1642  }
1643 
1644 
1645  function _isMember($a_user_id,$a_ref_id,$a_field = '')
1646  {
1647  global $rbacreview,$ilObjDataCache,$ilDB;
1648 
1649  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
1650  $user_roles = $rbacreview->assignedRoles($a_user_id);
1651 
1652  // Used for membership limitations -> check membership by given field
1653  if($a_field)
1654  {
1655  include_once './Services/User/classes/class.ilObjUser.php';
1656 
1657  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
1658  switch($a_field)
1659  {
1660  case 'login':
1661  $and = "AND login = '".$tmp_user->getLogin()."' ";
1662  break;
1663  case 'email':
1664  $and = "AND email = '".$tmp_user->getEmail()."' ";
1665  break;
1666  case 'matriculation':
1667  $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
1668  break;
1669 
1670  default:
1671  $and = "AND usr_id = '".$a_user_id."'";
1672  break;
1673  }
1674  if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
1675  {
1676  return false;
1677  }
1678  $query = "SELECT * FROM usr_data as ud ".
1679  "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
1680  $and;
1681  $res = $ilDB->query($query);
1682 
1683  return $res->numRows() ? true : false;
1684  }
1685 
1686  if (!array_intersect($local_roles,$user_roles))
1687  {
1688  return false;
1689  }
1690 
1691  return true;
1692  }
1693 
1694  function _getMembers($a_obj_id)
1695  {
1696  global $rbacreview;
1697 
1698  // get reference
1699  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1700  $ref_id = current($ref_ids);
1701 
1702  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
1703 
1704  $users = array();
1705  foreach($local_roles as $role_id)
1706  {
1707  $users = array_merge($users,$rbacreview->assignedUsers($role_id));
1708  }
1709 
1710  return array_unique($users);
1711  }
1712 
1720  public function getViewMode($a_translate_inherit = true)
1721  {
1722  $view = (int) $this->view_mode;
1723 
1724  if(!$view)
1725  {
1726  $view = ilContainer::VIEW_DEFAULT;
1727  }
1728 
1729  if($a_translate_inherit)
1730  {
1731  $view = self::translateViewMode($this->id, $view, $this->ref_id);
1732  }
1733 
1734  return $view;
1735  }
1736 
1741  public function setViewMode($a_view_mode)
1742  {
1743  $this->view_mode = $a_view_mode;
1744  }
1745 
1750  public static function lookupViewMode($a_obj_id)
1751  {
1752  global $ilDB;
1753 
1754  $query = 'SELECT view_mode FROM grp_settings '.
1755  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1756  $res = $ilDB->query($query);
1757 
1758  $view_mode = NULL;
1759  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1760  {
1761  $view_mode = $row->view_mode;
1762  }
1763  return self::translateViewMode($a_obj_id,$view_mode);
1764  }
1765 
1773  protected static function translateViewMode($a_obj_id,$a_view_mode,$a_ref_id = null)
1774  {
1775  global $tree;
1776 
1777  if(!$a_view_mode)
1778  {
1779  $a_view_mode = ilContainer::VIEW_DEFAULT;
1780  }
1781 
1782  // view mode is inherit => check for parent course
1783  if($a_view_mode == ilContainer::VIEW_INHERIT)
1784  {
1785  if(!$a_ref_id)
1786  {
1787  $ref = ilObject::_getAllReferences($a_obj_id);
1788  $a_ref_id = end($ref);
1789  }
1790 
1791  $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1792  if(!$crs_ref)
1793  {
1795  }
1796 
1797  include_once './Modules/Course/classes/class.ilObjCourse.php';
1799 
1800  // validate course view mode
1801  if(!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1803  {
1805  }
1806 
1807  return $view_mode;
1808  }
1809 
1810  return $a_view_mode;
1811  }
1812 
1817  function addAdditionalSubItemInformation(&$a_item_data)
1818  {
1819  include_once './Services/Object/classes/class.ilObjectActivation.php';
1821  }
1822 
1823  // Private / Protected
1824  function __initFileObject()
1825  {
1826  if($this->file_obj)
1827  {
1828  return $this->file_obj;
1829  }
1830  else
1831  {
1832  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1833 
1834  return $this->file_obj = new ilFileDataGroup($this);
1835  }
1836  }
1837 
1838  function getMessage()
1839  {
1840  return $this->message;
1841  }
1842  function setMessage($a_message)
1843  {
1844  $this->message = $a_message;
1845  }
1846  function appendMessage($a_message)
1847  {
1848  if($this->getMessage())
1849  {
1850  $this->message .= "<br /> ";
1851  }
1852  $this->message .= $a_message;
1853  }
1854 
1862  protected function prepareAppointments($a_mode = 'create')
1863  {
1864  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1865 
1866  switch($a_mode)
1867  {
1868  case 'create':
1869  case 'update':
1870  if($this->isRegistrationUnlimited())
1871  {
1872  return array();
1873  }
1874  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1875  $app->setTitle($this->getTitle());
1876  $app->setSubtitle('grp_cal_reg_start');
1877  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1878  $app->setDescription($this->getLongDescription());
1879  $app->setStart($this->getRegistrationStart());
1880  $apps[] = $app;
1881 
1882  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1883  $app->setTitle($this->getTitle());
1884  $app->setSubtitle('grp_cal_reg_end');
1885  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1886  $app->setDescription($this->getLongDescription());
1887  $app->setStart($this->getRegistrationEnd());
1888  $apps[] = $app;
1889 
1890  return $apps;
1891 
1892  case 'delete':
1893  // Nothing to do: The category and all assigned appointments will be deleted.
1894  return array();
1895  }
1896  }
1897 
1905  protected function initParticipants()
1906  {
1907  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1908  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1909  }
1910 
1915  public static function lookupObjectsByCode($a_code)
1916  {
1917  global $ilDB;
1918 
1919  $query = "SELECT obj_id FROM grp_settings ".
1920  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1921  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1922  $res = $ilDB->query($query);
1923 
1924  $obj_ids = array();
1925  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1926  {
1927  $obj_ids[] = $row->obj_id;
1928  }
1929  return $obj_ids;
1930  }
1931 
1938  public function register($a_user_id,$a_role = IL_GRP_MEMBER, $a_force_registration = false)
1939  {
1940  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1941  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1943 
1944  if($part->isAssigned($a_user_id))
1945  {
1946  return true;
1947  }
1948 
1949  if(!$a_force_registration)
1950  {
1951  // Availability
1952  if(!$this->isRegistrationEnabled())
1953  {
1954  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1955 
1957  {
1958  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
1959  ', group subscription is deactivated.', '456');
1960  }
1961  }
1962 
1963  // Time Limitation
1964  if(!$this->isRegistrationUnlimited())
1965  {
1966  $start = $this->getRegistrationStart();
1967  $end = $this->getRegistrationEnd();
1968  $time = new ilDateTime(time(),IL_CAL_UNIX);
1969 
1970  if( !(ilDateTime::_after($time, $start) and ilDateTime::_before($time,$end)) )
1971  {
1972  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
1973  ', group is out of registration time.', '789');
1974  }
1975  }
1976 
1977  // Max members
1978  if($this->isMembershipLimited())
1979  {
1980  $free = max(0,$this->getMaxMembers() - $part->getCountMembers());
1981  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
1982  $waiting_list = new ilGroupWaitingList($this->getId());
1983  if($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
1984  {
1985  $this->lng->loadLanguageModule("grp");
1986  $waiting_list->addToList($a_user_id);
1987 
1988  $info = sprintf($this->lng->txt('grp_added_to_list'),
1989  $this->getTitle(),
1990  $waiting_list->getPosition($a_user_id));
1991 
1992  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1993  include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
1994  $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
1995  $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER,$a_user_id);
1996 
1997  throw new ilMembershipRegistrationException($info, '124');
1998  }
1999 
2000  if(!$free or $waiting_list->getCountUsers())
2001  {
2002  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2003  ', membership is limited.', '123');
2004  }
2005  }
2006  }
2007 
2008  $part->add($a_user_id,$a_role);
2009  $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2010  return true;
2011  }
2012 
2013 } //END class.ilObjGroup
2014 ?>