ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjGroup.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 //TODO: function getRoleId($groupRole) returns the object-id of grouprole
5 
6 require_once "./Services/Container/classes/class.ilContainer.php";
7 include_once('./Services/Calendar/classes/class.ilDateTime.php');
8 include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
9 
10 define('GRP_REGISTRATION_DEACTIVATED', -1);
11 define('GRP_REGISTRATION_DIRECT', 0);
12 define('GRP_REGISTRATION_REQUEST', 1);
13 define('GRP_REGISTRATION_PASSWORD', 2);
14 
15 define('GRP_REGISTRATION_LIMITED', 1);
16 define('GRP_REGISTRATION_UNLIMITED', 2);
17 
18 define('GRP_TYPE_UNKNOWN', 0);
19 define('GRP_TYPE_CLOSED', 1);
20 define('GRP_TYPE_OPEN', 2);
21 define('GRP_TYPE_PUBLIC', 3);
22 
34 {
35  const CAL_REG_START = 1;
36  const CAL_REG_END = 2;
37  const CAL_START = 3;
38  const CAL_END = 4;
39 
40  const GRP_MEMBER = 1;
41  const GRP_ADMIN = 2;
42 
43  const ERR_MISSING_TITLE = 'msg_no_title';
44  const ERR_MISSING_GROUP_TYPE = 'grp_missing_grp_type';
45  const ERR_MISSING_PASSWORD = 'grp_missing_password';
46  const ERR_WRONG_MAX_MEMBERS = 'grp_wrong_max_members';
47  const ERR_WRONG_REG_TIME_LIMIT = 'grp_wrong_reg_time_limit';
48  const ERR_MISSING_MIN_MAX_MEMBERS = 'grp_wrong_min_max_members';
49  const ERR_WRONG_MIN_MAX_MEMBERS = 'grp_max_and_min_members_invalid';
50  const ERR_WRONG_REGISTRATION_LIMITED = 'grp_err_registration_limited';
51 
52  const MAIL_ALLOWED_ALL = 1;
54 
57 
58  protected $information;
59  protected $group_type = null;
61  protected $reg_enabled = true;
62  protected $reg_unlimited = true;
63  protected $reg_start = null;
64  protected $reg_end = null;
65  protected $reg_password = '';
66  protected $reg_membership_limitation = false;
67  protected $reg_min_members = 0;
68  protected $reg_max_members = 0;
69  protected $waiting_list = false;
70  protected $auto_fill_from_waiting; // [bool]
71  protected $leave_end; // [ilDate]
72  protected $show_members = 1;
73 
77  protected $auto_notification = true;
78 
79 
83  protected $grp_start_time_indication = false;
84 
85 
89  protected $start = null;
90 
94  protected $end = null;
95 
96 
97  // Map
98  private $latitude = '';
99  private $longitude = '';
100  private $locationzoom = 0;
101  private $enablemap = 0;
102 
103  private $reg_access_code = '';
104  private $reg_access_code_enabled = false;
105 
107 
108  private $mail_members = self::MAIL_ALLOWED_ALL;
109 
110 
111  public $members_obj;
112 
113 
117  public $file_obj = null;
118 
119  public $m_grpStatus;
120 
122 
124 
125 
132  public function __construct($a_id = 0, $a_call_by_reference = true)
133  {
134  global $DIC;
135 
136  $tree = $DIC['tree'];
137 
138  $this->tree = &$tree;
139 
140  $this->type = "grp";
141  parent::__construct($a_id, $a_call_by_reference);
142  $this->setRegisterMode(true); // ???
143  }
144 
150  public static function lookupGroupTye($a_id)
151  {
152  global $DIC;
153 
154  $ilDB = $DIC['ilDB'];
155 
156  $query = "SELECT grp_type FROM grp_settings " .
157  "WHERE obj_id = " . $ilDB->quote($a_id, 'integer');
158  $res = $ilDB->query($query);
159  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
160  return $row->grp_type;
161  }
162  return GRP_TYPE_UNKNOWN;
163  }
164 
165  // Setter/Getter
173  public function setInformation($a_information)
174  {
175  $this->information = $a_information;
176  }
177 
185  public function getInformation()
186  {
187  return $this->information;
188  }
189 
196  public function setGroupType($a_type)
197  {
198  $this->group_type = $a_type;
199  }
200 
207  public function getGroupType()
208  {
209  return $this->group_type;
210  }
211 
219  public function setRegistrationType($a_type)
220  {
221  $this->reg_type = $a_type;
222  }
223 
230  public function getRegistrationType()
231  {
232  return $this->reg_type;
233  }
234 
241  public function isRegistrationEnabled()
242  {
244  }
245 
253  public function enableUnlimitedRegistration($a_status)
254  {
255  $this->reg_unlimited = $a_status;
256  }
257 
264  public function isRegistrationUnlimited()
265  {
266  return $this->reg_unlimited;
267  }
268 
276  public function setRegistrationStart($a_start)
277  {
278  $this->reg_start = $a_start;
279  }
280 
287  public function getRegistrationStart()
288  {
289  return $this->reg_start;
290  }
291 
292 
300  public function setRegistrationEnd($a_end)
301  {
302  $this->reg_end = $a_end;
303  }
304 
311  public function getRegistrationEnd()
312  {
313  return $this->reg_end;
314  }
315 
322  public function setPassword($a_pass)
323  {
324  $this->reg_password = $a_pass;
325  }
326 
333  public function getPassword()
334  {
335  return $this->reg_password;
336  }
337 
345  public function enableMembershipLimitation($a_status)
346  {
347  $this->reg_membership_limitation = $a_status;
348  }
349 
356  public function isMembershipLimited()
357  {
358  return (bool) $this->reg_membership_limitation;
359  }
360 
367  public function setMinMembers($a_max)
368  {
369  $this->reg_min_members = $a_max;
370  }
371 
378  public function getMinMembers()
379  {
380  return $this->reg_min_members;
381  }
382 
389  public function setMaxMembers($a_max)
390  {
391  $this->reg_max_members = $a_max;
392  }
393 
400  public function getMaxMembers()
401  {
402  return $this->reg_max_members;
403  }
404 
412  public function enableWaitingList($a_status)
413  {
414  $this->waiting_list = $a_status;
415  }
416 
424  public function isWaitingListEnabled()
425  {
426  return $this->waiting_list;
427  }
428 
429  public function setWaitingListAutoFill($a_value)
430  {
431  $this->auto_fill_from_waiting = (bool) $a_value;
432  }
433 
434  public function hasWaitingListAutoFill()
435  {
436  return (bool) $this->auto_fill_from_waiting;
437  }
438 
444  public function setLatitude($a_latitude)
445  {
446  $this->latitude = $a_latitude;
447  }
448 
454  public function getLatitude()
455  {
456  return $this->latitude;
457  }
458 
464  public function setLongitude($a_longitude)
465  {
466  $this->longitude = $a_longitude;
467  }
468 
474  public function getLongitude()
475  {
476  return $this->longitude;
477  }
478 
484  public function setLocationZoom($a_locationzoom)
485  {
486  $this->locationzoom = $a_locationzoom;
487  }
488 
494  public function getLocationZoom()
495  {
496  return $this->locationzoom;
497  }
498 
504  public function setEnableGroupMap($a_enablemap)
505  {
506  $this->enablemap = $a_enablemap;
507  }
508 
513  public function getEnableMap()
514  {
515  return $this->getEnableGroupMap();
516  }
517 
523  public function getEnableGroupMap()
524  {
525  return (bool) $this->enablemap;
526  }
527 
532  public function getRegistrationAccessCode()
533  {
534  return $this->reg_access_code;
535  }
536 
542  public function setRegistrationAccessCode($a_code)
543  {
544  $this->reg_access_code = $a_code;
545  }
546 
552  {
553  return (bool) $this->reg_access_code_enabled;
554  }
555 
561  public function enableRegistrationAccessCode($a_status)
562  {
563  $this->reg_access_code_enabled = $a_status;
564  }
565 
571  public function setMailToMembersType($a_type)
572  {
573  $this->mail_members = $a_type;
574  }
575 
580  public function getMailToMembersType()
581  {
582  return $this->mail_members;
583  }
584 
585  public function setCancellationEnd(ilDate $a_value = null)
586  {
587  $this->leave_end = $a_value;
588  }
589 
590  public function getCancellationEnd()
591  {
592  return $this->leave_end;
593  }
594 
595  public function setShowMembers($a_status)
596  {
597  $this->show_members = $a_status;
598  }
599  public function getShowMembers()
600  {
601  return $this->show_members;
602  }
603 
607  public function setAutoNotification(bool $a_status)
608  {
609  $this->auto_notification = $a_status;
610  }
611 
615  public function getAutoNotification() : ?bool
616  {
618  }
619 
620 
626  public function setPeriod(\ilDateTime $start = null, \ilDateTime $end = null)
627  {
628  if (
629  ($start instanceof \ilDate && !$end instanceof ilDate) ||
630  ($end instanceof \ilDate && !$start instanceof ilDate)
631  ) {
632  throw new InvalidArgumentException('Different date types not supported.');
633  }
634 
635  if ($start instanceof \ilDate) {
636  $this->toggleStartTimeIndication(false);
637  } else {
638  $this->toggleStartTimeIndication(true);
639  }
640  $this->setStart($start);
641  $this->setEnd($end);
642  }
643 
647  protected function toggleStartTimeIndication(bool $time_indication)
648  {
649  $this->start_time_indication = $time_indication;
650  }
651 
655  public function getStartTimeIndication() : ?bool
656  {
657  return $this->start_time_indication;
658  }
659 
660 
664  protected function setStart(ilDateTime $a_value = null)
665  {
666  $this->grp_start = $a_value;
667  }
668 
672  public function getStart() : ?\ilDateTime
673  {
674  return $this->grp_start;
675  }
676 
680  protected function setEnd(ilDateTime $a_value = null)
681  {
682  $this->grp_end = $a_value;
683  }
684 
688  public function getEnd() : ?\ilDateTime
689  {
690  return $this->grp_end;
691  }
692 
693 
694 
701  public function validate()
702  {
703  global $DIC;
704 
705  $ilErr = $DIC['ilErr'];
706 
707  if (!$this->getTitle()) {
708  $this->title = '';
709  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
710  }
711  if ($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword())) {
712  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
713  }
714  /*
715  if(ilDateTime::_before($this->getRegistrationEnd(),$this->getRegistrationStart()))
716  {
717  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
718  }
719  */
720  if ($this->isMembershipLimited()) {
721  if ($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0) {
722  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
723  }
724  if ($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled()) {
725  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
726  }
727  if ($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers()) {
728  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
729  }
730  }
731  if (
732  ($this->getRegistrationStart() && !$this->getRegistrationEnd()) ||
733  (!$this->getRegistrationStart() && $this->getRegistrationEnd()) ||
734  $this->getRegistrationEnd() <= $this->getRegistrationStart()
735  ) {
736  $ilErr->appendMessage($this->lng->txt((self::ERR_WRONG_REGISTRATION_LIMITED)));
737  }
738 
739  return strlen($ilErr->getMessage()) == 0;
740  }
741 
742 
743 
744 
748  public function create()
749  {
750  global $DIC;
751 
752  $ilDB = $DIC['ilDB'];
753  $ilAppEventHandler = $DIC['ilAppEventHandler'];
754 
755  if (!parent::create()) {
756  return false;
757  }
758 
759  if (!$a_upload) {
760  $this->createMetaData();
761  }
762 
763 
764  $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled," .
765  "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit," .
766  "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type," .
767  "leave_end,registration_min_members,auto_wait, grp_start, grp_end, auto_notification) " .
768  "VALUES(" .
769  $ilDB->quote($this->getId(), 'integer') . ", " .
770  $ilDB->quote($this->getInformation(), 'text') . ", " .
771  $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
772  $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
773  $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0), 'integer') . ", " .
774  $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0), 'integer') . ", " .
775  $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
776  $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
777  $ilDB->quote($this->getPassword(), 'text') . ", " .
778  $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
779  $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
780  $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
781  $ilDB->quote($this->getLatitude(), 'text') . ", " .
782  $ilDB->quote($this->getLongitude(), 'text') . ", " .
783  $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
784  $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
785  $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
786  $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
787  $ilDB->quote($this->view_mode, 'integer') . ', ' .
788  $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
789  $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
790  $ilDB->quote($this->getMinMembers(), 'integer') . ', ' .
791  $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ', ' .
792  $ilDB->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
793  $ilDB->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
794  $ilDB->quote($this->getAutoNotification(), \ilDBConstants::T_INTEGER) . ' ' .
795  ")";
796  $res = $ilDB->manipulate($query);
797 
798  $ilAppEventHandler->raise(
799  'Modules/Group',
800  'create',
801  array('object' => $this,
802  'obj_id' => $this->getId(),
803  'appointments' => $this->prepareAppointments('create'))
804  );
805 
806  return $this->getId();
807  }
808 
812  public function update()
813  {
814  global $DIC;
815 
816  $ilDB = $DIC['ilDB'];
817  $ilAppEventHandler = $DIC['ilAppEventHandler'];
818 
819  if (!parent::update()) {
820  return false;
821  }
822 
823  $query = "UPDATE grp_settings " .
824  "SET information = " . $ilDB->quote($this->getInformation(), 'text') . ", " .
825  "grp_type = " . $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
826  "registration_type = " . $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
827  "registration_enabled = " . $ilDB->quote($this->isRegistrationEnabled() ? 1 : 0, 'integer') . ", " .
828  "registration_unlimited = " . $ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0, 'integer') . ", " .
829  "registration_start = " . $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
830  "registration_end = " . $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
831  "registration_password = " . $ilDB->quote($this->getPassword(), 'text') . ", " .
832 // "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
833  "registration_mem_limit = " . $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
834  "registration_max_members = " . $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
835  "waiting_list = " . $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
836  "latitude = " . $ilDB->quote($this->getLatitude(), 'text') . ", " .
837  "longitude = " . $ilDB->quote($this->getLongitude(), 'text') . ", " .
838  "location_zoom = " . $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
839  "enablemap = " . $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
840  'reg_ac_enabled = ' . $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
841  'reg_ac = ' . $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
842  'view_mode = ' . $ilDB->quote($this->view_mode, 'integer') . ', ' .
843  'mail_members_type = ' . $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
844  'leave_end = ' . $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
845  "registration_min_members = " . $ilDB->quote($this->getMinMembers(), 'integer') . ", " .
846  "auto_wait = " . $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ", " .
847  "show_members = " . $ilDB->quote((int) $this->getShowMembers(), 'integer') . ", " .
848  'period_start = ' . $ilDB->quote(\ilCalendarUtil::convertDateToUtcDBTimestamp($this->getStart()), \ilDBConstants::T_TIMESTAMP) . ', ' .
849  'period_end = ' . $ilDB->quote(\ilCalendarUtil::convertDateToUtcDBTimestamp($this->getEnd()), \ilDBConstants::T_TIMESTAMP) . ', ' .
850  'period_time_indication = ' . $ilDB->quote($this->getStartTimeIndication() ? 1 : 0, \ilDBConstants::T_INTEGER) . ', ' .
851  'auto_notification = ' . $ilDB->quote($this->getAutoNotification(), \ilDBConstants::T_INTEGER) . ' ' .
852  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
853  $res = $ilDB->manipulate($query);
854 
855  $ilAppEventHandler->raise(
856  'Modules/Group',
857  'update',
858  array('object' => $this,
859  'obj_id' => $this->getId(),
860  'appointments' => $this->prepareAppointments('update'))
861  );
862 
863 
864  return true;
865  }
866 
873  public function delete()
874  {
875  global $DIC;
876 
877  $ilDB = $DIC['ilDB'];
878  $ilAppEventHandler = $DIC['ilAppEventHandler'];
879 
880  // always call parent delete function first!!
881  if (!parent::delete()) {
882  return false;
883  }
884 
885  $query = "DELETE FROM grp_settings " .
886  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
887  $res = $ilDB->manipulate($query);
888 
889  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
891 
892  $ilAppEventHandler->raise(
893  'Modules/Group',
894  'delete',
895  array('object' => $this,
896  'obj_id' => $this->getId(),
897  'appointments' => $this->prepareAppointments('delete'))
898  );
899 
900 
901  return true;
902  }
903 
904 
908  public function read()
909  {
910  global $DIC;
911 
912  $ilDB = $DIC['ilDB'];
913 
914  parent::read();
915 
916  $query = "SELECT * FROM grp_settings " .
917  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
918 
919  $res = $ilDB->query($query);
920  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
921  $this->setInformation($row->information);
922  $this->setGroupType($row->grp_type);
923  $this->setRegistrationType($row->registration_type);
924  $this->enableUnlimitedRegistration($row->registration_unlimited);
925  $this->setRegistrationStart(new ilDateTime($row->registration_start, IL_CAL_DATETIME));
926  $this->setRegistrationEnd(new ilDateTime($row->registration_end, IL_CAL_DATETIME));
927  $this->setPassword($row->registration_password);
928  $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
929  $this->setMaxMembers($row->registration_max_members);
930  $this->enableWaitingList($row->waiting_list);
931  $this->setLatitude($row->latitude);
932  $this->setLongitude($row->longitude);
933  $this->setLocationZoom($row->location_zoom);
934  $this->setEnableGroupMap($row->enablemap);
935  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
936  $this->setRegistrationAccessCode($row->reg_ac);
937  $this->setViewMode($row->view_mode);
938  $this->setMailToMembersType($row->mail_members_type);
939  $this->setCancellationEnd($row->leave_end ? new ilDate($row->leave_end, IL_CAL_UNIX) : null);
940  $this->setMinMembers($row->registration_min_members);
941  $this->setWaitingListAutoFill($row->auto_wait);
942  $this->setShowMembers($row->show_members);
943  $this->setAutoNotification((bool) $row->auto_notification);
944  if ($row->period_time_indication) {
945  $this->setPeriod(
946  new \ilDateTime($row->period_start, IL_CAL_DATETIME, \ilTimeZone::UTC),
947  new \ilDateTime($row->period_end, IL_CAL_DATETIME, \ilTimeZone::UTC)
948  );
949  } elseif (!is_null($row->period_start) && !is_null($row->period_end)) {
950  $this->setPeriod(
951  new \ilDate($row->period_start, IL_CAL_DATE),
952  new \ilDate($row->period_end, IL_CAL_DATE)
953  );
954  }
955  $this->toggleStartTimeIndication((bool) $row->period_time_indication);
956  }
957  $this->initParticipants();
958 
959  // Inherit order type from parent course (if exists)
960  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
962  }
963 
972  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
973  {
974  global $DIC;
975 
976  $ilDB = $DIC['ilDB'];
977  $ilUser = $DIC['ilUser'];
978  $ilSetting = $DIC['ilSetting'];
979 
980  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
981 
982  // current template
983  $current_template = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId());
984  $new_obj->applyDidacticTemplate($current_template);
985  $this->cloneAutoGeneratedRoles($new_obj);
986  $this->cloneMetaData($new_obj);
987 
988  $new_obj->setRegistrationType($this->getRegistrationType());
989  $new_obj->setInformation($this->getInformation());
990  $new_obj->setRegistrationStart($this->getRegistrationStart());
991  $new_obj->setRegistrationEnd($this->getRegistrationEnd());
992  $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
993  $new_obj->setPassword($this->getPassword());
994  $new_obj->enableMembershipLimitation($this->isMembershipLimited());
995  $new_obj->setMaxMembers($this->getMaxMembers());
996  $new_obj->enableWaitingList($this->isWaitingListEnabled());
997  $new_obj->setShowMembers($this->getShowMembers());
998 
999  // map
1000  $new_obj->setLatitude($this->getLatitude());
1001  $new_obj->setLongitude($this->getLongitude());
1002  $new_obj->setLocationZoom($this->getLocationZoom());
1003  $new_obj->setEnableGroupMap($this->getEnableGroupMap());
1004  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1005  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1006  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1007 
1008  $new_obj->setViewMode($this->view_mode);
1009  $new_obj->setMailToMembersType($this->getMailToMembersType());
1010 
1011  $new_obj->setCancellationEnd($this->getCancellationEnd());
1012  $new_obj->setMinMembers($this->getMinMembers());
1013  $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
1014  $new_obj->setPeriod($this->getStart(), $this->getEnd());
1015  $new_obj->setAutoNotification($this->getAutoNotification());
1016  $new_obj->update();
1017 
1018  // #13008 - Group Defined Fields
1019  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1020  ilCourseDefinedFieldDefinition::_clone($this->getId(), $new_obj->getId());
1021 
1022  // Assign user as admin
1023  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1024  $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
1025  $part->add($ilUser->getId(), IL_GRP_ADMIN);
1026  $part->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
1027  $part->updateContact($ilUser->getId(), true);
1028 
1029  // Copy learning progress settings
1030  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
1031  $obj_settings = new ilLPObjSettings($this->getId());
1032  $obj_settings->cloneSettings($new_obj->getId());
1033  unset($obj_settings);
1034 
1035  return $new_obj;
1036  }
1037 
1046  public function cloneDependencies($a_target_id, $a_copy_id)
1047  {
1048  global $DIC;
1049 
1050  $tree = $DIC['tree'];
1051 
1052  parent::cloneDependencies($a_target_id, $a_copy_id);
1053 
1054  include_once('Services/Object/classes/class.ilObjectActivation.php');
1055  ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
1056 
1057  // clone membership limitation
1058  foreach (\ilObjCourseGrouping::_getGroupings($this->getId()) as $grouping_id) {
1059  \ilLoggerFactory::getLogger('grp')->info('Handling grouping id: ' . $grouping_id);
1060  $grouping = new \ilObjCourseGrouping($grouping_id);
1061  $grouping->cloneGrouping($a_target_id, $a_copy_id);
1062  }
1063 
1064  return true;
1065  }
1066 
1074  public function cloneAutoGeneratedRoles($new_obj)
1075  {
1076  global $DIC;
1077 
1078  $rbacadmin = $DIC['rbacadmin'];
1079  $rbacreview = $DIC['rbacreview'];
1080 
1081  $admin = $this->getDefaultAdminRole();
1082  $new_admin = $new_obj->getDefaultAdminRole();
1083  if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
1084  ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_admin');
1085  }
1086  $rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
1087  ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_admin.');
1088 
1089  $member = $this->getDefaultMemberRole();
1090  $new_member = $new_obj->getDefaultMemberRole();
1091  if (!$member || !$new_member) {
1092  ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_member');
1093  }
1094  $rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
1095  ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_member.');
1096  }
1097 
1098 
1104  public function join($a_user_id, $a_mem_role = "")
1105  {
1106  global $DIC;
1107 
1108  $rbacadmin = $DIC['rbacadmin'];
1109 
1110  if (is_array($a_mem_role)) {
1111  foreach ($a_mem_role as $role) {
1112  $rbacadmin->assignUser($role, $a_user_id, false);
1113  }
1114  } else {
1115  $rbacadmin->assignUser($a_mem_role, $a_user_id, false);
1116  }
1117 
1118  return true;
1119  }
1120 
1125  public function getDefaultMemberRole()
1126  {
1127  $local_group_Roles = $this->getLocalGroupRoles();
1128 
1129  return $local_group_Roles["il_grp_member_" . $this->getRefId()];
1130  }
1131 
1136  public function getDefaultAdminRole()
1137  {
1138  $local_group_Roles = $this->getLocalGroupRoles();
1139 
1140  return $local_group_Roles["il_grp_admin_" . $this->getRefId()];
1141  }
1142 
1149  public function addMember($a_user_id, $a_mem_role)
1150  {
1151  global $DIC;
1152 
1153  $rbacadmin = $DIC['rbacadmin'];
1154 
1155  if (isset($a_user_id) && isset($a_mem_role)) {
1156  $this->join($a_user_id, $a_mem_role);
1157  return true;
1158  } else {
1159  $this->ilias->raiseError(get_class($this) . "::addMember(): Missing parameters !", $this->ilias->error_obj->WARNING);
1160  return false;
1161  }
1162  }
1163 
1164 
1171  public function leaveGroup()
1172  {
1173  global $DIC;
1174 
1175  $rbacadmin = $DIC['rbacadmin'];
1176  $rbacreview = $DIC['rbacreview'];
1177 
1178  $member_ids = $this->getGroupMemberIds();
1179 
1180  if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids)) {
1181  return 2;
1182  } else {
1183  if (!$this->isAdmin($this->ilias->account->getId())) {
1184  $this->leave($this->ilias->account->getId());
1185  $this->recommended_content_manager->removeObjectRecommendation($this->user->getId(), $this->getRefId());
1186 
1187  return 0;
1188  } elseif (count($this->getGroupAdminIds()) == 1) {
1189  return 1;
1190  }
1191  }
1192  }
1193 
1198  public function leave($a_user_id)
1199  {
1200  global $DIC;
1201 
1202  $rbacadmin = $DIC['rbacadmin'];
1203 
1204  $arr_groupRoles = $this->getMemberRoles($a_user_id);
1205 
1206  if (is_array($arr_groupRoles)) {
1207  foreach ($arr_groupRoles as $groupRole) {
1208  $rbacadmin->deassignUser($groupRole, $a_user_id);
1209  }
1210  } else {
1211  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
1212  }
1213 
1214  return true;
1215  }
1216 
1223  public function getGroupMemberIds()
1224  {
1225  global $DIC;
1226 
1227  $rbacadmin = $DIC['rbacadmin'];
1228  $rbacreview = $DIC['rbacreview'];
1229 
1230  $usr_arr = array();
1231 
1232  $rol = $this->getLocalGroupRoles();
1233 
1234  foreach ($rol as $value) {
1235  foreach ($rbacreview->assignedUsers($value) as $member_id) {
1236  array_push($usr_arr, $member_id);
1237  }
1238  }
1239 
1240  $mem_arr = array_unique($usr_arr);
1241 
1242  return $mem_arr ? $mem_arr : array();
1243  }
1244 
1252  public function getGroupMemberData($a_mem_ids, $active = 1)
1253  {
1254  global $DIC;
1255 
1256  $rbacadmin = $DIC['rbacadmin'];
1257  $rbacreview = $DIC['rbacreview'];
1258  $ilBench = $DIC['ilBench'];
1259  $ilDB = $DIC['ilDB'];
1260 
1261  $usr_arr = array();
1262 
1263  $q = "SELECT login,firstname,lastname,title,usr_id,last_login " .
1264  "FROM usr_data " .
1265  "WHERE usr_id IN (" . implode(',', ilUtil::quoteArray($a_mem_ids)) . ") ";
1266 
1267  if (is_numeric($active) && $active > -1) {
1268  $q .= "AND active = '$active'";
1269  }
1270 
1271  $q .= 'ORDER BY lastname,firstname';
1272 
1273  $r = $ilDB->query($q);
1274 
1275  while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1276  $mem_arr[] = array("id" => $row->usr_id,
1277  "login" => $row->login,
1278  "firstname" => $row->firstname,
1279  "lastname" => $row->lastname,
1280  "last_login" => $row->last_login
1281  );
1282  }
1283 
1284  return $mem_arr ? $mem_arr : array();
1285  }
1286 
1287  public function getCountMembers()
1288  {
1289  return count($this->getGroupMemberIds());
1290  }
1291 
1298  public function getGroupAdminIds($a_grpId = "")
1299  {
1300  global $DIC;
1301 
1302  $rbacreview = $DIC['rbacreview'];
1303 
1304  if (!empty($a_grpId)) {
1305  $grp_id = $a_grpId;
1306  } else {
1307  $grp_id = $this->getRefId();
1308  }
1309 
1310  $usr_arr = array();
1311  $roles = $this->getDefaultGroupRoles($this->getRefId());
1312 
1313  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id) {
1314  array_push($usr_arr, $member_id);
1315  }
1316 
1317  return $usr_arr;
1318  }
1319 
1325  public function getDefaultGroupRoles($a_grp_id = "")
1326  {
1327  global $DIC;
1328 
1329  $rbacadmin = $DIC['rbacadmin'];
1330  $rbacreview = $DIC['rbacreview'];
1331 
1332  if (strlen($a_grp_id) > 0) {
1333  $grp_id = $a_grp_id;
1334  } else {
1335  $grp_id = $this->getRefId();
1336  }
1337 
1338  $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1339 
1340  foreach ($role_arr as $role_id) {
1341  $role_Obj = &$this->ilias->obj_factory->getInstanceByObjId($role_id);
1342 
1343  $grp_Member = "il_grp_member_" . $grp_id;
1344  $grp_Admin = "il_grp_admin_" . $grp_id;
1345 
1346  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0) {
1347  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1348  }
1349 
1350  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0) {
1351  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1352  }
1353  }
1354 
1355  return $arr_grpDefaultRoles;
1356  }
1357 
1364  public function getLocalGroupRoles($a_translate = false)
1365  {
1366  global $DIC;
1367 
1368  $rbacadmin = $DIC['rbacadmin'];
1369  $rbacreview = $DIC['rbacreview'];
1370 
1371  if (empty($this->local_roles)) {
1372  $this->local_roles = array();
1373  $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1374 
1375  foreach ($role_arr as $role_id) {
1376  if ($rbacreview->isAssignable($role_id, $this->getRefId()) == true) {
1377  $role_Obj = &$this->ilias->obj_factory->getInstanceByObjId($role_id);
1378 
1379  if ($a_translate) {
1380  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1381  } else {
1382  $role_name = $role_Obj->getTitle();
1383  }
1384 
1385  $this->local_roles[$role_name] = $role_Obj->getId();
1386  }
1387  }
1388  }
1389 
1390  return $this->local_roles;
1391  }
1392 
1399  {
1400  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1401  $res = $this->ilias->db->query($q);
1402  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1403 
1404  return $row["obj_id"];
1405  }
1406 
1412  public function getGrpStatusOpenTemplateId()
1413  {
1414  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1415  $res = $this->ilias->db->query($q);
1416  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1417 
1418  return $row["obj_id"];
1419  }
1420 
1427  public static function lookupGroupStatusTemplateId($a_obj_id)
1428  {
1429  global $DIC;
1430 
1431  $ilDB = $DIC['ilDB'];
1432 
1433  $type = self::lookupGroupTye($a_obj_id);
1434  if ($type == GRP_TYPE_CLOSED) {
1435  $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_closed', 'text');
1436  } else {
1437  $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_open', 'text');
1438  }
1439  $res = $ilDB->query($query);
1440  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1441 
1442  return isset($row['obj_id']) ? $row['obj_id'] : 0;
1443  }
1444 
1445 
1446 
1456  public function updateGroupType($a_group_type = GRP_TYPE_OPEN)
1457  {
1458  global $DIC;
1459 
1460  $logger = $DIC->logger()->grp();
1461 
1462  if ($a_group_type == GRP_TYPE_OPEN) {
1463  $this->applyDidacticTemplate(0);
1464  return;
1465  }
1466 
1467  $templates = ilDidacticTemplateSettings::getInstanceByObjectType($this->getType())->getTemplates();
1468  foreach ($templates as $template) {
1469  // the closed template
1470  if ($template->isAutoGenerated()) {
1471  $logger->info('Appying default closed template');
1472  $this->applyDidacticTemplate($template->getId());
1473  return;
1474  }
1475  }
1476  $logger->warning('No closed didactic template available.');
1477  }
1478 
1479 
1487  public function setGroupStatus($a_status)
1488  {
1489  $this->group_status = $a_status;
1490  }
1491 
1499  public function getGroupStatus()
1500  {
1501  return $this->group_status;
1502  }
1503 
1508  public function readGroupStatus() : int
1509  {
1510  global $DIC;
1511 
1512 
1514  $logger = $DIC->logger()->grp();
1515  $logger->dump($tpl_id);
1516  if (!$tpl_id) {
1517  return GRP_TYPE_OPEN;
1518  }
1519  return GRP_TYPE_CLOSED;
1520  }
1521 
1528  public function getMemberRoles($a_user_id)
1529  {
1530  global $DIC;
1531 
1532  $rbacadmin = $DIC['rbacadmin'];
1533  $rbacreview = $DIC['rbacreview'];
1534  $ilBench = $DIC['ilBench'];
1535 
1536  $ilBench->start("Group", "getMemberRoles");
1537 
1538  $arr_assignedRoles = array();
1539 
1540  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id), $this->getLocalGroupRoles());
1541 
1542  $ilBench->stop("Group", "getMemberRoles");
1543 
1544  return $arr_assignedRoles;
1545  }
1546 
1553  public function isAdmin($a_userId)
1554  {
1555  global $DIC;
1556 
1557  $rbacreview = $DIC['rbacreview'];
1558 
1559  $grp_Roles = $this->getDefaultGroupRoles();
1560 
1561  if (in_array($a_userId, $rbacreview->assignedUsers($grp_Roles["grp_admin_role"]))) {
1562  return true;
1563  } else {
1564  return false;
1565  }
1566  }
1572  public function initDefaultRoles()
1573  {
1574  include_once './Services/AccessControl/classes/class.ilObjRole.php';
1576  'il_grp_admin_' . $this->getRefId(),
1577  "Groupadmin group obj_no." . $this->getId(),
1578  'il_grp_admin',
1579  $this->getRefId()
1580  );
1581  $this->m_roleAdminId = $role->getId();
1582 
1584  'il_grp_member_' . $this->getRefId(),
1585  "Groupmember of group obj_no." . $this->getId(),
1586  'il_grp_member',
1587  $this->getRefId()
1588  );
1589  $this->m_roleMemberId = $role->getId();
1590 
1591  return array();
1592  }
1593 
1603  public function setParentRolePermissions($a_parent_ref)
1604  {
1605  $rbacadmin = $GLOBALS['DIC']->rbac()->admin();
1606  $rbacreview = $GLOBALS['DIC']->rbac()->review();
1607 
1608  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1609  foreach ((array) $parent_roles as $parent_role) {
1610  if ($parent_role['parent'] == $this->getRefId()) {
1611  continue;
1612  }
1613  if ($rbacreview->isProtected($parent_role['parent'], $parent_role['rol_id'])) {
1614  $operations = $rbacreview->getOperationsOfRole(
1615  $parent_role['obj_id'],
1616  $this->getType(),
1617  $parent_role['parent']
1618  );
1619  $rbacadmin->grantPermission(
1620  $parent_role['obj_id'],
1621  $operations,
1622  $this->getRefId()
1623  );
1624  continue;
1625  }
1626 
1627  $rbacadmin->initIntersectionPermissions(
1628  $this->getRefId(),
1629  $parent_role['obj_id'],
1630  $parent_role['parent'],
1631  $this->getGrpStatusOpenTemplateId(),
1632  ROLE_FOLDER_ID
1633  );
1634  }
1635  }
1636 
1637 
1642  public function applyDidacticTemplate($a_tpl_id)
1643  {
1644  parent::applyDidacticTemplate($a_tpl_id);
1645 
1646  if (!$a_tpl_id) {
1647  // init default type
1648  $this->setParentRolePermissions($this->getRefId());
1649  }
1650  }
1651 
1652 
1653  public static function _lookupIdByTitle($a_title)
1654  {
1655  global $DIC;
1656 
1657  $ilDB = $DIC['ilDB'];
1658 
1659  $query = "SELECT * FROM object_data WHERE title = " .
1660  $ilDB->quote($a_title, 'text') . " AND type = 'grp'";
1661  $res = $ilDB->query($query);
1662  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1663  return $row->obj_id;
1664  }
1665  return 0;
1666  }
1667 
1668 
1669  public function _isMember($a_user_id, $a_ref_id, $a_field = '')
1670  {
1671  global $DIC;
1672 
1673  $rbacreview = $DIC['rbacreview'];
1674  $ilObjDataCache = $DIC['ilObjDataCache'];
1675  $ilDB = $DIC['ilDB'];
1676 
1677  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
1678  $user_roles = $rbacreview->assignedRoles($a_user_id);
1679 
1680  // Used for membership limitations -> check membership by given field
1681  if ($a_field) {
1682  include_once './Services/User/classes/class.ilObjUser.php';
1683 
1684  $tmp_user = &ilObjectFactory::getInstanceByObjId($a_user_id);
1685  switch ($a_field) {
1686  case 'login':
1687  $and = "AND login = '" . $tmp_user->getLogin() . "' ";
1688  break;
1689  case 'email':
1690  $and = "AND email = '" . $tmp_user->getEmail() . "' ";
1691  break;
1692  case 'matriculation':
1693  $and = "AND matriculation = '" . $tmp_user->getMatriculation() . "' ";
1694  break;
1695 
1696  default:
1697  $and = "AND usr_id = '" . $a_user_id . "'";
1698  break;
1699  }
1700  if (!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id))) {
1701  return false;
1702  }
1703  $query = "SELECT * FROM usr_data as ud " .
1704  "WHERE usr_id IN (" . implode(",", ilUtil::quoteArray($members)) . ") " .
1705  $and;
1706  $res = $ilDB->query($query);
1707 
1708  return $res->numRows() ? true : false;
1709  }
1710 
1711  if (!array_intersect($local_roles, $user_roles)) {
1712  return false;
1713  }
1714 
1715  return true;
1716  }
1717 
1718  public function _getMembers($a_obj_id)
1719  {
1720  global $DIC;
1721 
1722  $rbacreview = $DIC['rbacreview'];
1723 
1724  // get reference
1725  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1726  $ref_id = current($ref_ids);
1727 
1728  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
1729 
1730  $users = array();
1731  foreach ($local_roles as $role_id) {
1732  $users = array_merge($users, $rbacreview->assignedUsers($role_id));
1733  }
1734 
1735  return array_unique($users);
1736  }
1737 
1742  public function getViewMode()
1743  {
1744  $tree = $this->tree;
1745 
1746  // default: by type
1747  $view = self::lookupViewMode($this->getId());
1748 
1749  if ($view != ilContainer::VIEW_INHERIT) {
1750  return $view;
1751  }
1752 
1753  $container_ref_id = $tree->checkForParentType($this->ref_id, 'crs');
1754  if ($container_ref_id) {
1756  // these three are available...
1757  if (
1761  return $view_mode;
1762  }
1763  }
1765  }
1766 
1767 
1772  public function setViewMode($a_view_mode)
1773  {
1774  $this->view_mode = $a_view_mode;
1775  }
1776 
1781  public static function lookupViewMode($a_obj_id)
1782  {
1783  global $DIC;
1784 
1785  $ilDB = $DIC['ilDB'];
1786 
1787  $query = 'SELECT view_mode FROM grp_settings ' .
1788  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1789  $res = $ilDB->query($query);
1790 
1791  $view_mode = null;
1792  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1793  $view_mode = $row->view_mode;
1794  }
1795  return $view_mode;
1796  }
1797 
1805  public static function translateViewMode($a_obj_id, $a_view_mode, $a_ref_id = null)
1806  {
1807  global $DIC;
1808 
1809  $tree = $DIC['tree'];
1810 
1811  if (!$a_view_mode) {
1812  $a_view_mode = ilContainer::VIEW_DEFAULT;
1813  }
1814 
1815  // view mode is inherit => check for parent course
1816  if ($a_view_mode == ilContainer::VIEW_INHERIT) {
1817  if (!$a_ref_id) {
1818  $ref = ilObject::_getAllReferences($a_obj_id);
1819  $a_ref_id = end($ref);
1820  }
1821 
1822  $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1823  if (!$crs_ref) {
1825  }
1826 
1827  include_once './Modules/Course/classes/class.ilObjCourse.php';
1829 
1830  // validate course view mode
1831  if (!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1834  }
1835 
1836  return $view_mode;
1837  }
1838 
1839  return $a_view_mode;
1840  }
1841 
1846  public function addAdditionalSubItemInformation(&$a_item_data)
1847  {
1848  include_once './Services/Object/classes/class.ilObjectActivation.php';
1850  }
1851 
1852  public function getMessage()
1853  {
1854  return $this->message;
1855  }
1856  public function setMessage($a_message)
1857  {
1858  $this->message = $a_message;
1859  }
1860  public function appendMessage($a_message)
1861  {
1862  if ($this->getMessage()) {
1863  $this->message .= "<br /> ";
1864  }
1865  $this->message .= $a_message;
1866  }
1867 
1875  protected function prepareAppointments($a_mode = 'create')
1876  {
1877  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1878 
1879  switch ($a_mode) {
1880  case 'create':
1881  case 'update':
1882 
1883  $apps = array();
1884  if ($this->getStart() && $this->getEnd()) {
1885  $app = new ilCalendarAppointmentTemplate(self::CAL_START);
1886  $app->setTitle($this->getTitle());
1887  $app->setSubtitle('grp_cal_start');
1888  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1889  $app->setDescription($this->getLongDescription());
1890  $app->setStart($this->getStart());
1891  $app->setFullday(!$this->getStartTimeIndication());
1892  $apps[] = $app;
1893 
1894  $app = new ilCalendarAppointmentTemplate(self::CAL_END);
1895  $app->setTitle($this->getTitle());
1896  $app->setSubtitle('grp_cal_end');
1897  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1898  $app->setDescription($this->getLongDescription());
1899  $app->setStart($this->getEnd());
1900  $app->setFullday(!$this->getStartTimeIndication());
1901  $apps[] = $app;
1902  }
1903  if ($this->isRegistrationUnlimited()) {
1904  return $apps;
1905  }
1906 
1907  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1908  $app->setTitle($this->getTitle());
1909  $app->setSubtitle('grp_cal_reg_start');
1910  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1911  $app->setDescription($this->getLongDescription());
1912  $app->setStart($this->getRegistrationStart());
1913  $apps[] = $app;
1914 
1915  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1916  $app->setTitle($this->getTitle());
1917  $app->setSubtitle('grp_cal_reg_end');
1918  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1919  $app->setDescription($this->getLongDescription());
1920  $app->setStart($this->getRegistrationEnd());
1921  $apps[] = $app;
1922 
1923 
1924  return $apps;
1925 
1926  case 'delete':
1927  // Nothing to do: The category and all assigned appointments will be deleted.
1928  return array();
1929  }
1930  }
1931 
1939  protected function initParticipants()
1940  {
1941  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1942  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1943  }
1944 
1950  public function getMembersObject()
1951  {
1952  // #17886
1953  if (!$this->members_obj instanceof ilGroupParticipants) {
1954  $this->initParticipants();
1955  }
1956  return $this->members_obj;
1957  }
1958 
1963  public static function lookupObjectsByCode($a_code)
1964  {
1965  global $DIC;
1966 
1967  $ilDB = $DIC['ilDB'];
1968 
1969  $query = "SELECT obj_id FROM grp_settings " .
1970  "WHERE reg_ac_enabled = " . $ilDB->quote(1, 'integer') . " " .
1971  "AND reg_ac = " . $ilDB->quote($a_code, 'text');
1972  $res = $ilDB->query($query);
1973 
1974  $obj_ids = array();
1975  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1976  $obj_ids[] = $row->obj_id;
1977  }
1978  return $obj_ids;
1979  }
1980 
1987  public function register($a_user_id, $a_role = IL_GRP_MEMBER, $a_force_registration = false)
1988  {
1989  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
1990  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
1992 
1993  if ($part->isAssigned($a_user_id)) {
1994  return true;
1995  }
1996 
1997  if (!$a_force_registration) {
1998  // Availability
1999  if (!$this->isRegistrationEnabled()) {
2000  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
2001 
2003  throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2004  ', group subscription is deactivated.', ilMembershipRegistrationException::REGISTRATION_CODE_DISABLED);
2005  }
2006  }
2007 
2008  // Time Limitation
2009  if (!$this->isRegistrationUnlimited()) {
2010  $start = $this->getRegistrationStart();
2011  $end = $this->getRegistrationEnd();
2012  $time = new ilDateTime(time(), IL_CAL_UNIX);
2013 
2014  if (!(ilDateTime::_after($time, $start) and ilDateTime::_before($time, $end))) {
2015  throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2016  ', group is out of registration time.', ilMembershipRegistrationException::OUT_OF_REGISTRATION_PERIOD);
2017  }
2018  }
2019 
2020  // Max members
2021  if ($this->isMembershipLimited()) {
2022  $free = max(0, $this->getMaxMembers() - $part->getCountMembers());
2023  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2024  $waiting_list = new ilGroupWaitingList($this->getId());
2025  if ($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
2026  $this->lng->loadLanguageModule("grp");
2027  $waiting_list->addToList($a_user_id);
2028 
2029  $info = sprintf(
2030  $this->lng->txt('grp_added_to_list'),
2031  $this->getTitle(),
2032  $waiting_list->getPosition($a_user_id)
2033  );
2034 
2035  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2036  include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
2037  $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
2038  $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $a_user_id);
2039 
2041  }
2042 
2043  if (!$free or $waiting_list->getCountUsers()) {
2044  throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2045  ', membership is limited.', ilMembershipRegistrationException::OBJECT_IS_FULL);
2046  }
2047  }
2048  }
2049 
2050  $part->add($a_user_id, $a_role);
2051  $part->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $a_user_id);
2052  $part->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2053  return true;
2054  }
2055 
2056  public function handleAutoFill()
2057  {
2058  if ($this->isWaitingListEnabled() &&
2059  $this->hasWaitingListAutoFill()) {
2060  $max = $this->getMaxMembers();
2062  if ($max > $now) {
2063  // see assignFromWaitingListObject()
2064  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2065  $waiting_list = new ilGroupWaitingList($this->getId());
2066 
2067  foreach ($waiting_list->getUserIds() as $user_id) {
2068  if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
2069  continue;
2070  }
2071  if ($this->getMembersObject()->isAssigned($user_id)) {
2072  continue;
2073  }
2074  $this->getMembersObject()->add($user_id, IL_GRP_MEMBER); // #18213
2075  include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
2077  $waiting_list->removeFromList($user_id);
2078 
2079  $now++;
2080  if ($now >= $max) {
2081  break;
2082  }
2083  }
2084  }
2085  }
2086  }
2087 
2088  public static function mayLeave($a_group_id, $a_user_id = null, &$a_date = null)
2089  {
2090  global $DIC;
2091 
2092  $ilUser = $DIC['ilUser'];
2093  $ilDB = $DIC['ilDB'];
2094 
2095  if (!$a_user_id) {
2096  $a_user_id = $ilUser->getId();
2097  }
2098 
2099  $set = $ilDB->query("SELECT leave_end" .
2100  " FROM grp_settings" .
2101  " WHERE obj_id = " . $ilDB->quote($a_group_id, "integer"));
2102  $row = $ilDB->fetchAssoc($set);
2103  if ($row && $row["leave_end"]) {
2104  // timestamp to date
2105  $limit = date("Ymd", $row["leave_end"]);
2106  if ($limit < date("Ymd")) {
2107  $a_date = new ilDate(date("Y-m-d", $row["leave_end"]), IL_CAL_DATE);
2108  return false;
2109  }
2110  }
2111  return true;
2112  }
2113 
2119  public static function findGroupsWithNotEnoughMembers()
2120  {
2121  $ilDB = $GLOBALS['DIC']->database();
2122  $tree = $GLOBALS['DIC']->repositoryTree();
2123 
2124  $res = array();
2125 
2126  $now = date("Y-m-d H:i:s");
2127 
2128  $before = new ilDateTime(time(), IL_CAL_UNIX);
2129  $before->increment(IL_CAL_DAY, -1);
2130  $now_date = $before->get(IL_CAL_DATETIME);
2131  $now = $before->get(IL_CAL_UNIX);
2132 
2133  $set = $ilDB->query($q = "SELECT obj_id, registration_min_members" .
2134  " FROM grp_settings" .
2135  " WHERE registration_min_members > " . $ilDB->quote(0, "integer") .
2136  " AND registration_mem_limit = " . $ilDB->quote(1, "integer") . // #17206
2137  " AND ((leave_end IS NOT NULL" .
2138  " AND leave_end < " . $ilDB->quote($now, "integer") . ")" .
2139  " OR (leave_end IS NULL" .
2140  " AND registration_end IS NOT NULL" .
2141  " AND registration_end < " . $ilDB->quote($now_date, "text") . "))" .
2142  " AND (period_start IS NULL OR period_start > " . $ilDB->quote($now, "integer") . ")");
2143  while ($row = $ilDB->fetchAssoc($set)) {
2144  $refs = ilObject::_getAllReferences($row['obj_id']);
2145  $ref = end($refs);
2146 
2147  if ($tree->isDeleted($ref)) {
2148  continue;
2149  }
2150 
2151  $part = new ilGroupParticipants($row["obj_id"]);
2152  $reci = $part->getNotificationRecipients();
2153  if (sizeof($reci)) {
2154  $missing = (int) $row["registration_min_members"] - $part->getCountMembers();
2155  if ($missing > 0) {
2156  $res[$row["obj_id"]] = array($missing, $reci);
2157  }
2158  }
2159  }
2160 
2161  return $res;
2162  }
2163 
2164  public static function lookupShowMembersEnabled(int $a_obj_id) : bool
2165  {
2166  global $DIC;
2167  $ilDB = $DIC["ilDB"];
2168  $query = 'SELECT show_members FROM grp_settings'
2169  .' WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
2170  $res = $ilDB->query($query);
2171  if($ilDB->numRows($res) == 0) {
2172  return false;
2173  }
2174  $row = $ilDB->fetchAssoc($res);
2175  return (bool)$row['show_members'];
2176  }
2177 } //END class.ilObjGroup
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
const GRP_TYPE_OPEN
static lookupGroupStatusTemplateId($a_obj_id)
$ilDB $ilDB
$app
Definition: cli.php:38
setCancellationEnd(ilDate $a_value=null)
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
cloneAutoGeneratedRoles($new_obj)
Clone group admin and member role permissions.
isRegistrationEnabled()
is registration enabled
__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
const IL_CAL_DATETIME
update()
Update group.
getDefaultMemberRole()
returns object id of created default member role public
const GRP_REGISTRATION_DEACTIVATED
static convertDateToUtcDBTimestamp(\ilDateTime $date=null)
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.
setParentRolePermissions($a_parent_ref)
This method is called before "initDefaultRoles".
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
const GRP_TYPE_UNKNOWN
createMetaData()
create meta data entry
setEnd(ilDateTime $a_value=null)
setLongitude($a_longitude)
Set Longitude.
_getMembers($a_obj_id)
getLatitude()
Get Latitude.
getRegistrationAccessCode()
get access code
const ERR_MISSING_GROUP_TYPE
Apointment templates are used for automatic generated apointments.
toggleStartTimeIndication(bool $time_indication)
static _lookupViewMode($a_id)
lookup view mode of container
const IL_CAL_UNIX
const IL_GRP_MEMBER
getEnableMap()
Type independent wrapper.
applyDidacticTemplate($a_tpl_id)
Apply template.
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.
user()
Definition: user.php:4
getDefaultGroupRoles($a_grp_id="")
get default group roles, returns the defaultlike create roles il_grp_member, il_grp_admin public ...
static _getAllReferences($a_id)
get all reference ids of object
getGrpStatusOpenTemplateId()
get group status open template public
$ilErr
Definition: raiseError.php:18
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
updateGroupType($a_group_type=GRP_TYPE_OPEN)
Change group type.
enableWaitingList($a_status)
enable waiting list
setMessage($a_message)
static findGroupsWithNotEnoughMembers()
Minimum members check $ilDB $ilDB.
$a_type
Definition: workflow.php:92
setShowMembers($a_status)
getGrpStatusClosedTemplateId()
get group status closed template public
appendMessage($a_message)
leave($a_user_id)
deassign member from group role private
getGroupType()
get group type
const IL_CAL_DAY
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
setLatitude($a_latitude)
Set Latitude.
static lookupShowMembersEnabled(int $a_obj_id)
Class for single dates.
foreach($_POST as $key=> $value) $res
getId()
get object id public
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.
const ERR_WRONG_REGISTRATION_LIMITED
getLocalGroupRoles($a_translate=false)
get ALL local roles of group, also those created and defined afterwards only fetch data once from dat...
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.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone group (no member data)
initParticipants()
init participants object
$ilUser
Definition: imgupload.php:18
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) ...
cloneMetaData($target_obj)
Copy meta data.
Class ilContainer.
$query
setGroupType($a_type)
set group type
getEnableGroupMap()
Get Enable Group Map.
getInformation()
get Information
setMinMembers($a_max)
set min members
leaveGroup()
is called when a member decides to leave group public
getType()
get object type public
setInformation($a_information)
set information
getGroupAdminIds($a_grpId="")
get Group Admin Id public
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
setPeriod(\ilDateTime $start=null, \ilDateTime $end=null)
getMailToMembersType()
Get mail to members type.
static _getTranslation($a_role_title)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
setEnableGroupMap($a_enablemap)
Set Enable Group Map.
setGroupStatus($a_status)
Set group status.
static _lookupIdByTitle($a_title)
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.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
setLocationZoom($a_locationzoom)
Set LocationZoom.
setOrderType($a_value)
static translateViewMode($a_obj_id, $a_view_mode, $a_ref_id=null)
translate view mode
static lookupObjectsByCode($a_code)
getGroupMemberData($a_mem_ids, $active=1)
get all group Members regardless of group role.
global $ilSetting
Definition: privfeed.php:17
static cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
Clone dependencies.
__construct(Container $dic, ilPlugin $plugin)
const MAIL_ALLOWED_ALL
global $ilBench
Definition: ilias.php:18
global $ilDB
static lookupGroupTye($a_id)
Lookup group type.
$DIC
Definition: xapitoken.php:46
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
$message
Definition: xapiexit.php:14
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
static _getGroupings($a_course_id)
setMailToMembersType($a_type)
Set mail to members type.
setAutoNotification(bool $a_status)
const GRP_REGISTRATION_DIRECT
static lookupViewMode($a_obj_id)
lookup view mode $ilDB
setStart(ilDateTime $a_value=null)
getViewMode()
Get effective container view mode.
setRegistrationAccessCode($a_code)
Set refistration access code.
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()
Read group type.
getMinMembers()
get min members
isWaitingListEnabled()
is waiting list enabled
static _lookupViewMode($a_id)
Lookup view mode.
isAdmin($a_userId)
is Admin public
const ERR_WRONG_REG_TIME_LIMIT
setRegisterMode($a_bool)