src/Entity/Categorie.php line 12
<?php
namespace App\Entity;
use App\Repository\CategorieRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CategorieRepository::class)]
class Categorie
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $titre = null;
#[ORM\Column(length: 255)]
private ?string $url = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'categories')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $categories;
#[ORM\Column(length: 255, nullable: true)]
private ?string $image = null;
#[ORM\Column(length: 255)]
private ?string $resume = null;
#[ORM\ManyToMany(targetEntity: Materiel::class, inversedBy: 'categories')]
#[ORM\JoinTable(name:"materiel_categorie")]
private Collection $materiels;
#[ORM\ManyToMany(targetEntity: Protocole::class, mappedBy: 'categories')]
#[ORM\JoinTable(name:"protocole_categorie")]
private Collection $protocoles;
public function __construct()
{
$this->categories = new ArrayCollection();
$this->materiels = new ArrayCollection();
$this->protocoles = new ArrayCollection();
}
public function __toString(): string
{
return $this->getTitre();
}
public function titreParent(): string
{
$prefix = '';
if($this->parent != null){
$prefix .= '';
if($this->parent->parent != null){
$prefix .= '---';
if($this->parent->parent->parent != null){
$prefix .= '---';
if($this->parent->parent->parent->parent != null){
$prefix .= '---';
}
}
}
$prefix .= ' ';
}
return $prefix.$this->getTitre();
}
public function titreParentAll(): string
{
$prefix = '';
if($this->parent != null){
$prefix .= '---';
if($this->parent->parent != null){
$prefix .= '---';
if($this->parent->parent->parent != null){
$prefix .= '---';
if($this->parent->parent->parent->parent != null){
$prefix .= '---';
}
}
}
$prefix .= ' ';
}
return $prefix.$this->getTitre();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(self $category): self
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->setParent($this);
}
return $this;
}
public function removeCategory(self $category): self
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getParent() === $this) {
$category->setParent(null);
}
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getResume(): ?string
{
return $this->resume;
}
public function setResume(string $resume): self
{
$this->resume = $resume;
return $this;
}
/**
* @return Collection<int, Materiel>
*/
public function getMateriels(): Collection
{
return $this->materiels;
}
public function addMateriel(Materiel $materiel): self
{
if (!$this->materiels->contains($materiel)) {
$this->materiels->add($materiel);
}
return $this;
}
public function removeMateriel(Materiel $materiel): self
{
$this->materiels->removeElement($materiel);
return $this;
}
/**
* @return Collection<int, Protocole>
*/
public function getProtocoles(): Collection
{
return $this->protocoles;
}
public function addProtocole(Protocole $protocole): self
{
if (!$this->protocoles->contains($protocole)) {
$this->protocoles->add($protocole);
$protocole->addCategory($this);
}
return $this;
}
public function removeProtocole(Protocole $protocole): self
{
if ($this->protocoles->removeElement($protocole)) {
$protocole->removeCategory($this);
}
return $this;
}
}