src/Entity/Service.php line 21

  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Uid\Ulid;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\ServiceRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassServiceRepository::class)]
  13. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  14. #[ORM\HasLifecycleCallbacks()]
  15. #[ApiResource(
  16.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  17. )]
  18. class Service
  19. {
  20.     use Timestamps;
  21.     #[ORM\Id]
  22.     #[ORM\Column(type'ulid'uniquetrue)]
  23.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  24.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  25.     #[Groups(['read:service:basic'])]
  26.     private ?Ulid $id null;
  27.     #[ORM\Column(type'string'length255)]
  28.     #[Groups(['read:service:basic'])]
  29.     private $name;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     #[Groups(['read:service:basic'])]
  32.     private $description;
  33.     #[ORM\Column(type'float')]
  34.     #[Groups(['read:service:basic'])]
  35.     private $price 0;
  36.     #[ORM\Column(type'integer')]
  37.     #[Groups(['read:service:basic'])]
  38.     private $duration 1;
  39.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'services')]
  40.     #[ORM\JoinColumn(nullablefalse)]
  41.     private $owner;
  42.     #[ORM\OneToMany(mappedBy'service'targetEntitySubscription::class, orphanRemovaltrue)]
  43.     private $subscriptions;
  44.     public function __construct()
  45.     {
  46.         $this->subscriptions = new ArrayCollection();
  47.     }
  48.     public function __toString()
  49.     {
  50.         return $this->name ' (' $this->price ' ' $this->owner->getCurrencie() . ')';
  51.     }
  52.     public function getId(): ?Ulid
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getName(): ?string
  57.     {
  58.         return $this->name;
  59.     }
  60.     public function setName(string $name): self
  61.     {
  62.         $this->name $name;
  63.         return $this;
  64.     }
  65.     public function getDescription(): ?string
  66.     {
  67.         return $this->description;
  68.     }
  69.     public function setDescription(?string $description): self
  70.     {
  71.         $this->description $description;
  72.         return $this;
  73.     }
  74.     public function getPrice(): ?float
  75.     {
  76.         return $this->price;
  77.     }
  78.     public function setPrice(float $price): self
  79.     {
  80.         $this->price $price;
  81.         return $this;
  82.     }
  83.     public function getDuration(): ?int
  84.     {
  85.         return $this->duration;
  86.     }
  87.     public function setDuration(int $duration): self
  88.     {
  89.         $this->duration $duration;
  90.         return $this;
  91.     }
  92.     public function getOwner(): ?Company
  93.     {
  94.         return $this->owner;
  95.     }
  96.     public function setOwner(?Company $owner): self
  97.     {
  98.         $this->owner $owner;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection<int, Subscription>
  103.      */
  104.     public function getSubscriptions(): Collection
  105.     {
  106.         return $this->subscriptions;
  107.     }
  108.     public function addSubscription(Subscription $subscription): self
  109.     {
  110.         if (!$this->subscriptions->contains($subscription)) {
  111.             $this->subscriptions[] = $subscription;
  112.             $subscription->setService($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeSubscription(Subscription $subscription): self
  117.     {
  118.         if ($this->subscriptions->removeElement($subscription)) {
  119.             // set the owning side to null (unless already changed)
  120.             if ($subscription->getService() === $this) {
  121.                 $subscription->setService(null);
  122.             }
  123.         }
  124.         return $this;
  125.     }
  126. }