<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\String\Slugger\AsciiSlugger;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields={"slug"}, message="Slug deja utilisé")
*/
class SubDomain
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=150, nullable=false)
* @Assert\NotBlank(message="Le titre est obligatoire.")
*/
private ?string $title = null;
/**
* @ORM\Column(type="string", length=255, unique=true, nullable=false)
* @Assert\NotBlank(message="Le slug est obligatoire.")
*/
private ?string $slug = null;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $isActivated = false;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $isPublic = false;
/**
* @ORM\ManyToOne(targetEntity=Domain::class)
* @ORM\JoinColumn(nullable=false)
* @Assert\NotNull(message="Le domaine est obligatoire.")
*/
private ?Domain $domain = null;
/**
* @ORM\ManyToMany(targetEntity=Instance::class)
* @Assert\NotNull(message="L’organisation est obligatoire.")
*/
private Collection $instances;
/**
* @ORM\ManyToMany(targetEntity=Roles::class)
*/
private Collection $roles;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $hasAllRoles = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $hasAllCriteria1 = null;
/**
* @ORM\ManyToMany(targetEntity=Criteria1Item::class)
*/
private Collection $criteria1Items;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $hasAllCriteria2 = null;
/**
* @ORM\ManyToMany(targetEntity=Criteria2Item::class)
*/
private Collection $criteria2Items;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $hasAllCriteria3 = null;
/**
* @ORM\ManyToMany(targetEntity=Criteria3Item::class)
*/
private Collection $criteria3Items;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $hasAllCriteria4 = null;
/**
* @ORM\ManyToMany(targetEntity=Criteria4Item::class)
*/
private Collection $criteria4Items;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $hasAllCriteria5 = null;
/**
* @ORM\ManyToMany(targetEntity=Criteria5Item::class)
*/
private Collection $criteria5Items;
/**
* @ORM\OneToOne(targetEntity=Media::class, cascade={"persist"})
*/
private ?Media $imagePreviewMedia = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $selectedMediaId = null;
/**
* Métadatas (dates)
* @ORM\Column(type="datetime")
*/
private \DateTime $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private \DateTime $updatedAt;
public function __construct()
{
$this->instances = new ArrayCollection();
$this->roles = new ArrayCollection();
$this->criteria1Items = new ArrayCollection();
$this->criteria2Items = new ArrayCollection();
$this->criteria3Items = new ArrayCollection();
$this->criteria4Items = new ArrayCollection();
$this->criteria5Items = new ArrayCollection();
$this->createdAt = new \DateTime('now');
$this->updatedAt = new \DateTime('now');
}
public function __toString(): string
{
return $this->getTitle() ?? '';
}
/**
* @ORM\PrePersist
*/
public function onPrePersist(): void
{
$this->updatedAt = new \DateTime('now');
if (!$this->slug && $this->title) {
$slugger = new AsciiSlugger();
$this->slug = strtolower($slugger->slug($this->title)->toString());
}
}
/**
* @ORM\PreUpdate
*/
public function onPreUpdate(): void
{
$this->updatedAt = new \DateTime('now');
if (!$this->slug && $this->title) {
$slugger = new AsciiSlugger();
$this->slug = strtolower($slugger->slug($this->title)->toString());
}
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function isActivated(): bool
{
return $this->isActivated;
}
public function setIsActivated(bool $isActivated): self
{
$this->isActivated = $isActivated;
return $this;
}
public function isPublic(): bool
{
return $this->isPublic;
}
public function setIsPublic(bool $isPublic): self
{
$this->isPublic = $isPublic;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
public function setDomain(?Domain $domain): self
{
$this->domain = $domain;
return $this;
}
private function inheritFromDomain(Domain $domain): void
{
$this->setHasAllRoles($domain->getHasAllRoles());
if ($this->instances->isEmpty()) {
$this->instances = new ArrayCollection();
foreach ($domain->getInstances() as $inst) {
$this->instances->add($inst);
}
}
$this->roles = new ArrayCollection();
foreach ($domain->getRoles() as $role) {
$this->roles->add($role);
}
$this->setHasAllCriteria1($domain->isHasAllCriteria1());
$this->criteria1Items = new ArrayCollection();
foreach ($domain->getCriteria1Items() as $it) {
$this->criteria1Items->add($it);
}
$this->setHasAllCriteria2($domain->isHasAllCriteria2());
$this->criteria2Items = new ArrayCollection();
foreach ($domain->getCriteria2Items() as $it) {
$this->criteria2Items->add($it);
}
$this->setHasAllCriteria3($domain->isHasAllCriteria3());
$this->criteria3Items = new ArrayCollection();
foreach ($domain->getCriteria3Items() as $it) {
$this->criteria3Items->add($it);
}
$this->setHasAllCriteria4($domain->isHasAllCriteria4());
$this->criteria4Items = new ArrayCollection();
foreach ($domain->getCriteria4Items() as $it) {
$this->criteria4Items->add($it);
}
$this->setHasAllCriteria5($domain->isHasAllCriteria5());
$this->criteria5Items = new ArrayCollection();
foreach ($domain->getCriteria5Items() as $it) {
$this->criteria5Items->add($it);
}
}
/**
* @return Collection<int, Instance>
*/
public function getInstances(): Collection
{
return $this->instances;
}
public function addInstance(Instance $instance): self
{
if (!$this->instances->contains($instance)) {
$this->instances[] = $instance;
}
return $this;
}
public function removeInstance(Instance $instance): self
{
$this->instances->removeElement($instance);
return $this;
}
/**
* @return Collection<int, Roles>
*/
public function getRoles(): Collection
{
return $this->roles;
}
public function addRole(Roles $role): self
{
if (!$this->roles->contains($role)) {
$this->roles[] = $role;
}
return $this;
}
public function removeRole(Roles $role): self
{
$this->roles->removeElement($role);
return $this;
}
public function getHasAllRoles(): ?bool
{
return $this->hasAllRoles;
}
public function setHasAllRoles(?bool $hasAllRoles): self
{
$this->hasAllRoles = $hasAllRoles;
return $this;
}
public function isHasAllCriteria1(): ?bool
{
return $this->hasAllCriteria1;
}
public function setHasAllCriteria1(?bool $hasAllCriteria1): self
{
$this->hasAllCriteria1 = $hasAllCriteria1;
return $this;
}
/**
* @return Collection<int, Criteria1Item>
*/
public function getCriteria1Items(): Collection
{
return $this->criteria1Items;
}
public function addCriteria1Item(Criteria1Item $item): self
{
if (!$this->criteria1Items->contains($item)) {
$this->criteria1Items[] = $item;
}
return $this;
}
public function removeCriteria1Item(Criteria1Item $item): self
{
$this->criteria1Items->removeElement($item);
return $this;
}
public function isHasAllCriteria2(): ?bool
{
return $this->hasAllCriteria2;
}
public function setHasAllCriteria2(?bool $hasAllCriteria2): self
{
$this->hasAllCriteria2 = $hasAllCriteria2;
return $this;
}
/**
* @return Collection<int, Criteria2Item>
*/
public function getCriteria2Items(): Collection
{
return $this->criteria2Items;
}
public function addCriteria2Item(Criteria2Item $item): self
{
if (!$this->criteria2Items->contains($item)) {
$this->criteria2Items[] = $item;
}
return $this;
}
public function removeCriteria2Item(Criteria2Item $item): self
{
$this->criteria2Items->removeElement($item);
return $this;
}
public function isHasAllCriteria3(): ?bool
{
return $this->hasAllCriteria3;
}
public function setHasAllCriteria3(?bool $hasAllCriteria3): self
{
$this->hasAllCriteria3 = $hasAllCriteria3;
return $this;
}
/**
* @return Collection<int, Criteria3Item>
*/
public function getCriteria3Items(): Collection
{
return $this->criteria3Items;
}
public function addCriteria3Item(Criteria3Item $item): self
{
if (!$this->criteria3Items->contains($item)) {
$this->criteria3Items[] = $item;
}
return $this;
}
public function removeCriteria3Item(Criteria3Item $item): self
{
$this->criteria3Items->removeElement($item);
return $this;
}
public function isHasAllCriteria4(): ?bool
{
return $this->hasAllCriteria4;
}
public function setHasAllCriteria4(?bool $hasAllCriteria4): self
{
$this->hasAllCriteria4 = $hasAllCriteria4;
return $this;
}
/**
* @return Collection<int, Criteria4Item>
*/
public function getCriteria4Items(): Collection
{
return $this->criteria4Items;
}
public function addCriteria4Item(Criteria4Item $item): self
{
if (!$this->criteria4Items->contains($item)) {
$this->criteria4Items[] = $item;
}
return $this;
}
public function removeCriteria4Item(Criteria4Item $item): self
{
$this->criteria4Items->removeElement($item);
return $this;
}
public function isHasAllCriteria5(): ?bool
{
return $this->hasAllCriteria5;
}
public function setHasAllCriteria5(?bool $hasAllCriteria5): self
{
$this->hasAllCriteria5 = $hasAllCriteria5;
return $this;
}
/**
* @return Collection<int, Criteria5Item>
*/
public function getCriteria5Items(): Collection
{
return $this->criteria5Items;
}
public function addCriteria5Item(Criteria5Item $item): self
{
if (!$this->criteria5Items->contains($item)) {
$this->criteria5Items[] = $item;
}
return $this;
}
public function removeCriteria5Item(Criteria5Item $item): self
{
$this->criteria5Items->removeElement($item);
return $this;
}
public function getImagePreviewMedia(): ?Media
{
return $this->imagePreviewMedia;
}
public function setImagePreviewMedia(?Media $imagePreviewMedia): self
{
$this->imagePreviewMedia = $imagePreviewMedia;
return $this;
}
public function getSelectedMediaId(): ?int
{
return $this->selectedMediaId;
}
public function setSelectedMediaId(?int $selectedMediaId): self
{
$this->selectedMediaId = $selectedMediaId;
return $this;
}
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getRubriquesCount(): int
{
return 0;
}
public function getContenusCount(): int
{
return 0;
}
}