src/Entity/Category.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. /**
  10. * @ORM\Entity(repositoryClass=CategoryRepository::class)
  11. *
  12. * @ORM\HasLifecycleCallbacks()
  13. *
  14. * @Vich\Uploadable
  15. */
  16. class Category {
  17. use MetaTrait;
  18. /**
  19. * @ORM\Id
  20. *
  21. * @ORM\GeneratedValue
  22. *
  23. * @ORM\Column(type="integer")
  24. */
  25. private $id;
  26. /**
  27. * @ORM\Column(type="string", length=255)
  28. */
  29. private $name;
  30. /**
  31. * @ORM\Column(type="text", nullable=true)
  32. */
  33. private $description;
  34. /**
  35. * @ORM\Column(type="string", length=255, nullable=true)
  36. */
  37. private $listImage;
  38. /**
  39. * @Vich\UploadableField(mapping="images", fileNameProperty="listImage")
  40. */
  41. private $listImageFile;
  42. /**
  43. * @ORM\Column(type="string", length=255, nullable=true)
  44. */
  45. private $headerImage;
  46. /**
  47. * @Vich\UploadableField(mapping="images", fileNameProperty="headerImage")
  48. */
  49. private $headerImageFile;
  50. /**
  51. * @ORM\ManyToMany(targetEntity=Product::class, inversedBy="categories")
  52. */
  53. private $products;
  54. /**
  55. * @ORM\ManyToOne(targetEntity=Tenant::class, inversedBy="categories")
  56. *
  57. * @ORM\JoinColumn(nullable=false)
  58. */
  59. private $tenant;
  60. public function __construct() {
  61. $this->products = new ArrayCollection();
  62. }
  63. public function __toString(): string {
  64. return $this->getName();
  65. }
  66. public function getId(): ?int {
  67. return $this->id;
  68. }
  69. public function getName(): ?string {
  70. return $this->name;
  71. }
  72. public function setName(string $name): self {
  73. $this->name = $name;
  74. return $this;
  75. }
  76. public function getDescription(): ?string {
  77. return $this->description;
  78. }
  79. public function setDescription(?string $description): self {
  80. $this->description = $description;
  81. return $this;
  82. }
  83. public function getListImage(): ?string {
  84. return $this->listImage;
  85. }
  86. public function setListImage(?string $listImage): self {
  87. $this->listImage = $listImage;
  88. return $this;
  89. }
  90. public function getListImageFile(): ?File {
  91. return $this->listImageFile;
  92. }
  93. public function setListImageFile(?File $listImageFile): self {
  94. $this->listImageFile = $listImageFile;
  95. if ($this->listImageFile instanceof File) {
  96. $this->modifiedAt = new \DateTime();
  97. }
  98. return $this;
  99. }
  100. public function getHeaderImage(): ?string {
  101. return $this->headerImage;
  102. }
  103. public function setHeaderImage(?string $headerImage): self {
  104. $this->headerImage = $headerImage;
  105. return $this;
  106. }
  107. public function getHeaderImageFile(): ?File {
  108. return $this->headerImageFile;
  109. }
  110. public function setHeaderImageFile(?File $headerImageFile): self {
  111. $this->headerImageFile = $headerImageFile;
  112. if ($this->headerImageFile instanceof File) {
  113. $this->modifiedAt = new \DateTime();
  114. }
  115. return $this;
  116. }
  117. /**
  118. * @return Collection<int, Product>
  119. */
  120. public function getProducts(): Collection {
  121. return $this->products;
  122. }
  123. public function addProduct(Product $product): self {
  124. if (!$this->products->contains($product)) {
  125. $this->products[] = $product;
  126. }
  127. return $this;
  128. }
  129. public function removeProduct(Product $product): self {
  130. $this->products->removeElement($product);
  131. return $this;
  132. }
  133. public function getTenant(): ?Tenant {
  134. return $this->tenant;
  135. }
  136. public function setTenant(?Tenant $tenant): self {
  137. $this->tenant = $tenant;
  138. return $this;
  139. }
  140. /**
  141. * @ORM\PrePersist
  142. */
  143. public function setDefaults(): self {
  144. return $this
  145. ->setCreatedAt(new \DateTime())
  146. ;
  147. }
  148. /**
  149. * @ORM\PreUpdate
  150. */
  151. public function setModified(): self {
  152. return $this
  153. ->setModifiedAt(new \DateTime())
  154. ;
  155. }
  156. }