src/Entity/Order.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\OrderRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassOrderRepository::class)]
  11. #[ORM\Table(name'`order`')]
  12. /**
  13.  * @ApiResource(
  14.  *      normalizationContext={"groups"={"order:read"}},
  15.  *      denormalizationContext={"groups"={"order:write"}}
  16.  *  )
  17.  */
  18. class Order
  19. {
  20.     public const STATUS = [
  21.         'PENDING' => 'PENDING',
  22.         'REJECTED' => 'REJECTED',
  23.         'SHIPPED' => 'SHIPPED',
  24.         'PAYED' => 'PAYED',
  25.     ];
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column]
  29.     #[Groups(['order:write''order:read'])]
  30.     private ?int $id null;
  31.     #[ORM\ManyToOne(inversedBy'orders')]
  32.     #[Groups(['order:write''order:read'])]
  33.     private ?User $patient null;
  34.     #[ORM\ManyToOne(inversedBy'orders')]
  35.     #[Groups(['order:write''order:read'])]
  36.     private ?User $pharmacy null;
  37.     #[ORM\OneToMany(mappedBy'commande'targetEntityProduct::class)]
  38.     private Collection $product;
  39.     #[ORM\Column]
  40.     #[Groups(['order:write''order:read'])]
  41.     private ?\DateTimeImmutable $created_at null;
  42.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  43.     #[Groups(['order:write''order:read'])]
  44.     private ?\DateTimeInterface $updated_at null;
  45.     #[ORM\Column(length255)]
  46.     #[Groups(['order:write''order:read'])]
  47.     private ?string $status 'PENDING';
  48.     public function __construct()
  49.     {
  50.         $this->product = new ArrayCollection();
  51.         $this->created_at = new \DateTimeImmutable();
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getPatient(): ?User
  58.     {
  59.         return $this->patient;
  60.     }
  61.     public function setPatient(?User $patient): static
  62.     {
  63.         $this->patient $patient;
  64.         return $this;
  65.     }
  66.     public function getPharmacy(): ?User
  67.     {
  68.         return $this->pharmacy;
  69.     }
  70.     public function setPharmacy(?User $pharmacy): static
  71.     {
  72.         $this->pharmacy $pharmacy;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return Collection<int, Product>
  77.      */
  78.     public function getProduct(): Collection
  79.     {
  80.         return $this->product;
  81.     }
  82.     public function addProduct(Product $product): static
  83.     {
  84.         if (!$this->product->contains($product)) {
  85.             $this->product->add($product);
  86.             $product->setCommande($this);
  87.         }
  88.         return $this;
  89.     }
  90.     public function removeProduct(Product $product): static
  91.     {
  92.         if ($this->product->removeElement($product)) {
  93.             // set the owning side to null (unless already changed)
  94.             if ($product->getCommande() === $this) {
  95.                 $product->setCommande(null);
  96.             }
  97.         }
  98.         return $this;
  99.     }
  100.     public function getCreatedAt(): ?\DateTimeImmutable
  101.     {
  102.         return $this->created_at;
  103.     }
  104.     public function setCreatedAt(\DateTimeImmutable $created_at): static
  105.     {
  106.         $this->created_at $created_at;
  107.         return $this;
  108.     }
  109.     public function getUpdatedAt(): ?\DateTimeInterface
  110.     {
  111.         return $this->updated_at;
  112.     }
  113.     public function setUpdatedAt(?\DateTimeInterface $updated_at): static
  114.     {
  115.         $this->updated_at $updated_at;
  116.         return $this;
  117.     }
  118.     public function getStatus(): ?string
  119.     {
  120.         return $this->status;
  121.     }
  122.     public function setStatus(string $status): static
  123.     {
  124.         $this->status $status;
  125.         return $this;
  126.     }
  127. }