* judge-year many to many implemented, no admin yet
* judge images renamed to use generated slug, may change in the future...
This commit is contained in:
@@ -8,10 +8,15 @@ use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="awardees")
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="awardees",
|
||||
* indexes={
|
||||
* @ORM\Index(name="a_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class Awardee
|
||||
class Awardee implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
|
||||
191
src/App/Entity/Judge.php
Normal file
191
src/App/Entity/Judge.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="judges",
|
||||
* indexes={
|
||||
* @ORM\Index(name="j_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class Judge implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=250)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="title", type="text", length=1500)
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="slug", type="string", length=250)
|
||||
* @Gedmo\Slug(fields={"name"})
|
||||
* @var string
|
||||
*/
|
||||
private $slug;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Year", mappedBy="judges")
|
||||
* @var Collection|Year[]
|
||||
*/
|
||||
private $years;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->years = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Judge
|
||||
*/
|
||||
public function setId(int $id): Judge
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return Judge
|
||||
*/
|
||||
public function setName(string $name): Judge
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return Judge
|
||||
*/
|
||||
public function setTitle(string $title): Judge
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSlug(): string
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return Judge
|
||||
*/
|
||||
public function setSlug(string $slug): Judge
|
||||
{
|
||||
$this->slug = $slug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Year[]|Collection
|
||||
*/
|
||||
public function getYears(): ?Collection
|
||||
{
|
||||
return $this->years;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Year $year
|
||||
* @return Judge
|
||||
*/
|
||||
public function addYear(Year $year): Judge
|
||||
{
|
||||
if ($this->years->contains($year)) {
|
||||
return $this;
|
||||
}
|
||||
$this->years->add($year);
|
||||
$year->addJudge($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Year $year
|
||||
* @return Judge
|
||||
*/
|
||||
public function removeYear(Year $year): Judge
|
||||
{
|
||||
if (!$this->years->contains($year)) {
|
||||
return $this;
|
||||
}
|
||||
$this->years->removeElement($year);
|
||||
$year->removeJudge($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Year[]|Collection $years
|
||||
* @return Judge
|
||||
*/
|
||||
public function setYears(?Collection $years)
|
||||
{
|
||||
$this->years = $years;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
'title' => $this->getTitle(),
|
||||
'slug' => $this->getSlug(),
|
||||
];
|
||||
}
|
||||
}
|
||||
149
src/App/Entity/Year.php
Normal file
149
src/App/Entity/Year.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="years",
|
||||
* indexes={
|
||||
* @ORM\Index(name="y_year_idx", columns={"year"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class Year implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="year", type="integer", nullable=false)
|
||||
* @var int
|
||||
*/
|
||||
private $year;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Judge", inversedBy="years")
|
||||
* @ORM\JoinTable(
|
||||
* name="years_judges",
|
||||
* joinColumns={
|
||||
* @ORM\JoinColumn(name="year_id", referencedColumnName="id")
|
||||
* },
|
||||
* inverseJoinColumns={
|
||||
* @ORM\JoinColumn(name="judge_id", referencedColumnName="id")
|
||||
* }
|
||||
* )
|
||||
* @var \Doctrine\Common\Collections\Collection|Judge[]
|
||||
*/
|
||||
private $judges;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->judges = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Year
|
||||
*/
|
||||
public function setId(int $id): Year
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getYear(): int
|
||||
{
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @return Year
|
||||
*/
|
||||
public function setYear(int $year): Year
|
||||
{
|
||||
$this->year = $year;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Judge[]|Collection
|
||||
*/
|
||||
public function getJudges(): ?Collection
|
||||
{
|
||||
return $this->judges;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Judge $judge
|
||||
* @return Year
|
||||
*/
|
||||
public function addJudge(Judge $judge): Year
|
||||
{
|
||||
if ($this->judges->contains($judge)) {
|
||||
return $this;
|
||||
}
|
||||
$this->judges->add($judge);
|
||||
$judge->addYear($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Judge $judge
|
||||
* @return Year
|
||||
*/
|
||||
public function removeJudge(Judge $judge): Year
|
||||
{
|
||||
if (!$this->judges->contains($judge)) {
|
||||
return $this;
|
||||
}
|
||||
$this->judges->removeElement($judge);
|
||||
$judge->removeYear($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Judge[]|Collection $judges
|
||||
* @return Year
|
||||
*/
|
||||
public function setJudges(?Collection $judges): Year
|
||||
{
|
||||
$this->judges = $judges;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'year' => $this->getYear(),
|
||||
'judges' => $this->getJudges()->getValues(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user