src/Entity/Domain.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\String\Slugger\AsciiSlugger;
  9. use App\Entity\SubDomain;
  10. use App\Repository\DomainRepository;
  11. /**
  12.  * @ORM\Entity(repositoryClass=DomainRepository::class)
  13.  * @ORM\HasLifecycleCallbacks()
  14.  * @UniqueEntity(fields={"slug"}, message="Slug deja utilisé")
  15.  */
  16. class Domain
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private ?int $id null;
  24.     /**
  25.      * Titre du domaine (obligatoire)
  26.      * @ORM\Column(type="string", length=150, nullable=false)
  27.      * @Assert\NotBlank(message="Le titre est obligatoire.")
  28.      */
  29.     private ?string $title null;
  30.     /**
  31.      * Slug unique (auto-généré à partir du titre si vide)
  32.      * @ORM\Column(type="string", length=255, unique=true, nullable=false)
  33.      * @Assert\NotBlank(message="Le slug est obligatoire.")
  34.      */
  35.     private ?string $slug null;
  36.     /**
  37.      * Activé (switch)
  38.      * @ORM\Column(type="boolean", options={"default": false})
  39.      */
  40.     private bool $isActivated false;
  41.     /**
  42.      * Visible en Front Office (switch)
  43.      * @ORM\Column(type="boolean", options={"default": false})
  44.      */
  45.     private bool $isPublic false;
  46.     /**
  47.      * Visible en Front Office (liste des domaines)
  48.      * @ORM\Column(type="boolean", options={"default": true})
  49.      */
  50.     private bool $isVisible true;
  51.     /**
  52.      * Couleur de fond (nouvelle API)
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private ?string $backgroundColor '#000000';
  56.     /**
  57.      * Couleur du titre (noir/blanc selon contraste)
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private ?string $titleColor '#FFFFFF';
  61.     /**
  62.      * Rôles associés (sélecteur lorsque le switch n'est pas sur "tous")
  63.      * @ORM\ManyToMany(targetEntity=Roles::class)
  64.      */
  65.     private Collection $roles;
  66.     /**
  67.      * Tous les rôles autorisés (switch)
  68.      * @ORM\Column(type="boolean", nullable=true)
  69.      */
  70.     private ?bool $hasAllRoles null;
  71.     /**
  72.      * Critère 1 – tous (switch)
  73.      * @ORM\Column(type="boolean", nullable=true)
  74.      */
  75.     private ?bool $hasAllCriteria1 null;
  76.     /**
  77.      * Critère 1 – éléments sélectionnés
  78.      * @ORM\ManyToMany(targetEntity=Criteria1Item::class)
  79.      */
  80.     private Collection $criteria1Items;
  81.     /**
  82.      * Critère 2 – tous (switch)
  83.      * @ORM\Column(type="boolean", nullable=true)
  84.      */
  85.     private ?bool $hasAllCriteria2 null;
  86.     /**
  87.      * Critère 2 – éléments sélectionnés
  88.      * @ORM\ManyToMany(targetEntity=Criteria2Item::class)
  89.      */
  90.     private Collection $criteria2Items;
  91.     /**
  92.      * Critère 3 – tous (switch)
  93.      * @ORM\Column(type="boolean", nullable=true)
  94.      */
  95.     private ?bool $hasAllCriteria3 null;
  96.     /**
  97.      * Critère 3 – éléments sélectionnés
  98.      * @ORM\ManyToMany(targetEntity=Criteria3Item::class)
  99.      */
  100.     private Collection $criteria3Items;
  101.     /**
  102.      * Critère 4 – tous (switch)
  103.      * @ORM\Column(type="boolean", nullable=true)
  104.      */
  105.     private ?bool $hasAllCriteria4 null;
  106.     /**
  107.      * Critère 4 – éléments sélectionnés
  108.      * @ORM\ManyToMany(targetEntity=Criteria4Item::class)
  109.      */
  110.     private Collection $criteria4Items;
  111.     /**
  112.      * Critère 5 – tous (switch)
  113.      * @ORM\Column(type="boolean", nullable=true)
  114.      */
  115.     private ?bool $hasAllCriteria5 null;
  116.     /**
  117.      * Critère 5 – éléments sélectionnés
  118.      * @ORM\ManyToMany(targetEntity=Criteria5Item::class)
  119.      */
  120.     private Collection $criteria5Items;
  121.     /**
  122.      * Organisations (Instances) – obligatoire si multi-organisation
  123.      * @ORM\ManyToMany(targetEntity=Instance::class)
  124.      */
  125.     private Collection $instances;
  126.     /**
  127.      * Sous-domaines rattachés
  128.      * @ORM\OneToMany(targetEntity=SubDomain::class, mappedBy="domain")
  129.      */
  130.     private Collection $subDomains;
  131.     /**
  132.      * Métadatas (dates)
  133.      * @ORM\Column(type="datetime")
  134.      */
  135.     private \DateTime $createdAt;
  136.     /**
  137.      * @ORM\Column(type="datetime")
  138.      */
  139.     private \DateTime $updatedAt;
  140.     public function __construct()
  141.     {
  142.         $this->roles = new ArrayCollection();
  143.         $this->criteria1Items = new ArrayCollection();
  144.         $this->criteria2Items = new ArrayCollection();
  145.         $this->criteria3Items = new ArrayCollection();
  146.         $this->criteria4Items = new ArrayCollection();
  147.         $this->criteria5Items = new ArrayCollection();
  148.         $this->instances = new ArrayCollection();
  149.         $this->subDomains = new ArrayCollection();
  150.         $this->createdAt = new \DateTime('now');
  151.         $this->updatedAt = new \DateTime('now');
  152.     }
  153.     public function __toString(): string
  154.     {
  155.         return $this->getTitle() ?? '';
  156.     }
  157.     /**
  158.      * @ORM\PrePersist
  159.      */
  160.     public function onPrePersist(): void
  161.     {
  162.         $this->updatedAt = new \DateTime('now');
  163.         if (!$this->slug && $this->title) {
  164.             $slugger = new AsciiSlugger();
  165.             $this->slug strtolower($slugger->slug($this->title)->toString());
  166.         }
  167.     }
  168.     /**
  169.      * @ORM\PreUpdate
  170.      */
  171.     public function onPreUpdate(): void
  172.     {
  173.         $this->updatedAt = new \DateTime('now');
  174.         if (!$this->slug && $this->title) {
  175.             $slugger = new AsciiSlugger();
  176.             $this->slug strtolower($slugger->slug($this->title)->toString());
  177.         }
  178.     }
  179.     public function getId(): ?int
  180.     {
  181.         return $this->id;
  182.     }
  183.     public function getTitle(): ?string
  184.     {
  185.         return $this->title;
  186.     }
  187.     public function setTitle(?string $title): self
  188.     {
  189.         $this->title $title;
  190.         return $this;
  191.     }
  192.     public function getSlug(): ?string
  193.     {
  194.         return $this->slug;
  195.     }
  196.     public function setSlug(?string $slug): self
  197.     {
  198.         $this->slug $slug;
  199.         return $this;
  200.     }
  201.     public function isActivated(): bool
  202.     {
  203.         return $this->isActivated;
  204.     }
  205.     public function setIsActivated(bool $isActivated): self
  206.     {
  207.         $this->isActivated $isActivated;
  208.         return $this;
  209.     }
  210.     public function isPublic(): bool
  211.     {
  212.         return $this->isPublic;
  213.     }
  214.     public function setIsPublic(bool $isPublic): self
  215.     {
  216.         $this->isPublic $isPublic;
  217.         return $this;
  218.     }
  219.     public function isVisible(): bool
  220.     {
  221.         return $this->isVisible;
  222.     }
  223.     public function setIsVisible(bool $isVisible): self
  224.     {
  225.         $this->isVisible $isVisible;
  226.         return $this;
  227.     }
  228.     public function getColor(): ?string
  229.     {
  230.         return $this->color;
  231.     }
  232.     public function getBackgroundColor(): ?string
  233.     {
  234.         return $this->backgroundColor;
  235.     }
  236.     public function setBackgroundColor(?string $backgroundColor): self
  237.     {
  238.         $this->backgroundColor $backgroundColor;
  239.         if ($backgroundColor && preg_match('/^#?[0-9a-fA-F]{6}$/'$backgroundColor)) {
  240.             $hex ltrim($backgroundColor'#');
  241.             $r hexdec(substr($hex02));
  242.             $g hexdec(substr($hex22));
  243.             $b hexdec(substr($hex42));
  244.             $luminance = (0.2126 $r 0.7152 $g 0.0722 $b) / 255;
  245.             $this->titleColor $luminance 0.6 '#000000' '#FFFFFF';
  246.         }
  247.         return $this;
  248.     }
  249.     public function getTitleColor(): ?string
  250.     {
  251.         return $this->titleColor;
  252.     }
  253.     public function setTitleColor(?string $titleColor): self
  254.     {
  255.         $this->titleColor $titleColor;
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return Collection<int, Roles>
  260.      */
  261.     public function getRoles(): Collection
  262.     {
  263.         return $this->roles;
  264.     }
  265.     public function addRole(Roles $role): self
  266.     {
  267.         if (!$this->roles->contains($role)) {
  268.             $this->roles[] = $role;
  269.         }
  270.         return $this;
  271.     }
  272.     public function removeRole(Roles $role): self
  273.     {
  274.         $this->roles->removeElement($role);
  275.         return $this;
  276.     }
  277.     public function getHasAllRoles(): ?bool
  278.     {
  279.         return $this->hasAllRoles;
  280.     }
  281.     public function setHasAllRoles(?bool $hasAllRoles): self
  282.     {
  283.         $this->hasAllRoles $hasAllRoles;
  284.         return $this;
  285.     }
  286.     public function isHasAllCriteria1(): ?bool
  287.     {
  288.         return $this->hasAllCriteria1;
  289.     }
  290.     public function setHasAllCriteria1(?bool $hasAllCriteria1): self
  291.     {
  292.         $this->hasAllCriteria1 $hasAllCriteria1;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection<int, Criteria1Item>
  297.      */
  298.     public function getCriteria1Items(): Collection
  299.     {
  300.         return $this->criteria1Items;
  301.     }
  302.     public function addCriteria1Item(Criteria1Item $item): self
  303.     {
  304.         if (!$this->criteria1Items->contains($item)) {
  305.             $this->criteria1Items[] = $item;
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeCriteria1Item(Criteria1Item $item): self
  310.     {
  311.         $this->criteria1Items->removeElement($item);
  312.         return $this;
  313.     }
  314.     public function isHasAllCriteria2(): ?bool
  315.     {
  316.         return $this->hasAllCriteria2;
  317.     }
  318.     public function setHasAllCriteria2(?bool $hasAllCriteria2): self
  319.     {
  320.         $this->hasAllCriteria2 $hasAllCriteria2;
  321.         return $this;
  322.     }
  323.     /**
  324.      * @return Collection<int, Criteria2Item>
  325.      */
  326.     public function getCriteria2Items(): Collection
  327.     {
  328.         return $this->criteria2Items;
  329.     }
  330.     public function addCriteria2Item(Criteria2Item $item): self
  331.     {
  332.         if (!$this->criteria2Items->contains($item)) {
  333.             $this->criteria2Items[] = $item;
  334.         }
  335.         return $this;
  336.     }
  337.     public function removeCriteria2Item(Criteria2Item $item): self
  338.     {
  339.         $this->criteria2Items->removeElement($item);
  340.         return $this;
  341.     }
  342.     public function isHasAllCriteria3(): ?bool
  343.     {
  344.         return $this->hasAllCriteria3;
  345.     }
  346.     public function setHasAllCriteria3(?bool $hasAllCriteria3): self
  347.     {
  348.         $this->hasAllCriteria3 $hasAllCriteria3;
  349.         return $this;
  350.     }
  351.     /**
  352.      * @return Collection<int, Criteria3Item>
  353.      */
  354.     public function getCriteria3Items(): Collection
  355.     {
  356.         return $this->criteria3Items;
  357.     }
  358.     public function addCriteria3Item(Criteria3Item $item): self
  359.     {
  360.         if (!$this->criteria3Items->contains($item)) {
  361.             $this->criteria3Items[] = $item;
  362.         }
  363.         return $this;
  364.     }
  365.     public function removeCriteria3Item(Criteria3Item $item): self
  366.     {
  367.         $this->criteria3Items->removeElement($item);
  368.         return $this;
  369.     }
  370.     public function isHasAllCriteria4(): ?bool
  371.     {
  372.         return $this->hasAllCriteria4;
  373.     }
  374.     public function setHasAllCriteria4(?bool $hasAllCriteria4): self
  375.     {
  376.         $this->hasAllCriteria4 $hasAllCriteria4;
  377.         return $this;
  378.     }
  379.     /**
  380.      * @return Collection<int, Criteria4Item>
  381.      */
  382.     public function getCriteria4Items(): Collection
  383.     {
  384.         return $this->criteria4Items;
  385.     }
  386.     public function addCriteria4Item(Criteria4Item $item): self
  387.     {
  388.         if (!$this->criteria4Items->contains($item)) {
  389.             $this->criteria4Items[] = $item;
  390.         }
  391.         return $this;
  392.     }
  393.     public function removeCriteria4Item(Criteria4Item $item): self
  394.     {
  395.         $this->criteria4Items->removeElement($item);
  396.         return $this;
  397.     }
  398.     public function isHasAllCriteria5(): ?bool
  399.     {
  400.         return $this->hasAllCriteria5;
  401.     }
  402.     public function setHasAllCriteria5(?bool $hasAllCriteria5): self
  403.     {
  404.         $this->hasAllCriteria5 $hasAllCriteria5;
  405.         return $this;
  406.     }
  407.     /**
  408.      * @return Collection<int, Criteria5Item>
  409.      */
  410.     public function getCriteria5Items(): Collection
  411.     {
  412.         return $this->criteria5Items;
  413.     }
  414.     public function addCriteria5Item(Criteria5Item $item): self
  415.     {
  416.         if (!$this->criteria5Items->contains($item)) {
  417.             $this->criteria5Items[] = $item;
  418.         }
  419.         return $this;
  420.     }
  421.     public function removeCriteria5Item(Criteria5Item $item): self
  422.     {
  423.         $this->criteria5Items->removeElement($item);
  424.         return $this;
  425.     }
  426.     /**
  427.      * @return Collection<int, Instance>
  428.      */
  429.     public function getInstances(): Collection
  430.     {
  431.         return $this->instances;
  432.     }
  433.     public function addInstance(Instance $instance): self
  434.     {
  435.         if (!$this->instances->contains($instance)) {
  436.             $this->instances[] = $instance;
  437.         }
  438.         return $this;
  439.     }
  440.     public function removeInstance(Instance $instance): self
  441.     {
  442.         $this->instances->removeElement($instance);
  443.         return $this;
  444.     }
  445.     /**
  446.      * @return Collection<int, SubDomain>
  447.      */
  448.     public function getSubDomains(): Collection
  449.     {
  450.         return $this->subDomains;
  451.     }
  452.     public function addSubDomain(SubDomain $subDomain): self
  453.     {
  454.         if (!$this->subDomains->contains($subDomain)) {
  455.             $this->subDomains[] = $subDomain;
  456.         }
  457.         return $this;
  458.     }
  459.     public function removeSubDomain(SubDomain $subDomain): self
  460.     {
  461.         $this->subDomains->removeElement($subDomain);
  462.         return $this;
  463.     }
  464.     public function getCreatedAt(): \DateTime
  465.     {
  466.         return $this->createdAt;
  467.     }
  468.     public function setCreatedAt(\DateTime $createdAt): self
  469.     {
  470.         $this->createdAt $createdAt;
  471.         return $this;
  472.     }
  473.     public function getUpdatedAt(): \DateTime
  474.     {
  475.         return $this->updatedAt;
  476.     }
  477.     public function setUpdatedAt(\DateTime $updatedAt): self
  478.     {
  479.         $this->updatedAt $updatedAt;
  480.         return $this;
  481.     }
  482. }