diff --git a/src/CoreBundle/Entity/Promotion.php b/src/CoreBundle/Entity/Promotion.php index eb33487fc3..2f68ea2c9b 100644 --- a/src/CoreBundle/Entity/Promotion.php +++ b/src/CoreBundle/Entity/Promotion.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace Chamilo\CoreBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Timestampable\Traits\TimestampableEntity; @@ -51,12 +52,17 @@ class Promotion /** * @var Collection|Session[] * - * @ORM\OneToMany( - * targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="promotion", cascade={"persist"} - * ) + * @ORM\OneToMany(targetEntity="Session", mappedBy="promotion", cascade={"persist"}) */ protected Collection $sessions; + /** + * @var Collection|SysAnnouncement[] + * + * @ORM\OneToMany(targetEntity="SysAnnouncement", mappedBy="promotion", cascade={"persist"}) + */ + protected Collection $announcements; + /** * @ORM\Column(name="status", type="integer", nullable=false) */ @@ -65,6 +71,8 @@ class Promotion public function __construct() { $this->status = self::PROMOTION_STATUS_ACTIVE; + $this->announcements = new ArrayCollection(); + $this->sessions = new ArrayCollection(); } /** @@ -84,12 +92,7 @@ class Promotion return $this; } - /** - * Get name. - * - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } @@ -154,4 +157,22 @@ class Promotion return $this; } + + /** + * @return SysAnnouncement[]|Collection + */ + public function getAnnouncements() + { + return $this->announcements; + } + + /** + * @param SysAnnouncement[]|Collection $announcements + */ + public function setAnnouncements($announcements): self + { + $this->announcements = $announcements; + + return $this; + } } diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php index 7b7028ad6e..b3d7f3107b 100644 --- a/src/CoreBundle/Entity/Session.php +++ b/src/CoreBundle/Entity/Session.php @@ -312,7 +312,7 @@ class Session implements ResourceWithAccessUrlInterface return $this->getName(); } - public function getDuration(): int + public function getDuration(): ?int { return $this->duration; } diff --git a/src/CoreBundle/Entity/SysAnnouncement.php b/src/CoreBundle/Entity/SysAnnouncement.php index e1ec02d495..af98ea9762 100644 --- a/src/CoreBundle/Entity/SysAnnouncement.php +++ b/src/CoreBundle/Entity/SysAnnouncement.php @@ -74,7 +74,7 @@ class SysAnnouncement protected ?Career $career = null; /** - * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion") + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Promotion", inversedBy="announcements") * @ORM\JoinColumn(name="promotion_id", referencedColumnName="id", onDelete="CASCADE") */ protected ?Promotion $promotion = null; diff --git a/tests/CoreBundle/Repository/PromotionRepositoryTest.php b/tests/CoreBundle/Repository/PromotionRepositoryTest.php index 982065fb80..3d3821084c 100644 --- a/tests/CoreBundle/Repository/PromotionRepositoryTest.php +++ b/tests/CoreBundle/Repository/PromotionRepositoryTest.php @@ -30,16 +30,19 @@ class PromotionRepositoryTest extends AbstractApiTest $em->persist($career); $em->flush(); - $item = (new Promotion()) + $promotion = (new Promotion()) ->setName('2000') ->setDescription('Promotion of 2000') ->setCareer($career) ->setStatus(1) ; - $this->assertHasNoEntityViolations($item); - $em->persist($item); + $this->assertHasNoEntityViolations($promotion); + $em->persist($promotion); $em->flush(); + $this->assertSame(0, $promotion->getAnnouncements()->count()); + $this->assertSame(0, $promotion->getSessions()->count()); + $this->assertSame($defaultCount + 1, $repo->count([])); } } diff --git a/tests/CoreBundle/Repository/SessionRepositoryTest.php b/tests/CoreBundle/Repository/SessionRepositoryTest.php index c96f30f982..133017a62b 100644 --- a/tests/CoreBundle/Repository/SessionRepositoryTest.php +++ b/tests/CoreBundle/Repository/SessionRepositoryTest.php @@ -44,8 +44,9 @@ class SessionRepositoryTest extends AbstractApiTest $this->assertSame(1, $repo->count([])); + $this->assertSame('session 1', (string) $session); $this->assertSame(0, \count($session->getAllUsersFromCourse(0))); - + $this->assertSame(100, $session->getDuration()); $this->assertTrue($session->isActiveForStudent()); $this->assertTrue($session->isActiveForCoach()); diff --git a/tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php b/tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php index d12b868c50..d92b166544 100644 --- a/tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php +++ b/tests/CoreBundle/Repository/SysAnnouncementRepositoryTest.php @@ -47,7 +47,28 @@ class SysAnnouncementRepositoryTest extends WebTestCase ; $em->persist($sysAnnouncement); $em->flush(); - $count = $repo->count([]); - $this->assertSame(2, $count); + + $repo->update($sysAnnouncement); + + $this->assertSame(2, $repo->count([])); + + $repo->delete($sysAnnouncement->getId()); + $this->assertSame(1, $repo->count([])); + } + + public function testGetVisibilityList(): void + { + self::bootKernel(); + $repo = self::getContainer()->get(SysAnnouncementRepository::class); + $this->assertIsArray($repo->getVisibilityList()); + } + + public function testGetAnnouncements(): void + { + self::bootKernel(); + $repo = self::getContainer()->get(SysAnnouncementRepository::class); + $user = $this->getUser('admin'); + $items = $repo->getAnnouncements($user, $this->getAccessUrl(), 'en'); + $this->assertSame(1, count($items)); } }