src/Entity/Product.php line 22
<?php
namespace App\Entity;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks()]
// #[ApiResource(
// attributes: ["security" => "is_granted('ROLE_SUPER_ADMIN')"],
// )]
class Product
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $description;
#[ORM\Column(type: 'string', length: 255)]
private $slug;
#[ORM\Column(type: 'integer', nullable: true)]
private $price;
#[ORM\Column(type: 'integer', nullable: true)]
private $duration;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: Order::class, orphanRemoval: true)]
private $orders;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: Abonnement::class, orphanRemoval: true)]
private $abonnements;
#[ORM\Column(nullable: true)]
private ?array $details = [];
public function __construct()
{
$this->orders = new ArrayCollection();
$this->abonnements = new ArrayCollection();
}
public function __toString()
{
return $this->name . " (" . $this->duration . " jours)";
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(?int $price): self
{
$this->price = $price;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(?int $duration): self
{
$this->duration = $duration;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setProduct($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getProduct() === $this) {
$order->setProduct(null);
}
}
return $this;
}
/**
* @return Collection<int, Abonnement>
*/
public function getAbonnements(): Collection
{
return $this->abonnements;
}
public function addAbonnement(Abonnement $abonnement): self
{
if (!$this->abonnements->contains($abonnement)) {
$this->abonnements[] = $abonnement;
$abonnement->setProduct($this);
}
return $this;
}
public function removeAbonnement(Abonnement $abonnement): self
{
if ($this->abonnements->removeElement($abonnement)) {
// set the owning side to null (unless already changed)
if ($abonnement->getProduct() === $this) {
$abonnement->setProduct(null);
}
}
return $this;
}
public function getDetails(): ?array
{
return $this->details;
}
public function setDetails(?array $details): static
{
$this->details = $details;
return $this;
}
}