src/Shop/Doctrine/Entity/Brand.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Shop\Doctrine\Entity;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use App\Shop\Doctrine\Repository\BrandRepository;
  7. use App\Shop\Filter\BrandFilter;
  8. use DateTimeImmutable;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping\Column;
  12. use Doctrine\ORM\Mapping\Entity;
  13. use Doctrine\ORM\Mapping\GeneratedValue;
  14. use Doctrine\ORM\Mapping\Id;
  15. use Doctrine\ORM\Mapping\OneToMany;
  16. use Doctrine\ORM\Mapping\Table;
  17. use Symfony\Component\HttpFoundation\File\File;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use Symfony\Component\Validator\Constraints\NotBlank;
  20. use Vich\UploaderBundle\Mapping\Annotation\Uploadable;
  21. use Vich\UploaderBundle\Mapping\Annotation\UploadableField;
  22. #[ApiResource(
  23.     collectionOperations: ['get'],
  24.     itemOperations: ['get'],
  25.     attributes: ['pagination_enabled' => false],
  26.     normalizationContext: ['groups' => ['read']]
  27. )]
  28. #[Uploadable]
  29. #[ApiFilter(BrandFilter::class)]
  30. #[Entity(repositoryClassBrandRepository::class)]
  31. #[Table(name'`shop_brand`')]
  32. class Brand
  33. {
  34.     #[Id]
  35.     #[Column(type'integer')]
  36.     #[GeneratedValue]
  37.     #[Groups(['read''product'])]
  38.     private ?int $id null;
  39.     #[Column]
  40.     #[NotBlank]
  41.     #[Groups(['read''product'])]
  42.     private string $name;
  43.     #[Column(nullabletrue)]
  44.     private ?string $logo null;
  45.     #[UploadableField(mapping'images'fileNameProperty'logo')]
  46.     private ?File $logoFile null;
  47.     #[Column(type'datetime_immutable')]
  48.     private DateTimeImmutable $updatedAt;
  49.     /**
  50.      * @var Collection<int, Product>
  51.      */
  52.     #[OneToMany(mappedBy'brand'targetEntityProduct::class, fetch'EXTRA_LAZY')]
  53.     private Collection $products;
  54.     public function __construct()
  55.     {
  56.         $this->updatedAt = new DateTimeImmutable();
  57.         $this->products = new ArrayCollection();
  58.     }
  59.     public function __toString(): string
  60.     {
  61.         return $this->getName();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getName(): string
  68.     {
  69.         return $this->name;
  70.     }
  71.     public function setName(string $name): void
  72.     {
  73.         $this->name $name;
  74.         $this->updatedAt = new DateTimeImmutable();
  75.     }
  76.     public function getLogo(): ?string
  77.     {
  78.         return $this->logo;
  79.     }
  80.     public function setLogo(?string $logo): void
  81.     {
  82.         $this->logo $logo;
  83.     }
  84.     public function getLogoFile(): ?File
  85.     {
  86.         return $this->logoFile;
  87.     }
  88.     public function setLogoFile(?File $logoFile): void
  89.     {
  90.         $this->logoFile $logoFile;
  91.         if (null !== $logoFile) {
  92.             $this->updatedAt = new DateTimeImmutable();
  93.         }
  94.     }
  95.     public function getUpdatedAt(): DateTimeImmutable
  96.     {
  97.         return $this->updatedAt;
  98.     }
  99.     /**
  100.      * @return Collection<int, Product>
  101.      */
  102.     public function getProducts(): Collection
  103.     {
  104.         return $this->products;
  105.     }
  106. }