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

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