ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
6require_once "./Services/Container/classes/class.ilContainer.php";
7include_once('./Services/Calendar/classes/class.ilDateTime.php');
8include_once './Services/Membership/interfaces/interface.ilMembershipRegistrationCodes.php';
9
10define('GRP_REGISTRATION_DEACTIVATED', -1);
11define('GRP_REGISTRATION_DIRECT', 0);
12define('GRP_REGISTRATION_REQUEST', 1);
13define('GRP_REGISTRATION_PASSWORD', 2);
14
15define('GRP_REGISTRATION_LIMITED', 1);
16define('GRP_REGISTRATION_UNLIMITED', 2);
17
18define('GRP_TYPE_UNKNOWN', 0);
19define('GRP_TYPE_CLOSED', 1);
20define('GRP_TYPE_OPEN', 2);
21define('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
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
75 protected $start = null;
76 protected $end = null;
77
78
79 // Map
80 private $latitude = '';
81 private $longitude = '';
82 private $locationzoom = 0;
83 private $enablemap = 0;
84
85 private $reg_access_code = '';
86 private $reg_access_code_enabled = false;
87
89
91
92
94
95
99 public $file_obj = null;
100
102
104
106
113 public function __construct($a_id = 0, $a_call_by_reference = true)
114 {
115 global $DIC;
116
117 $tree = $DIC['tree'];
118
119 $this->tree = &$tree;
120
121 $this->type = "grp";
122 parent::__construct($a_id, $a_call_by_reference);
123 $this->setRegisterMode(true); // ???
124 }
125
131 public static function lookupGroupTye($a_id)
132 {
133 global $DIC;
134
135 $ilDB = $DIC['ilDB'];
136
137 $query = "SELECT grp_type FROM grp_settings " .
138 "WHERE obj_id = " . $ilDB->quote($a_id, 'integer');
139 $res = $ilDB->query($query);
140 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
141 return $row->grp_type;
142 }
143 return GRP_TYPE_UNKNOWN;
144 }
145
146 // Setter/Getter
154 public function setInformation($a_information)
155 {
156 $this->information = $a_information;
157 }
158
166 public function getInformation()
167 {
168 return $this->information;
169 }
170
177 public function setGroupType($a_type)
178 {
179 $this->group_type = $a_type;
180 }
181
188 public function getGroupType()
189 {
190 return $this->group_type;
191 }
192
201 {
202 $this->reg_type = $a_type;
203 }
204
211 public function getRegistrationType()
212 {
213 return $this->reg_type;
214 }
215
222 public function isRegistrationEnabled()
223 {
225 }
226
234 public function enableUnlimitedRegistration($a_status)
235 {
236 $this->reg_unlimited = $a_status;
237 }
238
245 public function isRegistrationUnlimited()
246 {
248 }
249
257 public function setRegistrationStart($a_start)
258 {
259 $this->reg_start = $a_start;
260 }
261
268 public function getRegistrationStart()
269 {
270 return $this->reg_start;
271 }
272
273
281 public function setRegistrationEnd($a_end)
282 {
283 $this->reg_end = $a_end;
284 }
285
292 public function getRegistrationEnd()
293 {
294 return $this->reg_end;
295 }
296
303 public function setPassword($a_pass)
304 {
305 $this->reg_password = $a_pass;
306 }
307
314 public function getPassword()
315 {
316 return $this->reg_password;
317 }
318
326 public function enableMembershipLimitation($a_status)
327 {
328 $this->reg_membership_limitation = $a_status;
329 }
330
337 public function isMembershipLimited()
338 {
340 }
341
348 public function setMinMembers($a_max)
349 {
350 $this->reg_min_members = $a_max;
351 }
352
359 public function getMinMembers()
360 {
362 }
363
370 public function setMaxMembers($a_max)
371 {
372 $this->reg_max_members = $a_max;
373 }
374
381 public function getMaxMembers()
382 {
384 }
385
393 public function enableWaitingList($a_status)
394 {
395 $this->waiting_list = $a_status;
396 }
397
405 public function isWaitingListEnabled()
406 {
407 return $this->waiting_list;
408 }
409
410 public function setWaitingListAutoFill($a_value)
411 {
412 $this->auto_fill_from_waiting = (bool) $a_value;
413 }
414
415 public function hasWaitingListAutoFill()
416 {
417 return (bool) $this->auto_fill_from_waiting;
418 }
419
425 public function setLatitude($a_latitude)
426 {
427 $this->latitude = $a_latitude;
428 }
429
435 public function getLatitude()
436 {
437 return $this->latitude;
438 }
439
445 public function setLongitude($a_longitude)
446 {
447 $this->longitude = $a_longitude;
448 }
449
455 public function getLongitude()
456 {
457 return $this->longitude;
458 }
459
465 public function setLocationZoom($a_locationzoom)
466 {
467 $this->locationzoom = $a_locationzoom;
468 }
469
475 public function getLocationZoom()
476 {
477 return $this->locationzoom;
478 }
479
485 public function setEnableGroupMap($a_enablemap)
486 {
487 $this->enablemap = $a_enablemap;
488 }
489
494 public function getEnableMap()
495 {
496 return $this->getEnableGroupMap();
497 }
498
504 public function getEnableGroupMap()
505 {
506 return (bool) $this->enablemap;
507 }
508
514 {
516 }
517
523 public function setRegistrationAccessCode($a_code)
524 {
525 $this->reg_access_code = $a_code;
526 }
527
533 {
534 return (bool) $this->reg_access_code_enabled;
535 }
536
542 public function enableRegistrationAccessCode($a_status)
543 {
544 $this->reg_access_code_enabled = $a_status;
545 }
546
553 {
554 $this->mail_members = $a_type;
555 }
556
561 public function getMailToMembersType()
562 {
563 return $this->mail_members;
564 }
565
566 public function setCancellationEnd(ilDate $a_value = null)
567 {
568 $this->leave_end = $a_value;
569 }
570
571 public function getCancellationEnd()
572 {
573 return $this->leave_end;
574 }
575
576 public function setShowMembers($a_status)
577 {
578 $this->show_members = $a_status;
579 }
580 public function getShowMembers()
581 {
582 return $this->show_members;
583 }
584
589 public function getStart()
590 {
591 return $this->start;
592 }
593
598 public function setStart(ilDate $start = null)
599 {
600 $this->start = $start;
601 }
602
607 public function getEnd()
608 {
609 return $this->end;
610 }
611
616 public function setEnd(ilDate $end = null)
617 {
618 $this->end = $end;
619 }
620
627 public function validate()
628 {
629 global $DIC;
630
631 $ilErr = $DIC['ilErr'];
632
633 if (!$this->getTitle()) {
634 $this->title = '';
635 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_TITLE));
636 }
637 if ($this->getRegistrationType() == GRP_REGISTRATION_PASSWORD and !strlen($this->getPassword())) {
638 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_PASSWORD));
639 }
640 /*
641 if(ilDateTime::_before($this->getRegistrationEnd(),$this->getRegistrationStart()))
642 {
643 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_REG_TIME_LIMIT));
644 }
645 */
646 if ($this->isMembershipLimited()) {
647 if ($this->getMinMembers() <= 0 && $this->getMaxMembers() <= 0) {
648 $ilErr->appendMessage($this->lng->txt(self::ERR_MISSING_MIN_MAX_MEMBERS));
649 }
650 if ($this->getMaxMembers() <= 0 && $this->isWaitingListEnabled()) {
651 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MAX_MEMBERS));
652 }
653 if ($this->getMaxMembers() > 0 && $this->getMinMembers() > $this->getMaxMembers()) {
654 $ilErr->appendMessage($this->lng->txt(self::ERR_WRONG_MIN_MAX_MEMBERS));
655 }
656 }
657 if (
658 ($this->getRegistrationStart() && !$this->getRegistrationEnd()) ||
659 (!$this->getRegistrationStart() && $this->getRegistrationEnd()) ||
660 $this->getRegistrationEnd() <= $this->getRegistrationStart()
661 ) {
662 $ilErr->appendMessage($this->lng->txt((self::ERR_WRONG_REGISTRATION_LIMITED)));
663 }
664
665 return strlen($ilErr->getMessage()) == 0;
666 }
667
668
669
670
674 public function create()
675 {
676 global $DIC;
677
678 $ilDB = $DIC['ilDB'];
679 $ilAppEventHandler = $DIC['ilAppEventHandler'];
680
681 if (!parent::create()) {
682 return false;
683 }
684
685 if (!$a_upload) {
686 $this->createMetaData();
687 }
688
689
690 $query = "INSERT INTO grp_settings (obj_id,information,grp_type,registration_type,registration_enabled," .
691 "registration_unlimited,registration_start,registration_end,registration_password,registration_mem_limit," .
692 "registration_max_members,waiting_list,latitude,longitude,location_zoom,enablemap,reg_ac_enabled,reg_ac,view_mode,mail_members_type," .
693 "leave_end,registration_min_members,auto_wait, grp_start, grp_end) " .
694 "VALUES(" .
695 $ilDB->quote($this->getId(), 'integer') . ", " .
696 $ilDB->quote($this->getInformation(), 'text') . ", " .
697 $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
698 $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
699 $ilDB->quote(($this->isRegistrationEnabled() ? 1 : 0), 'integer') . ", " .
700 $ilDB->quote(($this->isRegistrationUnlimited() ? 1 : 0), 'integer') . ", " .
701 $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
702 $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
703 $ilDB->quote($this->getPassword(), 'text') . ", " .
704 $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
705 $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
706 $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
707 $ilDB->quote($this->getLatitude(), 'text') . ", " .
708 $ilDB->quote($this->getLongitude(), 'text') . ", " .
709 $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
710 $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
711 $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
712 $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
713 $ilDB->quote($this->view_mode, 'integer') . ', ' .
714 $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
715 $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
716 $ilDB->quote($this->getMinMembers(), 'integer') . ', ' .
717 $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ', ' .
718 $ilDB->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
719 $ilDB->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null, 'integer') . ' ' .
720 ")";
721 $res = $ilDB->manipulate($query);
722
723 $ilAppEventHandler->raise(
724 'Modules/Group',
725 'create',
726 array('object' => $this,
727 'obj_id' => $this->getId(),
728 'appointments' => $this->prepareAppointments('create'))
729 );
730
731 return $this->getId();
732 }
733
737 public function update()
738 {
739 global $DIC;
740
741 $ilDB = $DIC['ilDB'];
742 $ilAppEventHandler = $DIC['ilAppEventHandler'];
743
744 if (!parent::update()) {
745 return false;
746 }
747
748 $query = "UPDATE grp_settings " .
749 "SET information = " . $ilDB->quote($this->getInformation(), 'text') . ", " .
750 "grp_type = " . $ilDB->quote((int) $this->getGroupType(), 'integer') . ", " .
751 "registration_type = " . $ilDB->quote($this->getRegistrationType(), 'integer') . ", " .
752 "registration_enabled = " . $ilDB->quote($this->isRegistrationEnabled() ? 1 : 0, 'integer') . ", " .
753 "registration_unlimited = " . $ilDB->quote($this->isRegistrationUnlimited() ? 1 : 0, 'integer') . ", " .
754 "registration_start = " . $ilDB->quote(($this->getRegistrationStart() && !$this->getRegistrationStart()->isNull()) ? $this->getRegistrationStart()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
755 "registration_end = " . $ilDB->quote(($this->getRegistrationEnd() && !$this->getRegistrationEnd()->isNull()) ? $this->getRegistrationEnd()->get(IL_CAL_DATETIME, '') : null, 'timestamp') . ", " .
756 "registration_password = " . $ilDB->quote($this->getPassword(), 'text') . ", " .
757// "registration_membership_limited = ".$ilDB->quote((int) $this->isMembershipLimited() ,'integer').", ".
758 "registration_mem_limit = " . $ilDB->quote((int) $this->isMembershipLimited(), 'integer') . ", " .
759 "registration_max_members = " . $ilDB->quote($this->getMaxMembers(), 'integer') . ", " .
760 "waiting_list = " . $ilDB->quote($this->isWaitingListEnabled() ? 1 : 0, 'integer') . ", " .
761 "latitude = " . $ilDB->quote($this->getLatitude(), 'text') . ", " .
762 "longitude = " . $ilDB->quote($this->getLongitude(), 'text') . ", " .
763 "location_zoom = " . $ilDB->quote($this->getLocationZoom(), 'integer') . ", " .
764 "enablemap = " . $ilDB->quote((int) $this->getEnableGroupMap(), 'integer') . ", " .
765 'reg_ac_enabled = ' . $ilDB->quote($this->isRegistrationAccessCodeEnabled(), 'integer') . ', ' .
766 'reg_ac = ' . $ilDB->quote($this->getRegistrationAccessCode(), 'text') . ', ' .
767 'view_mode = ' . $ilDB->quote($this->view_mode, 'integer') . ', ' .
768 'mail_members_type = ' . $ilDB->quote($this->getMailToMembersType(), 'integer') . ', ' .
769 'leave_end = ' . $ilDB->quote(($this->getCancellationEnd() && !$this->getCancellationEnd()->isNull()) ? $this->getCancellationEnd()->get(IL_CAL_UNIX) : null, 'integer') . ', ' .
770 "registration_min_members = " . $ilDB->quote($this->getMinMembers(), 'integer') . ", " .
771 "auto_wait = " . $ilDB->quote($this->hasWaitingListAutoFill(), 'integer') . ", " .
772 "show_members = " . $ilDB->quote((int) $this->getShowMembers(), 'integer') . ", " .
773 'grp_start = ' . $ilDB->quote($this->getStart() instanceof ilDate ? $this->getStart()->get(IL_CAL_UNIX) : null) . ', ' .
774 'grp_end = ' . $ilDB->quote($this->getEnd() instanceof ilDate ? $this->getEnd()->get(IL_CAL_UNIX) : null) . ' ' .
775 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
776 $res = $ilDB->manipulate($query);
777
778 $ilAppEventHandler->raise(
779 'Modules/Group',
780 'update',
781 array('object' => $this,
782 'obj_id' => $this->getId(),
783 'appointments' => $this->prepareAppointments('update'))
784 );
785
786
787 return true;
788 }
789
796 public function delete()
797 {
798 global $DIC;
799
800 $ilDB = $DIC['ilDB'];
801 $ilAppEventHandler = $DIC['ilAppEventHandler'];
802
803 // always call parent delete function first!!
804 if (!parent::delete()) {
805 return false;
806 }
807
808 $query = "DELETE FROM grp_settings " .
809 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
810 $res = $ilDB->manipulate($query);
811
812 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
814
815 $ilAppEventHandler->raise(
816 'Modules/Group',
817 'delete',
818 array('object' => $this,
819 'obj_id' => $this->getId(),
820 'appointments' => $this->prepareAppointments('delete'))
821 );
822
823
824 return true;
825 }
826
827
831 public function read()
832 {
833 global $DIC;
834
835 $ilDB = $DIC['ilDB'];
836
837 parent::read();
838
839 $query = "SELECT * FROM grp_settings " .
840 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
841
842 $res = $ilDB->query($query);
843 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
844 $this->setInformation($row->information);
845 $this->setGroupType($row->grp_type);
846 $this->setRegistrationType($row->registration_type);
847 $this->enableUnlimitedRegistration($row->registration_unlimited);
848 $this->setRegistrationStart(new ilDateTime($row->registration_start, IL_CAL_DATETIME));
849 $this->setRegistrationEnd(new ilDateTime($row->registration_end, IL_CAL_DATETIME));
850 $this->setPassword($row->registration_password);
851 $this->enableMembershipLimitation((bool) $row->registration_mem_limit);
852 $this->setMaxMembers($row->registration_max_members);
853 $this->enableWaitingList($row->waiting_list);
854 $this->setLatitude($row->latitude);
855 $this->setLongitude($row->longitude);
856 $this->setLocationZoom($row->location_zoom);
857 $this->setEnableGroupMap($row->enablemap);
858 $this->enableRegistrationAccessCode($row->reg_ac_enabled);
859 $this->setRegistrationAccessCode($row->reg_ac);
860 $this->setViewMode($row->view_mode);
861 $this->setMailToMembersType($row->mail_members_type);
862 $this->setCancellationEnd($row->leave_end ? new ilDate($row->leave_end, IL_CAL_UNIX) : null);
863 $this->setMinMembers($row->registration_min_members);
864 $this->setWaitingListAutoFill($row->auto_wait);
865 $this->setShowMembers($row->show_members);
866 $this->setStart($row->grp_start ? new ilDate($row->grp_start, IL_CAL_UNIX) : null);
867 $this->setEnd($row->grp_end ? new ilDate($row->grp_end, IL_CAL_UNIX) : null);
868 }
869 $this->initParticipants();
870
871 // Inherit order type from parent course (if exists)
872 include_once('./Services/Container/classes/class.ilContainerSortingSettings.php');
874 }
875
884 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
885 {
886 global $DIC;
887
888 $ilDB = $DIC['ilDB'];
889 $ilUser = $DIC['ilUser'];
890 $ilSetting = $DIC['ilSetting'];
891
892 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
893
894 // current template
895 $current_template = ilDidacticTemplateObjSettings::lookupTemplateId($this->getRefId());
896 $new_obj->applyDidacticTemplate($current_template);
897 $this->cloneAutoGeneratedRoles($new_obj);
898 $this->cloneMetaData($new_obj);
899
900 $new_obj->setRegistrationType($this->getRegistrationType());
901 $new_obj->setInformation($this->getInformation());
902 $new_obj->setRegistrationStart($this->getRegistrationStart());
903 $new_obj->setRegistrationEnd($this->getRegistrationEnd());
904 $new_obj->enableUnlimitedRegistration($this->isRegistrationUnlimited());
905 $new_obj->setPassword($this->getPassword());
906 $new_obj->enableMembershipLimitation($this->isMembershipLimited());
907 $new_obj->setMaxMembers($this->getMaxMembers());
908 $new_obj->enableWaitingList($this->isWaitingListEnabled());
909 $new_obj->setShowMembers($this->getShowMembers());
910
911 // map
912 $new_obj->setLatitude($this->getLatitude());
913 $new_obj->setLongitude($this->getLongitude());
914 $new_obj->setLocationZoom($this->getLocationZoom());
915 $new_obj->setEnableGroupMap($this->getEnableGroupMap());
916 $new_obj->enableRegistrationAccessCode($this->isRegistrationAccessCodeEnabled());
917 include_once './Services/Membership/classes/class.ilMembershipRegistrationCodeUtils.php';
918 $new_obj->setRegistrationAccessCode(ilMembershipRegistrationCodeUtils::generateCode());
919
920 $new_obj->setViewMode($this->view_mode);
921 $new_obj->setMailToMembersType($this->getMailToMembersType());
922
923 $new_obj->setCancellationEnd($this->getCancellationEnd());
924 $new_obj->setMinMembers($this->getMinMembers());
925 $new_obj->setWaitingListAutoFill($this->hasWaitingListAutoFill());
926
927 $new_obj->setStart($this->getStart());
928 $new_obj->setEnd($this->getEnd());
929
930 $new_obj->update();
931
932 // #13008 - Group Defined Fields
933 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
934 ilCourseDefinedFieldDefinition::_clone($this->getId(), $new_obj->getId());
935
936 // Assign user as admin
937 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
938 $part = ilGroupParticipants::_getInstanceByObjId($new_obj->getId());
939 $part->add($ilUser->getId(), IL_GRP_ADMIN);
940 $part->updateNotification($ilUser->getId(), $ilSetting->get('mail_grp_admin_notification', true));
941 $part->updateContact($ilUser->getId(), true);
942
943 // Copy learning progress settings
944 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
945 $obj_settings = new ilLPObjSettings($this->getId());
946 $obj_settings->cloneSettings($new_obj->getId());
947 unset($obj_settings);
948
949 return $new_obj;
950 }
951
960 public function cloneDependencies($a_target_id, $a_copy_id)
961 {
962 global $DIC;
963
964 $tree = $DIC['tree'];
965
966 parent::cloneDependencies($a_target_id, $a_copy_id);
967
968 include_once('Services/Object/classes/class.ilObjectActivation.php');
969 ilObjectActivation::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
970
971 // clone membership limitation
972 foreach (\ilObjCourseGrouping::_getGroupings($this->getId()) as $grouping_id) {
973 \ilLoggerFactory::getLogger('grp')->info('Handling grouping id: ' . $grouping_id);
974 $grouping = new \ilObjCourseGrouping($grouping_id);
975 $grouping->cloneGrouping($a_target_id, $a_copy_id);
976 }
977
978 return true;
979 }
980
988 public function cloneAutoGeneratedRoles($new_obj)
989 {
990 global $DIC;
991
992 $rbacadmin = $DIC['rbacadmin'];
993 $rbacreview = $DIC['rbacreview'];
994
995 $admin = $this->getDefaultAdminRole();
996 $new_admin = $new_obj->getDefaultAdminRole();
997 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
998 ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_admin');
999 }
1000 $rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
1001 ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_admin.');
1002
1003 $member = $this->getDefaultMemberRole();
1004 $new_member = $new_obj->getDefaultMemberRole();
1005 if (!$member || !$new_member) {
1006 ilLoggerFactory::getLogger('grp')->warning('Error cloning auto generated rol: il_grp_member');
1007 }
1008 $rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
1009 ilLoggerFactory::getLogger('grp')->info('Finished copying of role il_grp_member.');
1010 }
1011
1012
1018 public function join($a_user_id, $a_mem_role = "")
1019 {
1020 global $DIC;
1021
1022 $rbacadmin = $DIC['rbacadmin'];
1023
1024 if (is_array($a_mem_role)) {
1025 foreach ($a_mem_role as $role) {
1026 $rbacadmin->assignUser($role, $a_user_id, false);
1027 }
1028 } else {
1029 $rbacadmin->assignUser($a_mem_role, $a_user_id, false);
1030 }
1031
1032 return true;
1033 }
1034
1039 public function getDefaultMemberRole()
1040 {
1041 $local_group_Roles = $this->getLocalGroupRoles();
1042
1043 return $local_group_Roles["il_grp_member_" . $this->getRefId()];
1044 }
1045
1050 public function getDefaultAdminRole()
1051 {
1052 $local_group_Roles = $this->getLocalGroupRoles();
1053
1054 return $local_group_Roles["il_grp_admin_" . $this->getRefId()];
1055 }
1056
1063 public function addMember($a_user_id, $a_mem_role)
1064 {
1065 global $DIC;
1066
1067 $rbacadmin = $DIC['rbacadmin'];
1068
1069 if (isset($a_user_id) && isset($a_mem_role)) {
1070 $this->join($a_user_id, $a_mem_role);
1071 return true;
1072 } else {
1073 $this->ilias->raiseError(get_class($this) . "::addMember(): Missing parameters !", $this->ilias->error_obj->WARNING);
1074 return false;
1075 }
1076 }
1077
1078
1085 public function leaveGroup()
1086 {
1087 global $DIC;
1088
1089 $rbacadmin = $DIC['rbacadmin'];
1090 $rbacreview = $DIC['rbacreview'];
1091
1092 $member_ids = $this->getGroupMemberIds();
1093
1094 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids)) {
1095 return 2;
1096 } else {
1097 if (!$this->isAdmin($this->ilias->account->getId())) {
1098 $this->leave($this->ilias->account->getId());
1099 $member = new ilObjUser($this->ilias->account->getId());
1100 $member->dropDesktopItem($this->getRefId(), "grp");
1101
1102 return 0;
1103 } elseif (count($this->getGroupAdminIds()) == 1) {
1104 return 1;
1105 }
1106 }
1107 }
1108
1113 public function leave($a_user_id)
1114 {
1115 global $DIC;
1116
1117 $rbacadmin = $DIC['rbacadmin'];
1118
1119 $arr_groupRoles = $this->getMemberRoles($a_user_id);
1120
1121 if (is_array($arr_groupRoles)) {
1122 foreach ($arr_groupRoles as $groupRole) {
1123 $rbacadmin->deassignUser($groupRole, $a_user_id);
1124 }
1125 } else {
1126 $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
1127 }
1128
1129 return true;
1130 }
1131
1138 public function getGroupMemberIds()
1139 {
1140 global $DIC;
1141
1142 $rbacadmin = $DIC['rbacadmin'];
1143 $rbacreview = $DIC['rbacreview'];
1144
1145 $usr_arr = array();
1146
1147 $rol = $this->getLocalGroupRoles();
1148
1149 foreach ($rol as $value) {
1150 foreach ($rbacreview->assignedUsers($value) as $member_id) {
1151 array_push($usr_arr, $member_id);
1152 }
1153 }
1154
1155 $mem_arr = array_unique($usr_arr);
1156
1157 return $mem_arr ? $mem_arr : array();
1158 }
1159
1167 public function getGroupMemberData($a_mem_ids, $active = 1)
1168 {
1169 global $DIC;
1170
1171 $rbacadmin = $DIC['rbacadmin'];
1172 $rbacreview = $DIC['rbacreview'];
1173 $ilBench = $DIC['ilBench'];
1174 $ilDB = $DIC['ilDB'];
1175
1176 $usr_arr = array();
1177
1178 $q = "SELECT login,firstname,lastname,title,usr_id,last_login " .
1179 "FROM usr_data " .
1180 "WHERE usr_id IN (" . implode(',', ilUtil::quoteArray($a_mem_ids)) . ") ";
1181
1182 if (is_numeric($active) && $active > -1) {
1183 $q .= "AND active = '$active'";
1184 }
1185
1186 $q .= 'ORDER BY lastname,firstname';
1187
1188 $r = $ilDB->query($q);
1189
1190 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1191 $mem_arr[] = array("id" => $row->usr_id,
1192 "login" => $row->login,
1193 "firstname" => $row->firstname,
1194 "lastname" => $row->lastname,
1195 "last_login" => $row->last_login
1196 );
1197 }
1198
1199 return $mem_arr ? $mem_arr : array();
1200 }
1201
1202 public function getCountMembers()
1203 {
1204 return count($this->getGroupMemberIds());
1205 }
1206
1213 public function getGroupAdminIds($a_grpId = "")
1214 {
1215 global $DIC;
1216
1217 $rbacreview = $DIC['rbacreview'];
1218
1219 if (!empty($a_grpId)) {
1220 $grp_id = $a_grpId;
1221 } else {
1222 $grp_id = $this->getRefId();
1223 }
1224
1225 $usr_arr = array();
1226 $roles = $this->getDefaultGroupRoles($this->getRefId());
1227
1228 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id) {
1229 array_push($usr_arr, $member_id);
1230 }
1231
1232 return $usr_arr;
1233 }
1234
1240 public function getDefaultGroupRoles($a_grp_id = "")
1241 {
1242 global $DIC;
1243
1244 $rbacadmin = $DIC['rbacadmin'];
1245 $rbacreview = $DIC['rbacreview'];
1246
1247 if (strlen($a_grp_id) > 0) {
1248 $grp_id = $a_grp_id;
1249 } else {
1250 $grp_id = $this->getRefId();
1251 }
1252
1253 $role_arr = $rbacreview->getRolesOfRoleFolder($grp_id);
1254
1255 foreach ($role_arr as $role_id) {
1256 $role_Obj = &$this->ilias->obj_factory->getInstanceByObjId($role_id);
1257
1258 $grp_Member = "il_grp_member_" . $grp_id;
1259 $grp_Admin = "il_grp_admin_" . $grp_id;
1260
1261 if (strcmp($role_Obj->getTitle(), $grp_Member) == 0) {
1262 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
1263 }
1264
1265 if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0) {
1266 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
1267 }
1268 }
1269
1270 return $arr_grpDefaultRoles;
1271 }
1272
1279 public function getLocalGroupRoles($a_translate = false)
1280 {
1281 global $DIC;
1282
1283 $rbacadmin = $DIC['rbacadmin'];
1284 $rbacreview = $DIC['rbacreview'];
1285
1286 if (empty($this->local_roles)) {
1287 $this->local_roles = array();
1288 $role_arr = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1289
1290 foreach ($role_arr as $role_id) {
1291 if ($rbacreview->isAssignable($role_id, $this->getRefId()) == true) {
1292 $role_Obj = &$this->ilias->obj_factory->getInstanceByObjId($role_id);
1293
1294 if ($a_translate) {
1295 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
1296 } else {
1297 $role_name = $role_Obj->getTitle();
1298 }
1299
1300 $this->local_roles[$role_name] = $role_Obj->getId();
1301 }
1302 }
1303 }
1304
1305 return $this->local_roles;
1306 }
1307
1314 {
1315 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1316 $res = $this->ilias->db->query($q);
1318
1319 return $row["obj_id"];
1320 }
1321
1328 {
1329 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1330 $res = $this->ilias->db->query($q);
1332
1333 return $row["obj_id"];
1334 }
1335
1342 public static function lookupGroupStatusTemplateId($a_obj_id)
1343 {
1344 global $DIC;
1345
1346 $ilDB = $DIC['ilDB'];
1347
1348 $type = self::lookupGroupTye($a_obj_id);
1349 if ($type == GRP_TYPE_CLOSED) {
1350 $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_closed', 'text');
1351 } else {
1352 $query = 'SELECT obj_id FROM object_data WHERE type = ' . $ilDB->quote('rolt', 'text') . ' AND title = ' . $ilDB->quote('il_grp_status_open', 'text');
1353 }
1354 $res = $ilDB->query($query);
1356
1357 return isset($row['obj_id']) ? $row['obj_id'] : 0;
1358 }
1359
1360
1361
1371 public function updateGroupType($a_group_type = GRP_TYPE_OPEN)
1372 {
1373 global $DIC;
1374
1375 $logger = $DIC->logger()->grp();
1376
1377 if ($a_group_type == GRP_TYPE_OPEN) {
1378 $this->applyDidacticTemplate(0);
1379 return;
1380 }
1381
1382 $templates = ilDidacticTemplateSettings::getInstanceByObjectType($this->getType())->getTemplates();
1383 foreach ($templates as $template) {
1384 // the closed template
1385 if ($template->isAutoGenerated()) {
1386 $logger->info('Appying default closed template');
1387 $this->applyDidacticTemplate($template->getId());
1388 return;
1389 }
1390 }
1391 $logger->warning('No closed didactic template available.');
1392 }
1393
1413 public function initGroupStatus($a_grpStatus = GRP_TYPE_PUBLIC)
1414 {
1415 global $DIC;
1416
1417 $rbacadmin = $DIC['rbacadmin'];
1418 $rbacreview = $DIC['rbacreview'];
1419 $rbacsystem = $DIC['rbacsystem'];
1420
1421 //define all relevant roles that rights are needed to be changed
1422 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
1423
1424 $real_local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId(), false);
1425 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles), $real_local_roles);
1426
1427 //group status open (aka public) or group status closed
1428 if ($a_grpStatus == GRP_TYPE_PUBLIC || $a_grpStatus == GRP_TYPE_CLOSED) {
1429 if ($a_grpStatus == GRP_TYPE_PUBLIC) {
1431 } else {
1433 }
1434 //get defined operations from template
1435 $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
1436
1437 foreach ($arr_relevantParentRoleIds as $parentRole) {
1438 if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'], $parentRole)) {
1439 continue;
1440 }
1441
1442 $granted_permissions = array();
1443
1444 // Delete the linked role for the parent role
1445 // (just in case if it already exists).
1446
1447 // Added additional check, since this operation is very dangerous.
1448 // If there is no role folder ALL parent roles are deleted.
1449
1450 // @todo refactor rolf
1451 $rbacadmin->deleteLocalRole($parentRole, $this->getRefId());
1452
1453 // Grant permissions on the group object for
1454 // the parent role. In the foreach loop we
1455 // compute the intersection of the role
1456 // template il_grp_status_open/_closed and the
1457 // permission template of the parent role.
1458 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
1459 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
1460 foreach ($template_ops as $template_op) {
1461 if (in_array($template_op, $current_ops)) {
1462 array_push($granted_permissions, $template_op);
1463 }
1464 }
1465 if (!empty($granted_permissions)) {
1466 $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
1467 }
1468
1469 // Create a linked role for the parent role and
1470 // initialize it with the intersection of
1471 // il_grp_status_open/_closed and the permission
1472 // template of the parent role
1473
1474 $rbacadmin->copyRolePermissionIntersection(
1476 ROLE_FOLDER_ID,
1477 $parentRole,
1478 $arr_parentRoles[$parentRole]['parent'],
1479 $this->getRefId(),
1480 $parentRole
1481 );
1482 $rbacadmin->assignRoleToFolder($parentRole, $this->getRefId(), "false");
1483 }//END foreach
1484 }
1485 }
1486
1494 public function setGroupStatus($a_status)
1495 {
1496 $this->group_status = $a_status;
1497 }
1498
1506 public function getGroupStatus()
1507 {
1508 return $this->group_status;
1509 }
1510
1516 public function readGroupStatus()
1517 {
1518 global $DIC;
1519
1520 $rbacsystem = $DIC['rbacsystem'];
1521 $rbacreview = $DIC['rbacreview'];
1522
1523 $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
1524
1525 //get all relevant roles
1526 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
1527
1528 //if one global role has no permission to join the group is officially closed !
1529 foreach ($arr_globalRoles as $globalRole) {
1530 if ($rbacsystem->checkPermission($this->getRefId(), $globalRole, "join")) {
1531 return $this->group_status = GRP_TYPE_PUBLIC;
1532 }
1533 }
1534
1535 return $this->group_status = GRP_TYPE_CLOSED;
1536 }
1537
1544 public function getMemberRoles($a_user_id)
1545 {
1546 global $DIC;
1547
1548 $rbacadmin = $DIC['rbacadmin'];
1549 $rbacreview = $DIC['rbacreview'];
1550 $ilBench = $DIC['ilBench'];
1551
1552 $ilBench->start("Group", "getMemberRoles");
1553
1554 $arr_assignedRoles = array();
1555
1556 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id), $this->getLocalGroupRoles());
1557
1558 $ilBench->stop("Group", "getMemberRoles");
1559
1560 return $arr_assignedRoles;
1561 }
1562
1569 public function isAdmin($a_userId)
1570 {
1571 global $DIC;
1572
1573 $rbacreview = $DIC['rbacreview'];
1574
1575 $grp_Roles = $this->getDefaultGroupRoles();
1576
1577 if (in_array($a_userId, $rbacreview->assignedUsers($grp_Roles["grp_admin_role"]))) {
1578 return true;
1579 } else {
1580 return false;
1581 }
1582 }
1588 public function initDefaultRoles()
1589 {
1590 include_once './Services/AccessControl/classes/class.ilObjRole.php';
1592 'il_grp_admin_' . $this->getRefId(),
1593 "Groupadmin group obj_no." . $this->getId(),
1594 'il_grp_admin',
1595 $this->getRefId()
1596 );
1597 $this->m_roleAdminId = $role->getId();
1598
1600 'il_grp_member_' . $this->getRefId(),
1601 "Groupmember of group obj_no." . $this->getId(),
1602 'il_grp_member',
1603 $this->getRefId()
1604 );
1605 $this->m_roleMemberId = $role->getId();
1606
1607 return array();
1608 }
1609
1619 public function setParentRolePermissions($a_parent_ref)
1620 {
1621 $rbacadmin = $GLOBALS['DIC']->rbac()->admin();
1622 $rbacreview = $GLOBALS['DIC']->rbac()->review();
1623
1624 $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1625 foreach ((array) $parent_roles as $parent_role) {
1626 if ($parent_role['parent'] == $this->getRefId()) {
1627 continue;
1628 }
1629 if ($rbacreview->isProtected($parent_role['parent'], $parent_role['rol_id'])) {
1630 $operations = $rbacreview->getOperationsOfRole(
1631 $parent_role['obj_id'],
1632 $this->getType(),
1633 $parent_role['parent']
1634 );
1635 $rbacadmin->grantPermission(
1636 $parent_role['obj_id'],
1637 $operations,
1638 $this->getRefId()
1639 );
1640 continue;
1641 }
1642
1643 $rbacadmin->initIntersectionPermissions(
1644 $this->getRefId(),
1645 $parent_role['obj_id'],
1646 $parent_role['parent'],
1648 ROLE_FOLDER_ID
1649 );
1650 }
1651 }
1652
1653
1658 public function applyDidacticTemplate($a_tpl_id)
1659 {
1660 parent::applyDidacticTemplate($a_tpl_id);
1661
1662 if (!$a_tpl_id) {
1663 // init default type
1664 $this->setParentRolePermissions($this->getRefId());
1665 }
1666 }
1667
1668
1669 public static function _lookupIdByTitle($a_title)
1670 {
1671 global $DIC;
1672
1673 $ilDB = $DIC['ilDB'];
1674
1675 $query = "SELECT * FROM object_data WHERE title = " .
1676 $ilDB->quote($a_title, 'text') . " AND type = 'grp'";
1677 $res = $ilDB->query($query);
1678 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1679 return $row->obj_id;
1680 }
1681 return 0;
1682 }
1683
1684
1685 public function _isMember($a_user_id, $a_ref_id, $a_field = '')
1686 {
1687 global $DIC;
1688
1689 $rbacreview = $DIC['rbacreview'];
1690 $ilObjDataCache = $DIC['ilObjDataCache'];
1691 $ilDB = $DIC['ilDB'];
1692
1693 $local_roles = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
1694 $user_roles = $rbacreview->assignedRoles($a_user_id);
1695
1696 // Used for membership limitations -> check membership by given field
1697 if ($a_field) {
1698 include_once './Services/User/classes/class.ilObjUser.php';
1699
1700 $tmp_user = &ilObjectFactory::getInstanceByObjId($a_user_id);
1701 switch ($a_field) {
1702 case 'login':
1703 $and = "AND login = '" . $tmp_user->getLogin() . "' ";
1704 break;
1705 case 'email':
1706 $and = "AND email = '" . $tmp_user->getEmail() . "' ";
1707 break;
1708 case 'matriculation':
1709 $and = "AND matriculation = '" . $tmp_user->getMatriculation() . "' ";
1710 break;
1711
1712 default:
1713 $and = "AND usr_id = '" . $a_user_id . "'";
1714 break;
1715 }
1716 if (!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id))) {
1717 return false;
1718 }
1719 $query = "SELECT * FROM usr_data as ud " .
1720 "WHERE usr_id IN (" . implode(",", ilUtil::quoteArray($members)) . ") " .
1721 $and;
1722 $res = $ilDB->query($query);
1723
1724 return $res->numRows() ? true : false;
1725 }
1726
1727 if (!array_intersect($local_roles, $user_roles)) {
1728 return false;
1729 }
1730
1731 return true;
1732 }
1733
1734 public function _getMembers($a_obj_id)
1735 {
1736 global $DIC;
1737
1738 $rbacreview = $DIC['rbacreview'];
1739
1740 // get reference
1741 $ref_ids = ilObject::_getAllReferences($a_obj_id);
1742 $ref_id = current($ref_ids);
1743
1744 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
1745
1746 $users = array();
1747 foreach ($local_roles as $role_id) {
1748 $users = array_merge($users, $rbacreview->assignedUsers($role_id));
1749 }
1750
1751 return array_unique($users);
1752 }
1753
1758 public function getViewMode()
1759 {
1761
1762 // default: by type
1763 $view = self::lookupViewMode($this->getId());
1764
1765 if ($view != ilContainer::VIEW_INHERIT) {
1766 return $view;
1767 }
1768
1769 $container_ref_id = $tree->checkForParentType($this->ref_id, 'crs');
1770 if ($container_ref_id) {
1772 // these three are available...
1773 if (
1777 return $view_mode;
1778 }
1779 }
1781 }
1782
1783
1788 public function setViewMode($a_view_mode)
1789 {
1790 $this->view_mode = $a_view_mode;
1791 }
1792
1797 public static function lookupViewMode($a_obj_id)
1798 {
1799 global $DIC;
1800
1801 $ilDB = $DIC['ilDB'];
1802
1803 $query = 'SELECT view_mode FROM grp_settings ' .
1804 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
1805 $res = $ilDB->query($query);
1806
1807 $view_mode = null;
1808 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1809 $view_mode = $row->view_mode;
1810 }
1811 return $view_mode;
1812 }
1813
1821 public static function translateViewMode($a_obj_id, $a_view_mode, $a_ref_id = null)
1822 {
1823 global $DIC;
1824
1825 $tree = $DIC['tree'];
1826
1827 if (!$a_view_mode) {
1828 $a_view_mode = ilContainer::VIEW_DEFAULT;
1829 }
1830
1831 // view mode is inherit => check for parent course
1832 if ($a_view_mode == ilContainer::VIEW_INHERIT) {
1833 if (!$a_ref_id) {
1834 $ref = ilObject::_getAllReferences($a_obj_id);
1835 $a_ref_id = end($ref);
1836 }
1837
1838 $crs_ref = $tree->checkForParentType($a_ref_id, 'crs');
1839 if (!$crs_ref) {
1841 }
1842
1843 include_once './Modules/Course/classes/class.ilObjCourse.php';
1845
1846 // validate course view mode
1847 if (!in_array($view_mode, array(ilContainer::VIEW_SESSIONS,
1850 }
1851
1852 return $view_mode;
1853 }
1854
1855 return $a_view_mode;
1856 }
1857
1862 public function addAdditionalSubItemInformation(&$a_item_data)
1863 {
1864 include_once './Services/Object/classes/class.ilObjectActivation.php';
1866 }
1867
1868 public function getMessage()
1869 {
1870 return $this->message;
1871 }
1872 public function setMessage($a_message)
1873 {
1874 $this->message = $a_message;
1875 }
1876 public function appendMessage($a_message)
1877 {
1878 if ($this->getMessage()) {
1879 $this->message .= "<br /> ";
1880 }
1881 $this->message .= $a_message;
1882 }
1883
1891 protected function prepareAppointments($a_mode = 'create')
1892 {
1893 include_once('./Services/Calendar/classes/class.ilCalendarAppointmentTemplate.php');
1894
1895 switch ($a_mode) {
1896 case 'create':
1897 case 'update':
1898
1899 $apps = array();
1900 if ($this->getStart() && $this->getEnd()) {
1901 $app = new ilCalendarAppointmentTemplate(self::CAL_START);
1902 $app->setTitle($this->getTitle());
1903 $app->setSubtitle('grp_cal_start');
1904 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1905 $app->setDescription($this->getLongDescription());
1906 $app->setStart($this->getStart());
1907 $app->setFullday(true);
1908 $apps[] = $app;
1909
1910 $app = new ilCalendarAppointmentTemplate(self::CAL_END);
1911 $app->setTitle($this->getTitle());
1912 $app->setSubtitle('grp_cal_end');
1913 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1914 $app->setDescription($this->getLongDescription());
1915 $app->setStart($this->getEnd());
1916 $app->setFullday(true);
1917 $apps[] = $app;
1918 }
1919 if ($this->isRegistrationUnlimited()) {
1920 return $apps;
1921 }
1922
1923 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_START);
1924 $app->setTitle($this->getTitle());
1925 $app->setSubtitle('grp_cal_reg_start');
1926 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1927 $app->setDescription($this->getLongDescription());
1928 $app->setStart($this->getRegistrationStart());
1929 $apps[] = $app;
1930
1931 $app = new ilCalendarAppointmentTemplate(self::CAL_REG_END);
1932 $app->setTitle($this->getTitle());
1933 $app->setSubtitle('grp_cal_reg_end');
1934 $app->setTranslationType(IL_CAL_TRANSLATION_SYSTEM);
1935 $app->setDescription($this->getLongDescription());
1936 $app->setStart($this->getRegistrationEnd());
1937 $apps[] = $app;
1938
1939
1940 return $apps;
1941
1942 case 'delete':
1943 // Nothing to do: The category and all assigned appointments will be deleted.
1944 return array();
1945 }
1946 }
1947
1955 protected function initParticipants()
1956 {
1957 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
1958 $this->members_obj = ilGroupParticipants::_getInstanceByObjId($this->getId());
1959 }
1960
1966 public function getMembersObject()
1967 {
1968 // #17886
1969 if (!$this->members_obj instanceof ilGroupParticipants) {
1970 $this->initParticipants();
1971 }
1972 return $this->members_obj;
1973 }
1974
1979 public static function lookupObjectsByCode($a_code)
1980 {
1981 global $DIC;
1982
1983 $ilDB = $DIC['ilDB'];
1984
1985 $query = "SELECT obj_id FROM grp_settings " .
1986 "WHERE reg_ac_enabled = " . $ilDB->quote(1, 'integer') . " " .
1987 "AND reg_ac = " . $ilDB->quote($a_code, 'text');
1988 $res = $ilDB->query($query);
1989
1990 $obj_ids = array();
1991 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1992 $obj_ids[] = $row->obj_id;
1993 }
1994 return $obj_ids;
1995 }
1996
2003 public function register($a_user_id, $a_role = IL_GRP_MEMBER, $a_force_registration = false)
2004 {
2005 include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
2006 include_once "./Modules/Group/classes/class.ilGroupParticipants.php";
2008
2009 if ($part->isAssigned($a_user_id)) {
2010 return true;
2011 }
2012
2013 if (!$a_force_registration) {
2014 // Availability
2015 if (!$this->isRegistrationEnabled()) {
2016 include_once './Modules/Group/classes/class.ilObjGroupAccess.php';
2017
2019 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2020 ', group subscription is deactivated.', ilMembershipRegistrationException::REGISTRATION_CODE_DISABLED);
2021 }
2022 }
2023
2024 // Time Limitation
2025 if (!$this->isRegistrationUnlimited()) {
2026 $start = $this->getRegistrationStart();
2027 $end = $this->getRegistrationEnd();
2028 $time = new ilDateTime(time(), IL_CAL_UNIX);
2029
2031 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2032 ', group is out of registration time.', ilMembershipRegistrationException::OUT_OF_REGISTRATION_PERIOD);
2033 }
2034 }
2035
2036 // Max members
2037 if ($this->isMembershipLimited()) {
2038 $free = max(0, $this->getMaxMembers() - $part->getCountMembers());
2039 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2040 $waiting_list = new ilGroupWaitingList($this->getId());
2041 if ($this->isWaitingListEnabled() and (!$free or $waiting_list->getCountUsers())) {
2042 $this->lng->loadLanguageModule("grp");
2043 $waiting_list->addToList($a_user_id);
2044
2045 $info = sprintf(
2046 $this->lng->txt('grp_added_to_list'),
2047 $this->getTitle(),
2048 $waiting_list->getPosition($a_user_id)
2049 );
2050
2051 include_once('./Modules/Group/classes/class.ilGroupParticipants.php');
2052 include_once('./Modules/Group/classes/class.ilGroupMembershipMailNotification.php');
2053 $participants = ilGroupParticipants::_getInstanceByObjId($this->getId());
2054 $participants->sendNotification(ilGroupMembershipMailNotification::TYPE_WAITING_LIST_MEMBER, $a_user_id);
2055
2057 }
2058
2059 if (!$free or $waiting_list->getCountUsers()) {
2060 throw new ilMembershipRegistrationException('Cannot registrate to group ' . $this->getId() .
2061 ', membership is limited.', ilMembershipRegistrationException::OBJECT_IS_FULL);
2062 }
2063 }
2064 }
2065
2066 $part->add($a_user_id, $a_role);
2067 $part->sendNotification(ilGroupMembershipMailNotification::TYPE_ADMISSION_MEMBER, $a_user_id);
2068 $part->sendNotification(ilGroupMembershipMailNotification::TYPE_NOTIFICATION_REGISTRATION, $a_user_id);
2069 return true;
2070 }
2071
2072 public function handleAutoFill()
2073 {
2074 if ($this->isWaitingListEnabled() &&
2075 $this->hasWaitingListAutoFill()) {
2076 $max = $this->getMaxMembers();
2078 if ($max > $now) {
2079 // see assignFromWaitingListObject()
2080 include_once('./Modules/Group/classes/class.ilGroupWaitingList.php');
2081 $waiting_list = new ilGroupWaitingList($this->getId());
2082
2083 foreach ($waiting_list->getUserIds() as $user_id) {
2084 if (!$tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
2085 continue;
2086 }
2087 if ($this->getMembersObject()->isAssigned($user_id)) {
2088 continue;
2089 }
2090 $this->getMembersObject()->add($user_id, IL_GRP_MEMBER); // #18213
2091 include_once './Modules/Group/classes/class.ilGroupMembershipMailNotification.php';
2093 $waiting_list->removeFromList($user_id);
2094
2095 $now++;
2096 if ($now >= $max) {
2097 break;
2098 }
2099 }
2100 }
2101 }
2102 }
2103
2104 public static function mayLeave($a_group_id, $a_user_id = null, &$a_date = null)
2105 {
2106 global $DIC;
2107
2108 $ilUser = $DIC['ilUser'];
2109 $ilDB = $DIC['ilDB'];
2110
2111 if (!$a_user_id) {
2112 $a_user_id = $ilUser->getId();
2113 }
2114
2115 $set = $ilDB->query("SELECT leave_end" .
2116 " FROM grp_settings" .
2117 " WHERE obj_id = " . $ilDB->quote($a_group_id, "integer"));
2118 $row = $ilDB->fetchAssoc($set);
2119 if ($row && $row["leave_end"]) {
2120 // timestamp to date
2121 $limit = date("Ymd", $row["leave_end"]);
2122 if ($limit < date("Ymd")) {
2123 $a_date = new ilDate(date("Y-m-d", $row["leave_end"]), IL_CAL_DATE);
2124 return false;
2125 }
2126 }
2127 return true;
2128 }
2129
2135 public static function findGroupsWithNotEnoughMembers()
2136 {
2137 $ilDB = $GLOBALS['DIC']->database();
2138 $tree = $GLOBALS['DIC']->repositoryTree();
2139
2140 $res = array();
2141
2142 $now = date("Y-m-d H:i:s");
2143
2144 $before = new ilDateTime(time(), IL_CAL_UNIX);
2145 $before->increment(IL_CAL_DAY, -1);
2146 $now_date = $before->get(IL_CAL_DATETIME);
2147 $now = $before->get(IL_CAL_UNIX);
2148
2149 $set = $ilDB->query($q = "SELECT obj_id, registration_min_members" .
2150 " FROM grp_settings" .
2151 " WHERE registration_min_members > " . $ilDB->quote(0, "integer") .
2152 " AND registration_mem_limit = " . $ilDB->quote(1, "integer") . // #17206
2153 " AND ((leave_end IS NOT NULL" .
2154 " AND leave_end < " . $ilDB->quote($now, "integer") . ")" .
2155 " OR (leave_end IS NULL" .
2156 " AND registration_end IS NOT NULL" .
2157 " AND registration_end < " . $ilDB->quote($now_date, "text") . "))" .
2158 " AND (grp_start IS NULL OR grp_start > " . $ilDB->quote($now, "integer") . ")");
2159 while ($row = $ilDB->fetchAssoc($set)) {
2160 $refs = ilObject::_getAllReferences($row['obj_id']);
2161 $ref = end($refs);
2162
2163 if ($tree->isDeleted($ref)) {
2164 continue;
2165 }
2166
2167 $part = new ilGroupParticipants($row["obj_id"]);
2168 $reci = $part->getNotificationRecipients();
2169 if (sizeof($reci)) {
2170 $missing = (int) $row["registration_min_members"] - $part->getCountMembers();
2171 if ($missing > 0) {
2172 $res[$row["obj_id"]] = array($missing, $reci);
2173 }
2174 }
2175 }
2176
2177 return $res;
2178 }
2179
2180 public static function lookupShowMembersEnabled(int $a_obj_id) : bool
2181 {
2182 global $DIC;
2183 $ilDB = $DIC["ilDB"];
2184 $query = 'SELECT show_members FROM grp_settings'
2185 .' WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer');
2186 $res = $ilDB->query($query);
2187 if($ilDB->numRows($res) == 0) {
2188 return false;
2189 }
2190 $row = $ilDB->fetchAssoc($res);
2191 return (bool)$row['show_members'];
2192 }
2193} //END class.ilObjGroup
$users
Definition: authpage.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_TRANSLATION_SYSTEM
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
const GRP_REGISTRATION_DIRECT
const GRP_REGISTRATION_PASSWORD
const GRP_TYPE_OPEN
const GRP_TYPE_CLOSED
const GRP_TYPE_UNKNOWN
const GRP_REGISTRATION_DEACTIVATED
const GRP_TYPE_PUBLIC
const IL_GRP_MEMBER
const IL_GRP_ADMIN
Apointment templates are used for automatic generated apointments.
static _lookupSortMode($a_obj_id)
lookup sort mode
Class ilContainer.
setOrderType($a_value)
static _clone($a_source_id, $a_target_id)
Clone fields.
@classDescription Date and time handling
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.
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.
Class for single dates.
static lookupTemplateId($a_ref_id)
Lookup template id @global ilDB $ilDB.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Waiting list for groups.
static getLogger($a_component_id)
Get component logger.
static generateCode()
Generate new registration key.
static _lookupViewMode($a_id)
Lookup view mode.
static _getGroupings($a_course_id)
static _lookupViewMode($a_id)
lookup view mode of container
static _usingRegistrationCode()
Using Registration code.
Class ilObjGroup.
getGroupMemberData($a_mem_ids, $active=1)
get all group Members regardless of group role.
setGroupStatus($a_status)
Set group status.
getInformation()
get Information
static lookupViewMode($a_obj_id)
lookup view mode @global $ilDB
getGroupType()
get group type
getLocationZoom()
Get LocationZoom.
getLongitude()
Get Longitude.
getLocalGroupRoles($a_translate=false)
get ALL local roles of group, also those created and defined afterwards only fetch data once from dat...
const ERR_MISSING_TITLE
getDefaultAdminRole()
returns object id of created default adminstrator role @access public
getPassword()
get password
getEnableMap()
Type independent wrapper.
getGroupMemberIds()
get all group Member ids regardless of role @access public
appendMessage($a_message)
enableRegistrationAccessCode($a_status)
En/disable registration access code.
getDefaultMemberRole()
returns object id of created default member role @access public
getMinMembers()
get min members
getMembersObject()
Get members objects.
static lookupShowMembersEnabled(int $a_obj_id)
getEnd()
Get end.
setPassword($a_pass)
set password
enableWaitingList($a_status)
enable waiting list
const MAIL_ALLOWED_TUTORS
applyDidacticTemplate($a_tpl_id)
Apply template.
static lookupObjectsByCode($a_code)
getRegistrationStart()
get registration start
readGroupStatus()
get group status, redundant method because @access public
initParticipants()
init participants object
setRegistrationAccessCode($a_code)
Set refistration access code.
setRegistrationStart($a_start)
set registration start
setInformation($a_information)
set information
setEnd(ilDate $end=null)
Set end.
getRegistrationType()
get registration type
setMaxMembers($a_max)
set max members
setStart(ilDate $start=null)
Set start.
getGrpStatusClosedTemplateId()
get group status closed template @access public
create()
Create group.
getMaxMembers()
get max members
const ERR_WRONG_REG_TIME_LIMIT
isMembershipLimited()
is max member limited
getDefaultGroupRoles($a_grp_id="")
get default group roles, returns the defaultlike create roles il_grp_member, il_grp_admin @access pub...
setEnableGroupMap($a_enablemap)
Set Enable Group Map.
setCancellationEnd(ilDate $a_value=null)
cloneAutoGeneratedRoles($new_obj)
Clone group admin and member role permissions.
setWaitingListAutoFill($a_value)
leave($a_user_id)
deassign member from group role @access private
const ERR_MISSING_MIN_MAX_MEMBERS
static lookupGroupTye($a_id)
Lookup group type.
_isMember($a_user_id, $a_ref_id, $a_field='')
setLongitude($a_longitude)
Set Longitude.
static _lookupIdByTitle($a_title)
addMember($a_user_id, $a_mem_role)
add Member to Group @access public
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies (crs items, preconditions)
setRegistrationEnd($a_end)
set registration end
getRegistrationAccessCode()
get access code
$file_obj
Group file object for handling of export files.
isAdmin($a_userId)
is Admin @access public
read()
Read group.
setGroupType($a_type)
set group type
getRegistrationEnd()
get registration end
update()
Update group.
initGroupStatus($a_grpStatus=GRP_TYPE_PUBLIC)
set group status
setMinMembers($a_max)
set min members
setMailToMembersType($a_type)
Set mail to members type.
setLatitude($a_latitude)
Set Latitude.
setLocationZoom($a_locationzoom)
Set LocationZoom.
join($a_user_id, $a_mem_role="")
join Group, assigns user to role @access private
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
const ERR_WRONG_REGISTRATION_LIMITED
setViewMode($a_view_mode)
Set group view mode.
validate()
validate group settings
getViewMode()
Get effective container view mode.
setRegistrationType($a_type)
set registration type
getGroupStatus()
get group status
const ERR_MISSING_GROUP_TYPE
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone group (no member data)
addAdditionalSubItemInformation(&$a_item_data)
Add additional information to sub item, e.g.
leaveGroup()
is called when a member decides to leave group @access public
enableMembershipLimitation($a_status)
enable max member limitation
const ERR_MISSING_PASSWORD
isRegistrationUnlimited()
is registration unlimited
setShowMembers($a_status)
isRegistrationEnabled()
is registration enabled
const ERR_WRONG_MIN_MAX_MEMBERS
isRegistrationAccessCodeEnabled()
Check if access code is enabled.
getLatitude()
Get Latitude.
getGrpStatusOpenTemplateId()
get group status open template @access public
const MAIL_ALLOWED_ALL
getMailToMembersType()
Get mail to members type.
static findGroupsWithNotEnoughMembers()
Minimum members check @global $ilDB $ilDB.
enableUnlimitedRegistration($a_status)
enable unlimited registration
getEnableGroupMap()
Get Enable Group Map.
static lookupGroupStatusTemplateId($a_obj_id)
@global $ilDB $ilDB
_getMembers($a_obj_id)
getStart()
Get group start.
static mayLeave($a_group_id, $a_user_id=null, &$a_date=null)
prepareAppointments($a_mode='create')
Prepare calendar appointments.
updateGroupType($a_group_type=GRP_TYPE_OPEN)
Change group type.
getGroupAdminIds($a_grpId="")
get Group Admin Id @access public
setParentRolePermissions($a_parent_ref)
This method is called before "initDefaultRoles".
const ERR_WRONG_MAX_MEMBERS
setMessage($a_message)
static translateViewMode($a_obj_id, $a_view_mode, $a_ref_id=null)
translate view mode
getMemberRoles($a_user_id)
get group member status @access public
initDefaultRoles()
init default roles settings @access public
isWaitingListEnabled()
is waiting list enabled
static _getTranslation($a_role_title)
static createDefaultRole($a_title, $a_description, $a_tpl_name, $a_ref_id)
static cloneDependencies($a_ref_id, $a_target_id, $a_copy_id)
Clone dependencies.
static addAdditionalSubItemInformation(array &$a_item)
Parse item data for list entries.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getType()
get object type @access public
static _lookupObjId($a_id)
setRegisterMode($a_bool)
createMetaData()
create meta data entry
getRefId()
get reference id @access public
getLongDescription()
get object long description (stored in object_description)
static _getAllReferences($a_id)
get all reference ids of object
cloneMetaData($target_obj)
Copy meta data.
getId()
get object id @access public
getTitle()
get object title @access public
static lookupNumberOfMembers($a_ref_id)
Lookup number of members @global ilRbacReview $rbacreview @global <type> $ilObjDataCache.
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.
$template
$r
Definition: example_031.php:79
global $ilBench
Definition: ilias.php:18
Interface for all objects that offer registration with access codes.
$time
Definition: cron.php:21
catch(Exception $e) $message
$info
Definition: index.php:5
$row
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
update($pash, $contents, Config $config)
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$query
$ilErr
Definition: raiseError.php:18
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$template_id