src/Entity/Instance.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\InstanceRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\SiteConfig;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * Represents an Instance entity.
  11.  *
  12.  * @ORM\Entity(repositoryClass=InstanceRepository::class)
  13.  * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"name"})})
  14.  * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(columns={"code"})})
  15.  */
  16. class Instance
  17. {
  18.     /**
  19.      * @var int|null The unique identifier of the instance.
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private ?int $id null;
  25.     /**
  26.      * @var string The name of the instance.
  27.      * @ORM\Column(type="string", length=255, unique=true)
  28.      */
  29.     private string $name;
  30.     /**
  31.      * @var bool Whether the instance is activated or not.
  32.      * @ORM\Column(type="boolean")
  33.      */
  34.     private bool $isActivated true;
  35.     /**
  36.      * @var Collection<int, Criteria1Item> Collection of Criteria1Items associated with this instance.
  37.      * @ORM\ManyToMany(targetEntity=Criteria1Item::class, inversedBy="instances")
  38.      */
  39.     private Collection $criteria1Items;
  40.     /**
  41.      * @var Collection<int, Criteria2Item> Collection of Criteria2Items associated with this instance.
  42.      * @ORM\ManyToMany(targetEntity=Criteria2Item::class, inversedBy="instances")
  43.      */
  44.     private Collection $criteria2Items;
  45.     /**
  46.      * @var Collection<int, Criteria3Item> Collection of Criteria3Items associated with this instance.
  47.      * @ORM\ManyToMany(targetEntity=Criteria3Item::class, inversedBy="instances")
  48.      */
  49.     private Collection $criteria3Items;
  50.     /**
  51.      * @var Collection<int, Criteria4Item> Collection of Criteria3Items associated with this instance.
  52.      * @ORM\ManyToMany(targetEntity=Criteria4Item::class, inversedBy="instances")
  53.      */
  54.     private Collection $criteria4Items;
  55.     /**
  56.      * @var Collection<int, Criteria5Item> Collection of Criteria3Items associated with this instance.
  57.      * @ORM\ManyToMany(targetEntity=Criteria5Item::class, inversedBy="instances")
  58.      */
  59.     private Collection $criteria5Items;
  60.     /**
  61.      * @var Collection<int, User> Collection of Users associated with this instance.
  62.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="instances")
  63.      */
  64.     private Collection $users;
  65.     /**
  66.      * @var Collection<int, BlogPostCategory> Collection of BlogPostCategories associated with this instance.
  67.      * @ORM\ManyToMany(targetEntity=BlogPostCategory::class, mappedBy="instances")
  68.      */
  69.     private Collection $blogPostCategories;
  70.     /**
  71.      * @var Collection<int, BlogPost> Collection of BlogPosts associated with this instance.
  72.      * @ORM\ManyToMany(targetEntity=BlogPost::class, mappedBy="instances")
  73.      */
  74.     private Collection $blogPosts;
  75.     /**
  76.      * @var Collection<int, Radio> Collection of Radios associated with this instance.
  77.      * @ORM\ManyToMany(targetEntity=Radio::class, mappedBy="instances")
  78.      */
  79.     private Collection $radios;
  80.      /**
  81.      * @var Collection<int, SiteConfig> Collection of SiteConfigs associated with this instance.
  82.      * @ORM\OneToMany(targetEntity=SiteConfig::class, mappedBy="instance")
  83.      */
  84.     private Collection $siteConfigs;
  85.     /**
  86.      * @var Collection<int, SiteCustomization> Collection of SiteCustomizations associated with this instance.
  87.      * @ORM\OneToMany(targetEntity=SiteCustomization::class, mappedBy="instance")
  88.      */
  89.      /**
  90.      * @ORM\Column(type="string", length=255, unique=true)
  91.      * @Assert\NotBlank(message="Le code de l'instance est obligatoire")
  92.      */
  93.     private $code;
  94.     private Collection $siteCustomizations;
  95.     public function __construct()
  96.     {
  97.         $this->criteria1Items = new ArrayCollection();
  98.         $this->criteria2Items = new ArrayCollection();
  99.         $this->criteria3Items = new ArrayCollection();
  100.         $this->criteria4Items = new ArrayCollection();
  101.         $this->criteria5Items = new ArrayCollection();
  102.         $this->users = new ArrayCollection();
  103.         $this->blogPostCategories = new ArrayCollection();
  104.         $this->blogPosts = new ArrayCollection();
  105.         $this->radios = new ArrayCollection();
  106.         $this->siteConfigs = new ArrayCollection();
  107.         $this->siteCustomizations = new ArrayCollection();
  108.     }
  109.     /**
  110.      * Get the instance ID.
  111.      *
  112.      * @return int|null
  113.      */
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     /**
  119.      * Get the instance name.
  120.      *
  121.      * @return string
  122.      */
  123.     public function getName(): string
  124.     {
  125.         return $this->name;
  126.     }
  127.     /**
  128.      * Set the instance name.
  129.      *
  130.      * @param string $name
  131.      * @return self
  132.      */
  133.     public function setName(string $name): self
  134.     {
  135.         $this->name $name;
  136.         return $this;
  137.     }
  138.     /**
  139.      * Check if the instance is activated.
  140.      *
  141.      * @return bool
  142.      */
  143.     public function isActivated(): bool
  144.     {
  145.         return $this->isActivated;
  146.     }
  147.     /**
  148.      * Set the instance activation status.
  149.      *
  150.      * @param bool $isActivated
  151.      * @return self
  152.      */
  153.     public function setIsActivated(bool $isActivated): self
  154.     {
  155.         $this->isActivated $isActivated;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection<int, Criteria1Item>
  160.      */
  161.     public function getCriteria1Items(): Collection
  162.     {
  163.         return $this->criteria1Items;
  164.     }
  165.     public function addCriteria1Item(Criteria1Item $criteria1Item): self
  166.     {
  167.         if (!$this->criteria1Items->contains($criteria1Item)) {
  168.             $this->criteria1Items[] = $criteria1Item;
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeCriteria1Item(Criteria1Item $criteria1Item): self
  173.     {
  174.         $this->criteria1Items->removeElement($criteria1Item);
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return Collection<int, Criteria2Item>
  179.      */
  180.     public function getCriteria2Items(): Collection
  181.     {
  182.         return $this->criteria2Items;
  183.     }
  184.     public function addCriteria2Item(Criteria2Item $criteria2Item): self
  185.     {
  186.         if (!$this->criteria2Items->contains($criteria2Item)) {
  187.             $this->criteria2Items[] = $criteria2Item;
  188.         }
  189.         return $this;
  190.     }
  191.     public function removeCriteria2Item(Criteria2Item $criteria2Item): self
  192.     {
  193.         $this->criteria2Items->removeElement($criteria2Item);
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return Collection<int, Criteria3Item>
  198.      */
  199.     public function getCriteria3Items(): Collection
  200.     {
  201.         return $this->criteria3Items;
  202.     }
  203.     public function addCriteria3Item(Criteria3Item $criteria3Item): self
  204.     {
  205.         if (!$this->criteria3Items->contains($criteria3Item)) {
  206.             $this->criteria3Items[] = $criteria3Item;
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeCriteria3Item(Criteria3Item $criteria3Item): self
  211.     {
  212.         $this->criteria3Items->removeElement($criteria3Item);
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return Collection<int, Criteria4Item>
  217.      */
  218.     public function getCriteria4Items(): Collection
  219.     {
  220.         return $this->criteria4Items;
  221.     }
  222.     public function addCriteria4Item(Criteria4Item $criteria4Item): self
  223.     {
  224.         if (!$this->criteria4Items->contains($criteria4Item)) {
  225.             $this->criteria4Items[] = $criteria4Item;
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeCriteria4Item(Criteria4Item $criteria4Item): self
  230.     {
  231.         $this->criteria4Items->removeElement($criteria4Item);
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return Collection<int, Criteria5Item>
  236.      */
  237.     public function getCriteria5Items(): Collection
  238.     {
  239.         return $this->criteria5Items;
  240.     }
  241.     public function addCriteria5Item(Criteria5Item $criteria5Item): self
  242.     {
  243.         if (!$this->criteria5Items->contains($criteria5Item)) {
  244.             $this->criteria5Items[] = $criteria5Item;
  245.         }
  246.         return $this;
  247.     }
  248.     public function removeCriteria5Item(Criteria5Item $criteria5Item): self
  249.     {
  250.         $this->criteria5Items->removeElement($criteria5Item);
  251.         return $this;
  252.     }
  253.     /**
  254.      * Get the string representation of the instance.
  255.      *
  256.      * @return string
  257.      */
  258.     public function __toString(): string
  259.     {
  260.         return $this->name;
  261.     }
  262.     /**
  263.      * Get the collection of Users.
  264.      *
  265.      * @return Collection<int, User>
  266.      */
  267.     public function getUsers(): Collection
  268.     {
  269.         return $this->users;
  270.     }
  271.     /**
  272.      * Add a User to the instance.
  273.      *
  274.      * @param User $user
  275.      * @return self
  276.      */
  277.     public function addUser(User $user): self
  278.     {
  279.         if (!$this->users->contains($user)) {
  280.             $this->users[] = $user;
  281.             $user->addInstance($this);
  282.         }
  283.         return $this;
  284.     }
  285.     /**
  286.      * Remove a User from the instance.
  287.      *
  288.      * @param User $user
  289.      * @return self
  290.      */
  291.     public function removeUser(User $user): self
  292.     {
  293.         if ($this->users->removeElement($user)) {
  294.             $user->removeInstance($this);
  295.         }
  296.         return $this;
  297.     }
  298.     /**
  299.      * @return Collection<int, BlogPostCategory>
  300.      */
  301.     public function getBlogPostCategories(): Collection
  302.     {
  303.         return $this->blogPostCategories;
  304.     }
  305.     public function addBlogPostCategory(BlogPostCategory $blogPostCategory): self
  306.     {
  307.         if (!$this->blogPostCategories->contains($blogPostCategory)) {
  308.             $this->blogPostCategories[] = $blogPostCategory;
  309.             $blogPostCategory->addInstance($this);
  310.         }
  311.         return $this;
  312.     }
  313.     public function removeBlogPostCategory(BlogPostCategory $blogPostCategory): self
  314.     {
  315.         if ($this->blogPostCategories->removeElement($blogPostCategory)) {
  316.             $blogPostCategory->removeInstance($this);
  317.         }
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return Collection<int, BlogPost>
  322.      */
  323.     public function getBlogPosts(): Collection
  324.     {
  325.         return $this->blogPosts;
  326.     }
  327.     public function addBlogPost(BlogPost $blogPost): self
  328.     {
  329.         if (!$this->blogPosts->contains($blogPost)) {
  330.             $this->blogPosts[] = $blogPost;
  331.             $blogPost->addInstance($this);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeBlogPost(BlogPost $blogPost): self
  336.     {
  337.         if ($this->blogPosts->removeElement($blogPost)) {
  338.             $blogPost->removeInstance($this);
  339.         }
  340.         return $this;
  341.     }
  342.     /**
  343.      * @return Collection<int, Radio>
  344.      */
  345.     public function getRadios(): Collection
  346.     {
  347.         return $this->radios;
  348.     }
  349.     public function addRadio(Radio $radio): self
  350.     {
  351.         if (!$this->radios->contains($radio)) {
  352.             $this->radios[] = $radio;
  353.             $radio->addInstance($this);
  354.         }
  355.         return $this;
  356.     }
  357.     public function removeRadio(Radio $radio): self
  358.     {
  359.         if ($this->radios->removeElement($radio)) {
  360.             $radio->removeInstance($this);
  361.         }
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection<int, SiteConfig>
  366.      */
  367.     public function getSiteConfigs(): Collection
  368.     {
  369.         return $this->siteConfigs;
  370.     }
  371.     public function addSiteConfig(SiteConfig $siteConfig): self
  372.     {
  373.         if (!$this->siteConfigs->contains($siteConfig)) {
  374.             $this->siteConfigs[] = $siteConfig;
  375.             $siteConfig->setInstance($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeSiteConfig(SiteConfig $siteConfig): self
  380.     {
  381.         if ($this->siteConfigs->removeElement($siteConfig)) {
  382.             // set the owning side to null (unless already changed)
  383.             if ($siteConfig->getInstance() === $this) {
  384.                 $siteConfig->setInstance(null);
  385.             }
  386.         }
  387.         return $this;
  388.     }
  389.     public function getSiteConfig(): ?SiteConfig
  390.     {
  391.         return $this->siteConfigs->first() ?: null;
  392.     }
  393.     /**
  394.      * @return Collection<int, SiteCustomization>
  395.      */
  396.     public function getSiteCustomizations(): Collection
  397.     {
  398.         return $this->siteCustomizations;
  399.     }
  400.     public function addSiteCustomization(SiteCustomization $siteCustomization): self
  401.     {
  402.         if (!$this->siteCustomizations->contains($siteCustomization)) {
  403.             $this->siteCustomizations[] = $siteCustomization;
  404.             $siteCustomization->setInstance($this);
  405.         }
  406.         return $this;
  407.     }
  408.     public function removeSiteCustomization(SiteCustomization $siteCustomization): self
  409.     {
  410.         if ($this->siteCustomizations->removeElement($siteCustomization)) {
  411.             // set the owning side to null (unless already changed)
  412.             if ($siteCustomization->getInstance() === $this) {
  413.                 $siteCustomization->setInstance(null);
  414.             }
  415.         }
  416.         return $this;
  417.     }
  418.     public function getSiteCustomization(): ?SiteCustomization
  419.     {
  420.         return $this->siteCustomizations->first() ?: null;
  421.     }
  422.     /**
  423.      * Get the instance code.
  424.      *
  425.      * @return string|null
  426.      */
  427.     public function getCode(): ?string
  428.     {
  429.         return $this->code;
  430.     }
  431.     /**
  432.      * Set the instance code.
  433.      *
  434.      * @param string $code
  435.      * @return self
  436.      */
  437.     public function setCode(string $code): self
  438.     {
  439.         $this->code $code;
  440.         return $this;
  441.     }
  442. }