src/Entity/SiteProducts.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\SiteProductsRepository;
  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. use ApiPlatform\Core\Annotation\ApiProperty;
  11. use ApiPlatform\Metadata\Get;
  12. use ApiPlatform\Metadata\GetCollection;
  13. use ApiPlatform\Metadata\Delete;
  14. use ApiPlatform\Metadata\Put;
  15. use ApiPlatform\Metadata\Post;
  16. use ApiPlatform\Metadata\Patch;
  17. #[ORM\Entity(repositoryClassSiteProductsRepository::class)]
  18. #[ApiResource(
  19.     operations: [
  20.         new Get(),
  21.         new Post(),
  22.         new Delete(),
  23.         new GetCollection(),
  24.         new Put(),
  25.         new Patch()
  26.     ],
  27.     normalizationContext: ['groups' => ['read']],
  28.     denormalizationContext: ['groups' => ['write']],
  29.     order: ['id' => 'DESC'],
  30.     paginationPartialtrue
  31. )]
  32. class SiteProducts
  33. {
  34.     #[ORM\Id]
  35.     #[ORM\GeneratedValue]
  36.     #[ORM\Column]
  37.     #[Groups(['read''write'])]
  38.     private ?int $id null;
  39.     #[Groups(['read''write'])]
  40.     #[ORM\Column(length255nullabletrue)]
  41.     private ?string $name null;
  42.     #[Groups(['read''write'])]
  43.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  44.     private ?string $description null;
  45.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  46.     private ?\DateTimeInterface $date_entered null;
  47.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  48.     private ?\DateTimeInterface $date_modified null;
  49.     #[ORM\ManyToOne]
  50.     private ?User $created_by null;
  51.     #[ORM\ManyToOne]
  52.     private ?User $modified_user null;
  53.     #[Groups(['read''write'])]
  54.     #[ORM\Column(length100nullabletrue)]
  55.     private ?string $status null;
  56.     #[Groups(['read''write'])]
  57.     #[ORM\Column(nullabletrue)]
  58.     private ?float $price null;
  59.     #[Groups(['read''write'])]
  60.     #[ORM\ManyToOne(inversedBy'siteProducts')]
  61.     private ?MeasurmentUnit $measurment_unit null;
  62.     #[Groups(['read''write'])]
  63.     #[ORM\OneToMany(mappedBy'site_product'targetEntityProducts::class)]
  64.     #[ApiProperty(writabletrue)]
  65.     private Collection $products;
  66.     public function __construct()
  67.     {
  68.         $this->products = new ArrayCollection();
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getName(): ?string
  75.     {
  76.         return $this->name;
  77.     }
  78.     public function setName(?string $name): self
  79.     {
  80.         $this->name $name;
  81.         return $this;
  82.     }
  83.     public function getDescription(): ?string
  84.     {
  85.         return $this->description;
  86.     }
  87.     public function setDescription(?string $description): self
  88.     {
  89.         $this->description $description;
  90.         return $this;
  91.     }
  92.     public function getDateEntered(): ?\DateTimeInterface
  93.     {
  94.         return $this->date_entered;
  95.     }
  96.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  97.     {
  98.         $this->date_entered $date_entered;
  99.         return $this;
  100.     }
  101.     public function getDateModified(): ?\DateTimeInterface
  102.     {
  103.         return $this->date_modified;
  104.     }
  105.     public function setDateModified(?\DateTimeInterface $date_modified): self
  106.     {
  107.         $this->date_modified $date_modified;
  108.         return $this;
  109.     }
  110.     public function getCreatedBy(): ?User
  111.     {
  112.         return $this->created_by;
  113.     }
  114.     public function setCreatedBy(?User $created_by): self
  115.     {
  116.         $this->created_by $created_by;
  117.         return $this;
  118.     }
  119.     public function getModifiedUser(): ?User
  120.     {
  121.         return $this->modified_user;
  122.     }
  123.     public function setModifiedUser(?User $modified_user): self
  124.     {
  125.         $this->modified_user $modified_user;
  126.         return $this;
  127.     }
  128.     public function getStatus(): ?string
  129.     {
  130.         return $this->status;
  131.     }
  132.     public function setStatus(?string $status): self
  133.     {
  134.         $this->status $status;
  135.         return $this;
  136.     }
  137.     public function getPrice(): ?float
  138.     {
  139.         return $this->price;
  140.     }
  141.     public function setPrice(?float $price): self
  142.     {
  143.         $this->price $price;
  144.         return $this;
  145.     }
  146.     public function getMeasurmentUnit(): ?MeasurmentUnit
  147.     {
  148.         return $this->measurment_unit;
  149.     }
  150.     public function setMeasurmentUnit(?MeasurmentUnit $measurment_unit): self
  151.     {
  152.         $this->measurment_unit $measurment_unit;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection<int, Products>
  157.      */
  158.     public function getProducts(): Collection
  159.     {
  160.         return $this->products;
  161.     }
  162.     public function addProduct(Products $product): self
  163.     {
  164.         if (!$this->products->contains($product)) {
  165.             $this->products->add($product);
  166.             $product->setSiteProduct($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeProduct(Products $product): self
  171.     {
  172.         if ($this->products->removeElement($product)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($product->getSiteProduct() === $this) {
  175.                 $product->setSiteProduct(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180. }