308 lines
5.7 KiB
PHP
308 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
/**
|
|
* Book.
|
|
*
|
|
* @ORM\Table(name="book")
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\BookRepository")
|
|
* @JMS\Serializer\Annotation\ExclusionPolicy("all")
|
|
*/
|
|
class Book
|
|
{
|
|
/**
|
|
* @var int
|
|
*
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var string
|
|
*
|
|
* @ORM\Column(name="title", type="string", length=255)
|
|
*/
|
|
private $title;
|
|
|
|
/**
|
|
* @var int
|
|
*
|
|
* @ORM\Column(name="pages", type="integer")
|
|
*/
|
|
private $pages;
|
|
|
|
/**
|
|
* @var \DateTime
|
|
*
|
|
* @ORM\Column(name="publishedAt", type="date")
|
|
*/
|
|
private $publishedAt;
|
|
|
|
/**
|
|
* @var \Doctrine\Common\Collections\Collection
|
|
*
|
|
* @ORM\ManyToMany(
|
|
* targetEntity="Category",
|
|
* cascade={"persist"}
|
|
* )
|
|
*/
|
|
private $categories;
|
|
|
|
/**
|
|
* @var Author
|
|
*
|
|
* @ORM\ManyToOne(
|
|
* targetEntity="Author",
|
|
* inversedBy="books",
|
|
* cascade={"persist", "remove", "merge"}
|
|
* )
|
|
* @ORM\JoinColumn(
|
|
* name="author_id",
|
|
* referencedColumnName="id"
|
|
* )
|
|
*/
|
|
private $author;
|
|
|
|
/**
|
|
* Constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
|
|
}
|
|
|
|
/**
|
|
* Get id.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Set title.
|
|
*
|
|
* @param string $title
|
|
*
|
|
* @return Book
|
|
*/
|
|
public function setTitle($title)
|
|
{
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get title.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getTitle()
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
/**
|
|
* Set pages.
|
|
*
|
|
* @param int $pages
|
|
*
|
|
* @return Book
|
|
*/
|
|
public function setPages($pages)
|
|
{
|
|
$this->pages = $pages;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get pages.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getPages()
|
|
{
|
|
return $this->pages;
|
|
}
|
|
|
|
/**
|
|
* Set publishedAt.
|
|
*
|
|
* @param \DateTime $publishedAt
|
|
*
|
|
* @return Book
|
|
*/
|
|
public function setPublishedAt($publishedAt)
|
|
{
|
|
$this->publishedAt = $publishedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get publishedAt.
|
|
*
|
|
* @return \DateTime
|
|
*/
|
|
public function getPublishedAt()
|
|
{
|
|
return $this->publishedAt;
|
|
}
|
|
|
|
/**
|
|
* Add category.
|
|
*
|
|
* @param \AppBundle\Entity\Category $category
|
|
*
|
|
* @return Book
|
|
*/
|
|
public function addCategory(\AppBundle\Entity\Category $category)
|
|
{
|
|
$this->categories[] = $category;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Remove category.
|
|
*
|
|
* @param \AppBundle\Entity\Category $category
|
|
*/
|
|
public function removeCategory(\AppBundle\Entity\Category $category)
|
|
{
|
|
$this->categories->removeElement($category);
|
|
}
|
|
|
|
/**
|
|
* Get categories.
|
|
*
|
|
* @return \Doctrine\Common\Collections\Collection
|
|
*/
|
|
public function getCategories()
|
|
{
|
|
return $this->categories;
|
|
}
|
|
|
|
/**
|
|
* Set author.
|
|
*
|
|
* @param \AppBundle\Entity\Author $author
|
|
*
|
|
* @return Book
|
|
*/
|
|
public function setAuthor(\AppBundle\Entity\Author $author = null)
|
|
{
|
|
$this->author = $author;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get author.
|
|
*
|
|
* @return \AppBundle\Entity\Author
|
|
*/
|
|
public function getAuthor()
|
|
{
|
|
return $this->author;
|
|
}
|
|
|
|
/**
|
|
* Rest: get id.
|
|
*
|
|
* @JMS\Serializer\Annotation\SerializedName("id")
|
|
* @JMS\Serializer\Annotation\Groups({"all"})
|
|
* @JMS\Serializer\Annotation\VirtualProperty
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getRestId()
|
|
{
|
|
return $this->getId();
|
|
}
|
|
|
|
/**
|
|
* Rest: get title.
|
|
*
|
|
* @JMS\Serializer\Annotation\SerializedName("title")
|
|
* @JMS\Serializer\Annotation\Groups({"all"})
|
|
* @JMS\Serializer\Annotation\VirtualProperty
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getRestTitle()
|
|
{
|
|
return $this->getTitle();
|
|
}
|
|
|
|
/**
|
|
* Rest: get publishedAt.
|
|
*
|
|
* @JMS\Serializer\Annotation\SerializedName("publishedAt")
|
|
* @JMS\Serializer\Annotation\Groups({"all"})
|
|
* @JMS\Serializer\Annotation\VirtualProperty
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getRestPublishedAt()
|
|
{
|
|
if ($this->getPublishedAt()) {
|
|
return $this->getPublishedAt()->format('Y-m-d');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Rest: get pages.
|
|
*
|
|
* @JMS\Serializer\Annotation\SerializedName("pages")
|
|
* @JMS\Serializer\Annotation\Groups({"all"})
|
|
* @JMS\Serializer\Annotation\VirtualProperty
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getRestPages()
|
|
{
|
|
return $this->getPages();
|
|
}
|
|
|
|
/**
|
|
* Rest: get categories.
|
|
*
|
|
* @JMS\Serializer\Annotation\SerializedName("categories")
|
|
* @JMS\Serializer\Annotation\Groups({"all"})
|
|
* @JMS\Serializer\Annotation\VirtualProperty
|
|
*
|
|
* @return ArrayCollection
|
|
*/
|
|
public function getRestCategories()
|
|
{
|
|
return $this->getCategories();
|
|
}
|
|
|
|
/**
|
|
* Rest: get author.
|
|
*
|
|
* @JMS\Serializer\Annotation\SerializedName("author")
|
|
* @JMS\Serializer\Annotation\Groups({"all"})
|
|
* @JMS\Serializer\Annotation\VirtualProperty
|
|
*
|
|
* @return Author
|
|
*/
|
|
public function getRestAuthor()
|
|
{
|
|
return $this->getAuthor();
|
|
}
|
|
}
|