src/Entity/WebMapItem.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\WebMapItemRepository")
  8.  */
  9. class WebMapItem
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;    
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity="App\Entity\WebMap", inversedBy="items")
  19.      * @ORM\JoinColumns({
  20.      *   @ORM\JoinColumn(name="map_id", referencedColumnName="id", onDelete="CASCADE")
  21.      * })
  22.      */
  23.     private $webMap;
  24.     
  25.     /**
  26.      * @ORM\Column(type="datetime", nullable=true)
  27.      */
  28.     private $createdAt;
  29.     /**
  30.      * @ORM\Column(type="datetime", nullable=true)
  31.      */
  32.     private $updatedAt;
  33.     /**
  34.      * @ORM\Column(type="integer", nullable=true, options={"default":0, "comment":"code de statut : 0=OK"})
  35.      */
  36.     private $state;
  37.     /**
  38.      * @ORM\Column(type="string", length=255)
  39.      */
  40.     private $label;
  41.     /**
  42.      * @ORM\Column(type="json", nullable=true)
  43.      */
  44.     private $labelTranslations;
  45.     /**
  46.      * @ORM\Column(type="boolean", nullable=true)
  47.      */
  48.     private $isCategory;
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity="App\Entity\Selection", inversedBy="webMapItems")
  51.      * @ORM\JoinColumns({
  52.      *   @ORM\JoinColumn(name="selection_id", referencedColumnName="id")
  53.      * })
  54.      */
  55.     private $selection;
  56.     /**
  57.      * @ORM\ManyToOne(targetEntity="App\Entity\Media", inversedBy="webMapItemsLegend")
  58.      * @ORM\JoinColumns({
  59.      *   @ORM\JoinColumn(name="legend_media_id", referencedColumnName="id")
  60.      * })
  61.      */
  62.     private $legendMedia;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity="App\Entity\Media", inversedBy="webMapItemsMap")
  65.      * @ORM\JoinColumns({
  66.      *   @ORM\JoinColumn(name="map_media_id", referencedColumnName="id")
  67.      * })
  68.      */
  69.     private $mapMedia;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity="App\Entity\WebMapItem", inversedBy="subItems")
  72.      * @ORM\JoinColumns({
  73.      *     @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  74.      * })
  75.      */
  76.     private $parent;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity="App\Entity\WebMapItem", mappedBy="parent", cascade={"persist", "remove"})
  79.      * @ORM\OrderBy({"ordering" = "ASC"})
  80.      */
  81.     private $subItems;
  82.     /**
  83.      * @ORM\Column(type="integer", nullable=true)
  84.      */
  85.     private $ordering;
  86.     /**
  87.      * @ORM\Column(type="json", nullable=true)
  88.      */
  89.     private $parameters;
  90.     /**
  91.      * Constructor
  92.      */
  93.     public function __construct()
  94.     {
  95.         $this->subItems = new ArrayCollection();
  96.     }
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function getWebMap(): ?WebMap
  102.     {
  103.         return $this->webMap;
  104.     }
  105.     public function setWebMap(?WebMap $webMap): self
  106.     {
  107.         $this->webMap $webMap;
  108.         return $this;
  109.     }
  110.     public function getCreatedAt(): ?\DateTimeInterface
  111.     {
  112.         return $this->createdAt;
  113.     }
  114.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  115.     {
  116.         $this->createdAt $createdAt;
  117.         return $this;
  118.     }
  119.     public function getUpdatedAt(): ?\DateTimeInterface
  120.     {
  121.         return $this->updatedAt;
  122.     }
  123.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  124.     {
  125.         $this->updatedAt $updatedAt;
  126.         return $this;
  127.     }
  128.     public function getState(): ?int
  129.     {
  130.         return $this->state;
  131.     }
  132.     public function setState(?int $state): self
  133.     {
  134.         $this->state $state;
  135.         return $this;
  136.     }
  137.     public function getLabel(): ?string
  138.     {
  139.         return $this->label;
  140.     }
  141.     public function setLabel(?string $label): self
  142.     {
  143.         $this->label $label;
  144.         return $this;
  145.     }
  146.     public function getLabelTranslations(): ?array
  147.     {
  148.         return $this->labelTranslations;
  149.     }
  150.     public function setLabelTranslations(?array $labelTranslations): self
  151.     {
  152.         $this->labelTranslations $labelTranslations;
  153.         return $this;
  154.     }
  155.     public function getIsCategory(): ?bool
  156.     {
  157.         return $this->isCategory;
  158.     }
  159.     public function setIsCategory(?bool $isCategory): self
  160.     {
  161.         $this->isCategory $isCategory;
  162.         return $this;
  163.     }
  164.     public function getSelection(): ?Selection
  165.     {
  166.         return $this->selection;
  167.     }
  168.     public function setSelection(?Selection $selection): self
  169.     {
  170.         $this->selection $selection;
  171.         return $this;
  172.     }
  173.     public function getLegendMedia(): ?Media
  174.     {
  175.         return $this->legendMedia;
  176.     }
  177.     public function setLegendMedia(?Media $legendMedia): self
  178.     {
  179.         $this->legendMedia $legendMedia;
  180.         return $this;
  181.     }
  182.     public function getMapMedia(): ?Media
  183.     {
  184.         return $this->mapMedia;
  185.     }
  186.     public function setMapMedia(?Media $mapMedia): self
  187.     {
  188.         $this->mapMedia $mapMedia;
  189.         return $this;
  190.     }
  191.     public function getParent(): ?WebMapItem
  192.     {
  193.         return $this->parent;
  194.     }
  195.     public function setParent(?WebMapItem $parent): self
  196.     {
  197.         $this->parent $parent;
  198.         return $this;
  199.     }
  200.     public function getOrdering(): ?int
  201.     {
  202.         return $this->ordering;
  203.     }
  204.     public function setOrdering(?int $ordering): self
  205.     {
  206.         $this->ordering $ordering;
  207.         return $this;
  208.     }
  209.     public function getParameters(): ?array
  210.     {
  211.         return $this->parameters;
  212.     }
  213.     public function setParameters(?array $parameters): self
  214.     {
  215.         $this->parameters $parameters;
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection|WebMapItem[]
  220.      */
  221.     public function getSubItems(): Collection
  222.     {
  223.         return $this->subItems;
  224.     }
  225.     public function addSubItem(WebMapItem $subItem): self
  226.     {
  227.         if (!$this->subItems->contains($subItem)) {
  228.             $this->subItems[] = $subItem;
  229.             // ajouter aussi la relation correspondante de l'autre côté pour éviter les incohérences
  230.             
  231.         }
  232.         $subItem->setParent($this);
  233.         // 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
  234.         // Il faut donc que les subItems aient IMPERATIVEMENT le champ webmap_id à null
  235.         // $subItem->setWebMap($this->getWebMap());
  236.         return $this;
  237.     }
  238.     public function removeSubItem(WebMapItem $subItem): self
  239.     {
  240.         if ($this->subItems->contains($subItem)) {
  241.             $this->subItems->removeElement($subItem);
  242.             // passer l'autre côté à null pour éviter les incohérences
  243.             // if ($subItem->getParent() === $this) {
  244.                 $subItem->setParent(null);
  245.             // }
  246.         }
  247.         return $this;
  248.     }
  249. }