<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\WebMapItemRepository")
*/
class WebMapItem
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\WebMap", inversedBy="items")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="map_id", referencedColumnName="id", onDelete="CASCADE")
* })
*/
private $webMap;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="integer", nullable=true, options={"default":0, "comment":"code de statut : 0=OK"})
*/
private $state;
/**
* @ORM\Column(type="string", length=255)
*/
private $label;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $labelTranslations;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isCategory;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Selection", inversedBy="webMapItems")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="selection_id", referencedColumnName="id")
* })
*/
private $selection;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media", inversedBy="webMapItemsLegend")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="legend_media_id", referencedColumnName="id")
* })
*/
private $legendMedia;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media", inversedBy="webMapItemsMap")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="map_media_id", referencedColumnName="id")
* })
*/
private $mapMedia;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\WebMapItem", inversedBy="subItems")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
* })
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\WebMapItem", mappedBy="parent", cascade={"persist", "remove"})
* @ORM\OrderBy({"ordering" = "ASC"})
*/
private $subItems;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $ordering;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $parameters;
/**
* Constructor
*/
public function __construct()
{
$this->subItems = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getWebMap(): ?WebMap
{
return $this->webMap;
}
public function setWebMap(?WebMap $webMap): self
{
$this->webMap = $webMap;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
public function setState(?int $state): self
{
$this->state = $state;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(?string $label): self
{
$this->label = $label;
return $this;
}
public function getLabelTranslations(): ?array
{
return $this->labelTranslations;
}
public function setLabelTranslations(?array $labelTranslations): self
{
$this->labelTranslations = $labelTranslations;
return $this;
}
public function getIsCategory(): ?bool
{
return $this->isCategory;
}
public function setIsCategory(?bool $isCategory): self
{
$this->isCategory = $isCategory;
return $this;
}
public function getSelection(): ?Selection
{
return $this->selection;
}
public function setSelection(?Selection $selection): self
{
$this->selection = $selection;
return $this;
}
public function getLegendMedia(): ?Media
{
return $this->legendMedia;
}
public function setLegendMedia(?Media $legendMedia): self
{
$this->legendMedia = $legendMedia;
return $this;
}
public function getMapMedia(): ?Media
{
return $this->mapMedia;
}
public function setMapMedia(?Media $mapMedia): self
{
$this->mapMedia = $mapMedia;
return $this;
}
public function getParent(): ?WebMapItem
{
return $this->parent;
}
public function setParent(?WebMapItem $parent): self
{
$this->parent = $parent;
return $this;
}
public function getOrdering(): ?int
{
return $this->ordering;
}
public function setOrdering(?int $ordering): self
{
$this->ordering = $ordering;
return $this;
}
public function getParameters(): ?array
{
return $this->parameters;
}
public function setParameters(?array $parameters): self
{
$this->parameters = $parameters;
return $this;
}
/**
* @return Collection|WebMapItem[]
*/
public function getSubItems(): Collection
{
return $this->subItems;
}
public function addSubItem(WebMapItem $subItem): self
{
if (!$this->subItems->contains($subItem)) {
$this->subItems[] = $subItem;
// ajouter aussi la relation correspondante de l'autre côté pour éviter les incohérences
}
$subItem->setParent($this);
// Patch ND 18/06/21 : si on fait ça, lors de la création d'un subItem il se retrouve à la fois à la racine et en tant que subItem
// Il faut donc que les subItems aient IMPERATIVEMENT le champ webmap_id à null
// $subItem->setWebMap($this->getWebMap());
return $this;
}
public function removeSubItem(WebMapItem $subItem): self
{
if ($this->subItems->contains($subItem)) {
$this->subItems->removeElement($subItem);
// passer l'autre côté à null pour éviter les incohérences
// if ($subItem->getParent() === $this) {
$subItem->setParent(null);
// }
}
return $this;
}
}