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