<?php
namespace App\Entity;
use App\Repository\BridgeComponentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=BridgeComponentRepository::class)
*/
class BridgeComponent
{
/**
* @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 $path;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $preview;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $parameters;
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
private $isActive;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $needsABlock;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $vueComponent;
/**
* @ORM\ManyToMany(targetEntity=BridgeComponentTag::class, inversedBy="bridgeComponents", cascade={"persist"})
*/
private $tags;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\WebPageBlock", mappedBy="bridgeComponent")
*/
private $webPageBlocks;
public function __construct()
{
$this->tags = new ArrayCollection();
$this->webPageBlocks = 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 getPath(): ?string
{
return $this->path;
}
public function setPath(?string $path): self
{
$this->path = $path;
return $this;
}
public function getPreview(): ?string
{
return $this->preview;
}
public function setPreview(?string $preview): self
{
$this->preview = $preview;
return $this;
}
public function getParameters(): ?array
{
return $this->parameters;
}
public function setParameters(?array $parameters): self
{
$this->parameters = $parameters;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getNeedsABlock(): ?bool
{
return $this->needsABlock;
}
public function setNeedsABlock(?bool $needsABlock): self
{
$this->needsABlock = $needsABlock;
return $this;
}
public function getVueComponent(): ?string
{
return $this->vueComponent;
}
public function setVueComponent(?string $vueComponent): self
{
$this->vueComponent = $vueComponent;
return $this;
}
/**
* @return Collection|BridgeComponentTag[]
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(BridgeComponentTag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
}
return $this;
}
public function removeTag(BridgeComponentTag $tag): self
{
$this->tags->removeElement($tag);
return $this;
}
/**
* @return Collection|WebPageBlock[]
*/
public function getWebPageBlocks(): Collection
{
return $this->webPageBlocks;
}
public function addWebPageBlock(WebPageBlock $webPageBlock): self
{
if (!$this->webPageBlocks->contains($webPageBlock)) {
$this->webPageBlocks[] = $webPageBlock;
// ajouter aussi la relation correspondante de l'autre côté pour éviter les incohérences
$webPageBlock->setBridgeComponent($this);
}
return $this;
}
public function removeWebPageBlock(WebPageBlock $webPageBlock): self
{
if ($this->webPageBlocks->contains($webPageBlock)) {
$this->webPageBlocks->removeElement($webPageBlock);
// passer l'autre côté à null pour éviter les incohérences
if ($webPageBlock->getBridgeComponent() === $this) {
$webPageBlock->setBridgeComponent(null);
}
}
return $this;
}
public function toExport(): array
{
$bridgeComponent = array();
$bridgeComponent['name'] = $this->getName();
$bridgeComponent['path'] = $this->getPath();
$bridgeComponent['preview'] = $this->getPreview();
$bridgeComponent['parameters'] = $this->getParameters();
$bridgeComponent['isActive'] = $this->getIsActive();
$bridgeComponent['needsABlock'] = $this->getNeedsABlock();
$bridgeComponent['vueComponent'] = $this->getVueComponent();
$bridgeComponent['tags'] = array();
foreach ($this->getTags() as $tag)
{
$bridgeComponent['tags'][] = $tag->toExport();
}
return $bridgeComponent;
}
}