feat: add Award entity and repository
This commit is contained in:
@@ -30,9 +30,14 @@ class Actor
|
|||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
private ?int $tmdbId = null;
|
private ?int $tmdbId = null;
|
||||||
|
|
||||||
|
/** @var Collection<int, Award> */
|
||||||
|
#[ORM\OneToMany(targetEntity: Award::class, mappedBy: 'actor')]
|
||||||
|
private Collection $awards;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->movieRoles = new ArrayCollection();
|
$this->movieRoles = new ArrayCollection();
|
||||||
|
$this->awards = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
@@ -105,4 +110,10 @@ class Actor
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, Award> */
|
||||||
|
public function getAwards(): Collection
|
||||||
|
{
|
||||||
|
return $this->awards;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
84
src/Entity/Award.php
Normal file
84
src/Entity/Award.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\AwardRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: AwardRepository::class)]
|
||||||
|
class Award
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: AwardType::class, inversedBy: 'awards')]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
private AwardType $awardType;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(targetEntity: Actor::class, inversedBy: 'awards')]
|
||||||
|
#[ORM\JoinColumn(nullable: false)]
|
||||||
|
private Actor $actor;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private string $name;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
private ?int $year = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Repository/AwardRepository.php
Normal file
29
src/Repository/AwardRepository.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Award;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/** @extends ServiceEntityRepository<Award> */
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user