src/Entity/CustomerCategory.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\UX\Turbo\Attribute\Broadcast;
  8. #[ORM\Entity(repositoryClassCustomerCategoryRepository::class)]
  9. #[Broadcast]
  10. class CustomerCategory
  11. {
  12.     use IdentifiableTrait;
  13.     #[ORM\Column(length255)]
  14.     private ?string $name null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $code null;
  17.     #[ORM\OneToMany(mappedBy'category'targetEntityCustomer::class)]
  18.     private Collection $customers;
  19.     public function __construct()
  20.     {
  21.         $this->customers = new ArrayCollection();
  22.     }
  23.     public function getId(): ?int
  24.     {
  25.         return $this->id;
  26.     }
  27.     public function getName(): ?string
  28.     {
  29.         return $this->name;
  30.     }
  31.     public function setName(string $name): self
  32.     {
  33.         $this->name $name;
  34.         return $this;
  35.     }
  36.     public function getCode(): ?string
  37.     {
  38.         return $this->code;
  39.     }
  40.     public function setCode(string $code): self
  41.     {
  42.         $this->code $code;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return Collection<int, Customer>
  47.      */
  48.     public function getCustomers(): Collection
  49.     {
  50.         return $this->customers;
  51.     }
  52.     public function addCustomer(Customer $customer): self
  53.     {
  54.         if (!$this->customers->contains($customer)) {
  55.             $this->customers->add($customer);
  56.             $customer->setCategory($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removeCustomer(Customer $customer): self
  61.     {
  62.         if ($this->customers->removeElement($customer)) {
  63.             // set the owning side to null (unless already changed)
  64.             if ($customer->getCategory() === $this) {
  65.                 $customer->setCategory(null);
  66.             }
  67.         }
  68.         return $this;
  69.     }
  70. }