src/Entity/Brand.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BrandRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassBrandRepository::class)]
  9. class Brand
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $name null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $slug null;
  19.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  20.     private ?string $description null;
  21.     #[ORM\Column(length255nullabletrue)]
  22.     private ?string $logo null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $website null;
  25.     #[ORM\Column]
  26.     private ?bool $isActive true;
  27.     #[ORM\Column]
  28.     private ?\DateTimeImmutable $createdAt null;
  29.     #[ORM\Column]
  30.     private ?\DateTimeImmutable $updatedAt null;
  31.     #[ORM\OneToMany(targetEntityProduct::class, mappedBy'brand')]
  32.     private Collection $products;
  33.     public function __construct()
  34.     {
  35.         $this->products = new ArrayCollection();
  36.         $this->createdAt = new \DateTimeImmutable();
  37.         $this->updatedAt = new \DateTimeImmutable();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): static
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getSlug(): ?string
  53.     {
  54.         return $this->slug;
  55.     }
  56.     public function setSlug(string $slug): static
  57.     {
  58.         $this->slug $slug;
  59.         return $this;
  60.     }
  61.     public function getDescription(): ?string
  62.     {
  63.         return $this->description;
  64.     }
  65.     public function setDescription(?string $description): static
  66.     {
  67.         $this->description $description;
  68.         return $this;
  69.     }
  70.     public function getLogo(): ?string
  71.     {
  72.         return $this->logo;
  73.     }
  74.     public function setLogo(?string $logo): static
  75.     {
  76.         $this->logo $logo;
  77.         return $this;
  78.     }
  79.     public function getWebsite(): ?string
  80.     {
  81.         return $this->website;
  82.     }
  83.     public function setWebsite(?string $website): static
  84.     {
  85.         $this->website $website;
  86.         return $this;
  87.     }
  88.     public function isIsActive(): ?bool
  89.     {
  90.         return $this->isActive;
  91.     }
  92.     public function setIsActive(bool $isActive): static
  93.     {
  94.         $this->isActive $isActive;
  95.         return $this;
  96.     }
  97.     public function getCreatedAt(): ?\DateTimeImmutable
  98.     {
  99.         return $this->createdAt;
  100.     }
  101.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  102.     {
  103.         $this->createdAt $createdAt;
  104.         return $this;
  105.     }
  106.     public function getUpdatedAt(): ?\DateTimeImmutable
  107.     {
  108.         return $this->updatedAt;
  109.     }
  110.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
  111.     {
  112.         $this->updatedAt $updatedAt;
  113.         return $this;
  114.     }
  115.     /**
  116.      * @return Collection<int, Product>
  117.      */
  118.     public function getProducts(): Collection
  119.     {
  120.         return $this->products;
  121.     }
  122.     public function addProduct(Product $product): static
  123.     {
  124.         if (!$this->products->contains($product)) {
  125.             $this->products->add($product);
  126.             $product->setBrand($this);
  127.         }
  128.         return $this;
  129.     }
  130.     public function removeProduct(Product $product): static
  131.     {
  132.         if ($this->products->removeElement($product)) {
  133.             if ($product->getBrand() === $this) {
  134.                 $product->setBrand(null);
  135.             }
  136.         }
  137.         return $this;
  138.     }
  139.     public function getActiveProductsCount(): int
  140.     {
  141.         return $this->products->filter(function(Product $product) {
  142.             return $product->isIsActive();
  143.         })->count();
  144.     }
  145. }