ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
74  private $session_limit = 0;
75  private $session_prev = -1;
76  private $session_next = -1;
77 
78 
82  protected $auto_notification = true;
83 
84 
88  protected $grp_start_time_indication = false;
89 
90 
94  protected $start = null;
95 
99  protected $end = null;
100 
101 
102  // Map
103  private $latitude = '';
104  private $longitude = '';
105  private $locationzoom = 0;
106  private $enablemap = 0;
107 
108  private $reg_access_code = '';
109  private $reg_access_code_enabled = false;
110 
112 
113  private $mail_members = self::MAIL_ALLOWED_ALL;
114 
115 
116  public $members_obj;
117 
118 
122  public $file_obj = null;
123 
124  public $m_grpStatus;
125 
127 
129 
130 
137  public function __construct($a_id = 0, $a_call_by_reference = true)
138  {
139  global $DIC;
140 
141  $tree = $DIC['tree'];
142 
143  $this->tree = &$tree;
144 
145  $this->type = "grp";
146  parent::__construct($a_id, $a_call_by_reference);
147  $this->setRegisterMode(true); // ???
148  }
149 
155  public static function lookupGroupTye($a_id)
156  {
157  global $DIC;
158 
159  $ilDB = $DIC['ilDB'];
160 
161  $query = "SELECT grp_type FROM grp_settings " .
162  "WHERE obj_id = " . $ilDB->quote($a_id, 'integer');
163  $res = $ilDB->query($query);
164  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
165  return $row->grp_type;
166  }
167  return GRP_TYPE_UNKNOWN;
168  }
169 
170  // Setter/Getter
178  public function setInformation($a_information)
179  {
180  $this->information = $a_information;
181  }
182 
190  public function getInformation()
191  {
192  return $this->information;
193  }
194 
201  public function setGroupType($a_type)
202  {
203  $this->group_type = $a_type;
204  }
205 
212  public function getGroupType()
213  {
214  return $this->group_type;
215  }
216 
224  public function setRegistrationType($a_type)
225  {
226  $this->reg_type = $a_type;
227  }
228 
235  public function getRegistrationType()
236  {
237  return $this->reg_type;
238  }
239 
246  public function isRegistrationEnabled()
247  {
249  }
250 
258  public function enableUnlimitedRegistration($a_status)
259  {
260  $this->reg_unlimited = $a_status;
261  }
262 
269  public function isRegistrationUnlimited()
270  {
271  return $this->reg_unlimited;
272  }
273 
281  public function setRegistrationStart($a_start)
282  {
283  $this->reg_start = $a_start;
284  }
285 
292  public function getRegistrationStart()
293  {
294  return $this->reg_start;
295  }
296 
297 
305  public function setRegistrationEnd($a_end)
306  {
307  $this->reg_end = $a_end;
308  }
309 
316  public function getRegistrationEnd()
317  {
318  return $this->reg_end;
319  }
320 
327  public function setPassword($a_pass)
328  {
329  $this->reg_password = $a_pass;
330  }
331 
338  public function getPassword()
339  {
340  return $this->reg_password;
341  }
342 
350  public function enableMembershipLimitation($a_status)
351  {
352  $this->reg_membership_limitation = $a_status;
353  }
354 
361  public function isMembershipLimited()
362  {
363  return (bool) $this->reg_membership_limitation;
364  }
365 
372  public function setMinMembers($a_max)
373  {
374  $this->reg_min_members = $a_max;
375  }
376 
383  public function getMinMembers()
384  {
385  return $this->reg_min_members;
386  }
387 
394  public function setMaxMembers($a_max)
395  {
396  $this->reg_max_members = $a_max;
397  }
398 
405  public function getMaxMembers()
406  {
407  return $this->reg_max_members;
408  }
409 
417  public function enableWaitingList($a_status)
418  {
419  $this->waiting_list = $a_status;
420  }
421 
429  public function isWaitingListEnabled()
430  {
431  return $this->waiting_list;
432  }
433 
434  public function setWaitingListAutoFill($a_value)
435  {
436  $this->auto_fill_from_waiting = (bool) $a_value;
437  }
438 
439  public function hasWaitingListAutoFill()
440  {
441  return (bool) $this->auto_fill_from_waiting;
442  }
443 
449  public function setLatitude($a_latitude)
450  {
451  $this->latitude = $a_latitude;
452  }
453 
459  public function getLatitude()
460  {
461  return $this->latitude;
462  }
463 
469  public function setLongitude($a_longitude)
470  {
471  $this->longitude = $a_longitude;
472  }
473 
479  public function getLongitude()
480  {
481  return $this->longitude;
482  }
483 
489  public function setLocationZoom($a_locationzoom)
490  {
491  $this->locationzoom = $a_locationzoom;
492  }
493 
499  public function getLocationZoom()
500  {
501  return $this->locationzoom;
502  }
503 
509  public function setEnableGroupMap($a_enablemap)
510  {
511  $this->enablemap = $a_enablemap;
512  }
513 
518  public function getEnableMap()
519  {
520  return $this->getEnableGroupMap();
521  }
522 
528  public function getEnableGroupMap()
529  {
530  return (bool) $this->enablemap;
531  }
532 
537  public function getRegistrationAccessCode()
538  {
539  return $this->reg_access_code;
540  }
541 
547  public function setRegistrationAccessCode($a_code)
548  {
549  $this->reg_access_code = $a_code;
550  }
551 
557  {
558  return (bool) $this->reg_access_code_enabled;
559  }
560 
566  public function enableRegistrationAccessCode($a_status)
567  {
568  $this->reg_access_code_enabled = $a_status;
569  }
570 
576  public function setMailToMembersType($a_type)
577  {
578  $this->mail_members = $a_type;
579  }
580 
585  public function getMailToMembersType()
586  {
587  return $this->mail_members;
588  }
589 
590  public function setCancellationEnd(ilDate $a_value = null)
591  {
592  $this->leave_end = $a_value;
593  }
594 
595  public function getCancellationEnd()
596  {
597  return $this->leave_end;
598  }
599 
600  public function setShowMembers($a_status)
601  {
602  $this->show_members = $a_status;
603  }
604  public function getShowMembers()
605  {
606  return $this->show_members;
607  }
608 
612  public function setAutoNotification(bool $a_status)
613  {
614  $this->auto_notification = $a_status;
615  }
616 
620  public function getAutoNotification() : ?bool
621  {
623  }
624 
625 
631  public function setPeriod(\ilDateTime $start = null, \ilDateTime $end = null)
632  {
633  if (
634  ($start instanceof \ilDate && !$end instanceof ilDate) ||
635  ($end instanceof \ilDate && !$start instanceof ilDate)
636  ) {
637  throw new InvalidArgumentException('Different date types not supported.');
638  }
639 
640  if ($start instanceof \ilDate) {
641  $this->toggleStartTimeIndication(false);
642  } else {
643  $this->toggleStartTimeIndication(true);
644  }
645  $this->setStart($start);
646  $this->setEnd($end);
647  }
648 
652  protected function toggleStartTimeIndication(bool $time_indication)
653  {
654  $this->start_time_indication = $time_indication;
655  }
656 
660  public function getStartTimeIndication() : ?bool
661  {
662  return $this->start_time_indication;
663  }
664 
665 
669  protected function setStart(ilDateTime $a_value = null)
670  {
671  $this->grp_start = $a_value;
672  }
673 
677  public function getStart() : ?\ilDateTime
678  {
679  return $this->grp_start;
680  }
681 
685  protected function setEnd(ilDateTime $a_value = null)
686  {
687  $this->grp_end = $a_value;
688  }
689 
693  public function getEnd() : ?\ilDateTime
694  {
695  return $this->grp_end;
696  }
697 
703  public function enableSessionLimit(bool $a_status)
704  {
705  $this->session_limit = $a_status;
706  }
707 
708  public function isSessionLimitEnabled() : bool
709  {
710  return (bool) $this->session_limit;
711  }
712 
717  public function setNumberOfPreviousSessions(int $a_num)
718  {
719  $this->session_prev = $a_num;
720  }
721 
726  public function getNumberOfPreviousSessions() : int
727  {
728  return $this->session_prev;
729  }
730 
735  public function setNumberOfNextSessions(int $a_num)
736  {
737  $this->session_next = $a_num;
738  }
739 
744  public function getNumberOfNextSessions() : int
745  {
746  return $this->session_next;
747  }
748 
749 
756  public function validate()
757  {
758  global $DIC;
759 
760  $ilErr = $DIC['ilErr'];
761 
762  if (!$this->getTitle()) {
763  $this->title = '';
764  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
765  }
766  if ($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword())) {
767  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
768  }
769  /*
770  if(ilDateTime::_before($this->getRegistrationEnd(),$this->getRegistrationStart()))
771  {
772  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
773  }
774  */
775  if ($this->isMembershipLimited()) {
776  if ($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0) {
777  $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
778  }
779  if ($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled()) {
780  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
781  }
782  if ($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers()) {
783  $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
784  }
785  }
786  if (
787  ($this->getRegistrationStart() && !$this->getRegistrationEnd()) ||
788  (!$this->getRegistrationStart() && $this->getRegistrationEnd()) ||
789  $this->getRegistrationEnd() <= $this->getRegistrationStart()
790  ) {
791  $ilErr->appendMessage($this->lng->txt((self::ERR_WRONG_REGISTRATION_LIMITED)));
792  }
793 
794  return strlen($ilErr->getMessage()) == 0;
795  }
796 
797 
798 
799 
803  public function create()
804  {
805  global $DIC;
806 
807  $ilDB = $DIC['ilDB'];
808  $ilAppEventHandler = $DIC['ilAppEventHandler'];
809 
810  if (!parent::create()) {
811  return false;
812  }
813 
814  if (!$a_upload) {
815  $this->createMetaData();
816  }
817 
818 
819  $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled," .
820  "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit," .
821  "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type," .
822  "leave_end,registration_min_members,auto_wait, grp_start, grp_end, auto_notification, session_limit, session_prev, session_next) " .
823  "VALUES(" .
824  $ilDB->quote($this->getId(), 'integer') . ", " .
825  $ilDB->quote($this->getInformation(), 'text') . ", " .
826  $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
827  $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
828  $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0), 'integer') . ", " .
829  $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0), 'integer') . ", " .
830  $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
831  $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
832  $ilDB->quote($this->getPassword(), 'text') . ", " .
833  $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
834  $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
835  $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
836  $ilDB->quote($this->getLatitude(), 'text') . ", " .
837  $ilDB->quote($this->getLongitude(), 'text') . ", " .
838  $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
839  $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
840  $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
841  $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
842  $ilDB->quote($this->view_mode, 'integer') . ', ' .
843  $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
844  $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
845  $ilDB->quote($this->getMinMembers(), 'integer') . ', ' .
846  $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ', ' .
847  $ilDB->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
848  $ilDB->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
849  $ilDB->quote($this->getAutoNotification(), \ilDBConstants::T_INTEGER) . ', ' .
850  $ilDB->quote($this->isSessionLimitEnabled(), ilDBConstants::T_INTEGER) . ', ' .
853  ')';
854  $res = $ilDB->manipulate($query);
855 
856  $ilAppEventHandler->raise(
857  'Modules/Group',
858  'create',
859  array('object' => $this,
860  'obj_id' => $this->getId(),
861  'appointments' => $this->prepareAppointments('create'))
862  );
863 
864  return $this->getId();
865  }
866 
870  public function update()
871  {
872  global $DIC;
873 
874  $ilDB = $DIC['ilDB'];
875  $ilAppEventHandler = $DIC['ilAppEventHandler'];
876 
877  if (!parent::update()) {
878  return false;
879  }
880 
881  $this->updateMetaData();
882 
883  $query = "UPDATE grp_settings " .
884  "SET information = " . $ilDB->quote($this->getInformation(), 'text') . ", " .
885  "grp_type = " . $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
886  "registration_type = " . $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
887  "registration_enabled = " . $ilDB->quote($this->isRegistrationEnabled() ? 1 : 0, 'integer') . ", " .
888  "registration_unlimited = " . $ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0, 'integer') . ", " .
889  "registration_start = " . $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
890  "registration_end = " . $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
891  "registration_password = " . $ilDB->quote($this->getPassword(), 'text') . ", " .
892 // "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
893  "registration_mem_limit = " . $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
894  "registration_max_members = " . $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
895  "waiting_list = " . $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
896  "latitude = " . $ilDB->quote($this->getLatitude(), 'text') . ", " .
897  "longitude = " . $ilDB->quote($this->getLongitude(), 'text') . ", " .
898  "location_zoom = " . $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
899  "enablemap = " . $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
900  'reg_ac_enabled = ' . $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
901  'reg_ac = ' . $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
902  'view_mode = ' . $ilDB->quote($this->view_mode, 'integer') . ', ' .
903  'mail_members_type = ' . $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
904  'leave_end = ' . $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
905  "registration_min_members = " . $ilDB->quote($this->getMinMembers(), 'integer') . ", " .
906  "auto_wait = " . $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ", " .
907  "show_members = " . $ilDB->quote((int) $this->getShowMembers(), 'integer') . ", " .
908  'period_start = ' . $ilDB->quote(\ilCalendarUtil::convertDateToUtcDBTimestamp($this->getStart()), \ilDBConstants::T_TIMESTAMP) . ', ' .
909  'period_end = ' . $ilDB->quote(\ilCalendarUtil::convertDateToUtcDBTimestamp($this->getEnd()), \ilDBConstants::T_TIMESTAMP) . ', ' .
910  'period_time_indication = ' . $ilDB->quote($this->getStartTimeIndication() ? 1 : 0, \ilDBConstants::T_INTEGER) . ', ' .
911  'auto_notification = ' . $ilDB->quote($this->getAutoNotification(), \ilDBConstants::T_INTEGER) . ', ' .
912  'session_limit = ' . $ilDB->quote($this->isSessionLimitEnabled(), ilDBConstants::T_INTEGER) . ', ' .
913  'session_prev = ' . $ilDB->quote($this->getNumberOfPreviousSessions(), ilDBConstants::T_INTEGER) . ', ' .
914  'session_next = ' . $ilDB->quote($this->getNumberOfNextSessions(), ilDBConstants::T_INTEGER) . ' ' .
915  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
916  $res = $ilDB->manipulate($query);
917 
918  $ilAppEventHandler->raise(
919  'Modules/Group',
920  'update',
921  array('object' => $this,
922  'obj_id' => $this->getId(),
923  'appointments' => $this->prepareAppointments('update'))
924  );
925 
926 
927  return true;
928  }
929 
936  public function delete()
937  {
938  global $DIC;
939 
940  $ilDB = $DIC['ilDB'];
941  $ilAppEventHandler = $DIC['ilAppEventHandler'];
942 
943  // always call parent delete function first!!
944  if (!parent::delete()) {
945  return false;
946  }
947 
948  $this->deleteMetaData();
949 
950  $query = "DELETE FROM grp_settings " .
951  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
952  $res = $ilDB->manipulate($query);
953 
954  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
956 
957  $ilAppEventHandler->raise(
958  'Modules/Group',
959  'delete',
960  array('object' => $this,
961  'obj_id' => $this->getId(),
962  'appointments' => $this->prepareAppointments('delete'))
963  );
964 
965 
966  return true;
967  }
968 
969 
973  public function read()
974  {
975  global $DIC;
976 
977  $ilDB = $DIC['ilDB'];
978 
979  parent::read();
980 
981  $query = "SELECT * FROM grp_settings " .
982  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
983 
984  $res = $ilDB->query($query);
985  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
986  $this->setInformation($row->information);
987  $this->setGroupType($row->grp_type);
988  $this->setRegistrationType($row->registration_type);
989  $this->enableUnlimitedRegistration($row->registration_unlimited);
990  $this->setRegistrationStart(new ilDateTime($row->registration_start, IL_CAL_DATETIME));
991  $this->setRegistrationEnd(new ilDateTime($row->registration_end, IL_CAL_DATETIME));
992  $this->setPassword($row->registration_password);
993  $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
994  $this->setMaxMembers($row->registration_max_members);
995  $this->enableWaitingList($row->waiting_list);
996  $this->setLatitude($row->latitude);
997  $this->setLongitude($row->longitude);
998  $this->setLocationZoom($row->location_zoom);
999  $this->setEnableGroupMap($row->enablemap);
1000  $this->enableRegistrationAccessCode($row->reg_ac_enabled);
1001  $this->setRegistrationAccessCode($row->reg_ac);
1002  $this->setViewMode($row->view_mode);
1003  $this->setMailToMembersType($row->mail_members_type);
1004  $this->setCancellationEnd($row->leave_end ? new ilDate($row->leave_end, IL_CAL_UNIX) : null);
1005  $this->setMinMembers($row->registration_min_members);
1006  $this->setWaitingListAutoFill($row->auto_wait);
1007  $this->setShowMembers($row->show_members);
1008  $this->setAutoNotification((bool) $row->auto_notification);
1009  if ($row->period_time_indication) {
1010  $this->setPeriod(
1011  new \ilDateTime($row->period_start, IL_CAL_DATETIME, \ilTimeZone::UTC),
1012  new \ilDateTime($row->period_end, IL_CAL_DATETIME, \ilTimeZone::UTC)
1013  );
1014  } elseif (!is_null($row->period_start) && !is_null($row->period_end)) {
1015  $this->setPeriod(
1016  new \ilDate($row->period_start, IL_CAL_DATE),
1017  new \ilDate($row->period_end, IL_CAL_DATE)
1018  );
1019  }
1020  $this->toggleStartTimeIndication((bool) $row->period_time_indication);
1021  $this->enableSessionLimit((bool) $row->session_limit);
1022  $this->setNumberOfPreviousSessions((int) $row->session_prev);
1023  $this->setNumberOfNextSessions((int) $row->session_next);
1024  }
1025  $this->initParticipants();
1026 
1027  // Inherit order type from parent course (if exists)
1028  include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
1030  }
1031 
1040  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
1041  {
1042  global $DIC;
1043 
1044  $ilDB = $DIC['ilDB'];
1045  $ilUser = $DIC['ilUser'];
1046  $ilSetting = $DIC['ilSetting'];
1047 
1051  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
1052 
1053  // current template
1054  $current_template = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId());
1055  $new_obj->applyDidacticTemplate($current_template);
1056  $this->cloneAutoGeneratedRoles($new_obj);
1057  $this->cloneMetaData($new_obj);
1058 
1059  $new_obj->setRegistrationType($this->getRegistrationType());
1060  $new_obj->setInformation($this->getInformation());
1061  $new_obj->setRegistrationStart($this->getRegistrationStart());
1062  $new_obj->setRegistrationEnd($this->getRegistrationEnd());
1063  $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
1064  $new_obj->setPassword($this->getPassword());
1065  $new_obj->enableMembershipLimitation($this->isMembershipLimited());
1066  $new_obj->setMaxMembers($this->getMaxMembers());
1067  $new_obj->enableWaitingList($this->isWaitingListEnabled());
1068  $new_obj->setShowMembers($this->getShowMembers());
1069 
1070  // map
1071  $new_obj->setLatitude($this->getLatitude());
1072  $new_obj->setLongitude($this->getLongitude());
1073  $new_obj->setLocationZoom($this->getLocationZoom());
1074  $new_obj->setEnableGroupMap($this->getEnableGroupMap());
1075  $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
1076  include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
1077  $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
1078 
1079  $new_obj->setViewMode($this->view_mode);
1080  $new_obj->setMailToMembersType($this->getMailToMembersType());
1081 
1082  $new_obj->setCancellationEnd($this->getCancellationEnd());
1083  $new_obj->setMinMembers($this->getMinMembers());
1084  $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
1085  $new_obj->setPeriod($this->getStart(), $this->getEnd());
1086  $new_obj->setAutoNotification($this->getAutoNotification());
1087  $new_obj->enableSessionLimit($this->isSessionLimitEnabled());
1088  $new_obj->setNumberOfPreviousSessions($this->getNumberOfPreviousSessions());
1089  $new_obj->setNumberOfNextSessions($this->getNumberOfNextSessions());
1090  $new_obj->update();
1091 
1092  // #13008 - Group Defined Fields
1093  include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
1094  ilCourseDefinedFieldDefinition::_clone($this->getId(), $new_obj->getId());
1095 
1096  // Assign user as admin
1097  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1098  $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
1099  $part->add($ilUser->getId(), IL_GRP_ADMIN);
1100  $part->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
1101  $part->updateContact($ilUser->getId(), true);
1102 
1103  // Copy learning progress settings
1104  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
1105  $obj_settings = new ilLPObjSettings($this->getId());
1106  $obj_settings->cloneSettings($new_obj->getId());
1107  unset($obj_settings);
1108 
1109  return $new_obj;
1110  }
1111 
1120  public function cloneDependencies($a_target_id, $a_copy_id)
1121  {
1122  global $DIC;
1123 
1124  $tree = $DIC['tree'];
1125 
1126  parent::cloneDependencies($a_target_id, $a_copy_id);
1127 
1128  include_once('Services/Object/classes/class.ilObjectActivation.php');
1129  ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
1130 
1131  // clone membership limitation
1132  foreach (\ilObjCourseGrouping::_getGroupings($this->getId()) as $grouping_id) {
1133  \ilLoggerFactory::getLogger('grp')->info('Handling grouping id: ' . $grouping_id);
1134  $grouping = new \ilObjCourseGrouping($grouping_id);
1135  $grouping->cloneGrouping($a_target_id, $a_copy_id);
1136  }
1137 
1138  return true;
1139  }
1140 
1148  public function cloneAutoGeneratedRoles($new_obj)
1149  {
1150  global $DIC;
1151 
1152  $rbacadmin = $DIC['rbacadmin'];
1153  $rbacreview = $DIC['rbacreview'];
1154 
1155  $admin = $this->getDefaultAdminRole();
1156  $new_admin = $new_obj->getDefaultAdminRole();
1157  if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
1158  ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_admin');
1159  }
1160  $rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
1161  ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_admin.');
1162 
1163  $member = $this->getDefaultMemberRole();
1164  $new_member = $new_obj->getDefaultMemberRole();
1165  if (!$member || !$new_member) {
1166  ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_member');
1167  }
1168  $rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
1169  ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_member.');
1170  }
1171 
1172 
1178  public function join($a_user_id, $a_mem_role = "")
1179  {
1180  global $DIC;
1181 
1182  $rbacadmin = $DIC['rbacadmin'];
1183 
1184  if (is_array($a_mem_role)) {
1185  foreach ($a_mem_role as $role) {
1186  $rbacadmin->assignUser($role, $a_user_id, false);
1187  }
1188  } else {
1189  $rbacadmin->assignUser($a_mem_role, $a_user_id, false);
1190  }
1191 
1192  return true;
1193  }
1194 
1199  public function getDefaultMemberRole()
1200  {
1201  $local_group_Roles = $this->getLocalGroupRoles();
1202 
1203  return $local_group_Roles["il_grp_member_" . $this->getRefId()];
1204  }
1205 
1210  public function getDefaultAdminRole()
1211  {
1212  $local_group_Roles = $this->getLocalGroupRoles();
1213 
1214  return $local_group_Roles["il_grp_admin_" . $this->getRefId()];
1215  }
1216 
1223  public function addMember($a_user_id, $a_mem_role)
1224  {
1225  global $DIC;
1226 
1227  $rbacadmin = $DIC['rbacadmin'];
1228 
1229  if (isset($a_user_id) && isset($a_mem_role)) {
1230  $this->join($a_user_id, $a_mem_role);
1231  return true;
1232  } else {
1233  $this->ilias->raiseError(get_class($this) . "::addMember(): Missing parameters !", $this->ilias->error_obj->WARNING);
1234  return false;
1235  }
1236  }
1237 
1238 
1245  public function leaveGroup()
1246  {
1247  global $DIC;
1248 
1249  $rbacadmin = $DIC['rbacadmin'];
1250  $rbacreview = $DIC['rbacreview'];
1251 
1252  $member_ids = $this->getGroupMemberIds();
1253 
1254  if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids)) {
1255  return 2;
1256  } else {
1257  if (!$this->isAdmin($this->ilias->account->getId())) {
1258  $this->leave($this->ilias->account->getId());
1259  $this->recommended_content_manager->removeObjectRecommendation($this->user->getId(), $this->getRefId());
1260 
1261  return 0;
1262  } elseif (count($this->getGroupAdminIds()) == 1) {
1263  return 1;
1264  }
1265  }
1266  }
1267 
1272  public function leave($a_user_id)
1273  {
1274  global $DIC;
1275 
1276  $rbacadmin = $DIC['rbacadmin'];
1277 
1278  $arr_groupRoles = $this->getMemberRoles($a_user_id);
1279 
1280  if (is_array($arr_groupRoles)) {
1281  foreach ($arr_groupRoles as $groupRole) {
1282  $rbacadmin->deassignUser($groupRole, $a_user_id);
1283  }
1284  } else {
1285  $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
1286  }
1287 
1288  return true;
1289  }
1290 
1297  public function getGroupMemberIds()
1298  {
1299  global $DIC;
1300 
1301  $rbacadmin = $DIC['rbacadmin'];
1302  $rbacreview = $DIC['rbacreview'];
1303 
1304  $usr_arr = array();
1305 
1306  $rol = $this->getLocalGroupRoles();
1307 
1308  foreach ($rol as $value) {
1309  foreach ($rbacreview->assignedUsers($value) as $member_id) {
1310  array_push($usr_arr, $member_id);
1311  }
1312  }
1313 
1314  $mem_arr = array_unique($usr_arr);
1315 
1316  return $mem_arr ? $mem_arr : array();
1317  }
1318 
1326  public function getGroupMemberData($a_mem_ids, $active = 1)
1327  {
1328  global $DIC;
1329 
1330  $rbacadmin = $DIC['rbacadmin'];
1331  $rbacreview = $DIC['rbacreview'];
1332  $ilBench = $DIC['ilBench'];
1333  $ilDB = $DIC['ilDB'];
1334 
1335  $usr_arr = array();
1336 
1337  $q = "SELECT login,firstname,lastname,title,usr_id,last_login " .
1338  "FROM usr_data " .
1339  "WHERE usr_id IN (" . implode(',', ilUtil::quoteArray($a_mem_ids)) . ") ";
1340 
1341  if (is_numeric($active) && $active > -1) {
1342  $q .= "AND active = '$active'";
1343  }
1344 
1345  $q .= 'ORDER BY lastname,firstname';
1346 
1347  $r = $ilDB->query($q);
1348 
1349  while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1350  $mem_arr[] = array("id" => $row->usr_id,
1351  "login" => $row->login,
1352  "firstname" => $row->firstname,
1353  "lastname" => $row->lastname,
1354  "last_login" => $row->last_login
1355  );
1356  }
1357 
1358  return $mem_arr ? $mem_arr : array();
1359  }
1360 
1361  public function getCountMembers()
1362  {
1363  return count($this->getGroupMemberIds());
1364  }
1365 
1372  public function getGroupAdminIds($a_grpId = "")
1373  {
1374  global $DIC;
1375 
1376  $rbacreview = $DIC['rbacreview'];
1377 
1378  if (!empty($a_grpId)) {
1379  $grp_id = $a_grpId;
1380  } else {
1381  $grp_id = $this->getRefId();
1382  }
1383 
1384  $usr_arr = array();
1385  $roles = $this->getDefaultGroupRoles($this->getRefId());
1386 
1387  foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id) {
1388  array_push($usr_arr, $member_id);
1389  }
1390 
1391  return $usr_arr;
1392  }
1393 
1399  public function getDefaultGroupRoles($a_grp_id = "")
1400  {
1401  global $DIC;
1402 
1403  $rbacadmin = $DIC['rbacadmin'];
1404  $rbacreview = $DIC['rbacreview'];
1405 
1406  if (strlen($a_grp_id) > 0) {
1407  $grp_id = $a_grp_id;
1408  } else {
1409  $grp_id = $this->getRefId();
1410  }
1411 
1412  $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1413 
1414  foreach ($role_arr as $role_id) {
1415  $role_Obj = &$this->ilias->obj_factory->getInstanceByObjId($role_id);
1416 
1417  $grp_Member = "il_grp_member_" . $grp_id;
1418  $grp_Admin = "il_grp_admin_" . $grp_id;
1419 
1420  if (strcmp($role_Obj->getTitle(), $grp_Member) == 0) {
1421  $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1422  }
1423 
1424  if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0) {
1425  $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1426  }
1427  }
1428 
1429  return $arr_grpDefaultRoles;
1430  }
1431 
1438  public function getLocalGroupRoles($a_translate = false)
1439  {
1440  global $DIC;
1441 
1442  $rbacadmin = $DIC['rbacadmin'];
1443  $rbacreview = $DIC['rbacreview'];
1444 
1445  if (empty($this->local_roles)) {
1446  $this->local_roles = array();
1447  $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1448 
1449  foreach ($role_arr as $role_id) {
1450  if ($rbacreview->isAssignable($role_id, $this->getRefId()) == true) {
1451  $role_Obj = &$this->ilias->obj_factory->getInstanceByObjId($role_id);
1452 
1453  if ($a_translate) {
1454  $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1455  } else {
1456  $role_name = $role_Obj->getTitle();
1457  }
1458 
1459  $this->local_roles[$role_name] = $role_Obj->getId();
1460  }
1461  }
1462  }
1463 
1464  return $this->local_roles;
1465  }
1466 
1473  {
1474  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1475  $res = $this->ilias->db->query($q);
1476  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1477 
1478  return $row["obj_id"];
1479  }
1480 
1486  public function getGrpStatusOpenTemplateId()
1487  {
1488  $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1489  $res = $this->ilias->db->query($q);
1490  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1491 
1492  return $row["obj_id"];
1493  }
1494 
1501  public static function lookupGroupStatusTemplateId($a_obj_id)
1502  {
1503  global $DIC;
1504 
1505  $ilDB = $DIC['ilDB'];
1506 
1507  $type = self::lookupGroupTye($a_obj_id);
1508  if ($type == GRP_TYPE_CLOSED) {
1509  $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_closed', 'text');
1510  } else {
1511  $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_open', 'text');
1512  }
1513  $res = $ilDB->query($query);
1514  $row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1515 
1516  return isset($row['obj_id']) ? $row['obj_id'] : 0;
1517  }
1518 
1519 
1520 
1530  public function updateGroupType($a_group_type = GRP_TYPE_OPEN)
1531  {
1532  global $DIC;
1533 
1534  $logger = $DIC->logger()->grp();
1535 
1536  if ($a_group_type == GRP_TYPE_OPEN) {
1537  $this->applyDidacticTemplate(0);
1538  return;
1539  }
1540 
1541  $templates = ilDidacticTemplateSettings::getInstanceByObjectType($this->getType())->getTemplates();
1542  foreach ($templates as $template) {
1543  // the closed template
1544  if ($template->isAutoGenerated()) {
1545  $logger->info('Appying default closed template');
1546  $this->applyDidacticTemplate($template->getId());
1547  return;
1548  }
1549  }
1550  $logger->warning('No closed didactic template available.');
1551  }
1552 
1553 
1561  public function setGroupStatus($a_status)
1562  {
1563  $this->group_status = $a_status;
1564  }
1565 
1573  public function getGroupStatus()
1574  {
1575  return $this->group_status;
1576  }
1577 
1582  public function readGroupStatus() : int
1583  {
1584  global $DIC;
1585 
1586 
1588  $logger = $DIC->logger()->grp();
1589  $logger->dump($tpl_id);
1590  if (!$tpl_id) {
1591  return GRP_TYPE_OPEN;
1592  }
1593  return GRP_TYPE_CLOSED;
1594  }
1595 
1602  public function getMemberRoles($a_user_id)
1603  {
1604  global $DIC;
1605 
1606  $rbacadmin = $DIC['rbacadmin'];
1607  $rbacreview = $DIC['rbacreview'];
1608  $ilBench = $DIC['ilBench'];
1609 
1610  $ilBench->start("Group", "getMemberRoles");
1611 
1612  $arr_assignedRoles = array();
1613 
1614  $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id), $this->getLocalGroupRoles());
1615 
1616  $ilBench->stop("Group", "getMemberRoles");
1617 
1618  return $arr_assignedRoles;
1619  }
1620 
1627  public function isAdmin($a_userId)
1628  {
1629  global $DIC;
1630 
1631  $rbacreview = $DIC['rbacreview'];
1632 
1633  $grp_Roles = $this->getDefaultGroupRoles();
1634 
1635  if (in_array($a_userId, $rbacreview->assignedUsers($grp_Roles["grp_admin_role"]))) {
1636  return true;
1637  } else {
1638  return false;
1639  }
1640  }
1646  public function initDefaultRoles()
1647  {
1648  include_once './Services/AccessControl/classes/class.ilObjRole.php';
1650  'il_grp_admin_' . $this->getRefId(),
1651  "Groupadmin group obj_no." . $this->getId(),
1652  'il_grp_admin',
1653  $this->getRefId()
1654  );
1655  $this->m_roleAdminId = $role->getId();
1656 
1658  'il_grp_member_' . $this->getRefId(),
1659  "Groupmember of group obj_no." . $this->getId(),
1660  'il_grp_member',
1661  $this->getRefId()
1662  );
1663  $this->m_roleMemberId = $role->getId();
1664 
1665  return array();
1666  }
1667 
1677  public function setParentRolePermissions($a_parent_ref)
1678  {
1679  $rbacadmin = $GLOBALS['DIC']->rbac()->admin();
1680  $rbacreview = $GLOBALS['DIC']->rbac()->review();
1681 
1682  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1683  foreach ((array) $parent_roles as $parent_role) {
1684  if ($parent_role['parent'] == $this->getRefId()) {
1685  continue;
1686  }
1687  if ($rbacreview->isProtected($parent_role['parent'], $parent_role['rol_id'])) {
1688  $operations = $rbacreview->getOperationsOfRole(
1689  $parent_role['obj_id'],
1690  $this->getType(),
1691  $parent_role['parent']
1692  );
1693  $rbacadmin->grantPermission(
1694  $parent_role['obj_id'],
1695  $operations,
1696  $this->getRefId()
1697  );
1698  continue;
1699  }
1700 
1701  $rbacadmin->initIntersectionPermissions(
1702  $this->getRefId(),
1703  $parent_role['obj_id'],
1704  $parent_role['parent'],
1705  $this->getGrpStatusOpenTemplateId(),
1707  );
1708  }
1709  }
1710 
1711 
1716  public function applyDidacticTemplate($a_tpl_id)
1717  {
1718  parent::applyDidacticTemplate($a_tpl_id);
1719 
1720  if (!$a_tpl_id) {
1721  // init default type
1722  $this->setParentRolePermissions($this->getRefId());
1723  }
1724  }
1725 
1726 
1727  public static function _lookupIdByTitle($a_title)
1728  {
1729  global $DIC;
1730 
1731  $ilDB = $DIC['ilDB'];
1732 
1733  $query = "SELECT * FROM object_data WHERE title = " .
1734  $ilDB->quote($a_title, 'text') . " AND type = 'grp'";
1735  $res = $ilDB->query($query);
1736  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1737  return $row->obj_id;
1738  }
1739  return 0;
1740  }
1741 
1742 
1743  public function _isMember($a_user_id, $a_ref_id, $a_field = '')
1744  {
1745  global $DIC;
1746 
1747  $rbacreview = $DIC['rbacreview'];
1748  $ilObjDataCache = $DIC['ilObjDataCache'];
1749  $ilDB = $DIC['ilDB'];
1750 
1751  $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
1752  $user_roles = $rbacreview->assignedRoles($a_user_id);
1753 
1754  // Used for membership limitations -> check membership by given field
1755  if ($a_field) {
1756  include_once './Services/User/classes/class.ilObjUser.php';
1757 
1758  $tmp_user = &ilObjectFactory::getInstanceByObjId($a_user_id);
1759  switch ($a_field) {
1760  case 'login':
1761  $and = "AND login = '" . $tmp_user->getLogin() . "' ";
1762  break;
1763  case 'email':
1764  $and = "AND email = '" . $tmp_user->getEmail() . "' ";
1765  break;
1766  case 'matriculation':
1767  $and = "AND matriculation = '" . $tmp_user->getMatriculation() . "' ";
1768  break;
1769 
1770  default:
1771  $and = "AND usr_id = '" . $a_user_id . "'";
1772  break;
1773  }
1774  if (!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id))) {
1775  return false;
1776  }
1777  $query = "SELECT * FROM usr_data as ud " .
1778  "WHERE usr_id IN (" . implode(",", ilUtil::quoteArray($members)) . ") " .
1779  $and;
1780  $res = $ilDB->query($query);
1781 
1782  return $res->numRows() ? true : false;
1783  }
1784 
1785  if (!array_intersect($local_roles, $user_roles)) {
1786  return false;
1787  }
1788 
1789  return true;
1790  }
1791 
1792  public function _getMembers($a_obj_id)
1793  {
1794  global $DIC;
1795 
1796  $rbacreview = $DIC['rbacreview'];
1797 
1798  // get reference
1799  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1800  $ref_id = current($ref_ids);
1801 
1802  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
1803 
1804  $users = array();
1805  foreach ($local_roles as $role_id) {
1806  $users = array_merge($users, $rbacreview->assignedUsers($role_id));
1807  }
1808 
1809  return array_unique($users);
1810  }
1811 
1816  public function getViewMode()
1817  {
1818  $tree = $this->tree;
1819 
1820  // default: by type
1821  $view = self::lookupViewMode($this->getId());
1822 
1823  if ($view != ilContainer::VIEW_INHERIT) {
1824  return $view;
1825  }
1826 
1827  $container_ref_id = $tree->checkForParentType($this->ref_id, 'crs');
1828  if ($container_ref_id) {
1830  // these three are available...
1831  if (
1835  return $view_mode;
1836  }
1837  }
1839  }
1840 
1841 
1846  public function setViewMode($a_view_mode)
1847  {
1848  $this->view_mode = $a_view_mode;
1849  }
1850 
1855  public static function lookupViewMode($a_obj_id)
1856  {
1857  global $DIC;
1858 
1859  $ilDB = $DIC['ilDB'];
1860 
1861  $query = 'SELECT view_mode FROM grp_settings ' .
1862  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1863  $res = $ilDB->query($query);
1864 
1865  $view_mode = null;
1866  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1867  $view_mode = $row->view_mode;
1868  }
1869  return $view_mode;
1870  }
1871 
1879  public static function translateViewMode($a_obj_id, $a_view_mode, $a_ref_id = null)
1880  {
1881  global $DIC;
1882 
1883  $tree = $DIC['tree'];
1884 
1885  if (!$a_view_mode) {
1886  $a_view_mode = ilContainer::VIEW_DEFAULT;
1887  }
1888 
1889  // view mode is inherit => check for parent course
1890  if ($a_view_mode == ilContainer::VIEW_INHERIT) {
1891  if (!$a_ref_id) {
1892  $ref = ilObject::_getAllReferences($a_obj_id);
1893  $a_ref_id = end($ref);
1894  }
1895 
1896  $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1897  if (!$crs_ref) {
1899  }
1900 
1901  include_once './Modules/Course/classes/class.ilObjCourse.php';
1903 
1904  // validate course view mode
1905  if (!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1908  }
1909 
1910  return $view_mode;
1911  }
1912 
1913  return $a_view_mode;
1914  }
1915 
1920  public function addAdditionalSubItemInformation(&$a_item_data)
1921  {
1922  include_once './Services/Object/classes/class.ilObjectActivation.php';
1924  }
1925 
1926  public function getMessage()
1927  {
1928  return $this->message;
1929  }
1930  public function setMessage($a_message)
1931  {
1932  $this->message = $a_message;
1933  }
1934  public function appendMessage($a_message)
1935  {
1936  if ($this->getMessage()) {
1937  $this->message .= "<br /> ";
1938  }
1939  $this->message .= $a_message;
1940  }
1941 
1949  protected function prepareAppointments($a_mode = 'create')
1950  {
1951  include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1952 
1953  switch ($a_mode) {
1954  case 'create':
1955  case 'update':
1956 
1957  $apps = array();
1958  if ($this->getStart() && $this->getEnd()) {
1959  $app = new ilCalendarAppointmentTemplate(self::CAL_START);
1960  $app->setTitle($this->getTitle());
1961  $app->setSubtitle('grp_cal_start');
1962  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1963  $app->setDescription($this->getLongDescription());
1964  $app->setStart($this->getStart());
1965  $app->setFullday(!$this->getStartTimeIndication());
1966  $apps[] = $app;
1967 
1968  $app = new ilCalendarAppointmentTemplate(self::CAL_END);
1969  $app->setTitle($this->getTitle());
1970  $app->setSubtitle('grp_cal_end');
1971  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1972  $app->setDescription($this->getLongDescription());
1973  $app->setStart($this->getEnd());
1974  $app->setFullday(!$this->getStartTimeIndication());
1975  $apps[] = $app;
1976  }
1977  if ($this->isRegistrationUnlimited()) {
1978  return $apps;
1979  }
1980 
1981  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1982  $app->setTitle($this->getTitle());
1983  $app->setSubtitle('grp_cal_reg_start');
1984  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1985  $app->setDescription($this->getLongDescription());
1986  $app->setStart($this->getRegistrationStart());
1987  $apps[] = $app;
1988 
1989  $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1990  $app->setTitle($this->getTitle());
1991  $app->setSubtitle('grp_cal_reg_end');
1992  $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1993  $app->setDescription($this->getLongDescription());
1994  $app->setStart($this->getRegistrationEnd());
1995  $apps[] = $app;
1996 
1997 
1998  return $apps;
1999 
2000  case 'delete':
2001  // Nothing to do: The category and all assigned appointments will be deleted.
2002  return array();
2003  }
2004  }
2005 
2013  protected function initParticipants()
2014  {
2015  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2016  $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
2017  }
2018 
2024  public function getMembersObject()
2025  {
2026  // #17886
2027  if (!$this->members_obj instanceof ilGroupParticipants) {
2028  $this->initParticipants();
2029  }
2030  return $this->members_obj;
2031  }
2032 
2037  public static function lookupObjectsByCode($a_code)
2038  {
2039  global $DIC;
2040 
2041  $ilDB = $DIC['ilDB'];
2042 
2043  $query = "SELECT obj_id FROM grp_settings " .
2044  "WHERE reg_ac_enabled = " . $ilDB->quote(1, 'integer') . " " .
2045  "AND reg_ac = " . $ilDB->quote($a_code, 'text');
2046  $res = $ilDB->query($query);
2047 
2048  $obj_ids = array();
2049  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2050  $obj_ids[] = $row->obj_id;
2051  }
2052  return $obj_ids;
2053  }
2054 
2061  public function register($a_user_id, $a_role = IL_GRP_MEMBER, $a_force_registration = false)
2062  {
2063  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
2064  include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
2066 
2067  if ($part->isAssigned($a_user_id)) {
2068  return true;
2069  }
2070 
2071  if (!$a_force_registration) {
2072  // Availability
2073  if (!$this->isRegistrationEnabled()) {
2074  include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
2075 
2077  throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2078  ', group subscription is deactivated.', ilMembershipRegistrationException::REGISTRATION_CODE_DISABLED);
2079  }
2080  }
2081 
2082  // Time Limitation
2083  if (!$this->isRegistrationUnlimited()) {
2084  $start = $this->getRegistrationStart();
2085  $end = $this->getRegistrationEnd();
2086  $time = new ilDateTime(time(), IL_CAL_UNIX);
2087 
2088  if (!(ilDateTime::_after($time, $start) and ilDateTime::_before($time, $end))) {
2089  throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2090  ', group is out of registration time.', ilMembershipRegistrationException::OUT_OF_REGISTRATION_PERIOD);
2091  }
2092  }
2093 
2094  // Max members
2095  if ($this->isMembershipLimited()) {
2096  $free = max(0, $this->getMaxMembers() - $part->getCountMembers());
2097  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2098  $waiting_list = new ilGroupWaitingList($this->getId());
2099  if ($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
2100  $this->lng->loadLanguageModule("grp");
2101  $waiting_list->addToList($a_user_id);
2102 
2103  $info = sprintf(
2104  $this->lng->txt('grp_added_to_list'),
2105  $this->getTitle(),
2106  $waiting_list->getPosition($a_user_id)
2107  );
2108 
2109  include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2110  include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
2111  $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
2112  $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $a_user_id);
2113 
2115  }
2116 
2117  if (!$free or $waiting_list->getCountUsers()) {
2118  throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2119  ', membership is limited.', ilMembershipRegistrationException::OBJECT_IS_FULL);
2120  }
2121  }
2122  }
2123 
2124  $part->add($a_user_id, $a_role);
2125  $part->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $a_user_id);
2126  $part->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2127  return true;
2128  }
2129 
2130  public function handleAutoFill()
2131  {
2132  if ($this->isWaitingListEnabled() &&
2133  $this->hasWaitingListAutoFill()) {
2134  $max = $this->getMaxMembers();
2136  if ($max > $now) {
2137  // see assignFromWaitingListObject()
2138  include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2139  $waiting_list = new ilGroupWaitingList($this->getId());
2140 
2141  foreach ($waiting_list->getUserIds() as $user_id) {
2142  if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
2143  continue;
2144  }
2145  if ($this->getMembersObject()->isAssigned($user_id)) {
2146  continue;
2147  }
2148  $this->getMembersObject()->add($user_id, IL_GRP_MEMBER); // #18213
2149  include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
2151  $waiting_list->removeFromList($user_id);
2152 
2153  $now++;
2154  if ($now >= $max) {
2155  break;
2156  }
2157  }
2158  }
2159  }
2160  }
2161 
2162  public static function mayLeave($a_group_id, $a_user_id = null, &$a_date = null)
2163  {
2164  global $DIC;
2165 
2166  $ilUser = $DIC['ilUser'];
2167  $ilDB = $DIC['ilDB'];
2168 
2169  if (!$a_user_id) {
2170  $a_user_id = $ilUser->getId();
2171  }
2172 
2173  $set = $ilDB->query("SELECT leave_end" .
2174  " FROM grp_settings" .
2175  " WHERE obj_id = " . $ilDB->quote($a_group_id, "integer"));
2176  $row = $ilDB->fetchAssoc($set);
2177  if ($row && $row["leave_end"]) {
2178  // timestamp to date
2179  $limit = date("Ymd", $row["leave_end"]);
2180  if ($limit < date("Ymd")) {
2181  $a_date = new ilDate(date("Y-m-d", $row["leave_end"]), IL_CAL_DATE);
2182  return false;
2183  }
2184  }
2185  return true;
2186  }
2187 
2193  public static function findGroupsWithNotEnoughMembers()
2194  {
2195  $ilDB = $GLOBALS['DIC']->database();
2196  $tree = $GLOBALS['DIC']->repositoryTree();
2197 
2198  $res = array();
2199 
2200  $now = date("Y-m-d H:i:s");
2201 
2202  $before = new ilDateTime(time(), IL_CAL_UNIX);
2203  $before->increment(IL_CAL_DAY, -1);
2204  $now_date = $before->get(IL_CAL_DATETIME);
2205  $now = $before->get(IL_CAL_UNIX);
2206 
2207  $set = $ilDB->query($q = "SELECT obj_id, registration_min_members" .
2208  " FROM grp_settings" .
2209  " WHERE registration_min_members > " . $ilDB->quote(0, "integer") .
2210  " AND registration_mem_limit = " . $ilDB->quote(1, "integer") . // #17206
2211  " AND ((leave_end IS NOT NULL" .
2212  " AND leave_end < " . $ilDB->quote($now, "integer") . ")" .
2213  " OR (leave_end IS NULL" .
2214  " AND registration_end IS NOT NULL" .
2215  " AND registration_end < " . $ilDB->quote($now_date, "text") . "))" .
2216  " AND (period_start IS NULL OR period_start > " . $ilDB->quote($now, "integer") . ")");
2217  while ($row = $ilDB->fetchAssoc($set)) {
2218  $refs = ilObject::_getAllReferences($row['obj_id']);
2219  $ref = end($refs);
2220 
2221  if ($tree->isDeleted($ref)) {
2222  continue;
2223  }
2224 
2225  $part = new ilGroupParticipants($row["obj_id"]);
2226  $reci = $part->getNotificationRecipients();
2227  if (sizeof($reci)) {
2228  $missing = (int) $row["registration_min_members"] - $part->getCountMembers();
2229  if ($missing > 0) {
2230  $res[$row["obj_id"]] = array($missing, $reci);
2231  }
2232  }
2233  }
2234 
2235  return $res;
2236  }
2237 
2238  public static function lookupShowMembersEnabled(int $a_obj_id) : bool
2239  {
2240  global $DIC;
2241  $ilDB = $DIC["ilDB"];
2242  $query = 'SELECT show_members FROM grp_settings'
2243  . ' WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
2244  $res = $ilDB->query($query);
2245  if ($ilDB->numRows($res) == 0) {
2246  return false;
2247  }
2248  $row = $ilDB->fetchAssoc($res);
2249  return (bool) $row['show_members'];
2250  }
2251 
2252 
2259  public function getSubItems(
2260  $a_admin_panel_enabled = false,
2261  $a_include_side_block = false,
2262  $a_get_single = 0,
2263  \ilContainerUserFilter $container_user_filter = null
2264  ) {
2265  // Caching
2266  if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block])) {
2267  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
2268  }
2269 
2270  // Results are stored in $this->items
2271  parent::getSubItems($a_admin_panel_enabled, $a_include_side_block, $a_get_single);
2273  $this->items,
2274  $this,
2275  (bool) $a_admin_panel_enabled,
2276  (bool) $a_include_side_block
2277  );
2278  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
2279  }
2280 } //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)
updateMetaData()
update meta data entry
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
setNumberOfPreviousSessions(int $a_num)
Set number of previous sessions.
Apointment templates are used for automatic generated apointments.
toggleStartTimeIndication(bool $time_indication)
getNumberOfPreviousSessions()
Get number of previous sessions.
static _lookupViewMode($a_id)
lookup view mode of container
setNumberOfNextSessions(int $a_num)
Set number of upcoming sessions.
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.
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
getSubItems( $a_admin_panel_enabled=false, $a_include_side_block=false, $a_get_single=0, \ilContainerUserFilter $container_user_filter=null)
Get subitems of container.
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
global $DIC
Definition: goto.php:24
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
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) ...
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.
const ROLE_FOLDER_ID
Definition: constants.php:32
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.
static prepareSessionPresentationLimitation(array $items, ilContainer $container, bool $admin_panel_enabled=false, bool $include_side_block=false)
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
getNumberOfNextSessions()
Get number of upcomoing sessions.
global $ilBench
Definition: ilias.php:21
global $ilDB
static lookupGroupTye($a_id)
Lookup group type.
getLongDescription()
get object long description (stored in object_description)
getRefId()
get reference id public
Class ilObjGroup.
deleteMetaData()
delete meta data entry
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
$ilUser
Definition: imgupload.php:18
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
enableSessionLimit(bool $a_status)
en/disable limited number of sessions
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)