diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index 1fbb9115c4..38e56cb78c 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -226,13 +226,13 @@ class GroupManager $places = (int) $places; // Default values - $docState = self::TOOL_PRIVATE; - $calendarState = self::TOOL_PRIVATE; - $workState = self::TOOL_PRIVATE; - $anonuncementState = self::TOOL_PRIVATE; - $forumState = self::TOOL_PRIVATE; - $wikiState = self::TOOL_PRIVATE; - $chatState = self::TOOL_PRIVATE; + $docState = CGroup::TOOL_PRIVATE; + $calendarState = CGroup::TOOL_PRIVATE; + $workState = CGroup::TOOL_PRIVATE; + $anonuncementState = CGroup::TOOL_PRIVATE; + $forumState = CGroup::TOOL_PRIVATE; + $wikiState = CGroup::TOOL_PRIVATE; + $chatState = CGroup::TOOL_PRIVATE; $selfRegAllowed = 0; $selfUnregAllwoed = 0; $documentAccess = 0; @@ -266,8 +266,7 @@ class GroupManager $category = Container::getGroupCategoryRepository()->find($category_id); } - $group = new CGroup(); - $group + $group = (new CGroup()) ->setName($name) ->setCategory($category) ->setMaxStudent($places) diff --git a/src/CourseBundle/Entity/CGroup.php b/src/CourseBundle/Entity/CGroup.php index 579ff28069..f5251071b2 100644 --- a/src/CourseBundle/Entity/CGroup.php +++ b/src/CourseBundle/Entity/CGroup.php @@ -31,10 +31,15 @@ use Symfony\Component\Validator\Constraints as Assert; * } * ) * - * @ORM\Entity + * @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CGroupRepository") */ class CGroup extends AbstractResource implements ResourceInterface { + public const TOOL_NOT_AVAILABLE = 0; + public const TOOL_PUBLIC = 1; + public const TOOL_PRIVATE = 2; + public const TOOL_PRIVATE_BETWEEN_USERS = 3; + /** * @ORM\Column(name="iid", type="integer") * @ORM\Id @@ -70,6 +75,7 @@ class CGroup extends AbstractResource implements ResourceInterface /** * @ORM\Column(name="max_student", type="integer") */ + #[Assert\NotBlank] protected int $maxStudent; /** @@ -141,6 +147,21 @@ class CGroup extends AbstractResource implements ResourceInterface $this->status = true; $this->members = new ArrayCollection(); $this->tutors = new ArrayCollection(); + + // Default values + $defaultVisibility = self::TOOL_PRIVATE; + + $this->docState = $defaultVisibility; + $this->calendarState = $defaultVisibility; + $this->workState = $defaultVisibility; + $this->announcementsState = $defaultVisibility; + $this->forumState = $defaultVisibility; + $this->wikiState = $defaultVisibility; + $this->chatState = $defaultVisibility; + $this->documentAccess = $defaultVisibility; + + $this->selfRegistrationAllowed = false; + $this->selfUnregistrationAllowed = false; } public function __toString(): string diff --git a/tests/CourseBundle/Repository/CGroupRepositoryTest.php b/tests/CourseBundle/Repository/CGroupRepositoryTest.php new file mode 100644 index 0000000000..364d026e1b --- /dev/null +++ b/tests/CourseBundle/Repository/CGroupRepositoryTest.php @@ -0,0 +1,40 @@ +get('doctrine')->getManager(); + $repo = self::getContainer()->get(CGroupRepository::class); + + $course = $this->createCourse('new'); + $teacher = $this->createUser('teacher'); + + $item = (new CGroup()) + ->setName('Group') + ->setParent($course) + ->setCreator($teacher) + ->setMaxStudent(100) + ; + $this->assertHasNoEntityViolations($item); + $em->persist($item); + $em->flush(); + + $this->assertSame(1, $repo->count([])); + } +}