ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjGroup.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 //TODO: function getRoleId($groupRole) returns the object-id of grouprole
26 
27 require_once "./Services/Container/classes/class.ilContainer.php";
28 include_once('./Services/Calendar/classes/class.ilDateTime.php');
29 include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
30 
31 define('GRP_REGISTRATION_DEACTIVATED',-1);
32 define('GRP_REGISTRATION_DIRECT',0);
33 define('GRP_REGISTRATION_REQUEST',1);
34 define('GRP_REGISTRATION_PASSWORD',2);
35 
36 define('GRP_REGISTRATION_LIMITED',1);
37 define('GRP_REGISTRATION_UNLIMITED',2);
38 
39 define('GRP_TYPE_UNKNOWN',0);
40 define('GRP_TYPE_CLOSED',1);
41 define('GRP_TYPE_OPEN',2);
42 define('GRP_TYPE_PUBLIC',3);
43 
55 {
56  const CAL_REG_START = 1;
57  const CAL_REG_END = 2;
58 
59  const GRP_MEMBER = 1;
60  const GRP_ADMIN = 2;
61 
62  const ERR_MISSING_TITLE = 'msg_no_title';
63  const ERR_MISSING_GROUP_TYPE = 'grp_missing_grp_type';
64  const ERR_MISSING_PASSWORD = 'grp_missing_password';
65  const ERR_WRONG_MAX_MEMBERS = 'grp_wrong_max_members';
66  const ERR_WRONG_REG_TIME_LIMIT = 'grp_wrong_reg_time_limit';
67 
68  protected $information;
69  protected $group_type = null;
71  protected $reg_enabled = true;
72  protected $reg_unlimited = true;
73  protected $reg_start = null;
74  protected $reg_end = null;
75  protected $reg_password = '';
76  protected $reg_membership_limitation = false;
77  protected $reg_max_members = 0;
78  protected $waiting_list = false;
79 
80 
81  // Map
82  private $latitude = '';
83  private $longitude = '';
84  private $locationzoom = 0;
85  private $enablemap = 0;
86 
87  private $reg_access_code = '';
88  private $reg_access_code_enabled = false;
89 
90  private $view_mode = NULL;
91 
92 
93 
94  public $members_obj;
95 
96 
100  var $file_obj = null;
101 
103 
105 
107 
114  public function __construct($a_id = 0,$a_call_by_reference = true)
115  {
116  global $tree;
117 
118  $this->tree =& $tree;
119 
120  $this->type = "grp";
121  $this->ilObject($a_id,$a_call_by_reference);
122  $this->setRegisterMode(true); // ???
123  }
124 
130  public static function lookupGroupTye($a_id)
131  {
132  global $ilDB;
133 
134  $query = "SELECT grp_type FROM grp_settings ".
135  "WHERE obj_id = ".$ilDB->quote($a_id,'integer');
136  $res = $ilDB->query($query);
137  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
138  {
139  return $row->grp_type;
140  }
141  return GRP_TYPE_UNKNOWN;
142  }
143 
144  // Setter/Getter
152  public function setInformation($a_information)
153  {
154  $this->information = $a_information;
155  }
156 
164  public function getInformation()
165  {
166  return $this->information;
167  }
168 
175  public function setGroupType($a_type)
176  {
177  $this->group_type = $a_type;
178  }
179 
186  public function getGroupType()
187  {
188  return $this->group_type;
189  }
190 
198  public function isGroupTypeModified($a_old_type)
199  {
200  if($a_old_type == GRP_TYPE_UNKNOWN)
201  {
202  $group_type = $this->readGroupStatus();
203  }
204  else
205  {
206  $group_type = $a_old_type;
207  }
208  return $group_type != $this->getGroupType();
209  }
210 
218  public function setRegistrationType($a_type)
219  {
220  $this->reg_type = $a_type;
221  }
222 
229  public function getRegistrationType()
230  {
231  return $this->reg_type;
232  }
233 
240  public function isRegistrationEnabled()
241  {
243  }
244 
252  public function enableUnlimitedRegistration($a_status)
253  {
254  $this->reg_unlimited = $a_status;
255  }
256 
263  public function isRegistrationUnlimited()
264  {
265  return $this->reg_unlimited;
266  }
267 
275  public function setRegistrationStart($a_start)
276  {
277  $this->reg_start = $a_start;
278  }
279 
286  public function getRegistrationStart()
287  {
288  return $this->reg_start ? $this->reg_start : $this->reg_start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
289  }
290 
291 
299  public function setRegistrationEnd($a_end)
300  {
301  $this->reg_end = $a_end;
302  }
303 
310  public function getRegistrationEnd()
311  {
312  return $this->reg_end ? $this->reg_end : $this->reg_end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
313  }
314 
321  public function setPassword($a_pass)
322  {
323  $this->reg_password = $a_pass;
324  }
325 
332  public function getPassword()
333  {
334  return $this->reg_password;
335  }
336 
344  public function enableMembershipLimitation($a_status)
345  {
346  $this->reg_membership_limitation = $a_status;
347  }
348 
355  public function isMembershipLimited()
356  {
357  return (bool) $this->reg_membership_limitation;
358  }
359 
366  public function setMaxMembers($a_max)
367  {
368  $this->reg_max_members = $a_max;
369  }
370 
377  public function getMaxMembers()
378  {
379  return $this->reg_max_members;
380  }
381 
389  public function enableWaitingList($a_status)
390  {
391  $this->waiting_list = $a_status;
392  }
393 
401  public function isWaitingListEnabled()
402  {
403  return $this->waiting_list;
404  }
405 
411  function setLatitude($a_latitude)
412  {
413  $this->latitude = $a_latitude;
414  }
415 
421  function getLatitude()
422  {
423  return $this->latitude;
424  }
425 
431  function setLongitude($a_longitude)
432  {
433  $this->longitude = $a_longitude;
434  }
435 
441  function getLongitude()
442  {
443  return $this->longitude;
444  }
445 
451  function setLocationZoom($a_locationzoom)
452  {
453  $this->locationzoom = $a_locationzoom;
454  }
455 
461  function getLocationZoom()
462  {
463  return $this->locationzoom;
464  }
465 
471  function setEnableGroupMap($a_enablemap)
472  {
473  $this->enablemap = $a_enablemap;
474  }
475 
481  function getEnableGroupMap()
482  {
483  return (bool) $this->enablemap;
484  }
485 
490  public function getRegistrationAccessCode()
491  {
492  return $this->reg_access_code;
493  }
494 
500  public function setRegistrationAccessCode($a_code)
501  {
502  $this->reg_access_code = $a_code;
503  }
504 
510  {
511  return (bool) $this->reg_access_code_enabled;
512  }
513 
519  public function enableRegistrationAccessCode($a_status)
520  {
521  $this->reg_access_code_enabled = $a_status;
522  }
523 
524 
525 
532  public function validate()
533  {
534  global $ilErr;
535 
536  if(!$this->getTitle())
537  {
538  $this->title = '';
539  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
540  }
541  if(!$this->getGroupType())
542  {
543  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_GROUP_TYPE));
544  }
545  if($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword()))
546  {
547  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
548  }
550  {
551  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
552  }
553  if($this->isMembershipLimited() and (!is_numeric($this->getMaxMembers()) or $this->getMaxMembers() <= 0))
554  {
555  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
556  }
557  return strlen($ilErr->getMessage()) == 0;
558  }
559 
560 
561 
562 
566  function create()
567  {
568  global $ilDB,$ilAppEventHandler;
569 
570  if(!parent::create())
571  {
572  return false;
573  }
574 
575  $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled,".
576  "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit,".
577  "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode) ".
578  "VALUES(".
579  $ilDB->quote($this->getId() ,'integer').", ".
580  $ilDB->quote($this->getInformation() ,'text').", ".
581  $ilDB->quote((int) $this->getGroupType() ,'integer').", ".
582  $ilDB->quote($this->getRegistrationType() ,'integer').", ".
583  $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0) ,'integer').", ".
584  $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0) ,'integer').", ".
585  $ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
586  $ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
587  $ilDB->quote($this->getPassword() ,'text').", ".
588  $ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
589  $ilDB->quote($this->getMaxMembers() ,'integer').", ".
590  $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
591  $ilDB->quote($this->getLatitude() ,'text').", ".
592  $ilDB->quote($this->getLongitude() ,'text').", ".
593  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
594  $ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
595  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
596  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
597  $ilDB->quote($this->getViewMode(false),'integer').' '.
598  ")";
599  $res = $ilDB->manipulate($query);
600 
601  $ilAppEventHandler->raise('Modules/Group',
602  'create',
603  array('object' => $this,
604  'obj_id' => $this->getId(),
605  'appointments' => $this->prepareAppointments('create')));
606 
607  return $this->getId();
608  }
609 
613  function update()
614  {
615  global $ilDB,$ilAppEventHandler;
616 
617  if (!parent::update())
618  {
619  return false;
620  }
621 
622  $query = "UPDATE grp_settings ".
623  "SET information = ".$ilDB->quote($this->getInformation() ,'text').", ".
624  "grp_type = ".$ilDB->quote((int) $this->getGroupType() ,'integer').", ".
625  "registration_type = ".$ilDB->quote($this->getRegistrationType() ,'integer').", ".
626  "registration_enabled = ".$ilDB->quote($this->isRegistrationEnabled() ? 1 : 0 ,'integer').", ".
627  "registration_unlimited = ".$ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0 ,'integer').", ".
628  "registration_start = ".$ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
629  "registration_end = ".$ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
630  "registration_password = ".$ilDB->quote($this->getPassword() ,'text').", ".
631 // "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
632  "registration_mem_limit = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
633  "registration_max_members = ".$ilDB->quote($this->getMaxMembers() ,'integer').", ".
634  "waiting_list = ".$ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
635  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
636  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
637  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
638  "enablemap = ".$ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
639  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
640  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
641  'view_mode = '.$ilDB->quote($this->getViewMode(false),'integer').' '.
642  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
643  $res = $ilDB->manipulate($query);
644 
645  $ilAppEventHandler->raise('Modules/Group',
646  'update',
647  array('object' => $this,
648  'obj_id' => $this->getId(),
649  'appointments' => $this->prepareAppointments('update')));
650 
651 
652  return true;
653  }
654 
661  public function delete()
662  {
663  global $ilDB,$ilAppEventHandler;
664 
665  // always call parent delete function first!!
666  if (!parent::delete())
667  {
668  return false;
669  }
670 
671  $query = "DELETE FROM grp_settings ".
672  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
673  $res = $ilDB->manipulate($query);
674 
675  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
677 
678  $ilAppEventHandler->raise('Modules/Group',
679  'delete',
680  array('object' => $this,
681  'obj_id' => $this->getId(),
682  'appointments' => $this->prepareAppointments('delete')));
683 
684 
685  return true;
686  }
687 
688 
692  function read()
693  {
694  global $ilDB;
695 
696  parent::read();
697 
698  $query = "SELECT * FROM grp_settings ".
699  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
700 
701  $res = $ilDB->query($query);
702  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
703  {
704  $this->setInformation($row->information);
705  $this->setGroupType($row->grp_type);
706  $this->setRegistrationType($row->registration_type);
707  $this->enableUnlimitedRegistration($row->registration_unlimited);
708  $this->setRegistrationStart(new ilDateTime($row->registration_start,IL_CAL_DATETIME));
709  $this->setRegistrationEnd(new ilDateTime($row->registration_end,IL_CAL_DATETIME));
710  $this->setPassword($row->registration_password);
711  $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
712  $this->setMaxMembers($row->registration_max_members);
713  $this->enableWaitingList($row->waiting_list);
714  $this->setLatitude($row->latitude);
715  $this->setLongitude($row->longitude);
716  $this->setLocationZoom($row->location_zoom);
717  $this->setEnableGroupMap($row->enablemap);
718  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
719  $this->setRegistrationAccessCode($row->reg_ac);
720  $this->setViewMode($row->view_mode);
721  }
722  $this->initParticipants();
723 
724  // Inherit order type from parent course (if exists)
725  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
727  }
728 
737  public function cloneObject($a_target_id,$a_copy_id = 0)
738  {
739  global $ilDB,$ilUser;
740 
741  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
742  $new_obj->setGroupType($this->getGroupType());
743  $new_obj->initGroupStatus($this->getGroupType() ? $this->getGroupType() : $this->readGroupStatus());
744 
745  $this->cloneAutoGeneratedRoles($new_obj);
746 
747  $new_obj->setRegistrationType($this->getRegistrationType());
748  $new_obj->setInformation($this->getInformation());
749  $new_obj->setRegistrationStart($this->getRegistrationStart());
750  $new_obj->setRegistrationEnd($this->getRegistrationEnd());
751  $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
752  $new_obj->setPassword($this->getPassword());
753  $new_obj->enableMembershipLimitation($this->isMembershipLimited());
754  $new_obj->setMaxMembers($this->getMaxMembers());
755  $new_obj->enableWaitingList($this->isWaitingListEnabled());
756 
757  // map
758  $new_obj->setLatitude($this->getLatitude());
759  $new_obj->setLongitude($this->getLongitude());
760  $new_obj->setLocationZoom($this->getLocationZoom());
761  $new_obj->setEnableGroupMap($this->getEnableGroupMap());
762  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
763  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
764  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
765 
766  $new_obj->setViewMode($this->getViewMode());
767 
768  $new_obj->update();
769 
770  // #13008 - Group Defined Fields
771  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
772  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
773 
774  global $ilLog;
775  $ilLog->write(__METHOD__.': Starting add user');
776 
777  // Assign user as admin
778  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
779  $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
780  $part->add($ilUser->getId(),IL_GRP_ADMIN);
781  $part->updateNotification($ilUser->getId(),1);
782 
783  // Copy learning progress settings
784  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
785  $obj_settings = new ilLPObjSettings($this->getId());
786  $obj_settings->cloneSettings($new_obj->getId());
787  unset($obj_settings);
788 
789  // clone icons
790  $new_obj->saveIcons($this->getBigIconPath(),
791  $this->getSmallIconPath(),
792  $this->getTinyIconPath());
793 
794  return $new_obj;
795  }
796 
805  public function cloneDependencies($a_target_id,$a_copy_id)
806  {
807  global $tree;
808 
809  parent::cloneDependencies($a_target_id,$a_copy_id);
810 
811  include_once('Services/Object/classes/class.ilObjectActivation.php');
812  ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
813 
814  include_once('Services/Tracking/classes/class.ilLPCollections.php');
815  $lp_collection = new ilLPCollections($this->getId());
816  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
817 
818  return true;
819  }
820 
828  public function cloneAutoGeneratedRoles($new_obj)
829  {
830  global $ilLog,$rbacadmin,$rbacreview;
831 
832  $admin = $this->getDefaultAdminRole();
833  $new_admin = $new_obj->getDefaultAdminRole();
834  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
835  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
836 
837  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
838  {
839  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_admin');
840  }
841  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$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,$source_rolf,$target_rolf,$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  $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
1100  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1101 
1102  foreach ($role_arr as $role_id)
1103  {
1104  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1105 
1106  $grp_Member ="il_grp_member_".$grp_id;
1107  $grp_Admin ="il_grp_admin_".$grp_id;
1108 
1109  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1110  {
1111  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1112  }
1113 
1114  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1115  {
1116  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1117  }
1118  }
1119 
1120  return $arr_grpDefaultRoles;
1121  }
1122 
1129  function getLocalGroupRoles($a_translate = false)
1130  {
1131  global $rbacadmin,$rbacreview;
1132 
1133  if (empty($this->local_roles))
1134  {
1135  $this->local_roles = array();
1136  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1137  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1138 
1139  foreach ($role_arr as $role_id)
1140  {
1141  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1142  {
1143  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1144 
1145  if ($a_translate)
1146  {
1147  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1148  }
1149  else
1150  {
1151  $role_name = $role_Obj->getTitle();
1152  }
1153 
1154  $this->local_roles[$role_name] = $role_Obj->getId();
1155  }
1156  }
1157  }
1158 
1159  return $this->local_roles;
1160  }
1161 
1168  {
1169  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1170  $res = $this->ilias->db->query($q);
1171  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1172 
1173  return $row["obj_id"];
1174  }
1175 
1182  {
1183  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1184  $res = $this->ilias->db->query($q);
1185  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1186 
1187  return $row["obj_id"];
1188  }
1189 
1190 
1191 
1201  public function updateGroupType()
1202  {
1203  global $tree,$rbacreview,$rbacadmin;
1204 
1205  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1206  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1207  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1208 
1209  // Delete parent roles with stopped inheritance
1210  foreach($real_parent_roles as $role_id)
1211  {
1212  // Delete local role
1213  if(isset($rolf_data['child']) and $rolf_data['child'])
1214  {
1215  $rbacadmin->deleteLocalRole($role_id,$rolf_data['child']);
1216  }
1217  }
1218  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1219  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1220 
1221  switch($this->getGroupType())
1222  {
1223  case GRP_TYPE_PUBLIC:
1224  $template_id = $this->getGrpStatusOpenTemplateId();
1225  break;
1226 
1227  case GRP_TYPE_CLOSED:
1228  $template_id = $this->getGrpStatusClosedTemplateId();
1229  break;
1230  }
1231 
1232  $first = true;
1233  foreach($tree->getFilteredSubTree($this->getRefId(),array('rolf','grp')) as $subnode)
1234  {
1235  // Read template operations
1236  $template_ops = $rbacreview->getOperationsOfRole($template_id,$subnode['type'], ROLE_FOLDER_ID);
1237 
1238  $rolf_data = $rbacreview->getRoleFolderOfObject($subnode['child']);
1239 
1240 
1241  // for all parent roles
1242  foreach($real_parent_roles as $role_id)
1243  {
1244  if($rbacreview->isProtected($parent_roles[$role_id]['parent'],$role_id))
1245  {
1246  continue;
1247  }
1248 
1249  // Delete local role
1250  if(isset($rolf_data['child']) and $rolf_data['child'])
1251  {
1252  $rbacadmin->deleteLocalRole($role_id,$rolf_data['child']);
1253  }
1254 
1255  // Store current operations
1256  $current_ops = $rbacreview->getOperationsOfRole($role_id,$subnode['type'],$parent_roles[$role_id]['parent']);
1257 
1258  // Revoke permissions
1259  $rbacadmin->revokePermission($subnode['child'],$role_id);
1260 
1261  // Grant permissions
1262  $granted = array();
1263  foreach($template_ops as $operation)
1264  {
1265  if(in_array($operation,$current_ops))
1266  {
1267  $granted[] = $operation;
1268  }
1269  }
1270  if($granted)
1271  {
1272  $rbacadmin->grantPermission($role_id, $granted,$subnode['child']);
1273  }
1274 
1275  if($first)
1276  {
1277  // This is the group itself
1278  $rbacadmin->copyRolePermissionIntersection(
1279  $template_id, ROLE_FOLDER_ID,
1280  $role_id, $parent_roles[$role_id]['parent'],
1281  $rolf_data["child"],$role_id);
1282  $rbacadmin->assignRoleToFolder($role_id,$rolf_data["child"],"n");
1283 
1284  }
1285  }
1286  $first = false;
1287  }
1288  }
1289 
1307  function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1308  {
1309  global $rbacadmin, $rbacreview, $rbacsystem;
1310 
1311  //get Rolefolder of group
1312  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1313 
1314  //define all relevant roles that rights are needed to be changed
1315  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1316 
1317  $real_local_roles = $rbacreview->getRolesOfRoleFolder($rolf_data['ref_id'],false);
1318  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$real_local_roles);
1319 
1320  //group status open (aka public) or group status closed
1321  if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED)
1322  {
1323  if ($a_grpStatus == GRP_TYPE_PUBLIC)
1324  {
1325  $template_id = $this->getGrpStatusOpenTemplateId();
1326  }
1327  else
1328  {
1329  $template_id = $this->getGrpStatusClosedTemplateId();
1330  }
1331  //get defined operations from template
1332  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1333 
1334  foreach ($arr_relevantParentRoleIds as $parentRole)
1335  {
1336  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1337  {
1338  continue;
1339  }
1340 
1341  $granted_permissions = array();
1342 
1343  // Delete the linked role for the parent role
1344  // (just in case if it already exists).
1345 
1346  // Added additional check, since this operation is very dangerous.
1347  // If there is no role folder ALL parent roles are deleted.
1348  if(isset($rolf_data['child']) and $rolf_data['child'])
1349  {
1350  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1351  }
1352 
1353  // Grant permissions on the group object for
1354  // the parent role. In the foreach loop we
1355  // compute the intersection of the role
1356  // template il_grp_status_open/_closed and the
1357  // permission template of the parent role.
1358  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1359  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1360  foreach ($template_ops as $template_op)
1361  {
1362  if (in_array($template_op,$current_ops))
1363  {
1364  array_push($granted_permissions,$template_op);
1365  }
1366  }
1367  if (!empty($granted_permissions))
1368  {
1369  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1370  }
1371 
1372  // Create a linked role for the parent role and
1373  // initialize it with the intersection of
1374  // il_grp_status_open/_closed and the permission
1375  // template of the parent role
1376  $rbacadmin->copyRolePermissionIntersection(
1377  $template_id, ROLE_FOLDER_ID,
1378  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1379  $rolf_data["child"], $parentRole
1380  );
1381  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1382  }//END foreach
1383  }
1384  }
1385 
1393  public function setGroupStatus($a_status)
1394  {
1395  $this->group_status = $a_status;
1396  }
1397 
1405  public function getGroupStatus()
1406  {
1407  return $this->group_status;
1408  }
1409 
1415  function readGroupStatus()
1416  {
1417  global $rbacsystem,$rbacreview;
1418 
1419  $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
1420  $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
1421 
1422  //get Rolefolder of group
1423  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1424  //get all relevant roles
1425  $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1426 
1427  //if one global role has no permission to join the group is officially closed !
1428  foreach ($arr_globalRoles as $globalRole)
1429  {
1430  $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
1431 
1432  if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
1433  {
1434  return $this->group_status = GRP_TYPE_PUBLIC;
1435  }
1436  }
1437 
1438  return $this->group_status = GRP_TYPE_CLOSED;
1439  }
1440 
1447  function getMemberRoles($a_user_id)
1448  {
1449  global $rbacadmin, $rbacreview,$ilBench;
1450 
1451  $ilBench->start("Group", "getMemberRoles");
1452 
1453  $arr_assignedRoles = array();
1454 
1455  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
1456 
1457  $ilBench->stop("Group", "getMemberRoles");
1458 
1459  return $arr_assignedRoles;
1460  }
1461 
1468  function isAdmin($a_userId)
1469  {
1470  global $rbacreview;
1471 
1472  $grp_Roles = $this->getDefaultGroupRoles();
1473 
1474  if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
1475  {
1476  return true;
1477  }
1478  else
1479  {
1480  return false;
1481  }
1482  }
1483 
1484 
1485 
1491  function initDefaultRoles()
1492  {
1493  global $rbacadmin, $rbacreview;
1494 
1495  // create a local role folder
1496  $rfoldObj =& $this->createRoleFolder();
1497 
1498  // ADMIN ROLE
1499  // create role and assign role to rolefolder...
1500  $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
1501  $this->m_roleAdminId = $roleObj->getId();
1502 
1503  //set permission template of new local role
1504  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
1505  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
1506  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
1507 
1508  // set object permissions of group object
1509  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
1510  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
1511 
1512  // set object permissions of role folder object
1513  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
1514  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
1515 
1516  // MEMBER ROLE
1517  // create role and assign role to rolefolder...
1518  $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
1519  $this->m_roleMemberId = $roleObj->getId();
1520 
1521  //set permission template of new local role
1522  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
1523  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
1524  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
1525 
1526  // set object permissions of group object
1527  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
1528  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
1529 
1530  // set object permissions of role folder object
1531  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
1532  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
1533 
1534  unset($rfoldObj);
1535  unset($roleObj);
1536 
1537  $roles[] = $this->m_roleAdminId;
1538  $roles[] = $this->m_roleMemberId;
1539 
1540  return $roles ? $roles : array();
1541  }
1542 
1553  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1554  {
1555  global $tree;
1556 
1557  $parent_id = (int) $tree->getParentId($a_node_id);
1558 
1559  if ($parent_id != 0)
1560  {
1561  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1562  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1563  }
1564 
1565  return true;
1566  }
1567 
1568 
1569  function exportXML()
1570  {
1571  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
1572 
1573  $xml_writer = new ilGroupXMLWriter($this);
1574  $xml_writer->start();
1575 
1576  $xml = $xml_writer->getXML();
1577 
1578  $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
1579 
1580  $this->__initFileObject();
1581 
1582  $this->file_obj->addGroupDirectory();
1583  $this->file_obj->addDirectory($name);
1584  $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
1585  $this->file_obj->zipFile($name,$name.'.zip');
1586  $this->file_obj->deleteDirectory($name);
1587 
1588  return true;
1589  }
1590 
1591  function deleteExportFiles($a_files)
1592  {
1593  $this->__initFileObject();
1594 
1595  foreach($a_files as $file)
1596  {
1597  $this->file_obj->deleteFile($file);
1598  }
1599  return true;
1600  }
1601 
1603  {
1604  $this->__initFileObject();
1605 
1606  if($abs_name = $this->file_obj->getExportFile($file))
1607  {
1608  ilUtil::deliverFile($abs_name,$file);
1609  // Not reached
1610  }
1611  return false;
1612  }
1613 
1622  function _importFromXMLString($xml,$parent_id)
1623  {
1624  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
1625 
1626  $import_parser = new ilGroupXMLParser($xml,$parent_id);
1627 
1628  return $import_parser->startParsing();
1629  }
1630 
1638  function _importFromFile($file,$parent_id)
1639  {
1640  global $lng;
1641 
1642  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1643 
1644  $file_obj = new ilFileDataGroup(null);
1645  $file_obj->addImportDirectory();
1646  $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
1647  $file_obj->unpackImportFile();
1648 
1649  if(!$file_obj->validateImportFile())
1650  {
1651  return false;
1652  }
1653  return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
1654  }
1655 
1656  function _lookupIdByTitle($a_title)
1657  {
1658  global $ilDB;
1659 
1660  $query = "SELECT * FROM object_data WHERE title = ".
1661  $ilDB->quote($a_title ,'text')." AND type = 'grp'";
1662  $res = $ilDB->query($query);
1663  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1664  {
1665  return $row->obj_id;
1666  }
1667  return 0;
1668  }
1669 
1670 
1671  function _isMember($a_user_id,$a_ref_id,$a_field = '')
1672  {
1673  global $rbacreview,$ilObjDataCache,$ilDB;
1674 
1675  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1676  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1677  $user_roles = $rbacreview->assignedRoles($a_user_id);
1678 
1679  // Used for membership limitations -> check membership by given field
1680  if($a_field)
1681  {
1682  include_once './Services/User/classes/class.ilObjUser.php';
1683 
1684  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
1685  switch($a_field)
1686  {
1687  case 'login':
1688  $and = "AND login = '".$tmp_user->getLogin()."' ";
1689  break;
1690  case 'email':
1691  $and = "AND email = '".$tmp_user->getEmail()."' ";
1692  break;
1693  case 'matriculation':
1694  $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
1695  break;
1696 
1697  default:
1698  $and = "AND usr_id = '".$a_user_id."'";
1699  break;
1700  }
1701  if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
1702  {
1703  return false;
1704  }
1705  $query = "SELECT * FROM usr_data as ud ".
1706  "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
1707  $and;
1708  $res = $ilDB->query($query);
1709 
1710  return $res->numRows() ? true : false;
1711  }
1712 
1713  if (!array_intersect($local_roles,$user_roles))
1714  {
1715  return false;
1716  }
1717 
1718  return true;
1719  }
1720 
1721  function _getMembers($a_obj_id)
1722  {
1723  global $rbacreview;
1724 
1725  // get reference
1726  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1727  $ref_id = current($ref_ids);
1728 
1729  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
1730  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
1731 
1732  $users = array();
1733  foreach($local_roles as $role_id)
1734  {
1735  $users = array_merge($users,$rbacreview->assignedUsers($role_id));
1736  }
1737 
1738  return array_unique($users);
1739  }
1740 
1748  public function getViewMode($a_translate_inherit = true)
1749  {
1750  $view = (int) $this->view_mode;
1751 
1752  if(!$view)
1753  {
1754  $view = ilContainer::VIEW_DEFAULT;
1755  }
1756 
1757  if($a_translate_inherit)
1758  {
1759  $view = self::translateViewMode($this->id, $view, $this->ref_id);
1760  }
1761 
1762  return $view;
1763  }
1764 
1769  public function setViewMode($a_view_mode)
1770  {
1771  $this->view_mode = $a_view_mode;
1772  }
1773 
1778  public static function lookupViewMode($a_obj_id)
1779  {
1780  global $ilDB;
1781 
1782  $query = 'SELECT view_mode FROM grp_settings '.
1783  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1784  $res = $ilDB->query($query);
1785 
1786  $view_mode = NULL;
1787  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1788  {
1789  $view_mode = $row->view_mode;
1790  }
1791  return self::translateViewMode($a_obj_id,$view_mode);
1792  }
1793 
1801  protected static function translateViewMode($a_obj_id,$a_view_mode,$a_ref_id = null)
1802  {
1803  global $tree;
1804 
1805  if(!$a_view_mode)
1806  {
1807  $a_view_mode = ilContainer::VIEW_DEFAULT;
1808  }
1809 
1810  // view mode is inherit => check for parent course
1811  if($a_view_mode == ilContainer::VIEW_INHERIT)
1812  {
1813  if(!$a_ref_id)
1814  {
1815  $ref = ilObject::_getAllReferences($a_obj_id);
1816  $a_ref_id = end($ref);
1817  }
1818 
1819  $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1820  if(!$crs_ref)
1821  {
1823  }
1824 
1825  include_once './Modules/Course/classes/class.ilObjCourse.php';
1827 
1828  // validate course view mode
1829  if(!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1831  {
1833  }
1834 
1835  return $view_mode;
1836  }
1837 
1838  return $a_view_mode;
1839  }
1840 
1845  function addAdditionalSubItemInformation(&$a_item_data)
1846  {
1847  include_once './Services/Object/classes/class.ilObjectActivation.php';
1849  }
1850 
1851  // Private / Protected
1852  function __initFileObject()
1853  {
1854  if($this->file_obj)
1855  {
1856  return $this->file_obj;
1857  }
1858  else
1859  {
1860  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1861 
1862  return $this->file_obj = new ilFileDataGroup($this);
1863  }
1864  }
1865 
1866  function getMessage()
1867  {
1868  return $this->message;
1869  }
1870  function setMessage($a_message)
1871  {
1872  $this->message = $a_message;
1873  }
1874  function appendMessage($a_message)
1875  {
1876  if($this->getMessage())
1877  {
1878  $this->message .= "<br /> ";
1879  }
1880  $this->message .= $a_message;
1881  }
1882 
1890  protected function prepareAppointments($a_mode = 'create')
1891  {
1892  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1893 
1894  switch($a_mode)
1895  {
1896  case 'create':
1897  case 'update':
1898  if($this->isRegistrationUnlimited())
1899  {
1900  return array();
1901  }
1902  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1903  $app->setTitle($this->getTitle());
1904  $app->setSubtitle('grp_cal_reg_start');
1905  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1906  $app->setDescription($this->getLongDescription());
1907  $app->setStart($this->getRegistrationStart());
1908  $apps[] = $app;
1909 
1910  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1911  $app->setTitle($this->getTitle());
1912  $app->setSubtitle('grp_cal_reg_end');
1913  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1914  $app->setDescription($this->getLongDescription());
1915  $app->setStart($this->getRegistrationEnd());
1916  $apps[] = $app;
1917 
1918  return $apps;
1919 
1920  case 'delete':
1921  // Nothing to do: The category and all assigned appointments will be deleted.
1922  return array();
1923  }
1924  }
1925 
1933  protected function initParticipants()
1934  {
1935  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1936  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1937  }
1938 
1943  public static function lookupObjectsByCode($a_code)
1944  {
1945  global $ilDB;
1946 
1947  $query = "SELECT obj_id FROM grp_settings ".
1948  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1949  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1950  $res = $ilDB->query($query);
1951 
1952  $obj_ids = array();
1953  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1954  {
1955  $obj_ids[] = $row->obj_id;
1956  }
1957  return $obj_ids;
1958  }
1959 
1966  public function register($a_user_id,$a_role = IL_GRP_MEMBER, $a_force_registration = false)
1967  {
1968  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1969  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1971 
1972  if($part->isAssigned($a_user_id))
1973  {
1974  return true;
1975  }
1976 
1977  if(!$a_force_registration)
1978  {
1979  // Availability
1980  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1982  {
1983  $this->lng->loadLanguageModule('crs');
1984  throw new ilMembershipRegistrationException('456',$this->getRefId());
1985  }
1986  // Max members
1987  if(!$this->isRegistrationUnlimited())
1988  {
1989  $free = max(0,$this->getMaxMembers() - $part->getCountMembers());
1990  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
1991  $waiting_list = new ilGroupWaitingList($this->getId());
1992  if($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
1993  {
1994  throw new ilMembershipRegistrationException('123',$this->getRefId());
1995  }
1996  }
1997  }
1998 
1999  $part->add($a_user_id,$a_role);
2000  $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2001  return true;
2002  }
2003 
2004 } //END class.ilObjGroup
2005 ?>