/example/app/Entity/Category.php

https://github.com/prolic/DoctrineExtensions-1 · PHP · 184 lines · 93 code · 32 blank · 59 comment · 0 complexity · 949b681810866db5f21da75b19f04198 MD5 · raw file

  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. */
  11. class Category
  12. {
  13. /**
  14. * @ORM\Column(type="integer")
  15. * @ORM\Id
  16. * @ORM\GeneratedValue
  17. */
  18. private $id;
  19. /**
  20. * @Gedmo\Translatable
  21. * @Gedmo\Slug(fields={"title"})
  22. * @ORM\Column(length=64, unique=true)
  23. */
  24. private $slug;
  25. /**
  26. * @Gedmo\Translatable
  27. * @ORM\Column(length=64)
  28. */
  29. private $title;
  30. /**
  31. * @Gedmo\TreeLeft
  32. * @ORM\Column(type="integer")
  33. */
  34. private $lft;
  35. /**
  36. * @Gedmo\TreeRight
  37. * @ORM\Column(type="integer")
  38. */
  39. private $rgt;
  40. /**
  41. * @Gedmo\TreeParent
  42. * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
  43. * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
  44. */
  45. private $parent;
  46. /**
  47. * @Gedmo\TreeRoot
  48. * @ORM\Column(type="integer", nullable=true)
  49. */
  50. private $root;
  51. /**
  52. * @Gedmo\TreeLevel
  53. * @ORM\Column(name="lvl", type="integer")
  54. */
  55. private $level;
  56. /**
  57. * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
  58. */
  59. private $children;
  60. /**
  61. * @Gedmo\Translatable
  62. * @ORM\Column(type="text", nullable=true)
  63. */
  64. private $description;
  65. /**
  66. * @Gedmo\Timestampable(on="create")
  67. * @ORM\Column(type="datetime")
  68. */
  69. private $created;
  70. /**
  71. * @Gedmo\Timestampable(on="update")
  72. * @ORM\Column(type="datetime")
  73. */
  74. private $updated;
  75. /**
  76. * Used locale to override Translation listener`s locale
  77. * @Gedmo\Locale
  78. */
  79. private $locale;
  80. public function __construct()
  81. {
  82. $this->children = new ArrayCollection();
  83. }
  84. public function getSlug()
  85. {
  86. return $this->slug;
  87. }
  88. public function getId()
  89. {
  90. return $this->id;
  91. }
  92. public function setTitle($title)
  93. {
  94. $this->title = $title;
  95. }
  96. public function getTitle()
  97. {
  98. return $this->title;
  99. }
  100. public function setDescription($description)
  101. {
  102. $this->description = strip_tags($description);
  103. }
  104. public function getDescription()
  105. {
  106. return $this->description;
  107. }
  108. public function setParent($parent)
  109. {
  110. $this->parent = $parent;
  111. }
  112. public function getParent()
  113. {
  114. return $this->parent;
  115. }
  116. public function getRoot()
  117. {
  118. return $this->root;
  119. }
  120. public function getLevel()
  121. {
  122. return $this->level;
  123. }
  124. public function getChildren()
  125. {
  126. return $this->children;
  127. }
  128. public function getLeft()
  129. {
  130. return $this->lft;
  131. }
  132. public function getRight()
  133. {
  134. return $this->rgt;
  135. }
  136. public function getCreated()
  137. {
  138. return $this->created;
  139. }
  140. public function getUpdated()
  141. {
  142. return $this->updated;
  143. }
  144. public function setTranslatableLocale($locale)
  145. {
  146. $this->locale = $locale;
  147. }
  148. public function __toString()
  149. {
  150. return $this->getTitle();
  151. }
  152. }