src/Flexy/ShopBundle/Entity/Customer/CustomerGroup.php line 19

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Customer;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
  5. use App\Flexy\ShopBundle\Repository\Customer\CustomerGroupRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ApiResource(
  12.     normalizationContext: ['groups' => ['read']],
  13.     denormalizationContext: ['groups' => ['write']],
  14. )]
  15. #[ORM\Entity(repositoryClassCustomerGroupRepository::class)]
  16. class CustomerGroup implements \Stringable
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column(type'integer')]
  21.     private $id;
  22.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  23.     private ?\DateTimeImmutable $createdAt null;
  24.     #[ORM\OneToMany(targetEntityCustomer::class, mappedBy'customerGroup')]
  25.     private \Doctrine\Common\Collections\Collection|array $customers;
  26.     #[ORM\OneToMany(targetEntityShippingMethod::class, mappedBy'customerGroup')]
  27.     #[Groups(["write","read"])]
  28.     private \Doctrine\Common\Collections\Collection|array $shippingMethods;
  29.     #[ORM\Column(type'string'length255)]
  30.     #[Groups(["write","read"])]
  31.     private ?string $name null;
  32.     #[ORM\Column(type'string'length255uniquetrue)]
  33.     private $code;
  34.     #[ORM\ManyToMany(targetEntityVendor::class, mappedBy'customerGroups')]
  35.     private Collection $vendors;
  36.     public function __toString(): string{
  37.         return (string)$this->name;
  38.     }
  39.     public function __construct()
  40.     {
  41.         $this->customers = new ArrayCollection();
  42.         $this->vendors = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getCreatedAt(): ?\DateTimeImmutable
  49.     {
  50.         return $this->createdAt;
  51.     }
  52.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  53.     {
  54.         $this->createdAt $createdAt;
  55.         return $this;
  56.     }
  57.     /**
  58.      * @return Collection|Customer[]
  59.      */
  60.     public function getCustomers(): Collection
  61.     {
  62.         return $this->customers;
  63.     }
  64.     public function addCustomer(Customer $customer): self
  65.     {
  66.         if (!$this->customers->contains($customer)) {
  67.             $this->customers[] = $customer;
  68.             $customer->setCustomerGroup($this);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeCustomer(Customer $customer): self
  73.     {
  74.         if ($this->customers->removeElement($customer)) {
  75.             // set the owning side to null (unless already changed)
  76.             if ($customer->getCustomerGroup() === $this) {
  77.                 $customer->setCustomerGroup(null);
  78.             }
  79.         }
  80.         return $this;
  81.     }
  82.         /**
  83.      * @return Collection|ShippingMethod[]
  84.      */
  85.     public function getShippingMethods(): Collection
  86.     {
  87.         return $this->shippingMethods;
  88.     }
  89.     public function addShippingMethod(ShippingMethod $shippingMethod): self
  90.     {
  91.         if (!$this->shippingMethods->contains($shippingMethod)) {
  92.             $this->shippingMethods[] = $shippingMethod;
  93.             $shippingMethod->setCustomerGroup($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeShippingMethod(ShippingMethod $shippingMethod): self
  98.     {
  99.         if ($this->shippingMethods->removeElement($shippingMethod)) {
  100.             // set the owning side to null (unless already changed)
  101.             if ($shippingMethod->getCustomerGroup() === $this) {
  102.                 $shippingMethod->setCustomerGroup(null);
  103.             }
  104.         }
  105.         return $this;
  106.     }
  107.     public function getName(): ?string
  108.     {
  109.         return $this->name;
  110.     }
  111.     public function setName(?string $name): self
  112.     {
  113.         $this->name $name;
  114.         return $this;
  115.     }
  116.     /**
  117.      * Get the value of code
  118.      */ 
  119.     public function getCode()
  120.     {
  121.         return $this->code;
  122.     }
  123.     /**
  124.      * Set the value of code
  125.      *
  126.      * @return  self
  127.      */ 
  128.     public function setCode($code)
  129.     {
  130.         $this->code $code;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, Vendor>
  135.      */
  136.     public function getVendors(): Collection
  137.     {
  138.         return $this->vendors;
  139.     }
  140.     public function addVendor(Vendor $vendor): self
  141.     {
  142.         if (!$this->vendors->contains($vendor)) {
  143.             $this->vendors->add($vendor);
  144.             $vendor->addCustomerGroup($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeVendor(Vendor $vendor): self
  149.     {
  150.         if ($this->vendors->removeElement($vendor)) {
  151.             $vendor->removeCustomerGroup($this);
  152.         }
  153.         return $this;
  154.     }
  155. }