src/Entity/Parametre.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ParametreRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassParametreRepository::class)]
  7. #[ORM\Table(name'parametre')]
  8. #[ORM\Index(name'idx_parametre_cle'columns: ['cle'])]
  9. #[ORM\Index(name'idx_parametre_categorie'columns: ['categorie'])]
  10. class Parametre
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length100uniquetrue)]
  17.     private ?string $cle null;
  18.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  19.     private ?string $valeur null;
  20.     #[ORM\Column(length50)]
  21.     private ?string $categorie 'general'// general, societe, contact, facturation, email, etc.
  22.     #[ORM\Column(length255nullabletrue)]
  23.     private ?string $label null// Libellé pour l'affichage
  24.     #[ORM\Column(length500nullabletrue)]
  25.     private ?string $description null// Description du paramètre
  26.     #[ORM\Column(length50)]
  27.     private ?string $type 'text'// text, textarea, number, email, tel, url, file, boolean, select
  28.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  29.     private ?array $options null// Options pour select, validation, etc.
  30.     #[ORM\Column]
  31.     private ?bool $estModifiable true// Peut être modifié par l'utilisateur
  32.     #[ORM\Column]
  33.     private ?\DateTimeImmutable $createdAt null;
  34.     #[ORM\Column(nullabletrue)]
  35.     private ?\DateTimeImmutable $updatedAt null;
  36.     public function __construct()
  37.     {
  38.         $this->createdAt = new \DateTimeImmutable();
  39.         $this->estModifiable true;
  40.         $this->categorie 'general';
  41.         $this->type 'text';
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getCle(): ?string
  48.     {
  49.         return $this->cle;
  50.     }
  51.     public function setCle(string $cle): static
  52.     {
  53.         $this->cle $cle;
  54.         return $this;
  55.     }
  56.     public function getValeur(): ?string
  57.     {
  58.         return $this->valeur;
  59.     }
  60.     public function setValeur(?string $valeur): static
  61.     {
  62.         $this->valeur $valeur;
  63.         $this->updatedAt = new \DateTimeImmutable();
  64.         return $this;
  65.     }
  66.     public function getCategorie(): ?string
  67.     {
  68.         return $this->categorie;
  69.     }
  70.     public function setCategorie(string $categorie): static
  71.     {
  72.         $this->categorie $categorie;
  73.         return $this;
  74.     }
  75.     public function getLabel(): ?string
  76.     {
  77.         return $this->label;
  78.     }
  79.     public function setLabel(?string $label): static
  80.     {
  81.         $this->label $label;
  82.         return $this;
  83.     }
  84.     public function getDescription(): ?string
  85.     {
  86.         return $this->description;
  87.     }
  88.     public function setDescription(?string $description): static
  89.     {
  90.         $this->description $description;
  91.         return $this;
  92.     }
  93.     public function getType(): ?string
  94.     {
  95.         return $this->type;
  96.     }
  97.     public function setType(string $type): static
  98.     {
  99.         $this->type $type;
  100.         return $this;
  101.     }
  102.     public function getOptions(): ?array
  103.     {
  104.         return $this->options;
  105.     }
  106.     public function setOptions(?array $options): static
  107.     {
  108.         $this->options $options;
  109.         return $this;
  110.     }
  111.     public function isEstModifiable(): ?bool
  112.     {
  113.         return $this->estModifiable;
  114.     }
  115.     public function setEstModifiable(bool $estModifiable): static
  116.     {
  117.         $this->estModifiable $estModifiable;
  118.         return $this;
  119.     }
  120.     public function getCreatedAt(): ?\DateTimeImmutable
  121.     {
  122.         return $this->createdAt;
  123.     }
  124.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  125.     {
  126.         $this->createdAt $createdAt;
  127.         return $this;
  128.     }
  129.     public function getUpdatedAt(): ?\DateTimeImmutable
  130.     {
  131.         return $this->updatedAt;
  132.     }
  133.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
  134.     {
  135.         $this->updatedAt $updatedAt;
  136.         return $this;
  137.     }
  138.     /**
  139.      * Retourne la valeur convertie selon le type
  140.      */
  141.     public function getValeurTypee()
  142.     {
  143.         if ($this->valeur === null) {
  144.             return null;
  145.         }
  146.         return match($this->type) {
  147.             'number' => (float) $this->valeur,
  148.             'boolean' => filter_var($this->valeurFILTER_VALIDATE_BOOLEAN),
  149.             'json' => json_decode($this->valeurtrue),
  150.             default => $this->valeur
  151.         };
  152.     }
  153.     public function __toString(): string
  154.     {
  155.         return $this->label ?? $this->cle ?? '';
  156.     }
  157. }