src/Entity/ProductCondition.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductConditionRepository;
  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(repositoryClassProductConditionRepository::class)]
  9. #[ORM\Table(name'product_condition')]
  10. class ProductCondition
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $name null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $slug null;
  20.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  21.     private ?string $description null;
  22.     #[ORM\Column]
  23.     private ?bool $isActive true;
  24.     #[ORM\Column]
  25.     private ?\DateTimeImmutable $createdAt null;
  26.     #[ORM\Column]
  27.     private ?\DateTimeImmutable $updatedAt null;
  28.     #[ORM\OneToMany(targetEntityProduct::class, mappedBy'condition')]
  29.     private Collection $products;
  30.     public function __construct()
  31.     {
  32.         $this->products = new ArrayCollection();
  33.         $this->createdAt = new \DateTimeImmutable();
  34.         $this->updatedAt = new \DateTimeImmutable();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getName(): ?string
  41.     {
  42.         return $this->name;
  43.     }
  44.     public function setName(string $name): static
  45.     {
  46.         $this->name $name;
  47.         return $this;
  48.     }
  49.     public function getSlug(): ?string
  50.     {
  51.         return $this->slug;
  52.     }
  53.     public function setSlug(string $slug): static
  54.     {
  55.         $this->slug $slug;
  56.         return $this;
  57.     }
  58.     public function getDescription(): ?string
  59.     {
  60.         return $this->description;
  61.     }
  62.     public function setDescription(?string $description): static
  63.     {
  64.         $this->description $description;
  65.         return $this;
  66.     }
  67.     public function isIsActive(): ?bool
  68.     {
  69.         return $this->isActive;
  70.     }
  71.     public function setIsActive(bool $isActive): static
  72.     {
  73.         $this->isActive $isActive;
  74.         return $this;
  75.     }
  76.     public function getCreatedAt(): ?\DateTimeImmutable
  77.     {
  78.         return $this->createdAt;
  79.     }
  80.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  81.     {
  82.         $this->createdAt $createdAt;
  83.         return $this;
  84.     }
  85.     public function getUpdatedAt(): ?\DateTimeImmutable
  86.     {
  87.         return $this->updatedAt;
  88.     }
  89.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
  90.     {
  91.         $this->updatedAt $updatedAt;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @return Collection<int, Product>
  96.      */
  97.     public function getProducts(): Collection
  98.     {
  99.         return $this->products;
  100.     }
  101.     public function addProduct(Product $product): static
  102.     {
  103.         if (!$this->products->contains($product)) {
  104.             $this->products->add($product);
  105.             $product->setCondition($this);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeProduct(Product $product): static
  110.     {
  111.         if ($this->products->removeElement($product)) {
  112.             if ($product->getCondition() === $this) {
  113.                 $product->setCondition(null);
  114.             }
  115.         }
  116.         return $this;
  117.     }
  118.     public function getActiveProductsCount(): int
  119.     {
  120.         return $this->products->filter(function(Product $product) {
  121.             return $product->isIsActive();
  122.         })->count();
  123.     }
  124. }