Add actors and their roles
This commit is contained in:
93
src/Entity/Actor.php
Normal file
93
src/Entity/Actor.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\ActorRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: ActorRepository::class)]
|
||||||
|
class Actor
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $name = null;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
private ?float $popularity = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection<int, MovieRole>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(targetEntity: MovieRole::class, mappedBy: 'actor')]
|
||||||
|
private Collection $movieRoles;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->movieRoles = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): static
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPopularity(): ?float
|
||||||
|
{
|
||||||
|
return $this->popularity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPopularity(?float $popularity): static
|
||||||
|
{
|
||||||
|
$this->popularity = $popularity;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, MovieRole>
|
||||||
|
*/
|
||||||
|
public function getMovieRoles(): Collection
|
||||||
|
{
|
||||||
|
return $this->movieRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addMovieRole(MovieRole $movieRole): static
|
||||||
|
{
|
||||||
|
if (!$this->movieRoles->contains($movieRole)) {
|
||||||
|
$this->movieRoles->add($movieRole);
|
||||||
|
$movieRole->setActor($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeMovieRole(MovieRole $movieRole): static
|
||||||
|
{
|
||||||
|
if ($this->movieRoles->removeElement($movieRole)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($movieRole->getActor() === $this) {
|
||||||
|
$movieRole->setActor(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\MovieRepository;
|
use App\Repository\MovieRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: MovieRepository::class)]
|
#[ORM\Entity(repositoryClass: MovieRepository::class)]
|
||||||
@@ -22,6 +24,17 @@ class Movie
|
|||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private ?string $title = null;
|
private ?string $title = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Collection<int, MovieRole>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(targetEntity: MovieRole::class, mappedBy: 'movie')]
|
||||||
|
private Collection $actors;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->actors = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@@ -62,4 +75,34 @@ class Movie
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, MovieRole>
|
||||||
|
*/
|
||||||
|
public function getActors(): Collection
|
||||||
|
{
|
||||||
|
return $this->actors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addActor(MovieRole $actor): static
|
||||||
|
{
|
||||||
|
if (!$this->actors->contains($actor)) {
|
||||||
|
$this->actors->add($actor);
|
||||||
|
$actor->setMovie($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeActor(MovieRole $actor): static
|
||||||
|
{
|
||||||
|
if ($this->actors->removeElement($actor)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($actor->getMovie() === $this) {
|
||||||
|
$actor->setMovie(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
65
src/Entity/MovieRole.php
Normal file
65
src/Entity/MovieRole.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\MovieRoleRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: MovieRoleRepository::class)]
|
||||||
|
class MovieRole
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $character = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'movieRoles')]
|
||||||
|
private ?Actor $actor = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'actors')]
|
||||||
|
private ?Movie $movie = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCharacter(): ?string
|
||||||
|
{
|
||||||
|
return $this->character;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCharacter(string $character): static
|
||||||
|
{
|
||||||
|
$this->character = $character;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActor(): ?Actor
|
||||||
|
{
|
||||||
|
return $this->actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActor(?Actor $actor): static
|
||||||
|
{
|
||||||
|
$this->actor = $actor;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMovie(): ?Movie
|
||||||
|
{
|
||||||
|
return $this->movie;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMovie(?Movie $movie): static
|
||||||
|
{
|
||||||
|
$this->movie = $movie;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/Repository/ActorRepository.php
Normal file
43
src/Repository/ActorRepository.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Actor;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<Actor>
|
||||||
|
*/
|
||||||
|
class ActorRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Actor::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Actor[] Returns an array of Actor objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('a')
|
||||||
|
// ->andWhere('a.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('a.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?Actor
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('a')
|
||||||
|
// ->andWhere('a.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
||||||
43
src/Repository/MovieRoleRepository.php
Normal file
43
src/Repository/MovieRoleRepository.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\MovieRole;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<MovieRole>
|
||||||
|
*/
|
||||||
|
class MovieRoleRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, MovieRole::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return MovieRole[] Returns an array of MovieRole objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('m')
|
||||||
|
// ->andWhere('m.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('m.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?MovieRole
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('m')
|
||||||
|
// ->andWhere('m.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user