src/Entity/MeasurmentUnit.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\MeasurmentUnitRepository;
  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 ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassMeasurmentUnitRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['read']],
  15.     denormalizationContext: ['groups' => ['write']],
  16.     order: ['id' => 'DESC']
  17. )]
  18. #[ApiFilter(SearchFilter::class, properties: ['code1c' => 'exact'])]
  19. #[ORM\HasLifecycleCallbacks]
  20. class MeasurmentUnit
  21. {
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     #[Groups(['read''write''order:read''pre_order:read''load_invoice:read''product:read''cat:read''order_product:read'])]
  26.     private ?int $id null;
  27.     #[ORM\Column(length100nullabletrue)]
  28.     #[Groups(['read''write''order:read''pre_order:read''load_invoice:read''product:read''cat:read''order_product:read'])]
  29.     private ?string $short_name null;
  30.     #[ORM\Column(length255)]
  31.     #[Groups(['read''write''order:read''pre_order:read''load_invoice:read''product:read''cat:read''order_product:read'])]
  32.     private ?string $name null;
  33.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  34.     private ?\DateTimeInterface $date_entered null;
  35.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  36.     private ?\DateTimeInterface $date_modified null;
  37.     #[ORM\Column(nullabletrue)]
  38.     private ?int $created_by null;
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?int $modified_user_id null;
  41.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  42.     private ?string $description null;
  43.     #[ORM\Column(length20nullabletrue)]
  44.     #[Groups(['read''write''order:read''pre_order:read''load_invoice:read'])]
  45.     private ?string $code1c null;
  46.     #[ORM\OneToMany(mappedBy'measurment_unit'targetEntitySiteProducts::class)]
  47.     private Collection $siteProducts;
  48.     public function __construct()
  49.     {
  50.         $this->siteProducts = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getShortName(): ?string
  57.     {
  58.         return $this->short_name;
  59.     }
  60.     public function setShortName(string $short_name): self
  61.     {
  62.         $this->short_name $short_name;
  63.         return $this;
  64.     }
  65.     public function getName(): ?string
  66.     {
  67.         return $this->name;
  68.     }
  69.     public function setName(string $name): self
  70.     {
  71.         $this->name $name;
  72.         return $this;
  73.     }
  74.     public function getDateEntered(): ?\DateTimeInterface
  75.     {
  76.         return $this->date_entered;
  77.     }
  78.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  79.     {
  80.         $this->date_entered $date_entered;
  81.         return $this;
  82.     }
  83.     public function getDateModified(): ?\DateTimeInterface
  84.     {
  85.         return $this->date_modified;
  86.     }
  87.     public function setDateModified(?\DateTimeInterface $date_modified): self
  88.     {
  89.         $this->date_modified $date_modified;
  90.         return $this;
  91.     }
  92.     public function getCreatedBy(): ?int
  93.     {
  94.         return $this->created_by;
  95.     }
  96.     public function setCreatedBy(?int $created_by): self
  97.     {
  98.         $this->created_by $created_by;
  99.         return $this;
  100.     }
  101.     public function getModifiedUserId(): ?int
  102.     {
  103.         return $this->modified_user_id;
  104.     }
  105.     public function setModifiedUserId(?int $modified_user_id): self
  106.     {
  107.         $this->modified_user_id $modified_user_id;
  108.         return $this;
  109.     }
  110.     public function getDescription(): ?string
  111.     {
  112.         return $this->description;
  113.     }
  114.     public function setDescription(?string $description): self
  115.     {
  116.         $this->description $description;
  117.         return $this;
  118.     }
  119.     public function getCode1c(): ?string
  120.     {
  121.         return $this->code1c;
  122.     }
  123.     public function setCode1c(?string $code1c): self
  124.     {
  125.         $this->code1c $code1c;
  126.         return $this;
  127.     }
  128.     #[ORM\PrePersist]
  129.     public function setCreatedAtValue(): void
  130.     {
  131.         $this->date_entered = new \DateTime();
  132.     }
  133.     // #[ORM\PrePersist]
  134.     #[ORM\PreUpdate]
  135.     public function setUpdatedAtValue(): void
  136.     {
  137.         $this->date_modified = new \DateTime();
  138.     }
  139.     /**
  140.      * @return Collection<int, SiteProducts>
  141.      */
  142.     public function getSiteProducts(): Collection
  143.     {
  144.         return $this->siteProducts;
  145.     }
  146.     public function addSiteProduct(SiteProducts $siteProduct): self
  147.     {
  148.         if (!$this->siteProducts->contains($siteProduct)) {
  149.             $this->siteProducts->add($siteProduct);
  150.             $siteProduct->setMeasurmentUnit($this);
  151.         }
  152.         return $this;
  153.     }
  154.     public function removeSiteProduct(SiteProducts $siteProduct): self
  155.     {
  156.         if ($this->siteProducts->removeElement($siteProduct)) {
  157.             // set the owning side to null (unless already changed)
  158.             if ($siteProduct->getMeasurmentUnit() === $this) {
  159.                 $siteProduct->setMeasurmentUnit(null);
  160.             }
  161.         }
  162.         return $this;
  163.     }
  164. }