src/Entity/System/Category.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * Category
  7. *
  8. * @ORM\Table(name="ps_category", indexes={
  9. *
  10. * @ORM\Index(name="nright", columns={"nright"}),
  11. * @ORM\Index(name="nleft", columns={"nleft"}),
  12. * @ORM\Index(name="nleftright", columns={"nleft", "nright"}),
  13. * @ORM\Index(name="level_depth", columns={"level_depth"}),
  14. * @ORM\Index(name="position", columns={"position"}),
  15. * @ORM\Index(name="nleftrightactive", columns={"nleft", "nright", "active"}),
  16. * @ORM\Index(name="category_parent", columns={"id_parent"})
  17. * })
  18. *
  19. * @ORM\Entity(repositoryClass="App\Repository\System\CategoryRepository")
  20. */
  21. class Category extends AbstractCategory
  22. {
  23. public const FULL_CATALOGUE_CATEGORY_ID = 2202;
  24. public const FANCY_DRESS_CATEGORY_ID = 2488;
  25. public const ORIGINAL_GIFTS_CATEGORY_ID = 2662;
  26. public const TELESHOPPING_CATEGORY_ID = 2672;
  27. public const OFFERS_CATEGORY_ID = 2678;
  28. public const VALENTINE_CATEGORY_ID = 3150;
  29. public const OUTLET_CATEGORY_ID = 2678;
  30. public const HOME_GARDEN_CATEGORY_ID = 2399;
  31. public const OPENBOX_CATEGORY_ID = 3045;
  32. public const ROOT_ID = 1;
  33. public const HOME_ID = 2;
  34. /**
  35. * @var int
  36. *
  37. * @ORM\Column(name="id_category", type="integer")
  38. *
  39. * @ORM\Id
  40. *
  41. * @ORM\GeneratedValue(strategy="NONE")
  42. */
  43. protected $id;
  44. /**
  45. * @var bool
  46. *
  47. * @ORM\Column(type="boolean", options={"default" : 0})
  48. */
  49. protected $active;
  50. /**
  51. * @var int
  52. *
  53. * @ORM\Column(type="integer", length=10, nullable=false)
  54. */
  55. protected $nleft;
  56. /**
  57. * @var int
  58. *
  59. * @ORM\Column(type="integer", length=10, nullable=false)
  60. */
  61. protected $nright;
  62. /**
  63. * @var int
  64. *
  65. * @ORM\Column(type="integer", nullable=false)
  66. */
  67. protected $levelDepth;
  68. /**
  69. * @var int
  70. *
  71. * @ORM\Column(type="integer", nullable=true)
  72. */
  73. protected $oldIdCategory;
  74. /**
  75. * @var int
  76. *
  77. * @ORM\Column(type="integer", length=10, nullable=false)
  78. */
  79. protected $position;
  80. /**
  81. * @var CategoryLang[]|ArrayCollection
  82. *
  83. * @ORM\OneToMany(targetEntity="CategoryLang", mappedBy="category", indexBy="language.name")
  84. */
  85. protected $langs;
  86. /**
  87. * @var Category
  88. *
  89. * @ORM\ManyToOne(targetEntity="App\Entity\System\Category")
  90. *
  91. * @ORM\JoinColumn(referencedColumnName="id_category", name="id_parent", nullable=true)
  92. */
  93. protected $parent;
  94. public function __construct()
  95. {
  96. parent::__construct();
  97. }
  98. /**
  99. * @return int
  100. */
  101. public function getId()
  102. {
  103. return $this->id;
  104. }
  105. public function setId(int $id): self
  106. {
  107. $this->id = $id;
  108. return $this;
  109. }
  110. /**
  111. * @return bool
  112. */
  113. public function isActive(): bool
  114. {
  115. return $this->active;
  116. }
  117. public function setActive(bool $active): AbstractCategory
  118. {
  119. $this->active = $active;
  120. return $this;
  121. }
  122. /**
  123. * @return CategoryLang[]|ArrayCollection
  124. */
  125. public function getLangs()
  126. {
  127. return $this->langs;
  128. }
  129. /**
  130. * @param CategoryLang[]|ArrayCollection $langs
  131. *
  132. * @return Category
  133. */
  134. public function setLangs($langs)
  135. {
  136. $this->langs = $langs;
  137. return $this;
  138. }
  139. public function getName(string $isoCode = 'es')
  140. {
  141. foreach ($this->getLangs() as $categoryLang) {
  142. if ($categoryLang->getLanguage()->getIsoCode() === $isoCode) {
  143. return $categoryLang->getName();
  144. }
  145. }
  146. return '';
  147. }
  148. public function setParent(Category $parent): Category
  149. {
  150. $this->parent = $parent;
  151. return $this;
  152. }
  153. public function getParent(): ?CategoryInterface
  154. {
  155. return $this->parent;
  156. }
  157. }