ILIAS  eassessment Revision 61809
 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 
91 
92  public $members_obj;
93 
94 
98  var $file_obj = null;
99 
101 
103 
105 
112  public function __construct($a_id = 0,$a_call_by_reference = true)
113  {
114  global $tree;
115 
116  $this->tree =& $tree;
117 
118  $this->type = "grp";
119  $this->ilObject($a_id,$a_call_by_reference);
120  $this->setRegisterMode(true); // ???
121  }
122 
128  public static function lookupGroupTye($a_id)
129  {
130  global $ilDB;
131 
132  $query = "SELECT grp_type FROM grp_settings ".
133  "WHERE obj_id = ".$ilDB->quote($a_id,'integer');
134  $res = $ilDB->query($query);
135  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
136  {
137  return $row->grp_type;
138  }
139  return GRP_TYPE_UNKNOWN;
140  }
141 
142  // Setter/Getter
150  public function setInformation($a_information)
151  {
152  $this->information = $a_information;
153  }
154 
162  public function getInformation()
163  {
164  return $this->information;
165  }
166 
173  public function setGroupType($a_type)
174  {
175  $this->group_type = $a_type;
176  }
177 
184  public function getGroupType()
185  {
186  return $this->group_type;
187  }
188 
196  public function isGroupTypeModified($a_old_type)
197  {
198  if($a_old_type == GRP_TYPE_UNKNOWN)
199  {
200  $group_type = $this->readGroupStatus();
201  }
202  else
203  {
204  $group_type = $a_old_type;
205  }
206  return $group_type != $this->getGroupType();
207  }
208 
216  public function setRegistrationType($a_type)
217  {
218  $this->reg_type = $a_type;
219  }
220 
227  public function getRegistrationType()
228  {
229  return $this->reg_type;
230  }
231 
238  public function isRegistrationEnabled()
239  {
241  }
242 
250  public function enableUnlimitedRegistration($a_status)
251  {
252  $this->reg_unlimited = $a_status;
253  }
254 
261  public function isRegistrationUnlimited()
262  {
263  return $this->reg_unlimited;
264  }
265 
273  public function setRegistrationStart($a_start)
274  {
275  $this->reg_start = $a_start;
276  }
277 
284  public function getRegistrationStart()
285  {
286  return $this->reg_start ? $this->reg_start : $this->reg_start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
287  }
288 
289 
297  public function setRegistrationEnd($a_end)
298  {
299  $this->reg_end = $a_end;
300  }
301 
308  public function getRegistrationEnd()
309  {
310  return $this->reg_end ? $this->reg_end : $this->reg_end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
311  }
312 
319  public function setPassword($a_pass)
320  {
321  $this->reg_password = $a_pass;
322  }
323 
330  public function getPassword()
331  {
332  return $this->reg_password;
333  }
334 
342  public function enableMembershipLimitation($a_status)
343  {
344  $this->reg_membership_limitation = $a_status;
345  }
346 
353  public function isMembershipLimited()
354  {
355  return (bool) $this->reg_membership_limitation;
356  }
357 
364  public function setMaxMembers($a_max)
365  {
366  $this->reg_max_members = $a_max;
367  }
368 
375  public function getMaxMembers()
376  {
377  return $this->reg_max_members;
378  }
379 
387  public function enableWaitingList($a_status)
388  {
389  $this->waiting_list = $a_status;
390  }
391 
399  public function isWaitingListEnabled()
400  {
401  return $this->waiting_list;
402  }
403 
409  function setLatitude($a_latitude)
410  {
411  $this->latitude = $a_latitude;
412  }
413 
419  function getLatitude()
420  {
421  return $this->latitude;
422  }
423 
429  function setLongitude($a_longitude)
430  {
431  $this->longitude = $a_longitude;
432  }
433 
439  function getLongitude()
440  {
441  return $this->longitude;
442  }
443 
449  function setLocationZoom($a_locationzoom)
450  {
451  $this->locationzoom = $a_locationzoom;
452  }
453 
459  function getLocationZoom()
460  {
461  return $this->locationzoom;
462  }
463 
469  function setEnableGroupMap($a_enablemap)
470  {
471  $this->enablemap = $a_enablemap;
472  }
473 
479  function getEnableGroupMap()
480  {
481  return (bool) $this->enablemap;
482  }
483 
488  public function getRegistrationAccessCode()
489  {
490  return $this->reg_access_code;
491  }
492 
498  public function setRegistrationAccessCode($a_code)
499  {
500  $this->reg_access_code = $a_code;
501  }
502 
508  {
509  return (bool) $this->reg_access_code_enabled;
510  }
511 
517  public function enableRegistrationAccessCode($a_status)
518  {
519  $this->reg_access_code_enabled = $a_status;
520  }
521 
522 
523 
530  public function validate()
531  {
532  global $ilErr;
533 
534  if(!$this->getTitle())
535  {
536  $this->title = '';
537  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
538  }
539  if(!$this->getGroupType())
540  {
541  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_GROUP_TYPE));
542  }
543  if($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword()))
544  {
545  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
546  }
548  {
549  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
550  }
551  if($this->isMembershipLimited() and (!is_numeric($this->getMaxMembers()) or $this->getMaxMembers() <= 0))
552  {
553  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
554  }
555  return strlen($ilErr->getMessage()) == 0;
556  }
557 
558 
559 
560 
564  function create()
565  {
566  global $ilDB,$ilAppEventHandler;
567 
568  if(!parent::create())
569  {
570  return false;
571  }
572 
573  $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled,".
574  "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit,".
575  "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac) ".
576  "VALUES(".
577  $ilDB->quote($this->getId() ,'integer').", ".
578  $ilDB->quote($this->getInformation() ,'text').", ".
579  $ilDB->quote((int) $this->getGroupType() ,'integer').", ".
580  $ilDB->quote($this->getRegistrationType() ,'integer').", ".
581  $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0) ,'integer').", ".
582  $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0) ,'integer').", ".
583  $ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
584  $ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
585  $ilDB->quote($this->getPassword() ,'text').", ".
586  $ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
587  $ilDB->quote($this->getMaxMembers() ,'integer').", ".
588  $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
589  $ilDB->quote($this->getLatitude() ,'text').", ".
590  $ilDB->quote($this->getLongitude() ,'text').", ".
591  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
592  $ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
593  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
594  $ilDB->quote($this->getRegistrationAccessCode(),'text').' '.
595  ")";
596  $res = $ilDB->manipulate($query);
597 
598  $ilAppEventHandler->raise('Modules/Group',
599  'create',
600  array('object' => $this,
601  'obj_id' => $this->getId(),
602  'appointments' => $this->prepareAppointments('create')));
603 
604  return $this->getId();
605  }
606 
610  function update()
611  {
612  global $ilDB,$ilAppEventHandler;
613 
614  if (!parent::update())
615  {
616  return false;
617  }
618 
619  $query = "UPDATE grp_settings ".
620  "SET information = ".$ilDB->quote($this->getInformation() ,'text').", ".
621  "grp_type = ".$ilDB->quote((int) $this->getGroupType() ,'integer').", ".
622  "registration_type = ".$ilDB->quote($this->getRegistrationType() ,'integer').", ".
623  "registration_enabled = ".$ilDB->quote($this->isRegistrationEnabled() ? 1 : 0 ,'integer').", ".
624  "registration_unlimited = ".$ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0 ,'integer').", ".
625  "registration_start = ".$ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
626  "registration_end = ".$ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
627  "registration_password = ".$ilDB->quote($this->getPassword() ,'text').", ".
628 // "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
629  "registration_mem_limit = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
630  "registration_max_members = ".$ilDB->quote($this->getMaxMembers() ,'integer').", ".
631  "waiting_list = ".$ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
632  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
633  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
634  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
635  "enablemap = ".$ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
636  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
637  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').' '.
638  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer')." ";
639  $res = $ilDB->manipulate($query);
640 
641  $ilAppEventHandler->raise('Modules/Group',
642  'update',
643  array('object' => $this,
644  'obj_id' => $this->getId(),
645  'appointments' => $this->prepareAppointments('update')));
646 
647 
648  return true;
649  }
650 
657  public function delete()
658  {
659  global $ilDB,$ilAppEventHandler;
660 
661  // always call parent delete function first!!
662  if (!parent::delete())
663  {
664  return false;
665  }
666 
667  $query = "DELETE FROM grp_settings ".
668  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
669  $res = $ilDB->manipulate($query);
670 
671  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
673 
674  $ilAppEventHandler->raise('Modules/Group',
675  'delete',
676  array('object' => $this,
677  'obj_id' => $this->getId(),
678  'appointments' => $this->prepareAppointments('delete')));
679 
680 
681  return true;
682  }
683 
684 
688  function read()
689  {
690  global $ilDB;
691 
692  parent::read();
693 
694  $query = "SELECT * FROM grp_settings ".
695  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
696 
697  $res = $ilDB->query($query);
698  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
699  {
700  $this->setInformation($row->information);
701  $this->setGroupType($row->grp_type);
702  $this->setRegistrationType($row->registration_type);
703  $this->enableUnlimitedRegistration($row->registration_unlimited);
704  $this->setRegistrationStart(new ilDateTime($row->registration_start,IL_CAL_DATETIME));
705  $this->setRegistrationEnd(new ilDateTime($row->registration_end,IL_CAL_DATETIME));
706  $this->setPassword($row->registration_password);
707  $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
708  $this->setMaxMembers($row->registration_max_members);
709  $this->enableWaitingList($row->waiting_list);
710  $this->setLatitude($row->latitude);
711  $this->setLongitude($row->longitude);
712  $this->setLocationZoom($row->location_zoom);
713  $this->setEnableGroupMap($row->enablemap);
714  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
715  $this->setRegistrationAccessCode($row->reg_ac);
716  }
717  $this->initParticipants();
718 
719  // Inherit order type from parent course (if exists)
720  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
722  }
723 
732  public function cloneObject($a_target_id,$a_copy_id = 0)
733  {
734  global $ilDB,$ilUser;
735 
736  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
737  $new_obj->setGroupType($this->getGroupType());
738  $new_obj->initGroupStatus($this->getGroupType() ? $this->getGroupType() : $this->readGroupStatus());
739 
740  $this->cloneAutoGeneratedRoles($new_obj);
741 
742  $new_obj->setRegistrationType($this->getRegistrationType());
743  $new_obj->setInformation($this->getInformation());
744  $new_obj->setRegistrationStart($this->getRegistrationStart());
745  $new_obj->setRegistrationEnd($this->getRegistrationEnd());
746  $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
747  $new_obj->setPassword($this->getPassword());
748  $new_obj->enableMembershipLimitation($this->isMembershipLimited());
749  $new_obj->setMaxMembers($this->getMaxMembers());
750  $new_obj->enableWaitingList($this->isWaitingListEnabled());
751 
752  // map
753  $new_obj->setLatitude($this->getLatitude());
754  $new_obj->setLongitude($this->getLongitude());
755  $new_obj->setLocationZoom($this->getLocationZoom());
756  $new_obj->setEnableGroupMap($this->getEnableGroupMap());
757  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
758  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
759  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
760 
761  $new_obj->update();
762 
763  global $ilLog;
764  $ilLog->write(__METHOD__.': Starting add user');
765 
766  // Assign user as admin
767  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
768  $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
769  $part->add($ilUser->getId(),IL_GRP_ADMIN);
770  $part->updateNotification($ilUser->getId(),1);
771 
772  // Copy learning progress settings
773  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
774  $obj_settings = new ilLPObjSettings($this->getId());
775  $obj_settings->cloneSettings($new_obj->getId());
776  unset($obj_settings);
777 
778  // clone icons
779  $new_obj->saveIcons($this->getBigIconPath(),
780  $this->getSmallIconPath(),
781  $this->getTinyIconPath());
782 
783  return $new_obj;
784  }
785 
794  public function cloneDependencies($a_target_id,$a_copy_id)
795  {
796  global $tree;
797 
798  parent::cloneDependencies($a_target_id,$a_copy_id);
799 
800  if($course_ref_id = $tree->checkForParentType($this->getRefId(),'crs') and
801  $new_course_ref_id = $tree->checkForParentType($a_target_id,'crs'))
802  {
803  include_once('Modules/Course/classes/class.ilCourseItems.php');
804  $course_obj =& ilObjectFactory::getInstanceByRefId($course_ref_id,false);
805  $course_items = new ilCourseItems($course_obj->getRefId(),$this->getRefId());
806  $course_items->cloneDependencies($a_target_id,$a_copy_id);
807  }
808 
809  include_once('Services/Tracking/classes/class.ilLPCollections.php');
810  $lp_collection = new ilLPCollections($this->getId());
811  $lp_collection->cloneCollections($a_target_id,$a_copy_id);
812 
813  return true;
814  }
815 
823  public function cloneAutoGeneratedRoles($new_obj)
824  {
825  global $ilLog,$rbacadmin,$rbacreview;
826 
827  $admin = $this->getDefaultAdminRole();
828  $new_admin = $new_obj->getDefaultAdminRole();
829  $source_rolf = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
830  $target_rolf = $rbacreview->getRoleFolderIdOfObject($new_obj->getRefId());
831 
832  if(!$admin || !$new_admin || !$source_rolf || !$target_rolf)
833  {
834  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_admin');
835  }
836  $rbacadmin->copyRolePermissions($admin,$source_rolf,$target_rolf,$new_admin,true);
837  $ilLog->write(__METHOD__.' : Finished copying of role il_grp_admin.');
838 
839  $member = $this->getDefaultMemberRole();
840  $new_member = $new_obj->getDefaultMemberRole();
841  if(!$member || !$new_member)
842  {
843  $ilLog->write(__METHOD__.' : Error cloning auto generated role: il_grp_member');
844  }
845  $rbacadmin->copyRolePermissions($member,$source_rolf,$target_rolf,$new_member,true);
846  $ilLog->write(__METHOD__.' : Finished copying of role grp_member.');
847  }
848 
849 
855  function join($a_user_id, $a_mem_role="")
856  {
857  global $rbacadmin;
858 
859  if (is_array($a_mem_role))
860  {
861  foreach ($a_mem_role as $role)
862  {
863  $rbacadmin->assignUser($role,$a_user_id, false);
864  }
865  }
866  else
867  {
868  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
869  }
870 
871  return true;
872  }
873 
879  {
880  $local_group_Roles = $this->getLocalGroupRoles();
881 
882  return $local_group_Roles["il_grp_member_".$this->getRefId()];
883  }
884 
890  {
891  $local_group_Roles = $this->getLocalGroupRoles();
892 
893  return $local_group_Roles["il_grp_admin_".$this->getRefId()];
894  }
895 
902  function addMember($a_user_id, $a_mem_role)
903  {
904  global $rbacadmin;
905 
906  if (isset($a_user_id) && isset($a_mem_role) )
907  {
908  $this->join($a_user_id,$a_mem_role);
909  return true;
910  }
911  else
912  {
913  $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
914  return false;
915  }
916  }
917 
918 
925  function leaveGroup()
926  {
927  global $rbacadmin, $rbacreview;
928 
929  $member_ids = $this->getGroupMemberIds();
930 
931  if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
932  {
933  return 2;
934  }
935  else
936  {
937  if (!$this->isAdmin($this->ilias->account->getId()))
938  {
939  $this->leave($this->ilias->account->getId());
940  $member = new ilObjUser($this->ilias->account->getId());
941  $member->dropDesktopItem($this->getRefId(), "grp");
942 
943  return 0;
944  }
945  else if (count($this->getGroupAdminIds()) == 1)
946  {
947  return 1;
948  }
949  }
950  }
951 
956  function leave($a_user_id)
957  {
958  global $rbacadmin;
959 
960  $arr_groupRoles = $this->getMemberRoles($a_user_id);
961 
962  if (is_array($arr_groupRoles))
963  {
964  foreach ($arr_groupRoles as $groupRole)
965  {
966  $rbacadmin->deassignUser($groupRole, $a_user_id);
967  }
968  }
969  else
970  {
971  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
972  }
973 
974  return true;
975  }
976 
983  function getGroupMemberIds()
984  {
985  global $rbacadmin, $rbacreview;
986 
987  $usr_arr= array();
988 
989  $rol = $this->getLocalGroupRoles();
990 
991  foreach ($rol as $value)
992  {
993  foreach ($rbacreview->assignedUsers($value) as $member_id)
994  {
995  array_push($usr_arr,$member_id);
996  }
997  }
998 
999  $mem_arr = array_unique($usr_arr);
1000 
1001  return $mem_arr ? $mem_arr : array();
1002  }
1003 
1011  function getGroupMemberData($a_mem_ids, $active = 1)
1012  {
1013  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
1014 
1015  $usr_arr= array();
1016 
1017  $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
1018  "FROM usr_data ".
1019  "WHERE usr_id IN (".implode(',',ilUtil::quoteArray($a_mem_ids)).") ";
1020 
1021  if (is_numeric($active) && $active > -1)
1022  $q .= "AND active = '$active'";
1023 
1024  $q .= 'ORDER BY lastname,firstname';
1025 
1026  $r = $ilDB->query($q);
1027 
1028  while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
1029  {
1030  $mem_arr[] = array("id" => $row->usr_id,
1031  "login" => $row->login,
1032  "firstname" => $row->firstname,
1033  "lastname" => $row->lastname,
1034  "last_login" => $row->last_login
1035  );
1036  }
1037 
1038  return $mem_arr ? $mem_arr : array();
1039  }
1040 
1041  function getCountMembers()
1042  {
1043  return count($this->getGroupMemberIds());
1044  }
1045 
1052  function getGroupAdminIds($a_grpId = "")
1053  {
1054  global $rbacreview;
1055 
1056  if (!empty($a_grpId))
1057  {
1058  $grp_id = $a_grpId;
1059  }
1060  else
1061  {
1062  $grp_id = $this->getRefId();
1063  }
1064 
1065  $usr_arr = array();
1066  $roles = $this->getDefaultGroupRoles($this->getRefId());
1067 
1068  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
1069  {
1070  array_push($usr_arr,$member_id);
1071  }
1072 
1073  return $usr_arr;
1074  }
1075 
1081  function getDefaultGroupRoles($a_grp_id="")
1082  {
1083  global $rbacadmin, $rbacreview;
1084 
1085  if (strlen($a_grp_id) > 0)
1086  {
1087  $grp_id = $a_grp_id;
1088  }
1089  else
1090  {
1091  $grp_id = $this->getRefId();
1092  }
1093 
1094  $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
1095  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1096 
1097  foreach ($role_arr as $role_id)
1098  {
1099  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1100 
1101  $grp_Member ="il_grp_member_".$grp_id;
1102  $grp_Admin ="il_grp_admin_".$grp_id;
1103 
1104  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1105  {
1106  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1107  }
1108 
1109  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1110  {
1111  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1112  }
1113  }
1114 
1115  return $arr_grpDefaultRoles;
1116  }
1117 
1124  function getLocalGroupRoles($a_translate = false)
1125  {
1126  global $rbacadmin,$rbacreview;
1127 
1128  if (empty($this->local_roles))
1129  {
1130  $this->local_roles = array();
1131  $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
1132  $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
1133 
1134  foreach ($role_arr as $role_id)
1135  {
1136  if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
1137  {
1138  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1139 
1140  if ($a_translate)
1141  {
1142  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1143  }
1144  else
1145  {
1146  $role_name = $role_Obj->getTitle();
1147  }
1148 
1149  $this->local_roles[$role_name] = $role_Obj->getId();
1150  }
1151  }
1152  }
1153 
1154  return $this->local_roles;
1155  }
1156 
1163  {
1164  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1165  $res = $this->ilias->db->query($q);
1166  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1167 
1168  return $row["obj_id"];
1169  }
1170 
1177  {
1178  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1179  $res = $this->ilias->db->query($q);
1180  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1181 
1182  return $row["obj_id"];
1183  }
1184 
1185 
1186 
1196  public function updateGroupType()
1197  {
1198  global $tree,$rbacreview,$rbacadmin;
1199 
1200  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1201  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1202  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1203 
1204  // Delete parent roles with stopped inheritance
1205  foreach($real_parent_roles as $role_id)
1206  {
1207  // Delete local role
1208  if(isset($rolf_data['child']) and $rolf_data['child'])
1209  {
1210  $rbacadmin->deleteLocalRole($role_id,$rolf_data['child']);
1211  }
1212  }
1213  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1214  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1215 
1216  switch($this->getGroupType())
1217  {
1218  case GRP_TYPE_PUBLIC:
1219  $template_id = $this->getGrpStatusOpenTemplateId();
1220  break;
1221 
1222  case GRP_TYPE_CLOSED:
1223  $template_id = $this->getGrpStatusClosedTemplateId();
1224  break;
1225  }
1226 
1227  $first = true;
1228  foreach($tree->getFilteredSubTree($this->getRefId(),array('rolf','grp')) as $subnode)
1229  {
1230  // Read template operations
1231  $template_ops = $rbacreview->getOperationsOfRole($template_id,$subnode['type'], ROLE_FOLDER_ID);
1232 
1233  $rolf_data = $rbacreview->getRoleFolderOfObject($subnode['child']);
1234 
1235 
1236  // for all parent roles
1237  foreach($real_parent_roles as $role_id)
1238  {
1239  if($rbacreview->isProtected($parent_roles[$role_id]['parent'],$role_id))
1240  {
1241  continue;
1242  }
1243 
1244  // Delete local role
1245  if(isset($rolf_data['child']) and $rolf_data['child'])
1246  {
1247  $rbacadmin->deleteLocalRole($role_id,$rolf_data['child']);
1248  }
1249 
1250  // Store current operations
1251  $current_ops = $rbacreview->getOperationsOfRole($role_id,$subnode['type'],$parent_roles[$role_id]['parent']);
1252 
1253  // Revoke permissions
1254  $rbacadmin->revokePermission($subnode['child'],$role_id);
1255 
1256  // Grant permissions
1257  $granted = array();
1258  foreach($template_ops as $operation)
1259  {
1260  if(in_array($operation,$current_ops))
1261  {
1262  $granted[] = $operation;
1263  }
1264  }
1265  if($granted)
1266  {
1267  $rbacadmin->grantPermission($role_id, $granted,$subnode['child']);
1268  }
1269 
1270  if($first)
1271  {
1272  // This is the group itself
1273  $rbacadmin->copyRolePermissionIntersection(
1274  $template_id, ROLE_FOLDER_ID,
1275  $role_id, $parent_roles[$role_id]['parent'],
1276  $rolf_data["child"],$role_id);
1277  $rbacadmin->assignRoleToFolder($role_id,$rolf_data["child"],"n");
1278 
1279  }
1280  }
1281  $first = false;
1282  }
1283  }
1284 
1302  function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1303  {
1304  global $rbacadmin, $rbacreview, $rbacsystem;
1305 
1306  //get Rolefolder of group
1307  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1308 
1309  //define all relevant roles that rights are needed to be changed
1310  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1311 
1312  $real_local_roles = $rbacreview->getRolesOfRoleFolder($rolf_data['ref_id'],false);
1313  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$real_local_roles);
1314 
1315  //group status open (aka public) or group status closed
1316  if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED)
1317  {
1318  if ($a_grpStatus == GRP_TYPE_PUBLIC)
1319  {
1320  $template_id = $this->getGrpStatusOpenTemplateId();
1321  }
1322  else
1323  {
1324  $template_id = $this->getGrpStatusClosedTemplateId();
1325  }
1326  //get defined operations from template
1327  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1328 
1329  foreach ($arr_relevantParentRoleIds as $parentRole)
1330  {
1331  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1332  {
1333  continue;
1334  }
1335 
1336  $granted_permissions = array();
1337 
1338  // Delete the linked role for the parent role
1339  // (just in case if it already exists).
1340 
1341  // Added additional check, since this operation is very dangerous.
1342  // If there is no role folder ALL parent roles are deleted.
1343  if(isset($rolf_data['child']) and $rolf_data['child'])
1344  {
1345  $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
1346  }
1347 
1348  // Grant permissions on the group object for
1349  // the parent role. In the foreach loop we
1350  // compute the intersection of the role
1351  // template il_grp_status_open/_closed and the
1352  // permission template of the parent role.
1353  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1354  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1355  foreach ($template_ops as $template_op)
1356  {
1357  if (in_array($template_op,$current_ops))
1358  {
1359  array_push($granted_permissions,$template_op);
1360  }
1361  }
1362  if (!empty($granted_permissions))
1363  {
1364  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1365  }
1366 
1367  // Create a linked role for the parent role and
1368  // initialize it with the intersection of
1369  // il_grp_status_open/_closed and the permission
1370  // template of the parent role
1371  $rbacadmin->copyRolePermissionIntersection(
1372  $template_id, ROLE_FOLDER_ID,
1373  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1374  $rolf_data["child"], $parentRole
1375  );
1376  $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
1377  }//END foreach
1378  }
1379  }
1380 
1388  public function setGroupStatus($a_status)
1389  {
1390  $this->group_status = $a_status;
1391  }
1392 
1400  public function getGroupStatus()
1401  {
1402  return $this->group_status;
1403  }
1404 
1410  function readGroupStatus()
1411  {
1412  global $rbacsystem,$rbacreview;
1413 
1414  $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
1415  $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
1416 
1417  //get Rolefolder of group
1418  $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
1419  //get all relevant roles
1420  $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1421 
1422  //if one global role has no permission to join the group is officially closed !
1423  foreach ($arr_globalRoles as $globalRole)
1424  {
1425  $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
1426 
1427  if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
1428  {
1429  return $this->group_status = GRP_TYPE_PUBLIC;
1430  }
1431  }
1432 
1433  return $this->group_status = GRP_TYPE_CLOSED;
1434  }
1435 
1442  function getMemberRoles($a_user_id)
1443  {
1444  global $rbacadmin, $rbacreview,$ilBench;
1445 
1446  $ilBench->start("Group", "getMemberRoles");
1447 
1448  $arr_assignedRoles = array();
1449 
1450  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
1451 
1452  $ilBench->stop("Group", "getMemberRoles");
1453 
1454  return $arr_assignedRoles;
1455  }
1456 
1463  function isAdmin($a_userId)
1464  {
1465  global $rbacreview;
1466 
1467  $grp_Roles = $this->getDefaultGroupRoles();
1468 
1469  if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
1470  {
1471  return true;
1472  }
1473  else
1474  {
1475  return false;
1476  }
1477  }
1478 
1479 
1480 
1486  function initDefaultRoles()
1487  {
1488  global $rbacadmin, $rbacreview;
1489 
1490  // create a local role folder
1491  $rfoldObj =& $this->createRoleFolder();
1492 
1493  // ADMIN ROLE
1494  // create role and assign role to rolefolder...
1495  $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
1496  $this->m_roleAdminId = $roleObj->getId();
1497 
1498  //set permission template of new local role
1499  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
1500  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
1501  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
1502 
1503  // set object permissions of group object
1504  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
1505  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
1506 
1507  // set object permissions of role folder object
1508  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
1509  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
1510 
1511  // MEMBER ROLE
1512  // create role and assign role to rolefolder...
1513  $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
1514  $this->m_roleMemberId = $roleObj->getId();
1515 
1516  //set permission template of new local role
1517  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
1518  $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
1519  $rbacadmin->copyRoleTemplatePermissions($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
1520 
1521  // set object permissions of group object
1522  $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
1523  $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
1524 
1525  // set object permissions of role folder object
1526  //$ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"rolf",$rfoldObj->getRefId());
1527  //$rbacadmin->grantPermission($roleObj->getId(),$ops,$rfoldObj->getRefId());
1528 
1529  unset($rfoldObj);
1530  unset($roleObj);
1531 
1532  $roles[] = $this->m_roleAdminId;
1533  $roles[] = $this->m_roleMemberId;
1534 
1535  return $roles ? $roles : array();
1536  }
1537 
1548  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1549  {
1550  global $tree;
1551 
1552  $parent_id = (int) $tree->getParentId($a_node_id);
1553 
1554  if ($parent_id != 0)
1555  {
1556  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1557  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1558  }
1559 
1560  return true;
1561  }
1562 
1563 
1564  function exportXML()
1565  {
1566  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
1567 
1568  $xml_writer = new ilGroupXMLWriter($this);
1569  $xml_writer->start();
1570 
1571  $xml = $xml_writer->getXML();
1572 
1573  $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
1574 
1575  $this->__initFileObject();
1576 
1577  $this->file_obj->addGroupDirectory();
1578  $this->file_obj->addDirectory($name);
1579  $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
1580  $this->file_obj->zipFile($name,$name.'.zip');
1581  $this->file_obj->deleteDirectory($name);
1582 
1583  return true;
1584  }
1585 
1586  function deleteExportFiles($a_files)
1587  {
1588  $this->__initFileObject();
1589 
1590  foreach($a_files as $file)
1591  {
1592  $this->file_obj->deleteFile($file);
1593  }
1594  return true;
1595  }
1596 
1598  {
1599  $this->__initFileObject();
1600 
1601  if($abs_name = $this->file_obj->getExportFile($file))
1602  {
1603  ilUtil::deliverFile($abs_name,$file);
1604  // Not reached
1605  }
1606  return false;
1607  }
1608 
1617  function _importFromXMLString($xml,$parent_id)
1618  {
1619  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
1620 
1621  $import_parser = new ilGroupXMLParser($xml,$parent_id);
1622 
1623  return $import_parser->startParsing();
1624  }
1625 
1633  function _importFromFile($file,$parent_id)
1634  {
1635  global $lng;
1636 
1637  include_once 'classes/class.ilFileDataGroup.php';
1638 
1639  $file_obj = new ilFileDataGroup(null);
1640  $file_obj->addImportDirectory();
1641  $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
1642  $file_obj->unpackImportFile();
1643 
1644  if(!$file_obj->validateImportFile())
1645  {
1646  return false;
1647  }
1648  return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
1649  }
1650 
1659  function _getLinkToObject($a_id)
1660  {
1661  return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjgroupgui","");
1662  }
1663 
1664  function _lookupIdByTitle($a_title)
1665  {
1666  global $ilDB;
1667 
1668  $query = "SELECT * FROM object_data WHERE title = ".
1669  $ilDB->quote($a_title ,'text')." AND type = 'grp'";
1670  $res = $ilDB->query($query);
1671  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1672  {
1673  return $row->obj_id;
1674  }
1675  return 0;
1676  }
1677 
1678 
1679  function _isMember($a_user_id,$a_ref_id,$a_field = '')
1680  {
1681  global $rbacreview,$ilObjDataCache,$ilDB;
1682 
1683  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
1684  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
1685  $user_roles = $rbacreview->assignedRoles($a_user_id);
1686 
1687  // Used for membership limitations -> check membership by given field
1688  if($a_field)
1689  {
1690  include_once './Services/User/classes/class.ilObjUser.php';
1691 
1692  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
1693  switch($a_field)
1694  {
1695  case 'login':
1696  $and = "AND login = '".$tmp_user->getLogin()."' ";
1697  break;
1698  case 'email':
1699  $and = "AND email = '".$tmp_user->getEmail()."' ";
1700  break;
1701  case 'matriculation':
1702  $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
1703  break;
1704 
1705  default:
1706  $and = "AND usr_id = '".$a_user_id."'";
1707  break;
1708  }
1709  if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
1710  {
1711  return false;
1712  }
1713  $query = "SELECT * FROM usr_data as ud ".
1714  "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
1715  $and;
1716  $res = $ilDB->query($query);
1717 
1718  return $res->numRows() ? true : false;
1719  }
1720 
1721  if (!array_intersect($local_roles,$user_roles))
1722  {
1723  return false;
1724  }
1725 
1726  return true;
1727  }
1728 
1729  function _getMembers($a_obj_id)
1730  {
1731  global $rbacreview;
1732 
1733  // get reference
1734  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1735  $ref_id = current($ref_ids);
1736 
1737  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
1738  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
1739 
1740  $users = array();
1741  foreach($local_roles as $role_id)
1742  {
1743  $users = array_merge($users,$rbacreview->assignedUsers($role_id));
1744  }
1745 
1746  return array_unique($users);
1747  }
1748 
1755  public function getViewMode()
1756  {
1757  global $tree;
1758 
1759  // default: by type
1760  $view = ilContainer::VIEW_BY_TYPE;
1761 
1762  if ($course_ref_id = $tree->checkForParentType($this->ref_id,'crs'))
1763  {
1764  include_once("./Modules/Course/classes/class.ilObjCourse.php");
1765  $view_mode = ilObjCourse::_lookupViewMode(
1766  ilObject::_lookupObjId($course_ref_id));
1767  if ($view_mode == ilContainer::VIEW_SESSIONS ||
1768  $view_mode == ilContainer::VIEW_BY_TYPE ||
1769  $view_mode == ilContainer::VIEW_SIMPLE)
1770  {
1771  $view = $view_mode;
1772  }
1773  }
1774  return $view;
1775  }
1776 
1781  function addAdditionalSubItemInformation(&$a_item_data)
1782  {
1783  global $tree;
1784 
1785  static $items = null;
1786 
1787  if(!is_object($items[$this->getRefId()]))
1788  {
1789  if ($course_ref_id = $tree->checkForParentType($this->getRefId(),'crs'))
1790  {
1791  include_once("./Modules/Course/classes/class.ilObjCourse.php");
1792  include_once("./Modules/Course/classes/class.ilCourseItems.php");
1793  $course_obj = new ilObjCourse($course_ref_id);
1794  $items[$this->getRefId()] = new ilCourseItems($course_obj->getRefId(), $this->getRefId());
1795  }
1796  }
1797  if(is_object($items[$this->getRefId()]))
1798  {
1799  $items[$this->getRefId()]->addAdditionalSubItemInformation($a_item_data);
1800  }
1801  }
1802 
1803 
1804  // Private / Protected
1805  function __initFileObject()
1806  {
1807  if($this->file_obj)
1808  {
1809  return $this->file_obj;
1810  }
1811  else
1812  {
1813  include_once 'classes/class.ilFileDataGroup.php';
1814 
1815  return $this->file_obj = new ilFileDataGroup($this);
1816  }
1817  }
1818 
1819  function getMessage()
1820  {
1821  return $this->message;
1822  }
1823  function setMessage($a_message)
1824  {
1825  $this->message = $a_message;
1826  }
1827  function appendMessage($a_message)
1828  {
1829  if($this->getMessage())
1830  {
1831  $this->message .= "<br /> ";
1832  }
1833  $this->message .= $a_message;
1834  }
1835 
1843  protected function prepareAppointments($a_mode = 'create')
1844  {
1845  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1846 
1847  switch($a_mode)
1848  {
1849  case 'create':
1850  case 'update':
1851  if($this->isRegistrationUnlimited())
1852  {
1853  return array();
1854  }
1855  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1856  $app->setTitle($this->getTitle());
1857  $app->setSubtitle('grp_cal_reg_start');
1858  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1859  $app->setDescription($this->getLongDescription());
1860  $app->setStart($this->getRegistrationStart());
1861  $apps[] = $app;
1862 
1863  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1864  $app->setTitle($this->getTitle());
1865  $app->setSubtitle('grp_cal_reg_end');
1866  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1867  $app->setDescription($this->getLongDescription());
1868  $app->setStart($this->getRegistrationEnd());
1869  $apps[] = $app;
1870 
1871  return $apps;
1872 
1873  case 'delete':
1874  // Nothing to do: The category and all assigned appointments will be deleted.
1875  return array();
1876  }
1877  }
1878 
1886  protected function initParticipants()
1887  {
1888  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1889  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1890  }
1891 
1896  public static function lookupObjectsByCode($a_code)
1897  {
1898  global $ilDB;
1899 
1900  $query = "SELECT obj_id FROM grp_settings ".
1901  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
1902  "AND reg_ac = ".$ilDB->quote($a_code,'text');
1903  $res = $ilDB->query($query);
1904 
1905  $obj_ids = array();
1906  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1907  {
1908  $obj_ids[] = $row->obj_id;
1909  }
1910  return $obj_ids;
1911  }
1912 
1919  public function register($a_user_id,$a_role = IL_GRP_MEMBER, $a_force_registration = false)
1920  {
1921  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1922  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1924 
1925  if($part->isAssigned($a_user_id))
1926  {
1927  return true;
1928  }
1929 
1930  if(!$a_force_registration)
1931  {
1932  // Availability
1933  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
1935  {
1936  $this->lng->loadLanguageModule('crs');
1937  throw new ilMembershipRegistrationException('456',$this->getRefId());
1938  }
1939  // Max members
1940  if(!$this->isRegistrationUnlimited())
1941  {
1942  $free = max(0,$this->getMaxMembers() - $part->getCountMembers());
1943  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
1944  $waiting_list = new ilGroupWaitingList($this->getId());
1945  if($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
1946  {
1947  throw new ilMembershipRegistrationException('123',$this->getRefId());
1948  }
1949  }
1950  }
1951 
1952  $part->add($a_user_id,$a_role);
1953  $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
1954  return true;
1955  }
1956 
1957 } //END class.ilObjGroup
1958 ?>