src/Entity/Plan.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PlanRepository;
  4. use App\Traits\DateTimeTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Overblog\GraphQLBundle\Annotation\Field;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassPlanRepository::class)]
  12. #[ORM\HasLifecycleCallbacks]
  13. #[UniqueEntity(
  14.     fields"name",
  15.     message"This name is already used."
  16. )]
  17. class Plan extends BasicEntity
  18. {
  19.     use DateTimeTrait;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type"integer")]
  23.     #[Field(name"id"type"int")]
  24.     private $id;
  25.     #[ORM\Column(type"integer")]
  26.     #[Assert\NotBlank]
  27.     #[Field(name"nbr_domains"type"int")]
  28.     private $nbrDomains;
  29.     #[ORM\Column(type"string"length255)]
  30.     #[Assert\NotBlank]
  31.     #[Field(name"name"type"string")]
  32.     private $name;
  33.     #[ORM\OneToMany(targetEntitySubscription::class, mappedBy"plan")]
  34.     private $subscriptions;
  35.     #[ORM\ManyToMany(targetEntityService::class)]
  36.     #[Field(name"services")]
  37.     private $services;
  38.     #[ORM\Column(type"float")]
  39.     #[Assert\NotBlank]
  40.     #[Field(name"price"type"float")]
  41.     private $price;
  42.     #[ORM\Column(type"string"length30nullabletrue)]
  43.     #[Assert\NotBlank]
  44.     #[Field(name"color"type"string")]
  45.     private $color;
  46.     #[ORM\Column(options: ['default' => false])]
  47.     #[Field(name"is_deleted"type"boolean")]
  48.     private ?bool $isDeleted null;
  49.     public function __construct()
  50.     {
  51.         $this->subscriptions = new ArrayCollection();
  52.         $this->services = new ArrayCollection();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getNbrDomains(): ?int
  59.     {
  60.         return $this->nbrDomains;
  61.     }
  62.     public function setNbrDomains(int $nbrDomains): self
  63.     {
  64.         $this->nbrDomains $nbrDomains;
  65.         return $this;
  66.     }
  67.     public function getName(): ?string
  68.     {
  69.         return $this->name;
  70.     }
  71.     public function setName(string $name): self
  72.     {
  73.         $this->name $name;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection|Subscription[]
  78.      */
  79.     public function getSubscriptions(): Collection
  80.     {
  81.         return $this->subscriptions;
  82.     }
  83.     public function addSubscription(Subscription $subscription): self
  84.     {
  85.         if (!$this->subscriptions->contains($subscription)) {
  86.             $this->subscriptions[] = $subscription;
  87.             $subscription->setPlan($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeSubscription(Subscription $subscription): self
  92.     {
  93.         if ($this->subscriptions->removeElement($subscription)) {
  94.             // set the owning side to null (unless already changed)
  95.             if ($subscription->getPlan() === $this) {
  96.                 $subscription->setPlan(null);
  97.             }
  98.         }
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection|Service[]
  103.      */
  104.     public function getServices(): ?Collection
  105.     {
  106.         return $this->services;
  107.     }
  108.     public function addService(Service $service): self
  109.     {
  110.         if (!$this->services->contains($service)) {
  111.             $this->services[] = $service;
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeService(Service $service): self
  116.     {
  117.         $this->services->removeElement($service);
  118.         return $this;
  119.     }
  120.     public function getPrice(): ?float
  121.     {
  122.         return $this->price;
  123.     }
  124.     public function setPrice(float $price): self
  125.     {
  126.         $this->price $price;
  127.         return $this;
  128.     }
  129.     public function __toString()
  130.     {
  131.         return $this->getName();
  132.     }
  133.     public function getColor(): ?string
  134.     {
  135.         return $this->color;
  136.     }
  137.     public function setColor(?string $color): self
  138.     {
  139.         $this->color $color;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @param array $services
  144.      * @return $this
  145.      */
  146.     public function setServices(array $services): self
  147.     {
  148.         $this->services = new ArrayCollection();
  149.         foreach ($services as $service) {
  150.             $this->addService($service);
  151.         }
  152.         return $this;
  153.     }
  154.     public function isIsDeleted(): ?bool
  155.     {
  156.         return $this->isDeleted;
  157.     }
  158.     public function setIsDeleted(bool $isDeleted): static
  159.     {
  160.         $this->isDeleted $isDeleted;
  161.         return $this;
  162.     }
  163. }