Tag.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. namespace Muzich\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use \Doctrine\Common\Collections\ArrayCollection;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. /**
  7. * Cet entité représente le Tag.
  8. *
  9. * @ORM\Entity
  10. * @ORM\Table(name="tag")
  11. * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\TagRepository")
  12. * @ORM\HasLifecycleCallbacks()
  13. */
  14. class Tag
  15. {
  16. /**
  17. * @ORM\Id
  18. * @ORM\Column(type="integer")
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. * @var type int
  21. */
  22. protected $id;
  23. /**
  24. * Cet attribu stocke la liste des élèments liés a ce tag.
  25. *
  26. * @ORM\ManyToMany(targetEntity="Element", mappedBy="tags")
  27. */
  28. protected $elements;
  29. /**
  30. * Cet attribu stocke la liste des propositions de tags liés a ce tag.
  31. *
  32. * @ORM\ManyToMany(targetEntity="ElementTagsProposition", mappedBy="tags")
  33. */
  34. protected $propositions;
  35. /**
  36. * Cet attribu stocke les enregistrements UsersTagsFavorites liés
  37. * a ce Tag dans le cadre des Tags favoris de l'user.
  38. *
  39. * @ORM\OneToMany(targetEntity="UsersTagsFavorites", mappedBy="tag")
  40. */
  41. protected $users_favorites;
  42. /**
  43. * Cet attribu stocke les enregistrements GroupsTagsFavorites liés
  44. * a ce Tag dans le cadre des Tags favoris du groupe.
  45. *
  46. * @ORM\OneToMany(targetEntity="GroupsTagsFavorites", mappedBy="tag")
  47. */
  48. protected $groups_favorites;
  49. /**
  50. * Nom du tag
  51. *
  52. * @ORM\Column(type="string", length=64, unique=true, nullable=false)
  53. * @var type string
  54. */
  55. protected $name;
  56. /**
  57. * @Gedmo\Slug(fields={"name"})
  58. * @ORM\Column(length=64, nullable=true)
  59. */
  60. protected $slug;
  61. /**
  62. * Compteur total d'utilisation. Utilisé pour faire ressortir les
  63. * tags les plus utilisés.
  64. *
  65. * @ORM\Column(type="integer")
  66. * @var int
  67. */
  68. protected $count = 0;
  69. /**
  70. * Booléen permettant de savoir si le tag est à modérer
  71. *
  72. * @ORM\Column(type="boolean", nullable=true)
  73. * @var type string
  74. */
  75. protected $tomoderate = false;
  76. /**
  77. * Lorsque le tag est a modérer on stocke ici les ids d'utilisateurs (json)
  78. * qui ont voulu l'utiliser. Afin qu'il n'y est que eux a le voir.
  79. *
  80. * @ORM\Column(type="text", nullable=true)
  81. * @var type string
  82. */
  83. protected $privateids;
  84. /**
  85. * Lorsque le tag est a modérer on stocke ici les argumentations pour
  86. * l'ajout du tag.
  87. *
  88. * @ORM\Column(type="text", nullable=true)
  89. * @var type string
  90. */
  91. protected $arguments;
  92. /**
  93. * @ORM\Column(type="text", nullable=true)
  94. * @var type string
  95. */
  96. protected $like_string;
  97. /**
  98. *
  99. */
  100. public function __construct()
  101. {
  102. $this->users_favorites = new ArrayCollection();
  103. $this->elements = new ArrayCollection();
  104. }
  105. public function __toString()
  106. {
  107. return $this->name;
  108. }
  109. /**
  110. * Get id
  111. *
  112. * @return integer
  113. */
  114. public function getId()
  115. {
  116. return $this->id;
  117. }
  118. /**
  119. * Set name
  120. *
  121. * @param string $name
  122. */
  123. public function setName($name)
  124. {
  125. $this->name = $name;
  126. }
  127. /**
  128. * Get name
  129. *
  130. * @return string
  131. */
  132. public function getName()
  133. {
  134. return $this->name;
  135. }
  136. public function getSlug()
  137. {
  138. return $this->slug;
  139. }
  140. public function setSlug($slug)
  141. {
  142. $this->slug = $slug;
  143. }
  144. /**
  145. * Add elements
  146. *
  147. * @param Element $elements
  148. */
  149. public function addElement(Element $elements)
  150. {
  151. $this->elements[] = $elements;
  152. }
  153. /**
  154. * Get elements
  155. *
  156. * @return Doctrine\Common\Collections\Collection
  157. */
  158. public function getElements()
  159. {
  160. return $this->elements;
  161. }
  162. /**
  163. * Add users_favorites
  164. *
  165. * @param UsersTagsFavorites $usersFavorites
  166. */
  167. public function addUsersTagsFavorites(UsersTagsFavorites $usersFavorites)
  168. {
  169. $this->users_favorites[] = $usersFavorites;
  170. }
  171. /**
  172. * Get users_favorites
  173. *
  174. * @return Doctrine\Common\Collections\Collection
  175. */
  176. public function getUsersFavorites()
  177. {
  178. return $this->users_favorites;
  179. }
  180. /**
  181. * Add groups_favorites
  182. *
  183. * @param GroupsTagsFavorites $groupsFavorites
  184. */
  185. public function addGroupsTagsFavorites(GroupsTagsFavorites $groupsFavorites)
  186. {
  187. $this->groups_favorites[] = $groupsFavorites;
  188. }
  189. /**
  190. * Get groups_favorites
  191. *
  192. * @return Doctrine\Common\Collections\Collection
  193. */
  194. public function getGroupsFavorites()
  195. {
  196. return $this->groups_favorites;
  197. }
  198. public function setTomoderate($tomoderate)
  199. {
  200. $this->tomoderate = $tomoderate;
  201. }
  202. public function getTomoderate()
  203. {
  204. return $this->tomoderate;
  205. }
  206. public function setPrivateids($privateids)
  207. {
  208. $this->privateids = $privateids;
  209. }
  210. public function getPrivateids()
  211. {
  212. return $this->privateids;
  213. }
  214. public function hasIdInPrivateIds($id)
  215. {
  216. foreach (json_decode($this->privateids) as $pid)
  217. {
  218. if ($pid == $id)
  219. {
  220. return true;
  221. }
  222. }
  223. return false;
  224. }
  225. public function getArguments()
  226. {
  227. return $this->arguments;
  228. }
  229. public function setArguments($arguments)
  230. {
  231. $this->arguments = $arguments;
  232. }
  233. public function setLikeString($like_string)
  234. {
  235. $this->like_string = $like_string;
  236. }
  237. public function getLikeString()
  238. {
  239. return $this->like_string;
  240. }
  241. }