UsersTagsFavorites.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace Muzich\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Cette classe représente la relation porteuse entre User et Tag,
  6. * en tant que Tags favoris de l'utilisateur.
  7. *
  8. * @ORM\Entity
  9. * @ORM\Table(name="users_tags_favorites")
  10. * @ORM\HasLifecycleCallbacks
  11. */
  12. class UsersTagsFavorites
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\Column(type="integer")
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. * @var type int
  19. */
  20. protected $id;
  21. /**
  22. * Cet attribut contient l'objet User lié
  23. *
  24. * @ORM\ManyToOne(targetEntity="User", inversedBy="tags_favorites")
  25. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  26. */
  27. protected $user;
  28. /**
  29. * Cet attribut contient l'objet Tag lié
  30. *
  31. * @ORM\ManyToOne(targetEntity="Tag", inversedBy="users_favorites")
  32. * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="CASCADE")
  33. */
  34. protected $tag;
  35. /**
  36. * L'attribut position permet de connaitre l'ordre de préfèrence de
  37. * l'utilisateur.
  38. *
  39. * @ORM\Column(type="integer", nullable=true)
  40. * @var type int
  41. */
  42. protected $position;
  43. /**
  44. * Set position
  45. *
  46. * @param integer $position
  47. */
  48. public function setPosition($position)
  49. {
  50. $this->position = $position;
  51. }
  52. /**
  53. * Get position
  54. *
  55. * @return integer
  56. */
  57. public function getPosition()
  58. {
  59. return $this->position;
  60. }
  61. /**
  62. * Get id
  63. *
  64. * @return integer
  65. */
  66. public function getId()
  67. {
  68. return $this->id;
  69. }
  70. /**
  71. * Set user
  72. *
  73. * @param User $user
  74. */
  75. public function setUser(User $user)
  76. {
  77. $this->user = $user;
  78. }
  79. /**
  80. * Get user
  81. *
  82. * @return User
  83. */
  84. public function getUser()
  85. {
  86. return $this->user;
  87. }
  88. /**
  89. * Set tag
  90. *
  91. * @param Tag $tag
  92. */
  93. public function setTag(Tag $tag)
  94. {
  95. $this->tag = $tag;
  96. }
  97. /**
  98. * Get tag
  99. *
  100. * @return Tag
  101. */
  102. public function getTag()
  103. {
  104. return $this->tag;
  105. }
  106. /**
  107. * @ORM\PrePersist
  108. */
  109. public function prePersist()
  110. {
  111. $this->getUser()->addTagFavoriteQuick($this->getTag());
  112. }
  113. /**
  114. * @ORM\PreRemove
  115. */
  116. public function preRemove()
  117. {
  118. $this->getUser()->removeTagFavoriteQuick($this->getTag());
  119. }
  120. }