* initial api stuff
This commit is contained in:
@@ -173,7 +173,7 @@ class Awardee implements JsonSerializable
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'year' => $this->getYear(),
|
||||
'name' => $this->getYear(),
|
||||
'name' => $this->getName(),
|
||||
'text' => $this->getText(),
|
||||
'imageLabel' => $this->getImageLabel(),
|
||||
'slug' => $this->getSlug(),
|
||||
|
||||
@@ -34,12 +34,6 @@ class Judge implements JsonSerializable
|
||||
*/
|
||||
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"})
|
||||
@@ -48,14 +42,15 @@ class Judge implements JsonSerializable
|
||||
private $slug;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Year", mappedBy="judges")
|
||||
* @var Collection|Year[]
|
||||
* @ORM\OneToMany(targetEntity="JudgeTitle", mappedBy="judge")
|
||||
* @var Collection|JudgeTitle[]
|
||||
*/
|
||||
private $years;
|
||||
private $titles;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->years = new ArrayCollection();
|
||||
$this->titles = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,24 +89,6 @@ class Judge implements JsonSerializable
|
||||
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
|
||||
*/
|
||||
@@ -131,48 +108,44 @@ class Judge implements JsonSerializable
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Year[]|Collection
|
||||
* @return JudgeTitle[]|Collection
|
||||
*/
|
||||
public function getYears(): ?Collection
|
||||
public function getTitles()
|
||||
{
|
||||
return $this->years;
|
||||
return $this->titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Year $year
|
||||
* @param JudgeTitle $title
|
||||
* @return Judge
|
||||
*/
|
||||
public function addYear(Year $year): Judge
|
||||
public function addTitle(JudgeTitle $title): Judge
|
||||
{
|
||||
if ($this->years->contains($year)) {
|
||||
return $this;
|
||||
if(!$this->titles->contains($title)) {
|
||||
$this->titles->add($title);
|
||||
}
|
||||
$this->years->add($year);
|
||||
$year->addJudge($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Year $year
|
||||
* @param JudgeTitle $title
|
||||
* @return Judge
|
||||
*/
|
||||
public function removeYear(Year $year): Judge
|
||||
public function removeTitle(JudgeTitle $title): Judge
|
||||
{
|
||||
if (!$this->years->contains($year)) {
|
||||
return $this;
|
||||
if($this->titles->contains($title)) {
|
||||
$this->titles->removeElement($title);
|
||||
}
|
||||
$this->years->removeElement($year);
|
||||
$year->removeJudge($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Year[]|Collection $years
|
||||
* @param JudgeTitle[]|Collection $titles
|
||||
* @return Judge
|
||||
*/
|
||||
public function setYears(?Collection $years)
|
||||
public function setTitles($titles)
|
||||
{
|
||||
$this->years = $years;
|
||||
$this->titles = $titles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -184,7 +157,7 @@ class Judge implements JsonSerializable
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
'title' => $this->getTitle(),
|
||||
'titles' => $this->getTitles()->getValues(),
|
||||
'slug' => $this->getSlug(),
|
||||
];
|
||||
}
|
||||
|
||||
131
src/App/Entity/JudgeTitle.php
Normal file
131
src/App/Entity/JudgeTitle.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="judge_titles",
|
||||
* indexes={
|
||||
* @ORM\Index(name="jt_year_idx", columns={"year"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class JudgeTitle implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="year", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $year;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="title", type="text", length=1500)
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Judge", inversedBy="titles")
|
||||
* @ORM\JoinColumn(name="title_id", referencedColumnName="id")
|
||||
* @var Judge
|
||||
*/
|
||||
private $judge;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return JudgeTitle
|
||||
*/
|
||||
public function setId(int $id): JudgeTitle
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getYear(): int
|
||||
{
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @return JudgeTitle
|
||||
*/
|
||||
public function setYear(int $year): JudgeTitle
|
||||
{
|
||||
$this->year = $year;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return JudgeTitle
|
||||
*/
|
||||
public function setTitle(string $title): JudgeTitle
|
||||
{
|
||||
$this->title = $title;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Judge
|
||||
*/
|
||||
public function getJudge(): Judge
|
||||
{
|
||||
return $this->judge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Judge $judge
|
||||
* @return JudgeTitle
|
||||
*/
|
||||
public function setJudge(Judge $judge): JudgeTitle
|
||||
{
|
||||
$this->judge = $judge;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'year' => $this->getYear(),
|
||||
'title' => $this->getTitle(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
<?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