<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\OneToMany(targetEntity=Livre::class, mappedBy="category")
*/
private $livres;
public function __construct()
{
$this->livres = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
/**
* @return Collection<int, livre>
*/
public function getLivres(): Collection
{
return $this->livres;
}
public function addLivre(livre $livre): self
{
if (!$this->livres->contains($livre)) {
$this->livres[] = $livre;
$livre->setCategory($this);
}
return $this;
}
public function removeLivre(livre $livre): self
{
if ($this->livres->removeElement($livre)) {
// set the owning side to null (unless already changed)
if ($livre->getCategory() === $this) {
$livre->setCategory(null);
}
}
return $this;
}
}