Skip to content

Instantly share code, notes, and snippets.

@melokki
Last active May 21, 2018
Embed
What would you like to do?
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="App\Repository\MovieRepository")
* @ORM\Table(name="movies")
* @ORM\HasLifecycleCallbacks()
*/
class Movie extends AbstractEntity
{
/**
* @ORM\Id
* @ORM\Column(type="string", name="id")
*/
protected $id;
/**
* @ORM\Column(type="string", name="title")
*/
protected $title;
/**
* @ORM\Column(type="string", name="hash")
*/
protected $hash;
/** @ORM\Column(type="string", name="internal_id") */
protected $internalId;
/**
* @ORM\OneToMany(targetEntity="MovieSource", mappedBy="movie", fetch="EAGER")
*/
protected $movieSource;
public function __construct(array $attributes = null)
{
parent::__construct($attributes);
$this->movieSource = new ArrayCollection();
}
public function addSource(Source $source, array $attributes = [])
{
$movieSource = new MovieSource($attributes);
$movieSource->setMovie($this);
$movieSource->setSource($source);
$this->movieSource[] = $movieSource;
}
/**
* @return ArrayCollection|Source[]
*/
public function getSources()
{
return $this->movieSource;
}
/* Setters */
/**
* @param string $id
* @return Movie
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @param string $title
* @return Movie
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Set the hash value of the entity
*
* @param $hash
* @return Movie
*/
public function setHash($hash)
{
$this->hash = $hash;
return $this;
}
public function setInternalId($value)
{
$this->internalId = $value;
return $this;
}
/* Getters */
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @return string
*/
public function getHash()
{
return $this->hash;
}
/* Helpers */
public function __toString()
{
return (string)$this->title;
}
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="movie_source")
* @ORM\HasLifecycleCallbacks()
*/
class MovieSource extends AbstractEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="integer", name="source_id")
*
* @ORM\ManyToOne(targetEntity="Source", inversedBy="movieSource")
* @ORM\JoinColumn(nullable=false)
*/
protected $source;
/**
* @ORM\Column(type="string", name="movie_id")
*
* @ORM\ManyToOne(targetEntity="Movie")
* @ORM\JoinColumn(name="movie_id", referencedColumnName="id", nullable=false)
*/
protected $movie;
/**
* @return mixed
*/
public function getSource()
{
return $this->source;
}
/**
* @param mixed $source
* @return MovieSource
*/
public function setSource(Source $source)
{
$this->source = $source->getId();
return $this;
}
/**
* @return mixed
*/
public function getMovie()
{
return $this->movie;
}
/**
* @param mixed $movie
* @return MovieSource
*/
public function setMovie(Movie $movie)
{
$this->movie = $movie->getId();
return $this;
}
/**
* @ORM\Column(type="text", name="description")
*/
protected $description;
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
* @return MovieSource
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
}
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="App\Repository\SourceRepository")
* @ORM\Table(name="sources")
* @ORM\HasLifecycleCallbacks()
*/
class Source extends AbstractEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", name="name")
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="MovieSource", mappedBy="source")
*/
protected $movieSource;
public function __construct(array $attributes = null)
{
parent::__construct($attributes);
$this->movieSource = new ArrayCollection();
}
public function addMovie(Movie $movie)
{
$this->movieSource[] = $movie;
}
/**
* Set the name of the source entity
*
* @param string $name
* @return Source
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Return the name of the source entity
*
* @return string
*/
public function getName()
{
return $this->name;
}
/* Helpers */
public function __toString()
{
return (string) $this->name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment