ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilObjGroup.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 //TODO: function getRoleId($groupRole) returns the object-id of grouprole
5 
6 require_once "./Services/Container/classes/class.ilContainer.php";
7 include_once('./Services/Calendar/classes/class.ilDateTime.php');
8 include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
9 
10 define('GRP_REGISTRATION_DEACTIVATED',-1);
11 define('GRP_REGISTRATION_DIRECT',0);
12 define('GRP_REGISTRATION_REQUEST',1);
13 define('GRP_REGISTRATION_PASSWORD',2);
14 
15 define('GRP_REGISTRATION_LIMITED',1);
16 define('GRP_REGISTRATION_UNLIMITED',2);
17 
18 define('GRP_TYPE_UNKNOWN',0);
19 define('GRP_TYPE_CLOSED',1);
20 define('GRP_TYPE_OPEN',2);
21 define('GRP_TYPE_PUBLIC',3);
22 
34 {
35  const CAL_REG_START = 1;
36  const CAL_REG_END = 2;
37 
38  const GRP_MEMBER = 1;
39  const GRP_ADMIN = 2;
40 
41  const ERR_MISSING_TITLE = 'msg_no_title';
42  const ERR_MISSING_GROUP_TYPE = 'grp_missing_grp_type';
43  const ERR_MISSING_PASSWORD = 'grp_missing_password';
44  const ERR_WRONG_MAX_MEMBERS = 'grp_wrong_max_members';
45  const ERR_WRONG_REG_TIME_LIMIT = 'grp_wrong_reg_time_limit';
46  const ERR_MISSING_MIN_MAX_MEMBERS = 'grp_wrong_min_max_members';
47  const ERR_WRONG_MIN_MAX_MEMBERS = 'grp_max_and_min_members_invalid';
48 
49  const MAIL_ALLOWED_ALL = 1;
51 
52  protected $information;
53  protected $group_type = null;
55  protected $reg_enabled = true;
56  protected $reg_unlimited = true;
57  protected $reg_start = null;
58  protected $reg_end = null;
59  protected $reg_password = '';
60  protected $reg_membership_limitation = false;
61  protected $reg_min_members = 0;
62  protected $reg_max_members = 0;
63  protected $waiting_list = false;
64  protected $auto_fill_from_waiting; // [bool]
65  protected $leave_end; // [ilDate]
66 
67 
68  // Map
69  private $latitude = '';
70  private $longitude = '';
71  private $locationzoom = 0;
72  private $enablemap = 0;
73 
74  private $reg_access_code = '';
75  private $reg_access_code_enabled = false;
76 
77  private $view_mode = NULL;
78 
79  private $mail_members = self::MAIL_ALLOWED_ALL;
80 
81 
82  public $members_obj;
83 
84 
88  var $file_obj = null;
89 
91 
93 
95 
102  public function __construct($a_id = 0,$a_call_by_reference = true)
103  {
104  global $tree;
105 
106  $this->tree =& $tree;
107 
108  $this->type = "grp";
109  $this->ilObject($a_id,$a_call_by_reference);
110  $this->setRegisterMode(true); // ???
111  }
112 
118  public static function lookupGroupTye($a_id)
119  {
120  global $ilDB;
121 
122  $query = "SELECT grp_type FROM grp_settings ".
123  "WHERE obj_id = ".$ilDB->quote($a_id,'integer');
124  $res = $ilDB->query($query);
125  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
126  {
127  return $row->grp_type;
128  }
129  return GRP_TYPE_UNKNOWN;
130  }
131 
132  // Setter/Getter
140  public function setInformation($a_information)
141  {
142  $this->information = $a_information;
143  }
144 
152  public function getInformation()
153  {
154  return $this->information;
155  }
156 
163  public function setGroupType($a_type)
164  {
165  $this->group_type = $a_type;
166  }
167 
174  public function getGroupType()
175  {
176  return $this->group_type;
177  }
178 
186  public function isGroupTypeModified($a_old_type)
187  {
188  if($a_old_type == GRP_TYPE_UNKNOWN)
189  {
190  $group_type = $this->readGroupStatus();
191  }
192  else
193  {
194  $group_type = $a_old_type;
195  }
196  return $group_type != $this->getGroupType();
197  }
198 
206  public function setRegistrationType($a_type)
207  {
208  $this->reg_type = $a_type;
209  }
210 
217  public function getRegistrationType()
218  {
219  return $this->reg_type;
220  }
221 
228  public function isRegistrationEnabled()
229  {
231  }
232 
240  public function enableUnlimitedRegistration($a_status)
241  {
242  $this->reg_unlimited = $a_status;
243  }
244 
251  public function isRegistrationUnlimited()
252  {
253  return $this->reg_unlimited;
254  }
255 
263  public function setRegistrationStart($a_start)
264  {
265  $this->reg_start = $a_start;
266  }
267 
274  public function getRegistrationStart()
275  {
276  return $this->reg_start ? $this->reg_start : $this->reg_start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
277  }
278 
279 
287  public function setRegistrationEnd($a_end)
288  {
289  $this->reg_end = $a_end;
290  }
291 
298  public function getRegistrationEnd()
299  {
300  return $this->reg_end ? $this->reg_end : $this->reg_end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
301  }
302 
309  public function setPassword($a_pass)
310  {
311  $this->reg_password = $a_pass;
312  }
313 
320  public function getPassword()
321  {
322  return $this->reg_password;
323  }
324 
332  public function enableMembershipLimitation($a_status)
333  {
334  $this->reg_membership_limitation = $a_status;
335  }
336 
343  public function isMembershipLimited()
344  {
345  return (bool) $this->reg_membership_limitation;
346  }
347 
354  public function setMinMembers($a_max)
355  {
356  $this->reg_min_members = $a_max;
357  }
358 
365  public function getMinMembers()
366  {
367  return $this->reg_min_members;
368  }
369 
376  public function setMaxMembers($a_max)
377  {
378  $this->reg_max_members = $a_max;
379  }
380 
387  public function getMaxMembers()
388  {
389  return $this->reg_max_members;
390  }
391 
399  public function enableWaitingList($a_status)
400  {
401  $this->waiting_list = $a_status;
402  }
403 
411  public function isWaitingListEnabled()
412  {
413  return $this->waiting_list;
414  }
415 
416  function setWaitingListAutoFill($a_value)
417  {
418  $this->auto_fill_from_waiting = (bool)$a_value;
419  }
420 
422  {
423  return (bool)$this->auto_fill_from_waiting;
424  }
425 
431  function setLatitude($a_latitude)
432  {
433  $this->latitude = $a_latitude;
434  }
435 
441  function getLatitude()
442  {
443  return $this->latitude;
444  }
445 
451  function setLongitude($a_longitude)
452  {
453  $this->longitude = $a_longitude;
454  }
455 
461  function getLongitude()
462  {
463  return $this->longitude;
464  }
465 
471  function setLocationZoom($a_locationzoom)
472  {
473  $this->locationzoom = $a_locationzoom;
474  }
475 
481  function getLocationZoom()
482  {
483  return $this->locationzoom;
484  }
485 
491  function setEnableGroupMap($a_enablemap)
492  {
493  $this->enablemap = $a_enablemap;
494  }
495 
501  function getEnableGroupMap()
502  {
503  return (bool) $this->enablemap;
504  }
505 
510  public function getRegistrationAccessCode()
511  {
512  return $this->reg_access_code;
513  }
514 
520  public function setRegistrationAccessCode($a_code)
521  {
522  $this->reg_access_code = $a_code;
523  }
524 
530  {
531  return (bool) $this->reg_access_code_enabled;
532  }
533 
539  public function enableRegistrationAccessCode($a_status)
540  {
541  $this->reg_access_code_enabled = $a_status;
542  }
543 
549  public function setMailToMembersType($a_type)
550  {
551  $this->mail_members = $a_type;
552  }
553 
558  public function getMailToMembersType()
559  {
560  return $this->mail_members;
561  }
562 
563  function setCancellationEnd(ilDate $a_value = null)
564  {
565  $this->leave_end = $a_value;
566  }
567 
569  {
570  return $this->leave_end;
571  }
572 
579  public function validate()
580  {
581  global $ilErr;
582 
583  if(!$this->getTitle())
584  {
585  $this->title = '';
586  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
587  }
588  if(!$this->getGroupType())
589  {
590  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_GROUP_TYPE));
591  }
592  if($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword()))
593  {
594  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
595  }
597  {
598  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
599  }
600  if($this->isMembershipLimited())
601  {
602  if($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0)
603  {
604  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
605  }
606  if($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled())
607  {
608  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
609  }
610  if($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers())
611  {
612  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
613  }
614  }
615  return strlen($ilErr->getMessage()) == 0;
616  }
617 
618 
619 
620 
624  function create()
625  {
626  global $ilDB,$ilAppEventHandler;
627 
628  if(!parent::create())
629  {
630  return false;
631  }
632 
633  $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled,".
634  "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit,".
635  "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type,".
636  "leave_end,registration_min_members,auto_wait) ".
637  "VALUES(".
638  $ilDB->quote($this->getId() ,'integer').", ".
639  $ilDB->quote($this->getInformation() ,'text').", ".
640  $ilDB->quote((int) $this->getGroupType() ,'integer').", ".
641  $ilDB->quote($this->getRegistrationType() ,'integer').", ".
642  $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0) ,'integer').", ".
643  $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0) ,'integer').", ".
644  $ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
645  $ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
646  $ilDB->quote($this->getPassword() ,'text').", ".
647  $ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
648  $ilDB->quote($this->getMaxMembers() ,'integer').", ".
649  $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
650  $ilDB->quote($this->getLatitude() ,'text').", ".
651  $ilDB->quote($this->getLongitude() ,'text').", ".
652  $ilDB->quote($this->getLocationZoom() ,'integer').", ".
653  $ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
654  $ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
655  $ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
656  $ilDB->quote($this->getViewMode(false),'integer').', '.
657  $ilDB->quote($this->getMailToMembersType(),'integer').', '.
658  $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer').', '.
659  $ilDB->quote($this->getMinMembers(),'integer').', '.
660  $ilDB->quote($this->hasWaitingListAutoFill(),'integer').' '.
661  ")";
662  $res = $ilDB->manipulate($query);
663 
664  $ilAppEventHandler->raise('Modules/Group',
665  'create',
666  array('object' => $this,
667  'obj_id' => $this->getId(),
668  'appointments' => $this->prepareAppointments('create')));
669 
670  return $this->getId();
671  }
672 
676  function update()
677  {
678  global $ilDB,$ilAppEventHandler;
679 
680  if (!parent::update())
681  {
682  return false;
683  }
684 
685  $query = "UPDATE grp_settings ".
686  "SET information = ".$ilDB->quote($this->getInformation() ,'text').", ".
687  "grp_type = ".$ilDB->quote((int) $this->getGroupType() ,'integer').", ".
688  "registration_type = ".$ilDB->quote($this->getRegistrationType() ,'integer').", ".
689  "registration_enabled = ".$ilDB->quote($this->isRegistrationEnabled() ? 1 : 0 ,'integer').", ".
690  "registration_unlimited = ".$ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0 ,'integer').", ".
691  "registration_start = ".$ilDB->quote($this->getRegistrationStart()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
692  "registration_end = ".$ilDB->quote($this->getRegistrationEnd()->get(IL_CAL_DATETIME,'') ,'timestamp').", ".
693  "registration_password = ".$ilDB->quote($this->getPassword() ,'text').", ".
694 // "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
695  "registration_mem_limit = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
696  "registration_max_members = ".$ilDB->quote($this->getMaxMembers() ,'integer').", ".
697  "waiting_list = ".$ilDB->quote($this->isWaitingListEnabled() ? 1 : 0 ,'integer').", ".
698  "latitude = ".$ilDB->quote($this->getLatitude() ,'text').", ".
699  "longitude = ".$ilDB->quote($this->getLongitude() ,'text').", ".
700  "location_zoom = ".$ilDB->quote($this->getLocationZoom() ,'integer').", ".
701  "enablemap = ".$ilDB->quote((int) $this->getEnableGroupMap() ,'integer').", ".
702  'reg_ac_enabled = '.$ilDB->quote($this->isRegistrationAccessCodeEnabled(),'integer').', '.
703  'reg_ac = '.$ilDB->quote($this->getRegistrationAccessCode(),'text').', '.
704  'view_mode = '.$ilDB->quote($this->getViewMode(false),'integer').', '.
705  'mail_members_type = '.$ilDB->quote($this->getMailToMembersType(),'integer').', '.
706  'leave_end = '.$ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer').', '.
707  "registration_min_members = ".$ilDB->quote($this->getMinMembers() ,'integer').", ".
708  "auto_wait = ".$ilDB->quote($this->hasWaitingListAutoFill() ,'integer')." ".
709  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
710  $res = $ilDB->manipulate($query);
711 
712  $ilAppEventHandler->raise('Modules/Group',
713  'update',
714  array('object' => $this,
715  'obj_id' => $this->getId(),
716  'appointments' => $this->prepareAppointments('update')));
717 
718 
719  return true;
720  }
721 
728  public function delete()
729  {
730  global $ilDB,$ilAppEventHandler;
731 
732  // always call parent delete function first!!
733  if (!parent::delete())
734  {
735  return false;
736  }
737 
738  $query = "DELETE FROM grp_settings ".
739  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
740  $res = $ilDB->manipulate($query);
741 
742  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
744 
745  $ilAppEventHandler->raise('Modules/Group',
746  'delete',
747  array('object' => $this,
748  'obj_id' => $this->getId(),
749  'appointments' => $this->prepareAppointments('delete')));
750 
751 
752  return true;
753  }
754 
755 
759  function read()
760  {
761  global $ilDB;
762 
763  parent::read();
764 
765  $query = "SELECT * FROM grp_settings ".
766  "WHERE obj_id = ".$ilDB->quote($this->getId() ,'integer');
767 
768  $res = $ilDB->query($query);
769  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
770  {
771  $this->setInformation($row->information);
772  $this->setGroupType($row->grp_type);
773  $this->setRegistrationType($row->registration_type);
774  $this->enableUnlimitedRegistration($row->registration_unlimited);
775  $this->setRegistrationStart(new ilDateTime($row->registration_start,IL_CAL_DATETIME));
776  $this->setRegistrationEnd(new ilDateTime($row->registration_end,IL_CAL_DATETIME));
777  $this->setPassword($row->registration_password);
778  $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
779  $this->setMaxMembers($row->registration_max_members);
780  $this->enableWaitingList($row->waiting_list);
781  $this->setLatitude($row->latitude);
782  $this->setLongitude($row->longitude);
783  $this->setLocationZoom($row->location_zoom);
784  $this->setEnableGroupMap($row->enablemap);
785  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
786  $this->setRegistrationAccessCode($row->reg_ac);
787  $this->setViewMode($row->view_mode);
788  $this->setMailToMembersType($row->mail_members_type);
789  $this->setCancellationEnd($row->leave_end ? new ilDate($row->leave_end, IL_CAL_UNIX) : null);
790  $this->setMinMembers($row->registration_min_members);
791  $this->setWaitingListAutoFill($row->auto_wait);
792  }
793  $this->initParticipants();
794 
795  // Inherit order type from parent course (if exists)
796  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
798  }
799 
808  public function cloneObject($a_target_id,$a_copy_id = 0)
809  {
810  global $ilDB,$ilUser, $ilSetting;
811 
812  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
813  $new_obj->setGroupType($this->getGroupType());
814  $new_obj->initGroupStatus($this->getGroupType() ? $this->getGroupType() : $this->readGroupStatus());
815 
816  $this->cloneAutoGeneratedRoles($new_obj);
817 
818  $new_obj->setRegistrationType($this->getRegistrationType());
819  $new_obj->setInformation($this->getInformation());
820  $new_obj->setRegistrationStart($this->getRegistrationStart());
821  $new_obj->setRegistrationEnd($this->getRegistrationEnd());
822  $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
823  $new_obj->setPassword($this->getPassword());
824  $new_obj->enableMembershipLimitation($this->isMembershipLimited());
825  $new_obj->setMaxMembers($this->getMaxMembers());
826  $new_obj->enableWaitingList($this->isWaitingListEnabled());
827 
828  // map
829  $new_obj->setLatitude($this->getLatitude());
830  $new_obj->setLongitude($this->getLongitude());
831  $new_obj->setLocationZoom($this->getLocationZoom());
832  $new_obj->setEnableGroupMap($this->getEnableGroupMap());
833  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
834  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
835  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
836 
837  $new_obj->setViewMode($this->getViewMode());
838  $new_obj->setMailToMembersType($this->getMailToMembersType());
839 
840  $new_obj->setCancellationEnd($this->getCancellationEnd());
841  $new_obj->setMinMembers($this->getMinMembers());
842  $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
843 
844  $new_obj->update();
845 
846  // #13008 - Group Defined Fields
847  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
848  ilCourseDefinedFieldDefinition::_clone($this->getId(),$new_obj->getId());
849 
850  ilLoggerFactory::getLogger('grp')->debug('Starting add user');
851 
852  // Assign user as admin
853  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
854  $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
855  $part->add($ilUser->getId(),IL_GRP_ADMIN);
856  $part->updateNotification($ilUser->getId(),$ilSetting->get('mail_grp_admin_notification', true));
857 
858  // Copy learning progress settings
859  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
860  $obj_settings = new ilLPObjSettings($this->getId());
861  $obj_settings->cloneSettings($new_obj->getId());
862  unset($obj_settings);
863 
864  // clone icons
865  $new_obj->saveIcons($this->getBigIconPath(),
866  $this->getSmallIconPath(),
867  $this->getTinyIconPath());
868 
869  return $new_obj;
870  }
871 
880  public function cloneDependencies($a_target_id,$a_copy_id)
881  {
882  global $tree;
883 
884  parent::cloneDependencies($a_target_id,$a_copy_id);
885 
886  include_once('Services/Object/classes/class.ilObjectActivation.php');
887  ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
888 
889  return true;
890  }
891 
899  public function cloneAutoGeneratedRoles($new_obj)
900  {
901  global $rbacadmin,$rbacreview;
902 
903  $admin = $this->getDefaultAdminRole();
904  $new_admin = $new_obj->getDefaultAdminRole();
905  if(!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId())
906  {
907  ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_admin');
908  }
909  $rbacadmin->copyRolePermissions($admin,$this->getRefId(),$new_obj->getRefId(),$new_admin,true);
910  ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_admin.');
911 
912  $member = $this->getDefaultMemberRole();
913  $new_member = $new_obj->getDefaultMemberRole();
914  if(!$member || !$new_member)
915  {
916  ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_member');
917  }
918  $rbacadmin->copyRolePermissions($member,$this->getRefId(),$new_obj->getRefId(),$new_member,true);
919  ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_member.');
920  }
921 
922 
928  function join($a_user_id, $a_mem_role="")
929  {
930  global $rbacadmin;
931 
932  if (is_array($a_mem_role))
933  {
934  foreach ($a_mem_role as $role)
935  {
936  $rbacadmin->assignUser($role,$a_user_id, false);
937  }
938  }
939  else
940  {
941  $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
942  }
943 
944  return true;
945  }
946 
952  {
953  $local_group_Roles = $this->getLocalGroupRoles();
954 
955  return $local_group_Roles["il_grp_member_".$this->getRefId()];
956  }
957 
963  {
964  $local_group_Roles = $this->getLocalGroupRoles();
965 
966  return $local_group_Roles["il_grp_admin_".$this->getRefId()];
967  }
968 
975  function addMember($a_user_id, $a_mem_role)
976  {
977  global $rbacadmin;
978 
979  if (isset($a_user_id) && isset($a_mem_role) )
980  {
981  $this->join($a_user_id,$a_mem_role);
982  return true;
983  }
984  else
985  {
986  $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
987  return false;
988  }
989  }
990 
991 
998  function leaveGroup()
999  {
1000  global $rbacadmin, $rbacreview;
1001 
1002  $member_ids = $this->getGroupMemberIds();
1003 
1004  if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
1005  {
1006  return 2;
1007  }
1008  else
1009  {
1010  if (!$this->isAdmin($this->ilias->account->getId()))
1011  {
1012  $this->leave($this->ilias->account->getId());
1013  $member = new ilObjUser($this->ilias->account->getId());
1014  $member->dropDesktopItem($this->getRefId(), "grp");
1015 
1016  return 0;
1017  }
1018  else if (count($this->getGroupAdminIds()) == 1)
1019  {
1020  return 1;
1021  }
1022  }
1023  }
1024 
1029  function leave($a_user_id)
1030  {
1031  global $rbacadmin;
1032 
1033  $arr_groupRoles = $this->getMemberRoles($a_user_id);
1034 
1035  if (is_array($arr_groupRoles))
1036  {
1037  foreach ($arr_groupRoles as $groupRole)
1038  {
1039  $rbacadmin->deassignUser($groupRole, $a_user_id);
1040  }
1041  }
1042  else
1043  {
1044  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
1045  }
1046 
1047  return true;
1048  }
1049 
1057  {
1058  global $rbacadmin, $rbacreview;
1059 
1060  $usr_arr= array();
1061 
1062  $rol = $this->getLocalGroupRoles();
1063 
1064  foreach ($rol as $value)
1065  {
1066  foreach ($rbacreview->assignedUsers($value) as $member_id)
1067  {
1068  array_push($usr_arr,$member_id);
1069  }
1070  }
1071 
1072  $mem_arr = array_unique($usr_arr);
1073 
1074  return $mem_arr ? $mem_arr : array();
1075  }
1076 
1084  function getGroupMemberData($a_mem_ids, $active = 1)
1085  {
1086  global $rbacadmin, $rbacreview, $ilBench, $ilDB;
1087 
1088  $usr_arr= array();
1089 
1090  $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
1091  "FROM usr_data ".
1092  "WHERE usr_id IN (".implode(',',ilUtil::quoteArray($a_mem_ids)).") ";
1093 
1094  if (is_numeric($active) && $active > -1)
1095  $q .= "AND active = '$active'";
1096 
1097  $q .= 'ORDER BY lastname,firstname';
1098 
1099  $r = $ilDB->query($q);
1100 
1101  while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
1102  {
1103  $mem_arr[] = array("id" => $row->usr_id,
1104  "login" => $row->login,
1105  "firstname" => $row->firstname,
1106  "lastname" => $row->lastname,
1107  "last_login" => $row->last_login
1108  );
1109  }
1110 
1111  return $mem_arr ? $mem_arr : array();
1112  }
1113 
1114  function getCountMembers()
1115  {
1116  return count($this->getGroupMemberIds());
1117  }
1118 
1125  function getGroupAdminIds($a_grpId = "")
1126  {
1127  global $rbacreview;
1128 
1129  if (!empty($a_grpId))
1130  {
1131  $grp_id = $a_grpId;
1132  }
1133  else
1134  {
1135  $grp_id = $this->getRefId();
1136  }
1137 
1138  $usr_arr = array();
1139  $roles = $this->getDefaultGroupRoles($this->getRefId());
1140 
1141  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
1142  {
1143  array_push($usr_arr,$member_id);
1144  }
1145 
1146  return $usr_arr;
1147  }
1148 
1154  function getDefaultGroupRoles($a_grp_id="")
1155  {
1156  global $rbacadmin, $rbacreview;
1157 
1158  if (strlen($a_grp_id) > 0)
1159  {
1160  $grp_id = $a_grp_id;
1161  }
1162  else
1163  {
1164  $grp_id = $this->getRefId();
1165  }
1166 
1167  $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1168 
1169  foreach ($role_arr as $role_id)
1170  {
1171  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1172 
1173  $grp_Member ="il_grp_member_".$grp_id;
1174  $grp_Admin ="il_grp_admin_".$grp_id;
1175 
1176  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
1177  {
1178  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1179  }
1180 
1181  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
1182  {
1183  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1184  }
1185  }
1186 
1187  return $arr_grpDefaultRoles;
1188  }
1189 
1196  function getLocalGroupRoles($a_translate = false)
1197  {
1198  global $rbacadmin,$rbacreview;
1199 
1200  if (empty($this->local_roles))
1201  {
1202  $this->local_roles = array();
1203  $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1204 
1205  foreach ($role_arr as $role_id)
1206  {
1207  if ($rbacreview->isAssignable($role_id,$this->getRefId()) == true)
1208  {
1209  $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
1210 
1211  if ($a_translate)
1212  {
1213  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1214  }
1215  else
1216  {
1217  $role_name = $role_Obj->getTitle();
1218  }
1219 
1220  $this->local_roles[$role_name] = $role_Obj->getId();
1221  }
1222  }
1223  }
1224 
1225  return $this->local_roles;
1226  }
1227 
1234  {
1235  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1236  $res = $this->ilias->db->query($q);
1237  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1238 
1239  return $row["obj_id"];
1240  }
1241 
1248  {
1249  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1250  $res = $this->ilias->db->query($q);
1251  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1252 
1253  return $row["obj_id"];
1254  }
1255 
1262  public static function lookupGroupStatusTemplateId($a_obj_id)
1263  {
1264  global $ilDB;
1265 
1266  $type = self::lookupGroupTye($a_obj_id);
1267  if($type == GRP_TYPE_CLOSED)
1268  {
1269  $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_grp_status_closed','text');
1270  }
1271  else
1272  {
1273  $query = 'SELECT obj_id FROM object_data WHERE type = '.$ilDB->quote('rolt','text').' AND title = '.$ilDB->quote('il_grp_status_open','text');
1274  }
1275  $res = $ilDB->query($query);
1276  $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
1277 
1278  return isset($row['obj_id']) ? $row['obj_id'] : 0;
1279  }
1280 
1281 
1282 
1292  public function updateGroupType()
1293  {
1294  global $tree,$rbacreview,$rbacadmin;
1295 
1296  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1297  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1298 
1299  // Delete parent roles with stopped inheritance
1300  foreach($real_parent_roles as $role_id)
1301  {
1302  // Delete local role
1303  $rbacadmin->deleteLocalRole($role_id,$this->getRefId());
1304  }
1305  $parent_roles = $rbacreview->getParentRoleIds($this->getRefId());
1306  $real_parent_roles = array_diff(array_keys($parent_roles),$this->getDefaultGroupRoles());
1307 
1308  switch($this->getGroupType())
1309  {
1310  case GRP_TYPE_PUBLIC:
1312  break;
1313 
1314  case GRP_TYPE_CLOSED:
1316  break;
1317  }
1318 
1319  $first = true;
1320  foreach($tree->getFilteredSubTree($this->getRefId(),array('grp')) as $subnode)
1321  {
1322  // Read template operations
1323  $template_ops = $rbacreview->getOperationsOfRole($template_id,$subnode['type'], ROLE_FOLDER_ID);
1324 
1325  // for all parent roles
1326  foreach($real_parent_roles as $role_id)
1327  {
1328  if($rbacreview->isProtected($parent_roles[$role_id]['parent'],$role_id))
1329  {
1330  continue;
1331  }
1332 
1333  $rbacadmin->deleteLocalRole($role_id,$subnode['child']);
1334 
1335  // Store current operations
1336  $current_ops = $rbacreview->getOperationsOfRole($role_id,$subnode['type'],$parent_roles[$role_id]['parent']);
1337 
1338  // Revoke permissions
1339  $rbacadmin->revokePermission($subnode['child'],$role_id);
1340 
1341  // Grant permissions
1342  $granted = array();
1343  foreach($template_ops as $operation)
1344  {
1345  if(in_array($operation,$current_ops))
1346  {
1347  $granted[] = $operation;
1348  }
1349  }
1350  if($granted)
1351  {
1352  $rbacadmin->grantPermission($role_id, $granted,$subnode['child']);
1353  }
1354 
1355  if($first)
1356  {
1357  // This is the group itself
1358  $rbacadmin->copyRolePermissionIntersection(
1359  $template_id, ROLE_FOLDER_ID,
1360  $role_id, $parent_roles[$role_id]['parent'],
1361  $subnode["child"],$role_id);
1362  $rbacadmin->assignRoleToFolder($role_id,$subnode['child'],"n");
1363 
1364  }
1365  }
1366  $first = false;
1367  }
1368  }
1369 
1387  function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1388  {
1389  global $rbacadmin, $rbacreview, $rbacsystem;
1390 
1391  //define all relevant roles that rights are needed to be changed
1392  $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1393 
1394  $real_local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId(),false);
1395  $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$real_local_roles);
1396 
1397  //group status open (aka public) or group status closed
1398  if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED)
1399  {
1400  if ($a_grpStatus == GRP_TYPE_PUBLIC)
1401  {
1403  }
1404  else
1405  {
1407  }
1408  //get defined operations from template
1409  $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1410 
1411  foreach ($arr_relevantParentRoleIds as $parentRole)
1412  {
1413  if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
1414  {
1415  continue;
1416  }
1417 
1418  $granted_permissions = array();
1419 
1420  // Delete the linked role for the parent role
1421  // (just in case if it already exists).
1422 
1423  // Added additional check, since this operation is very dangerous.
1424  // If there is no role folder ALL parent roles are deleted.
1425 
1426  // @todo refactor rolf
1427  $rbacadmin->deleteLocalRole($parentRole,$this->getRefId());
1428 
1429  // Grant permissions on the group object for
1430  // the parent role. In the foreach loop we
1431  // compute the intersection of the role
1432  // template il_grp_status_open/_closed and the
1433  // permission template of the parent role.
1434  $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1435  $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1436  foreach ($template_ops as $template_op)
1437  {
1438  if (in_array($template_op,$current_ops))
1439  {
1440  array_push($granted_permissions,$template_op);
1441  }
1442  }
1443  if (!empty($granted_permissions))
1444  {
1445  $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1446  }
1447 
1448  // Create a linked role for the parent role and
1449  // initialize it with the intersection of
1450  // il_grp_status_open/_closed and the permission
1451  // template of the parent role
1452 
1453  $rbacadmin->copyRolePermissionIntersection(
1454  $template_id, ROLE_FOLDER_ID,
1455  $parentRole, $arr_parentRoles[$parentRole]['parent'],
1456  $this->getRefId(), $parentRole
1457  );
1458  $rbacadmin->assignRoleToFolder($parentRole,$this->getRefId(),"false");
1459  }//END foreach
1460  }
1461  }
1462 
1470  public function setGroupStatus($a_status)
1471  {
1472  $this->group_status = $a_status;
1473  }
1474 
1482  public function getGroupStatus()
1483  {
1484  return $this->group_status;
1485  }
1486 
1492  function readGroupStatus()
1493  {
1494  global $rbacsystem,$rbacreview;
1495 
1496  $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1497 
1498  //get all relevant roles
1499  $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1500 
1501  //if one global role has no permission to join the group is officially closed !
1502  foreach ($arr_globalRoles as $globalRole)
1503  {
1504  if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
1505  {
1506  return $this->group_status = GRP_TYPE_PUBLIC;
1507  }
1508  }
1509 
1510  return $this->group_status = GRP_TYPE_CLOSED;
1511  }
1512 
1519  function getMemberRoles($a_user_id)
1520  {
1521  global $rbacadmin, $rbacreview,$ilBench;
1522 
1523  $ilBench->start("Group", "getMemberRoles");
1524 
1525  $arr_assignedRoles = array();
1526 
1527  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
1528 
1529  $ilBench->stop("Group", "getMemberRoles");
1530 
1531  return $arr_assignedRoles;
1532  }
1533 
1540  function isAdmin($a_userId)
1541  {
1542  global $rbacreview;
1543 
1544  $grp_Roles = $this->getDefaultGroupRoles();
1545 
1546  if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
1547  {
1548  return true;
1549  }
1550  else
1551  {
1552  return false;
1553  }
1554  }
1555 
1556 
1557 
1563  function initDefaultRoles()
1564  {
1565  include_once './Services/AccessControl/classes/class.ilObjRole.php';
1567  'il_grp_admin_'.$this->getRefId(),
1568  "Groupadmin group obj_no.".$this->getId(),
1569  'il_grp_admin',
1570  $this->getRefId()
1571  );
1572  $this->m_roleAdminId = $role->getId();
1573 
1575  'il_grp_member_'.$this->getRefId(),
1576  "Groupmember of group obj_no.".$this->getId(),
1577  'il_grp_member',
1578  $this->getRefId()
1579  );
1580  $this->m_roleMemberId = $role->getId();
1581 
1582  return array();
1583  }
1584 
1595  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1596  {
1597  global $tree;
1598 
1599  $parent_id = (int) $tree->getParentId($a_node_id);
1600 
1601  if ($parent_id != 0)
1602  {
1603  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1604  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1605  }
1606 
1607  return true;
1608  }
1609 
1610 
1611  function exportXML()
1612  {
1613  include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
1614 
1615  $xml_writer = new ilGroupXMLWriter($this);
1616  $xml_writer->start();
1617 
1618  $xml = $xml_writer->getXML();
1619 
1620  $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
1621 
1622  $this->__initFileObject();
1623 
1624  $this->file_obj->addGroupDirectory();
1625  $this->file_obj->addDirectory($name);
1626  $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
1627  $this->file_obj->zipFile($name,$name.'.zip');
1628  $this->file_obj->deleteDirectory($name);
1629 
1630  return true;
1631  }
1632 
1633  function deleteExportFiles($a_files)
1634  {
1635  $this->__initFileObject();
1636 
1637  foreach($a_files as $file)
1638  {
1639  $this->file_obj->deleteFile($file);
1640  }
1641  return true;
1642  }
1643 
1645  {
1646  $this->__initFileObject();
1647 
1648  if($abs_name = $this->file_obj->getExportFile($file))
1649  {
1650  ilUtil::deliverFile($abs_name,$file);
1651  // Not reached
1652  }
1653  return false;
1654  }
1655 
1664  function _importFromXMLString($xml,$parent_id)
1665  {
1666  include_once 'Modules/Group/classes/class.ilGroupXMLParser.php';
1667 
1668  $import_parser = new ilGroupXMLParser($xml,$parent_id);
1669 
1670  return $import_parser->startParsing();
1671  }
1672 
1680  function _importFromFile($file,$parent_id)
1681  {
1682  global $lng;
1683 
1684  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1685 
1686  $file_obj = new ilFileDataGroup(null);
1687  $file_obj->addImportDirectory();
1688  $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
1689  $file_obj->unpackImportFile();
1690 
1691  if(!$file_obj->validateImportFile())
1692  {
1693  return false;
1694  }
1695  return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
1696  }
1697 
1698  function _lookupIdByTitle($a_title)
1699  {
1700  global $ilDB;
1701 
1702  $query = "SELECT * FROM object_data WHERE title = ".
1703  $ilDB->quote($a_title ,'text')." AND type = 'grp'";
1704  $res = $ilDB->query($query);
1705  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1706  {
1707  return $row->obj_id;
1708  }
1709  return 0;
1710  }
1711 
1712 
1713  function _isMember($a_user_id,$a_ref_id,$a_field = '')
1714  {
1715  global $rbacreview,$ilObjDataCache,$ilDB;
1716 
1717  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
1718  $user_roles = $rbacreview->assignedRoles($a_user_id);
1719 
1720  // Used for membership limitations -> check membership by given field
1721  if($a_field)
1722  {
1723  include_once './Services/User/classes/class.ilObjUser.php';
1724 
1725  $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
1726  switch($a_field)
1727  {
1728  case 'login':
1729  $and = "AND login = '".$tmp_user->getLogin()."' ";
1730  break;
1731  case 'email':
1732  $and = "AND email = '".$tmp_user->getEmail()."' ";
1733  break;
1734  case 'matriculation':
1735  $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
1736  break;
1737 
1738  default:
1739  $and = "AND usr_id = '".$a_user_id."'";
1740  break;
1741  }
1742  if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
1743  {
1744  return false;
1745  }
1746  $query = "SELECT * FROM usr_data as ud ".
1747  "WHERE usr_id IN (".implode(",",ilUtil::quoteArray($members)).") ".
1748  $and;
1749  $res = $ilDB->query($query);
1750 
1751  return $res->numRows() ? true : false;
1752  }
1753 
1754  if (!array_intersect($local_roles,$user_roles))
1755  {
1756  return false;
1757  }
1758 
1759  return true;
1760  }
1761 
1762  function _getMembers($a_obj_id)
1763  {
1764  global $rbacreview;
1765 
1766  // get reference
1767  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1768  $ref_id = current($ref_ids);
1769 
1770  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
1771 
1772  $users = array();
1773  foreach($local_roles as $role_id)
1774  {
1775  $users = array_merge($users,$rbacreview->assignedUsers($role_id));
1776  }
1777 
1778  return array_unique($users);
1779  }
1780 
1788  public function getViewMode($a_translate_inherit = true)
1789  {
1790  $view = (int) $this->view_mode;
1791 
1792  if(!$view)
1793  {
1794  $view = ilContainer::VIEW_DEFAULT;
1795  }
1796 
1797  if($a_translate_inherit)
1798  {
1799  $view = self::translateViewMode($this->id, $view, $this->ref_id);
1800  }
1801 
1802  return $view;
1803  }
1804 
1809  public function setViewMode($a_view_mode)
1810  {
1811  $this->view_mode = $a_view_mode;
1812  }
1813 
1818  public static function lookupViewMode($a_obj_id)
1819  {
1820  global $ilDB;
1821 
1822  $query = 'SELECT view_mode FROM grp_settings '.
1823  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
1824  $res = $ilDB->query($query);
1825 
1826  $view_mode = NULL;
1827  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1828  {
1829  $view_mode = $row->view_mode;
1830  }
1831  return self::translateViewMode($a_obj_id,$view_mode);
1832  }
1833 
1841  protected static function translateViewMode($a_obj_id,$a_view_mode,$a_ref_id = null)
1842  {
1843  global $tree;
1844 
1845  if(!$a_view_mode)
1846  {
1847  $a_view_mode = ilContainer::VIEW_DEFAULT;
1848  }
1849 
1850  // view mode is inherit => check for parent course
1851  if($a_view_mode == ilContainer::VIEW_INHERIT)
1852  {
1853  if(!$a_ref_id)
1854  {
1855  $ref = ilObject::_getAllReferences($a_obj_id);
1856  $a_ref_id = end($ref);
1857  }
1858 
1859  $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1860  if(!$crs_ref)
1861  {
1863  }
1864 
1865  include_once './Modules/Course/classes/class.ilObjCourse.php';
1867 
1868  // validate course view mode
1869  if(!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1871  {
1873  }
1874 
1875  return $view_mode;
1876  }
1877 
1878  return $a_view_mode;
1879  }
1880 
1885  function addAdditionalSubItemInformation(&$a_item_data)
1886  {
1887  include_once './Services/Object/classes/class.ilObjectActivation.php';
1889  }
1890 
1891  // Private / Protected
1892  function __initFileObject()
1893  {
1894  if($this->file_obj)
1895  {
1896  return $this->file_obj;
1897  }
1898  else
1899  {
1900  include_once './Modules/Group/classes/class.ilFileDataGroup.php';
1901 
1902  return $this->file_obj = new ilFileDataGroup($this);
1903  }
1904  }
1905 
1906  function getMessage()
1907  {
1908  return $this->message;
1909  }
1910  function setMessage($a_message)
1911  {
1912  $this->message = $a_message;
1913  }
1914  function appendMessage($a_message)
1915  {
1916  if($this->getMessage())
1917  {
1918  $this->message .= "<br /> ";
1919  }
1920  $this->message .= $a_message;
1921  }
1922 
1930  protected function prepareAppointments($a_mode = 'create')
1931  {
1932  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1933 
1934  switch($a_mode)
1935  {
1936  case 'create':
1937  case 'update':
1938  if($this->isRegistrationUnlimited())
1939  {
1940  return array();
1941  }
1942  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1943  $app->setTitle($this->getTitle());
1944  $app->setSubtitle('grp_cal_reg_start');
1945  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1946  $app->setDescription($this->getLongDescription());
1947  $app->setStart($this->getRegistrationStart());
1948  $apps[] = $app;
1949 
1950  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1951  $app->setTitle($this->getTitle());
1952  $app->setSubtitle('grp_cal_reg_end');
1953  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1954  $app->setDescription($this->getLongDescription());
1955  $app->setStart($this->getRegistrationEnd());
1956  $apps[] = $app;
1957 
1958  return $apps;
1959 
1960  case 'delete':
1961  // Nothing to do: The category and all assigned appointments will be deleted.
1962  return array();
1963  }
1964  }
1965 
1973  protected function initParticipants()
1974  {
1975  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1976  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1977  }
1978 
1984  public function getMembersObject()
1985  {
1986  // #17886
1987  if(!$this->members_obj instanceof ilGroupParticipants)
1988  {
1989  $this->initParticipants();
1990  }
1991  return $this->members_obj;
1992  }
1993 
1998  public static function lookupObjectsByCode($a_code)
1999  {
2000  global $ilDB;
2001 
2002  $query = "SELECT obj_id FROM grp_settings ".
2003  "WHERE reg_ac_enabled = ".$ilDB->quote(1,'integer')." ".
2004  "AND reg_ac = ".$ilDB->quote($a_code,'text');
2005  $res = $ilDB->query($query);
2006 
2007  $obj_ids = array();
2008  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2009  {
2010  $obj_ids[] = $row->obj_id;
2011  }
2012  return $obj_ids;
2013  }
2014 
2021  public function register($a_user_id,$a_role = IL_GRP_MEMBER, $a_force_registration = false)
2022  {
2023  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
2024  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
2026 
2027  if($part->isAssigned($a_user_id))
2028  {
2029  return true;
2030  }
2031 
2032  if(!$a_force_registration)
2033  {
2034  // Availability
2035  if(!$this->isRegistrationEnabled())
2036  {
2037  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
2038 
2040  {
2041  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2042  ', group subscription is deactivated.', '456');
2043  }
2044  }
2045 
2046  // Time Limitation
2047  if(!$this->isRegistrationUnlimited())
2048  {
2049  $start = $this->getRegistrationStart();
2050  $end = $this->getRegistrationEnd();
2051  $time = new ilDateTime(time(),IL_CAL_UNIX);
2052 
2053  if( !(ilDateTime::_after($time, $start) and ilDateTime::_before($time,$end)) )
2054  {
2055  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2056  ', group is out of registration time.', '789');
2057  }
2058  }
2059 
2060  // Max members
2061  if($this->isMembershipLimited())
2062  {
2063  $free = max(0,$this->getMaxMembers() - $part->getCountMembers());
2064  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2065  $waiting_list = new ilGroupWaitingList($this->getId());
2066  if($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers()))
2067  {
2068  $this->lng->loadLanguageModule("grp");
2069  $waiting_list->addToList($a_user_id);
2070 
2071  $info = sprintf($this->lng->txt('grp_added_to_list'),
2072  $this->getTitle(),
2073  $waiting_list->getPosition($a_user_id));
2074 
2075  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2076  include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
2077  $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
2078  $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER,$a_user_id);
2079 
2080  throw new ilMembershipRegistrationException($info, '124');
2081  }
2082 
2083  if(!$free or $waiting_list->getCountUsers())
2084  {
2085  throw new ilMembershipRegistrationException('Cant registrate to group '.$this->getId().
2086  ', membership is limited.', '123');
2087  }
2088  }
2089  }
2090 
2091  $part->add($a_user_id,$a_role);
2092  $part->sendNotification($part->TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2093  return true;
2094  }
2095 
2096  public function handleAutoFill()
2097  {
2098  if($this->isWaitingListEnabled() &&
2099  $this->hasWaitingListAutoFill())
2100  {
2101  $max = $this->getMaxMembers();
2103  if($max > $now)
2104  {
2105  // see assignFromWaitingListObject()
2106  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2107  $waiting_list = new ilGroupWaitingList($this->getId());
2108 
2109  foreach($waiting_list->getUserIds() as $user_id)
2110  {
2111  if(!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id,false))
2112  {
2113  continue;
2114  }
2115  if($this->getMembersObject()->isAssigned($user_id))
2116  {
2117  continue;
2118  }
2119  $this->getMembersObject()->add($user_id,IL_GRP_MEMBER); // #18213
2120  $this->getMembersObject()->sendNotification($this->getMembersObject()->NOTIFY_ACCEPT_USER,$user_id);
2121  $waiting_list->removeFromList($user_id);
2122 
2123  $now++;
2124  if($now >= $max)
2125  {
2126  break;
2127  }
2128  }
2129  }
2130  }
2131  }
2132 
2133  public static function mayLeave($a_group_id, $a_user_id = null, &$a_date = null)
2134  {
2135  global $ilUser, $ilDB;
2136 
2137  if(!$a_user_id)
2138  {
2139  $a_user_id = $ilUser->getId();
2140  }
2141 
2142  $set = $ilDB->query("SELECT leave_end".
2143  " FROM grp_settings".
2144  " WHERE obj_id = ".$ilDB->quote($a_group_id, "integer"));
2145  $row = $ilDB->fetchAssoc($set);
2146  if($row && $row["leave_end"])
2147  {
2148  // timestamp to date
2149  $limit = date("Ymd", $row["leave_end"]);
2150  if($limit < date("Ymd"))
2151  {
2152  $a_date = new ilDate(date("Y-m-d", $row["leave_end"]), IL_CAL_DATE);
2153  return false;
2154  }
2155  }
2156  return true;
2157  }
2158 
2164  public static function findGroupsWithNotEnoughMembers()
2165  {
2166  global $ilDB;
2167 
2168  $res = array();
2169 
2170  $now = date("Y-m-d H:i:s");
2171 
2172  include_once "Modules/Group/classes/class.ilGroupParticipants.php";
2173 
2174  $set = $ilDB->query("SELECT obj_id, registration_min_members".
2175  " FROM grp_settings".
2176  " WHERE registration_min_members > ".$ilDB->quote(0, "integer").
2177  " AND registration_mem_limit = ".$ilDB->quote(1, "integer"). // #17206
2178  " AND ((leave_end IS NOT NULL".
2179  " AND leave_end < ".$ilDB->quote($now, "text").")".
2180  " OR (leave_end IS NULL".
2181  " AND registration_end IS NOT NULL".
2182  " AND registration_end < ".$ilDB->quote($now, "text")."))"
2183  // :TODO: there is no group start ?!
2184  /* " AND (grp_start IS NULL OR grp_start > ".$ilDB->quote($now, "integer").")" */);
2185  while($row = $ilDB->fetchAssoc($set))
2186  {
2187  $refs = ilObject::_getAllReferences($row['obj_id']);
2188  $ref = end($refs);
2189 
2190  if($GLOBALS['tree']->isDeleted($ref))
2191  {
2192  continue;
2193  }
2194 
2195  $part = new ilGroupParticipants($row["obj_id"]);
2196  $reci = $part->getNotificationRecipients();
2197  if(sizeof($reci))
2198  {
2199  $missing = (int)$row["registration_min_members"]-$part->getCountMembers();
2200  if($missing > 0)
2201  {
2202  $res[$row["obj_id"]] = array($missing, $reci);
2203  }
2204  }
2205  }
2206 
2207  return $res;
2208  }
2209 
2210 } //END class.ilObjGroup
2211 ?>
static lookupGroupStatusTemplateId($a_obj_id)
$ilDB $ilDB
setCancellationEnd(ilDate $a_value=null)
_importFromXMLString($xml, $parent_id)
Static used for importing a group from xml string.
getMaxMembers()
get max members
static mayLeave($a_group_id, $a_user_id=null, &$a_date=null)
getDefaultAdminRole()
returns object id of created default adminstrator role public
dropDesktopItem($a_item_id, $a_type)
drop an item from user&#39;s personal desktop
cloneAutoGeneratedRoles($new_obj)
Clone group admin and member role permissions.
isRegistrationEnabled()
is registration enabled
print $file
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
getLongitude()
Get Longitude.
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
static lookupNumberOfMembers($a_ref_id)
Lookup number of members ilRbacReview $rbacreview <type> $ilObjDataCache.
validate()
validate group settings
isRegistrationUnlimited()
is registration unlimited
$template_id
Definition: example_062.php:89
const IL_CAL_DATETIME
update()
Update group.
getDefaultMemberRole()
returns object id of created default member role public
const GRP_REGISTRATION_DEACTIVATED
const ERR_MISSING_PASSWORD
getMembersObject()
Get members objects.
isMembershipLimited()
is max member limited
getRegistrationType()
get registration type
const IL_GRP_ADMIN
const IL_CAL_TRANSLATION_SYSTEM
const ERR_WRONG_MAX_MEMBERS
getRegistrationEnd()
get registration end
setWaitingListAutoFill($a_value)
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
getGroupStatus()
get group status
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies (crs items, preconditions)
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
join($a_user_id, $a_mem_role="")
join Group, assigns user to role private
_getTranslation($a_role_title)
const GRP_TYPE_UNKNOWN
getBigIconPath()
Get path for big icon.
setLongitude($a_longitude)
Set Longitude.
_getMembers($a_obj_id)
getLatitude()
Get Latitude.
getRegistrationAccessCode()
get access code
getTinyIconPath()
Get path for tiny icon.
const ERR_MISSING_GROUP_TYPE
Apointment templates are used for automatic generated apointments.
getViewMode()
Get container view mode.
const IL_CAL_UNIX
const IL_GRP_MEMBER
initGroupStatus($a_grpStatus=GRP_TYPE_PUBLIC)
set group status
const GRP_REGISTRATION_PASSWORD
enableUnlimitedRegistration($a_status)
enable unlimited registration
getRegistrationStart()
get registration start
const ERR_MISSING_MIN_MAX_MEMBERS
static _clone($a_source_id, $a_target_id)
Clone fields.
getDefaultGroupRoles($a_grp_id="")
get default group roles, returns the defaultlike create roles il_grp_member, il_grp_admin public ...
ilObject($a_id=0, $a_reference=true)
Constructor public.
static _getAllReferences($a_id)
get all reference ids of object
const GRP_TYPE_PUBLIC
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getGrpStatusOpenTemplateId()
get group status open template public
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
cloneObject($a_target_id, $a_copy_id=0)
Clone group (no member data)
_lookupIdByTitle($a_title)
enableWaitingList($a_status)
enable waiting list
setMessage($a_message)
static findGroupsWithNotEnoughMembers()
Minimum members check $ilDB $ilDB.
getGrpStatusClosedTemplateId()
get group status closed template public
appendMessage($a_message)
leave($a_user_id)
deassign member from group role private
getGroupType()
get group type
$info
Definition: example_052.php:80
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
$r
Definition: example_031.php:79
setLatitude($a_latitude)
Set Latitude.
Class for single dates.
downloadExportFile($file)
getId()
get object id public
getViewMode($a_translate_inherit=true)
get view mode
const ERR_WRONG_MIN_MAX_MEMBERS
Interface for all objects that offer registration with access codes.
const MAIL_ALLOWED_TUTORS
static _usingRegistrationCode()
Using Registration code.
getLocalGroupRoles($a_translate=false)
get ALL local roles of group, also those created and defined afterwards only fetch data once from dat...
isGroupTypeModified($a_old_type)
check if group type is modified
prepareAppointments($a_mode='create')
Prepare calendar appointments.
const ERR_MISSING_TITLE
const GRP_TYPE_CLOSED
static _lookupObjId($a_id)
enableMembershipLimitation($a_status)
enable max member limitation
getLocationZoom()
Get LocationZoom.
setPassword($a_pass)
set password
setViewMode($a_view_mode)
Set group view mode.
setMaxMembers($a_max)
set max members
setRegistrationEnd($a_end)
set registration end
Waiting list for groups.
setRegistrationType($a_type)
set registration type
getTitle()
get object title public
Date and time handling
initParticipants()
init participants object
getMemberRoles($a_user_id)
get group member status public
$file_obj
Group file object for handling of export files.
redirection script todo: (a better solution should control the processing via a xml file) ...
Class ilContainer.
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
setGroupType($a_type)
set group type
getEnableGroupMap()
Get Enable Group Map.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
getInformation()
get Information
setMinMembers($a_max)
set min members
leaveGroup()
is called when a member decides to leave group public
setInformation($a_information)
set information
getGroupAdminIds($a_grpId="")
get Group Admin Id public
getMailToMembersType()
Get mail to members type.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
setEnableGroupMap($a_enablemap)
Set Enable Group Map.
setGroupStatus($a_status)
Set group status.
getSmallIconPath()
Get path for small icon.
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.
getPassword()
get password
const IL_CAL_DATE
static generateCode()
Generate new registration key.
setRegistrationStart($a_start)
set registration start
enableRegistrationAccessCode($a_status)
En/disable registration access code.
isRegistrationAccessCodeEnabled()
Check if access code is enabled.
deleteExportFiles($a_files)
setLocationZoom($a_locationzoom)
Set LocationZoom.
global $ilUser
Definition: imgupload.php:15
setOrderType($a_value)
static translateViewMode($a_obj_id, $a_view_mode, $a_ref_id=null)
translate view mode
Group Import Parser.
static lookupObjectsByCode($a_code)
getGroupMemberData($a_mem_ids, $active=1)
get all group Members regardless of group role.
global $ilSetting
Definition: privfeed.php:40
static cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
Clone dependencies.
const MAIL_ALLOWED_ALL
XML writer class.
global $ilBench
Definition: ilias.php:18
global $ilDB
updateGroupType()
Change group type.
static lookupGroupTye($a_id)
Lookup group type.
getLongDescription()
get object long description (stored in object_description)
getRefId()
get reference id public
Class ilObjGroup.
addAdditionalSubItemInformation(&$a_item_data)
Add additional information to sub item, e.g.
getGroupMemberIds()
get all group Member ids regardless of role public
notify($a_event, $a_ref_id, $a_parent_non_rbac_id, $a_node_id, $a_params=0)
notifys an object about an event occured Based on the event happend, each object may decide how it re...
create()
Create group.
static getLogger($a_component_id)
Get component logger.
static _lookupSortMode($a_obj_id)
lookup sort mode
initDefaultRoles()
init default roles settings public
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
setMailToMembersType($a_type)
Set mail to members type.
const GRP_REGISTRATION_DIRECT
static lookupViewMode($a_obj_id)
lookup view mode $ilDB
setRegistrationAccessCode($a_code)
Set refistration access code.
_importFromFile($file, $parent_id)
Static used for importing an group from xml zip file.
read()
Read group.
_isMember($a_user_id, $a_ref_id, $a_field='')
addMember($a_user_id, $a_mem_role)
add Member to Group public
readGroupStatus()
get group status, redundant method because public
getMinMembers()
get min members
isWaitingListEnabled()
is waiting list enabled
isAdmin($a_userId)
is Admin public
const ERR_WRONG_REG_TIME_LIMIT
setRegisterMode($a_bool)