Category.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Gedmo\Mapping\Annotation as Gedmo;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @Gedmo\Tree(type="nested")
  8. * @ORM\Table(name="ext_categories")
  9. * @ORM\Entity(repositoryClass="Entity\Repository\CategoryRepository")
  10. * @Gedmo\TranslationEntity(class="Entity\CategoryTranslation")
  11. */
  12. class Category
  13. {
  14. /**
  15. * @ORM\Column(type="integer")
  16. * @ORM\Id
  17. * @ORM\GeneratedValue
  18. */
  19. private $id;
  20. /**
  21. * @Gedmo\Translatable
  22. * @ORM\Column(length=64)
  23. */
  24. private $title;
  25. /**
  26. * @Gedmo\Translatable
  27. * @ORM\Column(type="text", nullable=true)
  28. */
  29. private $description;
  30. /**
  31. * @Gedmo\Translatable
  32. * @Gedmo\Slug(fields={"title"})
  33. * @ORM\Column(length=64, unique=true)
  34. */
  35. private $slug;
  36. /**
  37. * @Gedmo\TreeLeft
  38. * @ORM\Column(type="integer")
  39. */
  40. private $lft;
  41. /**
  42. * @Gedmo\TreeRight
  43. * @ORM\Column(type="integer")
  44. */
  45. private $rgt;
  46. /**
  47. * @Gedmo\TreeParent
  48. * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
  49. * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
  50. */
  51. private $parent;
  52. /**
  53. * @Gedmo\TreeRoot
  54. * @ORM\Column(type="integer", nullable=true)
  55. */
  56. private $root;
  57. /**
  58. * @Gedmo\TreeLevel
  59. * @ORM\Column(name="lvl", type="integer")
  60. */
  61. private $level;
  62. /**
  63. * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
  64. */
  65. private $children;
  66. /**
  67. * @Gedmo\Timestampable(on="create")
  68. * @ORM\Column(type="datetime")
  69. */
  70. private $created;
  71. /**
  72. * @Gedmo\Timestampable(on="update")
  73. * @ORM\Column(type="datetime")
  74. */
  75. private $updated;
  76. /**
  77. * @ORM\OneToMany(
  78. * targetEntity="CategoryTranslation",
  79. * mappedBy="object",
  80. * cascade={"persist", "remove"}
  81. * )
  82. */
  83. private $translations;
  84. public function __construct()
  85. {
  86. $this->children = new ArrayCollection();
  87. $this->translations = new ArrayCollection();
  88. }
  89. public function getTranslations()
  90. {
  91. return $this->translations;
  92. }
  93. public function addTranslation(CategoryTranslation $t)
  94. {
  95. if (!$this->translations->contains($t)) {
  96. $this->translations[] = $t;
  97. $t->setObject($this);
  98. }
  99. }
  100. public function getSlug()
  101. {
  102. return $this->slug;
  103. }
  104. public function getId()
  105. {
  106. return $this->id;
  107. }
  108. public function setTitle($title)
  109. {
  110. $this->title = $title;
  111. }
  112. public function getTitle()
  113. {
  114. return $this->title;
  115. }
  116. public function setDescription($description)
  117. {
  118. $this->description = $description;
  119. }
  120. public function getDescription()
  121. {
  122. return $this->description;
  123. }
  124. public function setParent($parent)
  125. {
  126. $this->parent = $parent;
  127. }
  128. public function getParent()
  129. {
  130. return $this->parent;
  131. }
  132. public function getRoot()
  133. {
  134. return $this->root;
  135. }
  136. public function getLevel()
  137. {
  138. return $this->level;
  139. }
  140. public function getChildren()
  141. {
  142. return $this->children;
  143. }
  144. public function getLeft()
  145. {
  146. return $this->lft;
  147. }
  148. public function getRight()
  149. {
  150. return $this->rgt;
  151. }
  152. public function getCreated()
  153. {
  154. return $this->created;
  155. }
  156. public function getUpdated()
  157. {
  158. return $this->updated;
  159. }
  160. public function __toString()
  161. {
  162. return $this->getTitle();
  163. }
  164. }