src/Entity/SubDomain.php line 17

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