ILIAS  Release_4_4_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  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
838  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
839 
840  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
841  {
842  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_admin');
843  }
844  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
845  $ilLog->write(__METHOD__.' : Finished copying of role il_grp_admin.');
846 
847  $member = $this->getDefaultMemberRole();
848  $new_member = $new_obj->getDefaultMemberRole();
849  if(!$member || !$new_member)
850  {
851  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_member');
852  }
853  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
854  $ilLog->write(__METHOD__.' : Finished copying of role grp_member.');
855  }
856 
857 
863  function join($a_user_id, $a_mem_role="")
864  {
865  global $rbacadmin;
866 
867  if (is_array($a_mem_role))
868  {
869  foreach ($a_mem_role as $role)
870  {
871  $rbacadmin->assignUser($role,$a_user_id, false);
872  }
873  }
874  else
875  {
876  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
877  }
878 
879  return true;
880  }
881 
887  {
888  $local_group_Roles = $this->getLocalGroupRoles();
889 
890  return $local_group_Roles["il_grp_member_".$this->getRefId()];
891  }
892 
898  {
899  $local_group_Roles = $this->getLocalGroupRoles();
900 
901  return $local_group_Roles["il_grp_admin_".$this->getRefId()];
902  }
903 
910  function addMember($a_user_id, $a_mem_role)
911  {
912  global $rbacadmin;
913 
914  if (isset($a_user_id) && isset($a_mem_role) )
915  {
916  $this->join($a_user_id,$a_mem_role);
917  return true;
918  }
919  else
920  {
921  $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
922  return false;
923  }
924  }
925 
926 
933  function leaveGroup()
934  {
935  global $rbacadmin, $rbacreview;
936 
937  $member_ids = $this->getGroupMemberIds();
938 
939  if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
940  {
941  return 2;
942  }
943  else
944  {
945  if (!$this->isAdmin($this->ilias->account->getId()))
946  {
947  $this->leave($this->ilias->account->getId());
948  $member = new ilObjUser($this->ilias->account->getId());
949  $member->dropDesktopItem($this->getRefId(), "grp");
950 
951  return 0;
952  }
953  else if (count($this->getGroupAdminIds()) == 1)
954  {
955  return 1;
956  }
957  }
958  }
959 
964  function leave($a_user_id)
965  {
966  global $rbacadmin;
967 
968  $arr_groupRoles = $this->getMemberRoles($a_user_id);
969 
970  if (is_array($arr_groupRoles))
971  {
972  foreach ($arr_groupRoles as $groupRole)
973  {
974  $rbacadmin->deassignUser($groupRole, $a_user_id);
975  }
976  }
977  else
978  {
979  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
980  }
981 
982  return true;
983  }
984 
991  function getGroupMemberIds()
992  {
993  global $rbacadmin, $rbacreview;
994 
995  $usr_arr= array();
996 
997  $rol = $this->getLocalGroupRoles();
998 
999  foreach ($rol as $value)
1000  {
1001  foreach ($rbacreview->assignedUsers($value) as $member_id)
1002  {
1003  array_push($usr_arr,$member_id);
1004  }
1005  }
1006 
1007  $mem_arr = array_unique($usr_arr);
1008 
1009  return $mem_arr ? $mem_arr : array();
1010  }
1011 
1019  function getGroupMemberData($a_mem_ids, $active = 1)
1020  {
1021  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
1022 
1023  $usr_arr= array();
1024 
1025  $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
1026  "FROM usr_data ".
1027  "WHERE usr_id IN (".implode(',',ilUtil::quoteArray($a_mem_ids)).") ";
1028 
1029  if (is_numeric($active) && $active > -1)
1030  $q .= "AND active = '$active'";
1031 
1032  $q .= 'ORDER BY lastname,firstname';
1033 
1034  $r = $ilDB->query($q);
1035 
1036  while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
1037  {
1038  $mem_arr[] = array("id" => $row->usr_id,
1039  "login" => $row->login,
1040  "firstname" => $row->firstname,
1041  "lastname" => $row->lastname,
1042  "last_login" => $row->last_login
1043  );
1044  }
1045 
1046  return $mem_arr ? $mem_arr : array();
1047  }
1048 
1049  function getCountMembers()
1050  {
1051  return count($this->getGroupMemberIds());
1052  }
1053 
1060  function getGroupAdminIds($a_grpId = "")
1061  {
1062  global $rbacreview;
1063 
1064  if (!empty($a_grpId))
1065  {
1066  $grp_id = $a_grpId;
1067  }
1068  else
1069  {
1070  $grp_id = $this->getRefId();
1071  }
1072 
1073  $usr_arr = array();
1074  $roles = $this->getDefaultGroupRoles($this->getRefId());
1075 
1076  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
1077  {
1078  array_push($usr_arr,$member_id);
1079  }
1080 
1081  return $usr_arr;
1082  }
1083 
1089  function getDefaultGroupRoles($a_grp_id="")
1090  {
1091  global $rbacadmin, $rbacreview;
1092 
1093  if (strlen($a_grp_id) > 0)
1094  {
1095  $grp_id = $a_grp_id;
1096  }
1097  else
1098  {
1099  $grp_id = $this->getRefId();
1100  }
1101 
1102  $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
1103  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1104 
1105  foreach ($role_arr as $role_id)
1106  {
1107  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1108 
1109  $grp_Member ="il_grp_member_".$grp_id;
1110  $grp_Admin ="il_grp_admin_".$grp_id;
1111 
1112  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1113  {
1114  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1115  }
1116 
1117  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1118  {
1119  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1120  }
1121  }
1122 
1123  return $arr_grpDefaultRoles;
1124  }
1125 
1132  function getLocalGroupRoles($a_translate = false)
1133  {
1134  global $rbacadmin,$rbacreview;
1135 
1136  if (empty($this->local_roles))
1137  {
1138  $this->local_roles = array();
1139  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1140  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1141 
1142  foreach ($role_arr as $role_id)
1143  {
1144  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1145  {
1146  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1147 
1148  if ($a_translate)
1149  {
1150  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1151  }
1152  else
1153  {
1154  $role_name = $role_Obj->getTitle();
1155  }
1156 
1157  $this->local_roles[$role_name] = $role_Obj->getId();
1158  }
1159  }
1160  }
1161 
1162  return $this->local_roles;
1163  }
1164 
1171  {
1172  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1173  $res = $this->ilias->db->query($q);
1174  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1175 
1176  return $row["obj_id"];
1177  }
1178 
1185  {
1186  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1187  $res = $this->ilias->db->query($q);
1188  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1189 
1190  return $row["obj_id"];
1191  }
1192 
1193 
1194 
1204  public function updateGroupType()
1205  {
1206  global $tree,$rbacreview,$rbacadmin;
1207 
1208  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1209  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1210  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1211 
1212  // Delete parent roles with stopped inheritance
1213  foreach($real_parent_roles as $role_id)
1214  {
1215  // Delete local role
1216  if(isset($rolf_data['child']) and $rolf_data['child'])
1217  {
1218  $rbacadmin->deleteLocalRole($role_id,$rolf_data['child']);
1219  }
1220  }
1221  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1222  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1223 
1224  switch($this->getGroupType())
1225  {
1226  case GRP_TYPE_PUBLIC:
1227  $template_id = $this->getGrpStatusOpenTemplateId();
1228  break;
1229 
1230  case GRP_TYPE_CLOSED:
1231  $template_id = $this->getGrpStatusClosedTemplateId();
1232  break;
1233  }
1234 
1235  $first = true;
1236  foreach($tree->getFilteredSubTree($this->getRefId(),array('rolf','grp')) as $subnode)
1237  {
1238  // Read template operations
1239  $template_ops = $rbacreview->getOperationsOfRole($template_id,$subnode['type'], ROLE_FOLDER_ID);
1240 
1241  $rolf_data = $rbacreview->getRoleFolderOfObject($subnode['child']);
1242 
1243 
1244  // for all parent roles
1245  foreach($real_parent_roles as $role_id)
1246  {
1247  if($rbacreview->isProtected($parent_roles[$role_id]['parent'],$role_id))
1248  {
1249  continue;
1250  }
1251 
1252  // Delete local role
1253  if(isset($rolf_data['child']) and $rolf_data['child'])
1254  {
1255  $rbacadmin->deleteLocalRole($role_id,$rolf_data['child']);
1256  }
1257 
1258  // Store current operations
1259  $current_ops = $rbacreview->getOperationsOfRole($role_id,$subnode['type'],$parent_roles[$role_id]['parent']);
1260 
1261  // Revoke permissions
1262  $rbacadmin->revokePermission($subnode['child'],$role_id);
1263 
1264  // Grant permissions
1265  $granted = array();
1266  foreach($template_ops as $operation)
1267  {
1268  if(in_array($operation,$current_ops))
1269  {
1270  $granted[] = $operation;
1271  }
1272  }
1273  if($granted)
1274  {
1275  $rbacadmin->grantPermission($role_id, $granted,$subnode['child']);
1276  }
1277 
1278  if($first)
1279  {
1280  // This is the group itself
1281  $rbacadmin->copyRolePermissionIntersection(
1282  $template_id, ROLE_FOLDER_ID,
1283  $role_id, $parent_roles[$role_id]['parent'],
1284  $rolf_data["child"],$role_id);
1285  $rbacadmin->assignRoleToFolder($role_id,$rolf_data["child"],"n");
1286 
1287  }
1288  }
1289  $first = false;
1290  }
1291  }
1292 
1310  function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1311  {
1312  global $rbacadmin, $rbacreview, $rbacsystem;
1313 
1314  //get Rolefolder of group
1315  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1316 
1317  //define all relevant roles that rights are needed to be changed
1318  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1319 
1320  $real_local_roles = $rbacreview->getRolesOfRoleFolder($rolf_data['ref_id'],false);
1321  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$real_local_roles);
1322 
1323  //group status open (aka public) or group status closed
1324  if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED)
1325  {
1326  if ($a_grpStatus == GRP_TYPE_PUBLIC)
1327  {
1328  $template_id = $this->getGrpStatusOpenTemplateId();
1329  }
1330  else
1331  {
1332  $template_id = $this->getGrpStatusClosedTemplateId();
1333  }
1334  //get defined operations from template
1335  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1336 
1337  foreach ($arr_relevantParentRoleIds as $parentRole)
1338  {
1339  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1340  {
1341  continue;
1342  }
1343 
1344  $granted_permissions = array();
1345 
1346  // Delete the linked role for the parent role
1347  // (just in case if it already exists).
1348 
1349  // Added additional check, since this operation is very dangerous.
1350  // If there is no role folder ALL parent roles are deleted.
1351  if(isset($rolf_data['child']) and $rolf_data['child'])
1352  {
1353  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1354  }
1355 
1356  // Grant permissions on the group object for
1357  // the parent role. In the foreach loop we
1358  // compute the intersection of the role
1359  // template il_grp_status_open/_closed and the
1360  // permission template of the parent role.
1361  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1362  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1363  foreach ($template_ops as $template_op)
1364  {
1365  if (in_array($template_op,$current_ops))
1366  {
1367  array_push($granted_permissions,$template_op);
1368  }
1369  }
1370  if (!empty($granted_permissions))
1371  {
1372  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1373  }
1374 
1375  // Create a linked role for the parent role and
1376  // initialize it with the intersection of
1377  // il_grp_status_open/_closed and the permission
1378  // template of the parent role
1379  $rbacadmin->copyRolePermissionIntersection(
1380  $template_id, ROLE_FOLDER_ID,
1381  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1382  $rolf_data["child"], $parentRole
1383  );
1384  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1385  }//END foreach
1386  }
1387  }
1388 
1396  public function setGroupStatus($a_status)
1397  {
1398  $this->group_status = $a_status;
1399  }
1400 
1408  public function getGroupStatus()
1409  {
1410  return $this->group_status;
1411  }
1412 
1418  function readGroupStatus()
1419  {
1420  global $rbacsystem,$rbacreview;
1421 
1422  $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
1423  $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
1424 
1425  //get Rolefolder of group
1426  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1427  //get all relevant roles
1428  $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1429 
1430  //if one global role has no permission to join the group is officially closed !
1431  foreach ($arr_globalRoles as $globalRole)
1432  {
1433  $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
1434 
1435  if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
1436  {
1437  return $this->group_status = GRP_TYPE_PUBLIC;
1438  }
1439  }
1440 
1441  return $this->group_status = GRP_TYPE_CLOSED;
1442  }
1443 
1450  function getMemberRoles($a_user_id)
1451  {
1452  global $rbacadmin, $rbacreview,$ilBench;
1453 
1454  $ilBench->start("Group", "getMemberRoles");
1455 
1456  $arr_assignedRoles = array();
1457 
1458  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
1459 
1460  $ilBench->stop("Group", "getMemberRoles");
1461 
1462  return $arr_assignedRoles;
1463  }
1464 
1471  function isAdmin($a_userId)
1472  {
1473  global $rbacreview;
1474 
1475  $grp_Roles = $this->getDefaultGroupRoles();
1476 
1477  if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
1478  {
1479  return true;
1480  }
1481  else
1482  {
1483  return false;
1484  }
1485  }
1486 
1487 
1488 
1494  function initDefaultRoles()
1495  {
1496  global $rbacadmin, $rbacreview;
1497 
1498  // create a local role folder
1499  $rfoldObj =& $this->createRoleFolder();
1500 
1501  // ADMIN ROLE
1502  // create role and assign role to rolefolder...
1503  $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
1504  $this->m_roleAdminId = $roleObj->getId();
1505 
1506  //set permission template of new local role
1507  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
1508  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
1509  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
1510 
1511  // set object permissions of group object
1512  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
1513  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
1514 
1515  // set object permissions of role folder object
1516  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
1517  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
1518 
1519  // MEMBER ROLE
1520  // create role and assign role to rolefolder...
1521  $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
1522  $this->m_roleMemberId = $roleObj->getId();
1523 
1524  //set permission template of new local role
1525  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
1526  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
1527  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
1528 
1529  // set object permissions of group object
1530  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
1531  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
1532 
1533  // set object permissions of role folder object
1534  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
1535  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
1536 
1537  unset($rfoldObj);
1538  unset($roleObj);
1539 
1540  $roles[] = $this->m_roleAdminId;
1541  $roles[] = $this->m_roleMemberId;
1542 
1543  return $roles ? $roles : array();
1544  }
1545 
1556  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1557  {
1558  global $tree;
1559 
1560  $parent_id = (int) $tree->getParentId($a_node_id);
1561 
1562  if ($parent_id != 0)
1563  {
1564  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1565  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1566  }
1567 
1568  return true;
1569  }
1570 
1571 
1572  function exportXML()
1573  {
1574  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
1575 
1576  $xml_writer = new ilGroupXMLWriter($this);
1577  $xml_writer->start();
1578 
1579  $xml = $xml_writer->getXML();
1580 
1581  $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
1582 
1583  $this->__initFileObject();
1584 
1585  $this->file_obj->addGroupDirectory();
1586  $this->file_obj->addDirectory($name);
1587  $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
1588  $this->file_obj->zipFile($name,$name.'.zip');
1589  $this->file_obj->deleteDirectory($name);
1590 
1591  return true;
1592  }
1593 
1594  function deleteExportFiles($a_files)
1595  {
1596  $this->__initFileObject();
1597 
1598  foreach($a_files as $file)
1599  {
1600  $this->file_obj->deleteFile($file);
1601  }
1602  return true;
1603  }
1604 
1606  {
1607  $this->__initFileObject();
1608 
1609  if($abs_name = $this->file_obj->getExportFile($file))
1610  {
1611  ilUtil::deliverFile($abs_name,$file);
1612  // Not reached
1613  }
1614  return false;
1615  }
1616 
1625  function _importFromXMLString($xml,$parent_id)
1626  {
1627  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
1628 
1629  $import_parser = new ilGroupXMLParser($xml,$parent_id);
1630 
1631  return $import_parser->startParsing();
1632  }
1633 
1641  function _importFromFile($file,$parent_id)
1642  {
1643  global $lng;
1644 
1645  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1646 
1647  $file_obj = new ilFileDataGroup(null);
1648  $file_obj->addImportDirectory();
1649  $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
1650  $file_obj->unpackImportFile();
1651 
1652  if(!$file_obj->validateImportFile())
1653  {
1654  return false;
1655  }
1656  return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
1657  }
1658 
1659  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(DB_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  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1679  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1680  $user_roles = $rbacreview->assignedRoles($a_user_id);
1681 
1682  // Used for membership limitations -> check membership by given field
1683  if($a_field)
1684  {
1685  include_once './Services/User/classes/class.ilObjUser.php';
1686 
1687  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
1688  switch($a_field)
1689  {
1690  case 'login':
1691  $and = "AND login = '".$tmp_user->getLogin()."' ";
1692  break;
1693  case 'email':
1694  $and = "AND email = '".$tmp_user->getEmail()."' ";
1695  break;
1696  case 'matriculation':
1697  $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
1698  break;
1699 
1700  default:
1701  $and = "AND usr_id = '".$a_user_id."'";
1702  break;
1703  }
1704  if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
1705  {
1706  return false;
1707  }
1708  $query = "SELECT * FROM usr_data as ud ".
1709  "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
1710  $and;
1711  $res = $ilDB->query($query);
1712 
1713  return $res->numRows() ? true : false;
1714  }
1715 
1716  if (!array_intersect($local_roles,$user_roles))
1717  {
1718  return false;
1719  }
1720 
1721  return true;
1722  }
1723 
1724  function _getMembers($a_obj_id)
1725  {
1726  global $rbacreview;
1727 
1728  // get reference
1729  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1730  $ref_id = current($ref_ids);
1731 
1732  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
1733  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
1734 
1735  $users = array();
1736  foreach($local_roles as $role_id)
1737  {
1738  $users = array_merge($users,$rbacreview->assignedUsers($role_id));
1739  }
1740 
1741  return array_unique($users);
1742  }
1743 
1751  public function getViewMode($a_translate_inherit = true)
1752  {
1753  $view = (int) $this->view_mode;
1754 
1755  if(!$view)
1756  {
1757  $view = ilContainer::VIEW_DEFAULT;
1758  }
1759 
1760  if($a_translate_inherit)
1761  {
1762  $view = self::translateViewMode($this->id, $view, $this->ref_id);
1763  }
1764 
1765  return $view;
1766  }
1767 
1772  public function setViewMode($a_view_mode)
1773  {
1774  $this->view_mode = $a_view_mode;
1775  }
1776 
1781  public static function lookupViewMode($a_obj_id)
1782  {
1783  global $ilDB;
1784 
1785  $query = 'SELECT view_mode FROM grp_settings '.
1786  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1787  $res = $ilDB->query($query);
1788 
1789  $view_mode = NULL;
1790  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1791  {
1792  $view_mode = $row->view_mode;
1793  }
1794  return self::translateViewMode($a_obj_id,$view_mode);
1795  }
1796 
1804  protected static function translateViewMode($a_obj_id,$a_view_mode,$a_ref_id = null)
1805  {
1806  global $tree;
1807 
1808  if(!$a_view_mode)
1809  {
1810  $a_view_mode = ilContainer::VIEW_DEFAULT;
1811  }
1812 
1813  // view mode is inherit => check for parent course
1814  if($a_view_mode == ilContainer::VIEW_INHERIT)
1815  {
1816  if(!$a_ref_id)
1817  {
1818  $ref = ilObject::_getAllReferences($a_obj_id);
1819  $a_ref_id = end($ref);
1820  }
1821 
1822  $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1823  if(!$crs_ref)
1824  {
1826  }
1827 
1828  include_once './Modules/Course/classes/class.ilObjCourse.php';
1830 
1831  // validate course view mode
1832  if(!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1834  {
1836  }
1837 
1838  return $view_mode;
1839  }
1840 
1841  return $a_view_mode;
1842  }
1843 
1848  function addAdditionalSubItemInformation(&$a_item_data)
1849  {
1850  include_once './Services/Object/classes/class.ilObjectActivation.php';
1852  }
1853 
1854  // Private / Protected
1855  function __initFileObject()
1856  {
1857  if($this->file_obj)
1858  {
1859  return $this->file_obj;
1860  }
1861  else
1862  {
1863  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1864 
1865  return $this->file_obj = new ilFileDataGroup($this);
1866  }
1867  }
1868 
1869  function getMessage()
1870  {
1871  return $this->message;
1872  }
1873  function setMessage($a_message)
1874  {
1875  $this->message = $a_message;
1876  }
1877  function appendMessage($a_message)
1878  {
1879  if($this->getMessage())
1880  {
1881  $this->message .= "<br /> ";
1882  }
1883  $this->message .= $a_message;
1884  }
1885 
1893  protected function prepareAppointments($a_mode = 'create')
1894  {
1895  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1896 
1897  switch($a_mode)
1898  {
1899  case 'create':
1900  case 'update':
1901  if($this->isRegistrationUnlimited())
1902  {
1903  return array();
1904  }
1905  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1906  $app->setTitle($this->getTitle());
1907  $app->setSubtitle('grp_cal_reg_start');
1908  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1909  $app->setDescription($this->getLongDescription());
1910  $app->setStart($this->getRegistrationStart());
1911  $apps[] = $app;
1912 
1913  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1914  $app->setTitle($this->getTitle());
1915  $app->setSubtitle('grp_cal_reg_end');
1916  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1917  $app->setDescription($this->getLongDescription());
1918  $app->setStart($this->getRegistrationEnd());
1919  $apps[] = $app;
1920 
1921  return $apps;
1922 
1923  case 'delete':
1924  // Nothing to do: The category and all assigned appointments will be deleted.
1925  return array();
1926  }
1927  }
1928 
1936  protected function initParticipants()
1937  {
1938  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1939  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1940  }
1941 
1946  public static function lookupObjectsByCode($a_code)
1947  {
1948  global $ilDB;
1949 
1950  $query = "SELECT obj_id FROM grp_settings ".
1951  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1952  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1953  $res = $ilDB->query($query);
1954 
1955  $obj_ids = array();
1956  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1957  {
1958  $obj_ids[] = $row->obj_id;
1959  }
1960  return $obj_ids;
1961  }
1962 
1969  public function register($a_user_id,$a_role = IL_GRP_MEMBER, $a_force_registration = false)
1970  {
1971  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1972  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1974 
1975  if($part->isAssigned($a_user_id))
1976  {
1977  return true;
1978  }
1979 
1980  if(!$a_force_registration)
1981  {
1982  // Availability
1983  if(!$this->isRegistrationEnabled())
1984  {
1985  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1986 
1988  {
1989  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
1990  ', group subscription is deactivated.', '456');
1991  }
1992  }
1993 
1994  // Time Limitation
1995  if(!$this->isRegistrationUnlimited())
1996  {
1997  $start = $this->getRegistrationStart();
1998  $end = $this->getRegistrationEnd();
1999  $time = new ilDateTime(time(),IL_CAL_UNIX);
2000 
2001  if( !(ilDateTime::_after($time, $start) and ilDateTime::_before($time,$end)) )
2002  {
2003  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2004  ', group is out of registration time.', '789');
2005  }
2006  }
2007 
2008  // Max members
2009  if($this->isMembershipLimited())
2010  {
2011  $free = max(0,$this->getMaxMembers() - $part->getCountMembers());
2012  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2013  $waiting_list = new ilGroupWaitingList($this->getId());
2014  if($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
2015  {
2016  $this->lng->loadLanguageModule("grp");
2017  $waiting_list->addToList($a_user_id);
2018 
2019  $info = sprintf($this->lng->txt('grp_added_to_list'),
2020  $this->getTitle(),
2021  $waiting_list->getPosition($a_user_id));
2022 
2023  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2024  include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
2025  $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
2026  $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER,$a_user_id);
2027 
2028  throw new ilMembershipRegistrationException($info, '124');
2029  }
2030 
2031  if(!$free or $waiting_list->getCountUsers())
2032  {
2033  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2034  ', membership is limited.', '123');
2035  }
2036  }
2037  }
2038 
2039  $part->add($a_user_id,$a_role);
2040  $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2041  return true;
2042  }
2043 
2044 } //END class.ilObjGroup
2045 ?>