User.php 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace Muzich\CoreBundle\Entity;
  3. use FOS\UserBundle\Entity\User as BaseUser;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use \Doctrine\Common\Collections\ArrayCollection;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. /**
  8. * Cet entité est l'utilisateur ayant effectué la requête.
  9. *
  10. * @ORM\Entity
  11. * @ORM\Table(name="m_user")
  12. * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\UserRepository")
  13. */
  14. class User extends BaseUser
  15. {
  16. /**
  17. * @ORM\Id
  18. * @ORM\Column(type="integer")
  19. * @ORM\generatedValue(strategy="AUTO")
  20. */
  21. protected $id;
  22. /**
  23. * @Gedmo\Slug(fields={"username"})
  24. * @ORM\Column(length=128, unique=true)
  25. */
  26. protected $slug;
  27. /**
  28. * Cet attribut contient les enregistrements UsersTagsFavorites lié
  29. * a cet utilisateur dans le cadre des Tags Favoris.
  30. *
  31. * @ORM\OneToMany(targetEntity="UsersTagsFavorites", mappedBy="user")
  32. */
  33. protected $tags_favorites;
  34. /**
  35. * Cet attribut contient les enregistrements UsersElementsFavorites lié
  36. * a cet utilisateur dans le cadre des éléments Favoris.
  37. *
  38. * @ORM\OneToMany(targetEntity="UsersElementsFavorites", mappedBy="user")
  39. */
  40. protected $elements_favorites;
  41. /**
  42. * Liste des Elements appartenant a cet utilisateur.
  43. *
  44. * @ORM\OneToMany(targetEntity="Element", mappedBy="owner")
  45. */
  46. protected $elements;
  47. /**
  48. * Users que cet utilisateur suit.
  49. *
  50. * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="follower")
  51. */
  52. protected $followeds_users;
  53. /**
  54. * Users qui suivent cet utilisateur.
  55. *
  56. * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="followed")
  57. */
  58. protected $followers_users;
  59. /**
  60. * Cet attribut contient les enregistrements FollowGroup lié
  61. * a cet utilisateur dans le cadre des groupes suivis.
  62. *
  63. * @ORM\OneToMany(targetEntity="FollowGroup", mappedBy="follower")
  64. */
  65. protected $followed_groups;
  66. /**
  67. * Liste des Groupes appartenant a cet utilisateur.
  68. *
  69. * @ORM\OneToMany(targetEntity="Group", mappedBy="owner")
  70. */
  71. protected $groups_owned;
  72. /**
  73. *
  74. */
  75. public function __construct()
  76. {
  77. $this->tags_favorites = new ArrayCollection();
  78. $this->elements = new ArrayCollection();
  79. $this->elements_favorites = new ArrayCollection();
  80. $this->followeds_users = new ArrayCollection();
  81. $this->followers_users = new ArrayCollection();
  82. $this->followed_groups = new ArrayCollection();
  83. $this->groups = new ArrayCollection();
  84. parent::__construct();
  85. }
  86. /**
  87. * Get id
  88. *
  89. * @return integer
  90. */
  91. public function getId()
  92. {
  93. return $this->id;
  94. }
  95. /**
  96. * Get tags_favorites
  97. *
  98. * @return Doctrine\Common\Collections\Collection
  99. */
  100. public function getTagsFavorites()
  101. {
  102. return $this->tags_favorites;
  103. }
  104. /**
  105. * Add tags_favorites
  106. *
  107. * @param UsersTagsFavorites $tagsFavorites
  108. */
  109. public function addUsersTagsFavorites(UsersTagsFavorites $tagsFavorites)
  110. {
  111. $this->tags_favorites[] = $tagsFavorites;
  112. }
  113. /**
  114. * Add elements_favorites
  115. *
  116. * @param UsersElementsFavorites $elementsFavorites
  117. */
  118. public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
  119. {
  120. $this->elements_favorites[] = $elementsFavorites;
  121. }
  122. /**
  123. * Get elements_favorites
  124. *
  125. * @return Doctrine\Common\Collections\Collection
  126. */
  127. public function getElementsFavorites()
  128. {
  129. return $this->elements_favorites;
  130. }
  131. /**
  132. * Add elements
  133. *
  134. * @param Element $elements
  135. */
  136. public function addElement(Element $elements)
  137. {
  138. $this->elements[] = $elements;
  139. }
  140. /**
  141. * Get elements
  142. *
  143. * @return Doctrine\Common\Collections\Collection
  144. */
  145. public function getElements()
  146. {
  147. return $this->elements;
  148. }
  149. /**
  150. * Add followeds_users
  151. *
  152. * @param FollowUser $followedsUsers
  153. */
  154. public function addFollowUser(FollowUser $followedsUsers)
  155. {
  156. $this->followeds_users[] = $followedsUsers;
  157. }
  158. /**
  159. * Get followeds_users
  160. *
  161. * @return Doctrine\Common\Collections\Collection
  162. */
  163. public function getFollowedsUsers()
  164. {
  165. $users = array();
  166. foreach ($this->followeds_users as $follow_user)
  167. {
  168. $users[] = $follow_user->getFollowed();
  169. }
  170. return $users;
  171. }
  172. /**
  173. * Get followers_users
  174. *
  175. * @return Doctrine\Common\Collections\Collection
  176. */
  177. public function getFollowersUsers()
  178. {
  179. $users = array();
  180. foreach ($this->followers_users as $follow_user)
  181. {
  182. $users[] = $follow_user->getFollower();
  183. }
  184. return $users;
  185. }
  186. /**
  187. * Add followed_groups
  188. *
  189. * @param FollowGroup $followedGroups
  190. */
  191. public function addFollowGroup(FollowGroup $followedGroups)
  192. {
  193. $this->followed_groups[] = $followedGroups;
  194. }
  195. /**
  196. * Get followed_groups
  197. *
  198. * @return Doctrine\Common\Collections\Collection
  199. */
  200. public function getFollowedGroups()
  201. {
  202. $groups = array();
  203. foreach ($this->followed_groups as $follow_group)
  204. {
  205. $groups[] = $follow_group->getGroup();
  206. }
  207. return $groups;
  208. }
  209. /**
  210. * Add groups
  211. *
  212. * @param Group $groups
  213. */
  214. public function addGroupOwned(Group $groups)
  215. {
  216. $this->groups[] = $groups;
  217. }
  218. /**
  219. * Get groups
  220. *
  221. * @return Doctrine\Common\Collections\Collection
  222. */
  223. public function getGroupsOnwed()
  224. {
  225. return $this->groups;
  226. }
  227. public function getSlug()
  228. {
  229. return $this->slug;
  230. }
  231. public function setSlug($slug)
  232. {
  233. $this->slug = $slug;
  234. }
  235. /*
  236. *
  237. *
  238. */
  239. public function getName()
  240. {
  241. return $this->getUsername();
  242. }
  243. /**
  244. * Retourn si l'user_id transmis fait partis des enregistrements
  245. * followed de l'objet.
  246. *
  247. * @param int $user_id
  248. * @return boolean
  249. */
  250. public function isFollowingUser($user_id)
  251. {
  252. foreach ($this->followeds_users as $followed_user)
  253. {
  254. if ($followed_user->getFollowed()->getId() == $user_id)
  255. {
  256. return true;
  257. }
  258. }
  259. return false;
  260. }
  261. /**
  262. * Retourn si l'user_id transmis est l'un des User suivis
  263. *
  264. * @param Symfony\Bundle\DoctrineBundle\Registry doctrine
  265. * @param int $user_id
  266. * @return boolean
  267. */
  268. public function isFollowingUserByQuery($doctrine, $user_id)
  269. {
  270. return $doctrine
  271. ->getRepository('MuzichCoreBundle:User')
  272. ->isFollowingUser($this->getId(), $user_id)
  273. ;
  274. }
  275. /**
  276. * Retourn si l'group_id transmis est l'un des groupe suivis
  277. *
  278. * @param Symfony\Bundle\DoctrineBundle\Registry doctrine
  279. * @param int $user_id
  280. * @return boolean
  281. */
  282. public function isFollowingGroupByQuery($doctrine, $group_id)
  283. {
  284. return $doctrine
  285. ->getRepository('MuzichCoreBundle:User')
  286. ->isFollowingGroup($this->getId(), $group_id)
  287. ;
  288. }
  289. }