src/Entity/Categories.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoriesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: CategoriesRepository::class)]
  8. class Categories
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column(type: 'integer')]
  13. private $id;
  14. #[ORM\ManyToOne(targetEntity: Categories::class, inversedBy: 'children')]
  15. private $parent;
  16. #[ORM\OneToMany(targetEntity: Categories::class, mappedBy: 'parent')]
  17. private $children;
  18. #[ORM\Column(type: 'string', length: 255)]
  19. private $category;
  20. #[ORM\Column(type: 'datetime')]
  21. private $modified;
  22. #[ORM\Column(type: 'datetime')]
  23. private $created;
  24. #[ORM\Column(type: 'integer', nullable: true)]
  25. private $rootId;
  26. #[ORM\Column(type: 'integer', nullable: true)]
  27. private $isRoot;
  28. #[ORM\OneToMany(targetEntity: Products::class, mappedBy: 'category')]
  29. private $products;
  30. #[ORM\Column(type: 'json', nullable: true)]
  31. private $childIds = [];
  32. #[ORM\OneToMany(targetEntity: SubCategories::class, mappedBy: 'category')]
  33. private $subCategories;
  34. public function __construct()
  35. {
  36. $date = new \DateTime("now", new \DateTimeZone('Asia/Dubai'));
  37. $this->setModified($date);
  38. if ($this->getCreated() == null)
  39. {
  40. $this->setCreated($date);
  41. }
  42. $this->children = new ArrayCollection();
  43. $this->products = new ArrayCollection();
  44. $this->subCategories = new ArrayCollection();
  45. }
  46. public function getId(): ?int
  47. {
  48. return $this->id;
  49. }
  50. public function getParent(): ?self
  51. {
  52. return $this->parent;
  53. }
  54. public function setParent(?self $parent): self
  55. {
  56. $this->parent = $parent;
  57. return $this;
  58. }
  59. /**
  60. * @return Collection<int, self>
  61. */
  62. public function getChildren(): Collection
  63. {
  64. return $this->children;
  65. }
  66. public function addChild(self $child): self
  67. {
  68. if (!$this->children->contains($child)) {
  69. $this->children[] = $child;
  70. $child->setParent($this);
  71. }
  72. return $this;
  73. }
  74. public function removeChild(self $child): self
  75. {
  76. if ($this->children->removeElement($child)) {
  77. // set the owning side to null (unless already changed)
  78. if ($child->getParent() === $this) {
  79. $child->setParent(null);
  80. }
  81. }
  82. return $this;
  83. }
  84. public function getCategory(): ?string
  85. {
  86. return $this->category;
  87. }
  88. public function setCategory(string $category): self
  89. {
  90. $this->category = $category;
  91. return $this;
  92. }
  93. public function getModified(): ?\DateTimeInterface
  94. {
  95. return $this->modified;
  96. }
  97. public function setModified(\DateTimeInterface $modified): self
  98. {
  99. $this->modified = $modified;
  100. return $this;
  101. }
  102. public function getCreated(): ?\DateTimeInterface
  103. {
  104. return $this->created;
  105. }
  106. public function setCreated(\DateTimeInterface $created): self
  107. {
  108. $this->created = $created;
  109. return $this;
  110. }
  111. public function getRootId(): ?int
  112. {
  113. return $this->rootId;
  114. }
  115. public function setRootId(?int $rootId): self
  116. {
  117. $this->rootId = $rootId;
  118. return $this;
  119. }
  120. public function getIsRoot(): ?int
  121. {
  122. return $this->isRoot;
  123. }
  124. public function setIsRoot(?int $isRoot): self
  125. {
  126. $this->isRoot = $isRoot;
  127. return $this;
  128. }
  129. /**
  130. * @return Collection|Products[]
  131. */
  132. public function getProducts(): Collection
  133. {
  134. return $this->products;
  135. }
  136. public function addProduct(Products $product): self
  137. {
  138. if (!$this->products->contains($product)) {
  139. $this->products[] = $product;
  140. $product->setCategory($this);
  141. }
  142. return $this;
  143. }
  144. public function removeProduct(Products $product): self
  145. {
  146. if ($this->products->removeElement($product)) {
  147. // set the owning side to null (unless already changed)
  148. if ($product->getCategory() === $this) {
  149. $product->setCategory(null);
  150. }
  151. }
  152. return $this;
  153. }
  154. public function getChildIds(): ?array
  155. {
  156. return $this->childIds;
  157. }
  158. public function setChildIds(?array $childIds): self
  159. {
  160. $this->childIds = $childIds;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection|SubCategories[]
  165. */
  166. public function getSubCategories(): Collection
  167. {
  168. return $this->subCategories;
  169. }
  170. public function addSubCategories(SubCategories $subCategories): self
  171. {
  172. if (!$this->subCategories->contains($subCategories)) {
  173. $this->subCategories[] = $subCategories;
  174. $subCategories->setCategory($this);
  175. }
  176. return $this;
  177. }
  178. public function removeSubCategories(SubCategories $subCategories): self
  179. {
  180. if ($this->subCategories->removeElement($subCategories)) {
  181. // set the owning side to null (unless already changed)
  182. if ($subCategories->getCategory() === $this) {
  183. $subCategories->setCategory(null);
  184. }
  185. }
  186. return $this;
  187. }
  188. }