<?php
namespace App\Entity;
use App\Repository\FrontZoneRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: FrontZoneRepository::class)]
class FrontZone
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups('frontZone')]
private ?int $id = null;
#[ORM\Column(length: 32, nullable: true)]
private ?string $htmlFileName = null;
#[Gedmo\Translatable]
#[ORM\Column(length: 255, nullable: true)]
private ?string $title = null;
#[ORM\Column(length: 16, nullable: true)]
private ?string $backgroundColor = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
private ?FileData $backgroundImage = null;
#[ORM\Column]
#[Groups('frontZone')]
private ?bool $active = null;
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
private ?int $nbElementsToDisplay = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $query = null;
#[ORM\OneToMany(mappedBy: 'frontZone', targetEntity: FrontZoneParamValue::class, cascade: ['Persist' ,'Remove'], orphanRemoval: true)]
#[ORM\OrderBy(['parameter' =>'ASC'])]
private Collection $frontZoneParamValues;
public function __construct()
{
$this->frontZoneParamValues = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getHtmlFileName(): ?string
{
return $this->htmlFileName;
}
public function setHtmlFileName(?string $htmlFileName): static
{
$this->htmlFileName = $htmlFileName;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): static
{
$this->title = $title;
return $this;
}
public function getBackgroundColor(): ?string
{
return $this->backgroundColor;
}
public function setBackgroundColor(?string $backgroundColor): static
{
$this->backgroundColor = $backgroundColor;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): static
{
$this->active = $active;
return $this;
}
public function getNbElementsToDisplay(): ?int
{
return $this->nbElementsToDisplay;
}
public function setNbElementsToDisplay(?int $nbElementsToDisplay): static
{
$this->nbElementsToDisplay = $nbElementsToDisplay;
return $this;
}
public function getBackgroundImage(): ?FileData
{
return $this->backgroundImage;
}
public function setBackgroundImage(?FileData $backgroundImage): self
{
$this->backgroundImage = $backgroundImage;
return $this;
}
public function getQuery(): ?string
{
return $this->query;
}
public function setQuery(?string $query): static
{
$this->query = $query;
return $this;
}
/**
* @return Collection<int, FrontZoneParamValue>
*/
public function getFrontZoneParamValues(): Collection
{
return $this->frontZoneParamValues;
}
public function getParametersValues(): array
{
$parameters = [];
foreach ($this->getFrontZoneParamValues() as $frontZoneParamValue){
$parameters[$frontZoneParamValue->getParameter()][] = $frontZoneParamValue->getValue();
}
return $parameters;
}
public function addFrontZoneParamValue(FrontZoneParamValue $frontZoneParamValue): static
{
if (!$this->frontZoneParamValues->contains($frontZoneParamValue)) {
$this->frontZoneParamValues->add($frontZoneParamValue);
$frontZoneParamValue->setFrontZone($this);
}
return $this;
}
public function removeFrontZoneParamValue(FrontZoneParamValue $frontZoneParamValue): static
{
if ($this->frontZoneParamValues->removeElement($frontZoneParamValue)) {
// set the owning side to null (unless already changed)
if ($frontZoneParamValue->getFrontZone() === $this) {
$frontZoneParamValue->setFrontZone(null);
}
}
return $this;
}
public function __toString(): string
{
return 'Zone ' .$this->id;
}
public function removeAllParamValues(): void
{
foreach ($this->frontZoneParamValues as $paramValue){
$this->removeFrontZoneParamValue($paramValue);
}
}
public function addParameterValues(string $parameterName, mixed $values): void
{
foreach ($values as $value){
$parameterValue = new FrontZoneParamValue();
$parameterValue->setValue($value);
$parameterValue->setParameter($parameterName);
$this->addFrontZoneParamValue($parameterValue);
}
}
}