<?php
namespace App\Entity;
use App\Repository\BlocRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: BlocRepository::class)]
class Bloc
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(nullable: true)]
private ?int $ordre = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $titre = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $emplacement = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $type = null;
#[ORM\Column(type: 'boolean', options: ["default" => true])]
private ?bool $actif = true;
#[ORM\Column(length: 255, nullable: true)]
private ?string $config = null;
#[ORM\ManyToOne(inversedBy: 'bloc')]
private ?Section $section = null;
public function __construct()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getOrdre(): ?int
{
return $this->ordre;
}
public function setOrdre(?int $ordre): static
{
$this->ordre = $ordre;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(?string $titre): static
{
$this->titre = $titre;
return $this;
}
public function getEmplacement(): ?string
{
return $this->emplacement;
}
public function setEmplacement(?string $emplacement): static
{
$this->emplacement = $emplacement;
return $this;
}
public function getDocument(): ?Document
{
return $this->section ? $this->section->getDocument() : null;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): static
{
$this->type = $type;
return $this;
}
public function isActif(): ?bool
{
return $this->actif;
}
public function setActif(?bool $actif): static
{
$this->actif = $actif;
return $this;
}
public function getConfig(): ?string
{
return $this->config;
}
public function getDecodedConfig(): array
{
return $this->decodeConfig();
}
public function getWidth(): ?string
{
$config = $this->decodeConfig();
return $config['width'] ?? null; // Return width if it exists, otherwise null
}
public function getHeight(): ?string
{
$config = $this->decodeConfig();
return $config['height'] ?? null; // Return height if it exists, otherwise null
}
public function getAlign(): ?string
{
$config = $this->decodeConfig();
return $config['align'] ?? null; // Return align if it exists, otherwise null
}
private function decodeConfig(): array
{
if ($this->config === null) {
return [];
}
// Decode the JSON string, return empty array on failure
$decoded = json_decode($this->config, true);
return is_array($decoded) ? $decoded : [];
}
public function setConfig(?string $config): static
{
$this->config = $config;
return $this;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): static
{
$this->section = $section;
return $this;
}
}