src/Entity/BridgeComponent.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BridgeComponentRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=BridgeComponentRepository::class)
  9.  */
  10. class BridgeComponent
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.      /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $path;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $preview;
  30.     /**
  31.      * @ORM\Column(type="json", nullable=true)
  32.      */
  33.     private $parameters;
  34.     /**
  35.      * @ORM\Column(type="boolean", options={"default": true})
  36.      */
  37.     private $isActive;
  38.     /**
  39.      * @ORM\Column(type="boolean", options={"default": false})
  40.      */
  41.     private $needsABlock;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $vueComponent;
  46.     /**
  47.      * @ORM\ManyToMany(targetEntity=BridgeComponentTag::class, inversedBy="bridgeComponents", cascade={"persist"})
  48.      */
  49.     private $tags;
  50.     /**
  51.      * @var \Doctrine\Common\Collections\Collection
  52.      *
  53.      * @ORM\OneToMany(targetEntity="App\Entity\WebPageBlock", mappedBy="bridgeComponent")
  54.      */
  55.     private $webPageBlocks;
  56.     
  57.     public function __construct()
  58.     {
  59.         $this->tags = new ArrayCollection();
  60.         $this->webPageBlocks = new ArrayCollection();
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getName(): ?string
  67.     {
  68.         return $this->name;
  69.     }
  70.     public function setName(string $name): self
  71.     {
  72.         $this->name $name;
  73.         return $this;
  74.     }
  75.     public function getPath(): ?string
  76.     {
  77.         return $this->path;
  78.     }
  79.     public function setPath(?string $path): self
  80.     {
  81.         $this->path $path;
  82.         return $this;
  83.     }
  84.     public function getPreview(): ?string
  85.     {
  86.         return $this->preview;
  87.     }
  88.     public function setPreview(?string $preview): self
  89.     {
  90.         $this->preview $preview;
  91.         return $this;
  92.     }
  93.     public function getParameters(): ?array
  94.     {
  95.         return $this->parameters;
  96.     }
  97.     public function setParameters(?array $parameters): self
  98.     {
  99.         $this->parameters $parameters;
  100.         return $this;
  101.     }
  102.     public function getIsActive(): ?bool
  103.     {
  104.         return $this->isActive;
  105.     }
  106.     public function setIsActive(?bool $isActive): self
  107.     {
  108.         $this->isActive $isActive;
  109.         return $this;
  110.     }
  111.     public function getNeedsABlock(): ?bool
  112.     {
  113.         return $this->needsABlock;
  114.     }
  115.     public function setNeedsABlock(?bool $needsABlock): self
  116.     {
  117.         $this->needsABlock $needsABlock;
  118.         return $this;
  119.     }
  120.     public function getVueComponent(): ?string
  121.     {
  122.         return $this->vueComponent;
  123.     }
  124.     public function setVueComponent(?string $vueComponent): self
  125.     {
  126.         $this->vueComponent $vueComponent;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @return Collection|BridgeComponentTag[]
  131.      */
  132.     public function getTags(): Collection
  133.     {
  134.         return $this->tags;
  135.     }
  136.     public function addTag(BridgeComponentTag $tag): self
  137.     {
  138.         if (!$this->tags->contains($tag)) {
  139.             $this->tags[] = $tag;
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeTag(BridgeComponentTag $tag): self
  144.     {
  145.         $this->tags->removeElement($tag);
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection|WebPageBlock[]
  150.      */
  151.     public function getWebPageBlocks(): Collection
  152.     {
  153.         return $this->webPageBlocks;
  154.     }
  155.     public function addWebPageBlock(WebPageBlock $webPageBlock): self
  156.     {
  157.         if (!$this->webPageBlocks->contains($webPageBlock)) {
  158.             $this->webPageBlocks[] = $webPageBlock;
  159.             // ajouter aussi la relation correspondante de l'autre côté pour éviter les incohérences
  160.             $webPageBlock->setBridgeComponent($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeWebPageBlock(WebPageBlock $webPageBlock): self
  165.     {
  166.         if ($this->webPageBlocks->contains($webPageBlock)) {
  167.             $this->webPageBlocks->removeElement($webPageBlock);
  168.             // passer l'autre côté à null pour éviter les incohérences
  169.             if ($webPageBlock->getBridgeComponent() === $this) {
  170.                 $webPageBlock->setBridgeComponent(null);
  171.             }
  172.         }
  173.         return $this;
  174.     }
  175.     public function toExport(): array
  176.     {
  177.         $bridgeComponent = array();
  178.         $bridgeComponent['name'] = $this->getName();
  179.         $bridgeComponent['path'] = $this->getPath();
  180.         $bridgeComponent['preview'] = $this->getPreview();
  181.         $bridgeComponent['parameters'] = $this->getParameters();
  182.         $bridgeComponent['isActive'] = $this->getIsActive();
  183.         $bridgeComponent['needsABlock'] = $this->getNeedsABlock();
  184.         $bridgeComponent['vueComponent'] = $this->getVueComponent();
  185.         $bridgeComponent['tags'] = array();
  186.         foreach ($this->getTags() as $tag)
  187.         {
  188.             $bridgeComponent['tags'][] = $tag->toExport();
  189.         }
  190.         return $bridgeComponent;
  191.     }
  192. }