From 859a5a10674564f02885ec255110f9202f36f643 Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Wed, 1 Apr 2026 14:23:23 +0200 Subject: [PATCH] feat: add Award entity and repository --- src/Entity/Actor.php | 11 ++++ src/Entity/Award.php | 84 ++++++++++++++++++++++++++++++ src/Repository/AwardRepository.php | 29 +++++++++++ 3 files changed, 124 insertions(+) create mode 100644 src/Entity/Award.php create mode 100644 src/Repository/AwardRepository.php diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 4a3f72c..fc24f46 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -30,9 +30,14 @@ class Actor #[ORM\Column(nullable: true)] private ?int $tmdbId = null; + /** @var Collection */ + #[ORM\OneToMany(targetEntity: Award::class, mappedBy: 'actor')] + private Collection $awards; + public function __construct() { $this->movieRoles = new ArrayCollection(); + $this->awards = new ArrayCollection(); } public function getId(): ?int @@ -105,4 +110,10 @@ class Actor return $this; } + + /** @return Collection */ + public function getAwards(): Collection + { + return $this->awards; + } } diff --git a/src/Entity/Award.php b/src/Entity/Award.php new file mode 100644 index 0000000..50aa397 --- /dev/null +++ b/src/Entity/Award.php @@ -0,0 +1,84 @@ +id; + } + + public function getAwardType(): AwardType + { + return $this->awardType; + } + + public function setAwardType(AwardType $awardType): static + { + $this->awardType = $awardType; + + return $this; + } + + public function getActor(): Actor + { + return $this->actor; + } + + public function setActor(Actor $actor): static + { + $this->actor = $actor; + + return $this; + } + + public function getName(): string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getYear(): ?int + { + return $this->year; + } + + public function setYear(?int $year): static + { + $this->year = $year; + + return $this; + } +} diff --git a/src/Repository/AwardRepository.php b/src/Repository/AwardRepository.php new file mode 100644 index 0000000..2ec010e --- /dev/null +++ b/src/Repository/AwardRepository.php @@ -0,0 +1,29 @@ + */ +class AwardRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Award::class); + } + + public function findOneRandomByActor(int $actorId): ?Award + { + return $this->createQueryBuilder('a') + ->andWhere('a.actor = :actorId') + ->setParameter('actorId', $actorId) + ->orderBy('RANDOM()') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } +}