src/Entity/CatalogCategories.php line 136

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Interfaces\DefaultLinkedEntity;
  4. use App\Entity\Traits\ActiveTrait;
  5. use App\Entity\Traits\DeleteTrait;
  6. use App\Entity\Traits\LinkTrait;
  7. use App\Entity\Traits\MetaTrait;
  8. use App\Entity\Traits\TitleAndContentTrait;
  9. use App\Entity\Traits\TranslateTrait;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Gedmo\Mapping\Annotation as Gedmo;
  14. use Gedmo\Timestampable\Traits\TimestampableEntity;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. /**
  17. * Catalog.
  18. *
  19. * @Gedmo\Loggable
  20. *
  21. * @Gedmo\TranslationEntity(class="App\Entity\CatalogCategoriesTranslations")
  22. */
  23. #[ORM\Entity(repositoryClass: \App\Repository\CatalogRepository::class)]
  24. #[ORM\Table(name: 'catalog_categories')]
  25. class CatalogCategories implements DefaultLinkedEntity
  26. {
  27. use TitleAndContentTrait;
  28. use LinkTrait;
  29. use MetaTrait;
  30. use ActiveTrait;
  31. use DeleteTrait;
  32. use TimestampableEntity;
  33. use TranslateTrait;
  34. #[ORM\Column(name: 'id', type: 'integer')]
  35. #[ORM\Id]
  36. #[ORM\GeneratedValue(strategy: 'AUTO')]
  37. private readonly int $id;
  38. /**
  39. * @Gedmo\Translatable
  40. *
  41. * @Gedmo\Versioned
  42. */
  43. #[Assert\NotBlank(message: 'The description should not be blank')]
  44. #[ORM\Column(name: 'description', type: 'text', nullable: true)]
  45. private ?string $description = null;
  46. #[ORM\OneToMany(targetEntity: 'CatalogProducts', mappedBy: 'category')]
  47. private Collection $products;
  48. #[ORM\ManyToOne(targetEntity: 'CatalogCategories')]
  49. #[ORM\JoinColumn(name: 'parent', unique: false, referencedColumnName: 'id', nullable: true)]
  50. private ?CatalogCategories $parent = null;
  51. /**
  52. * Constructor.
  53. */
  54. public function __construct()
  55. {
  56. $this->products = new ArrayCollection();
  57. }
  58. /**
  59. * Get id.
  60. *
  61. * @return int
  62. */
  63. public function getId()
  64. {
  65. return $this->id;
  66. }
  67. /**
  68. * Set description.
  69. *
  70. * @param string $description
  71. *
  72. * @return CatalogCategories
  73. */
  74. public function setDescription($description)
  75. {
  76. $this->description = $description;
  77. return $this;
  78. }
  79. /**
  80. * Get description.
  81. *
  82. * @return string
  83. */
  84. public function getDescription()
  85. {
  86. return $this->description;
  87. }
  88. /**
  89. * Add products.
  90. *
  91. * @return CatalogCategories
  92. */
  93. public function addProduct(CatalogProducts $products)
  94. {
  95. $this->products[] = $products;
  96. return $this;
  97. }
  98. /**
  99. * Remove products.
  100. */
  101. public function removeProduct(CatalogProducts $products)
  102. {
  103. $this->products->removeElement($products);
  104. }
  105. /**
  106. * Get products.
  107. *
  108. * @return ArrayCollection
  109. */
  110. public function getProducts()
  111. {
  112. return $this->products;
  113. }
  114. /**
  115. * Set parent.
  116. *
  117. * @return CatalogCategories
  118. */
  119. public function setParent(CatalogCategories $parent = null)
  120. {
  121. $this->parent = $parent;
  122. return $this;
  123. }
  124. /**
  125. * Get parent.
  126. *
  127. * @return CatalogCategories
  128. */
  129. public function getParent()
  130. {
  131. return $this->parent;
  132. }
  133. // REQUIRED BY THE META LINKS TRAIT
  134. public function getLinkedPageId(): int
  135. {
  136. // CW TODO _ SET THIS CORRECTLY
  137. return 0;
  138. }
  139. }