src/Entity/Product.php line 22

  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Uid\Ulid;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\ProductRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassProductRepository::class)]
  13. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  14. #[ORM\HasLifecycleCallbacks()]
  15. // #[ApiResource(
  16. //     attributes: ["security" => "is_granted('ROLE_SUPER_ADMIN')"],
  17. // )]
  18. class Product
  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.     private ?Ulid $id null;
  26.     #[ORM\Column(type'string'length255)]
  27.     private $name;
  28.     #[ORM\Column(type'string'length255nullabletrue)]
  29.     private $description;
  30.     #[ORM\Column(type'string'length255)]
  31.     private $slug;
  32.     #[ORM\Column(type'integer'nullabletrue)]
  33.     private $price;
  34.     #[ORM\Column(type'integer'nullabletrue)]
  35.     private $duration;
  36.     #[ORM\OneToMany(mappedBy'product'targetEntityOrder::class, orphanRemovaltrue)]
  37.     private $orders;
  38.     #[ORM\OneToMany(mappedBy'product'targetEntityAbonnement::class, orphanRemovaltrue)]
  39.     private $abonnements;
  40.     #[ORM\Column(nullabletrue)]
  41.     private ?array $details = [];
  42.     public function __construct()
  43.     {
  44.         $this->orders = new ArrayCollection();
  45.         $this->abonnements = new ArrayCollection();
  46.     }
  47.     public function __toString()
  48.     {
  49.         return $this->name "  (" $this->duration " jours)";
  50.     }
  51.     public function getId(): ?Ulid
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getName(): ?string
  56.     {
  57.         return $this->name;
  58.     }
  59.     public function setName(string $name): self
  60.     {
  61.         $this->name $name;
  62.         return $this;
  63.     }
  64.     public function getDescription(): ?string
  65.     {
  66.         return $this->description;
  67.     }
  68.     public function setDescription(?string $description): self
  69.     {
  70.         $this->description $description;
  71.         return $this;
  72.     }
  73.     public function getSlug(): ?string
  74.     {
  75.         return $this->slug;
  76.     }
  77.     public function setSlug(string $slug): self
  78.     {
  79.         $this->slug $slug;
  80.         return $this;
  81.     }
  82.     public function getPrice(): ?int
  83.     {
  84.         return $this->price;
  85.     }
  86.     public function setPrice(?int $price): self
  87.     {
  88.         $this->price $price;
  89.         return $this;
  90.     }
  91.     public function getDuration(): ?int
  92.     {
  93.         return $this->duration;
  94.     }
  95.     public function setDuration(?int $duration): self
  96.     {
  97.         $this->duration $duration;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection<int, Order>
  102.      */
  103.     public function getOrders(): Collection
  104.     {
  105.         return $this->orders;
  106.     }
  107.     public function addOrder(Order $order): self
  108.     {
  109.         if (!$this->orders->contains($order)) {
  110.             $this->orders[] = $order;
  111.             $order->setProduct($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeOrder(Order $order): self
  116.     {
  117.         if ($this->orders->removeElement($order)) {
  118.             // set the owning side to null (unless already changed)
  119.             if ($order->getProduct() === $this) {
  120.                 $order->setProduct(null);
  121.             }
  122.         }
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return Collection<int, Abonnement>
  127.      */
  128.     public function getAbonnements(): Collection
  129.     {
  130.         return $this->abonnements;
  131.     }
  132.     public function addAbonnement(Abonnement $abonnement): self
  133.     {
  134.         if (!$this->abonnements->contains($abonnement)) {
  135.             $this->abonnements[] = $abonnement;
  136.             $abonnement->setProduct($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeAbonnement(Abonnement $abonnement): self
  141.     {
  142.         if ($this->abonnements->removeElement($abonnement)) {
  143.             // set the owning side to null (unless already changed)
  144.             if ($abonnement->getProduct() === $this) {
  145.                 $abonnement->setProduct(null);
  146.             }
  147.         }
  148.         return $this;
  149.     }
  150.     public function getDetails(): ?array
  151.     {
  152.         return $this->details;
  153.     }
  154.     public function setDetails(?array $details): static
  155.     {
  156.         $this->details $details;
  157.         return $this;
  158.     }
  159. }