User.php 26KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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 \Doctrine\Common\Collections\Collection;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Doctrine\ORM\EntityManager;
  9. use Muzich\CoreBundle\Entity\UsersTagsFavorites;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Muzich\CoreBundle\Validator as MuzichAssert;
  12. use Muzich\CoreBundle\Entity\ElementTagsProposition;
  13. use Muzich\CoreBundle\Entity\Tag;
  14. /**
  15. * Cet entité est l'utilisateur ayant effectué la requête.
  16. *
  17. * @ORM\Entity
  18. * @ORM\Table(name="m_user")
  19. * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\UserRepository")
  20. * @ORM\HasLifecycleCallbacks()
  21. */
  22. class User extends BaseUser
  23. {
  24. /**
  25. * Data ordre des tags de sa page favoris
  26. * @var string
  27. */
  28. const DATA_TAGS_ORDER_PAGE_FAV = "data_tags_order_page_fav";
  29. /**
  30. * Data ordre des tags de ses diffusions
  31. * @var string
  32. */
  33. const DATA_TAGS_ORDER_DIFF = "data_tags_order_diff";
  34. /**
  35. * Data, les favoris ont ils été modifiés
  36. * @var string
  37. */
  38. const DATA_FAV_UPDATED = "data_fav_updated";
  39. /**
  40. * Data, les favoris ont ils été modifiés
  41. * @var string
  42. */
  43. const DATA_DIFF_UPDATED = "data_diff_updated";
  44. const HELP_TOUR_HOME = "home";
  45. /**
  46. * @ORM\Id
  47. * @ORM\Column(type="integer")
  48. * @ORM\GeneratedValue(strategy="AUTO")
  49. */
  50. protected $id;
  51. /**
  52. * @Gedmo\Slug(fields={"username"})
  53. * @ORM\Column(length=128, unique=true)
  54. */
  55. protected $slug;
  56. /**
  57. * @ORM\Column(type="text", nullable=true)
  58. * @ORM\Column(length=256)
  59. */
  60. protected $email_requested;
  61. /**
  62. * @ORM\Column(type="integer", nullable=true)
  63. */
  64. protected $email_requested_datetime;
  65. /**
  66. * Cet attribut contient les enregistrements UsersTagsFavorites lié
  67. * a cet utilisateur dans le cadre des Tags Favoris.
  68. *
  69. * @ORM\OneToMany(targetEntity="UsersTagsFavorites", mappedBy="user")
  70. */
  71. protected $tags_favorites;
  72. /**
  73. * @ORM\OneToMany(targetEntity="UserPlaylistPicked", mappedBy="user")
  74. */
  75. protected $user_playlists_pickeds;
  76. /**
  77. * Cet attribut contient les enregistrements UsersElementsFavorites lié
  78. * a cet utilisateur dans le cadre des éléments Favoris.
  79. *
  80. * @ORM\OneToMany(targetEntity="UsersElementsFavorites", mappedBy="user")
  81. */
  82. protected $elements_favorites;
  83. /**
  84. * Liste des Elements appartenant a cet utilisateur.
  85. *
  86. * @ORM\OneToMany(targetEntity="Element", mappedBy="owner")
  87. */
  88. protected $elements;
  89. /**
  90. * Liste des propositions de tags effectués par cet utilisateur
  91. *
  92. * @ORM\OneToMany(targetEntity="ElementTagsProposition", mappedBy="user")
  93. */
  94. protected $element_tags_propositions;
  95. /**
  96. * Users que cet utilisateur suit.
  97. *
  98. * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="follower")
  99. */
  100. protected $followeds_users;
  101. /**
  102. * Users qui suivent cet utilisateur.
  103. *
  104. * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="followed")
  105. */
  106. protected $followers_users;
  107. /**
  108. * Cet attribut contient les enregistrements FollowGroup lié
  109. * a cet utilisateur dans le cadre des groupes suivis.
  110. *
  111. * @ORM\OneToMany(targetEntity="FollowGroup", mappedBy="follower")
  112. */
  113. protected $followed_groups;
  114. /**
  115. * Liste des Groupes appartenant a cet utilisateur.
  116. *
  117. * @ORM\OneToMany(targetEntity="Group", mappedBy="owner")
  118. */
  119. protected $groups_owned;
  120. /**
  121. * @ORM\OneToMany(targetEntity="Playlist", mappedBy="owner")
  122. */
  123. protected $playlists_owneds;
  124. /**
  125. * @ORM\Column(type="integer", nullable=true)
  126. * @var int
  127. */
  128. protected $bad_count;
  129. /**
  130. * Compteur de signalements inutiles
  131. *
  132. * @ORM\Column(type="integer", nullable=true)
  133. * @var int
  134. */
  135. protected $bad_report_count;
  136. /**
  137. * Compteur de contenus refusés par la modération
  138. *
  139. * @ORM\Column(type="integer", nullable=true)
  140. * @var int
  141. */
  142. protected $moderated_element_count;
  143. /**
  144. * Compteur de contenus refusés par la modération
  145. *
  146. * @ORM\Column(type="integer", nullable=true)
  147. * @var int
  148. */
  149. protected $moderated_tag_count;
  150. /**
  151. * Compteur de contenus refusés par la modération
  152. *
  153. * @ORM\Column(type="integer", nullable=true)
  154. * @var int
  155. */
  156. protected $moderated_comment_count;
  157. /**
  158. * @ORM\Column(type="text", nullable=true)
  159. * @ORM\Column(length=256)
  160. */
  161. protected $town;
  162. /**
  163. * @ORM\Column(type="text", nullable=true)
  164. * @ORM\Column(length=128)
  165. */
  166. protected $country;
  167. /**
  168. * Reputation
  169. *
  170. * @ORM\Column(type="integer", nullable=true)
  171. * @var int
  172. */
  173. protected $reputation;
  174. /**
  175. * Liste des Events appartenant a cet utilisateur.
  176. *
  177. * @ORM\OneToMany(targetEntity="Event", mappedBy="user")
  178. */
  179. protected $events;
  180. /**
  181. * Contient des données pratique pour par exemple influencer l'affichange dans twig.
  182. *
  183. * @var array
  184. */
  185. protected $live_datas = array();
  186. /**
  187. * Contient des données pratique, comme l'ordre des tags de sa page favoris etc.
  188. *
  189. * @ORM\Column(type="text", nullable=true)
  190. * @var type string
  191. */
  192. protected $datas = null;
  193. /**
  194. * Tableau contenant les id => name des tags favoris
  195. * de l'user. Ces donnée sont faites pour optimiser les calculs.
  196. * Ce chamsp est mis ajour a chaque fois qu'un UsersTagsFavorite est manipulé.
  197. *
  198. * @ORM\Column(type="text", unique=false, nullable=true)
  199. * @var array
  200. */
  201. private $tags_favorites_quick;
  202. /**
  203. * @Assert\Image(maxSize="6000000")
  204. */
  205. public $avatar;
  206. /**
  207. * @ORM\Column(type="text", length=255, nullable=true)
  208. */
  209. public $avatar_path;
  210. /**
  211. * @ORM\Column(type="text", unique=false, nullable=true)
  212. * @var array
  213. */
  214. private $help_tour;
  215. /**
  216. * @ORM\Column(type="boolean")
  217. * @Assert\NotBlank()
  218. * @var type boolean
  219. */
  220. public $cgu_accepted = false;
  221. /**
  222. * @ORM\Column(type="boolean")
  223. * @var type boolean
  224. */
  225. public $mail_newsletter = true;
  226. /**
  227. * @ORM\Column(type="boolean")
  228. * @var type boolean
  229. */
  230. public $mail_partner = true;
  231. /**
  232. * @ORM\Column(type="boolean", nullable=true)
  233. * @var type boolean
  234. */
  235. private $username_updatable = false;
  236. /**
  237. * @ORM\Column(type="boolean", nullable=false)
  238. * @var type boolean
  239. */
  240. private $email_confirmed = true;
  241. /**
  242. * @ORM\Column(type="integer")
  243. */
  244. protected $email_confirmation_sent_timestamp = 0;
  245. /**
  246. * @ORM\Column(type="boolean", nullable=false)
  247. * @var type boolean
  248. */
  249. private $password_set = true;
  250. /** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
  251. protected $facebook_id;
  252. /**
  253. *
  254. */
  255. public function __construct()
  256. {
  257. $this->tags_favorites = new ArrayCollection();
  258. $this->elements = new ArrayCollection();
  259. $this->elements_favorites = new ArrayCollection();
  260. $this->followeds_users = new ArrayCollection();
  261. $this->followers_users = new ArrayCollection();
  262. $this->followed_groups = new ArrayCollection();
  263. $this->groups = new ArrayCollection();
  264. $this->groups_owned = new ArrayCollection();
  265. $this->user_playlists_pickeds = new ArrayCollection();
  266. $this->playlists_owneds = new ArrayCollection();
  267. $this->help_tour = json_encode(array(
  268. self::HELP_TOUR_HOME => true
  269. ));
  270. parent::__construct();
  271. }
  272. public function __toString()
  273. {
  274. return $this->getName();
  275. }
  276. /**
  277. * Get id
  278. *
  279. * @return integer
  280. */
  281. public function getId()
  282. {
  283. return $this->id;
  284. }
  285. /**
  286. * Get tags_favorites
  287. *
  288. * @return Doctrine\Common\Collections\Collection
  289. */
  290. public function getTagsFavorites()
  291. {
  292. return $this->tags_favorites;
  293. }
  294. /**
  295. * Add tags_favorites
  296. *
  297. * @param UsersTagsFavorites $tagsFavorites
  298. */
  299. public function addUsersTagsFavorites(UsersTagsFavorites $tagsFavorites)
  300. {
  301. $this->tags_favorites[] = $tagsFavorites;
  302. }
  303. /**
  304. * Add elements_favorites
  305. *
  306. * @param UsersElementsFavorites $elementsFavorites
  307. */
  308. public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
  309. {
  310. $this->elements_favorites[] = $elementsFavorites;
  311. }
  312. /**
  313. * Get elements_favorites
  314. *
  315. * @return Doctrine\Common\Collections\Collection
  316. */
  317. public function getElementsFavorites()
  318. {
  319. return $this->elements_favorites;
  320. }
  321. /**
  322. * Add elements
  323. *
  324. * @param Element $elements
  325. */
  326. public function addElement(Element $elements)
  327. {
  328. $this->elements[] = $elements;
  329. }
  330. /**
  331. * Get elements
  332. *
  333. * @return Doctrine\Common\Collections\Collection
  334. */
  335. public function getElements()
  336. {
  337. return $this->elements;
  338. }
  339. /**
  340. * Add elements
  341. *
  342. * @param Element $elements
  343. */
  344. public function addElementTagsProposition(ElementTagsProposition $proposition)
  345. {
  346. $this->element_tags_propositions[] = $proposition;
  347. }
  348. /**
  349. * Get elements
  350. *
  351. * @return Doctrine\Common\Collections\Collection
  352. */
  353. public function getElementTagsPropositions()
  354. {
  355. return $this->element_tags_propositions;
  356. }
  357. /**
  358. * Add followeds_users
  359. *
  360. * @param FollowUser $followedsUsers
  361. */
  362. public function addFollowUser(FollowUser $followedsUsers)
  363. {
  364. $this->followeds_users[] = $followedsUsers;
  365. }
  366. /**
  367. * Get followeds_users
  368. *
  369. * @return Doctrine\Common\Collections\Collection
  370. */
  371. public function getFollowedsUsers()
  372. {
  373. $users = array();
  374. foreach ($this->followeds_users as $follow_user)
  375. {
  376. $users[] = $follow_user->getFollowed();
  377. }
  378. return $users;
  379. }
  380. /**
  381. * Get followers_users
  382. *
  383. * @return Doctrine\Common\Collections\Collection
  384. */
  385. public function getFollowersUsers()
  386. {
  387. $users = array();
  388. foreach ($this->followers_users as $follow_user)
  389. {
  390. $users[] = $follow_user->getFollower();
  391. }
  392. return $users;
  393. }
  394. /**
  395. * Add followed_groups
  396. *
  397. * @param FollowGroup $followedGroups
  398. */
  399. public function addFollowGroup(FollowGroup $followedGroups)
  400. {
  401. $this->followed_groups[] = $followedGroups;
  402. }
  403. /**
  404. * Get followed_groups
  405. *
  406. * @return Doctrine\Common\Collections\Collection
  407. */
  408. public function getFollowedGroups()
  409. {
  410. $groups = array();
  411. foreach ($this->followed_groups as $follow_group)
  412. {
  413. $groups[] = $follow_group->getGroup();
  414. }
  415. return $groups;
  416. }
  417. /**
  418. * Add groups
  419. *
  420. * @param Group $groups
  421. */
  422. public function addGroupOwned(Group $groups)
  423. {
  424. $this->groups[] = $groups;
  425. }
  426. /**
  427. * Get groups
  428. *
  429. * @return Doctrine\Common\Collections\Collection
  430. */
  431. public function getGroupsOwned()
  432. {
  433. return $this->groups_owned;
  434. }
  435. /**
  436. * Get groups in array (id => name)
  437. *
  438. * @return Doctrine\Common\Collections\Collection
  439. */
  440. public function getGroupsOwnedArray()
  441. {
  442. $groups = array();
  443. foreach ($this->groups_owned as $group)
  444. {
  445. $groups[$group->getId()] = $group->getName();
  446. }
  447. return $groups;
  448. }
  449. public function getSlug()
  450. {
  451. return $this->slug;
  452. }
  453. public function setSlug($slug)
  454. {
  455. $this->slug = $slug;
  456. }
  457. public function getEmailRequested()
  458. {
  459. return $this->email_requested;
  460. }
  461. public function setEmailRequested($email_requested)
  462. {
  463. $this->email_requested = $email_requested;
  464. }
  465. public function getBadReportCount()
  466. {
  467. return $this->bad_report_count;
  468. }
  469. public function setBadReportCount($count)
  470. {
  471. $this->bad_report_count = $count;
  472. $this->updateBadCount();
  473. }
  474. public function addBadReport()
  475. {
  476. $this->setBadReportCount($this->getBadReportCount()+1);
  477. }
  478. public function getTown()
  479. {
  480. return $this->town;
  481. }
  482. public function setTown($town)
  483. {
  484. $this->town = $town;
  485. }
  486. public function getCountry()
  487. {
  488. return $this->country;
  489. }
  490. public function setCountry($country)
  491. {
  492. $this->country = $country;
  493. }
  494. public function setReputation($reputation)
  495. {
  496. $this->reputation = $reputation;
  497. }
  498. public function getReputation()
  499. {
  500. if ($this->reputation === null)
  501. {
  502. return 0;
  503. }
  504. return $this->reputation;
  505. }
  506. public function getEvents()
  507. {
  508. return $this->events;
  509. }
  510. public function setEvents($events)
  511. {
  512. $this->events = $events;
  513. }
  514. public function getModeratedElementCount()
  515. {
  516. if ($this->moderated_element_count === null)
  517. {
  518. return 0;
  519. }
  520. return $this->moderated_element_count;
  521. }
  522. public function setModeratedElementCount($count)
  523. {
  524. $this->moderated_element_count = $count;
  525. $this->updateBadCount();
  526. }
  527. public function addModeratedElementCount()
  528. {
  529. $this->setModeratedElementCount($this->getModeratedElementCount()+1);
  530. }
  531. public function getModeratedTagCount()
  532. {
  533. if ($this->moderated_tag_count === null)
  534. {
  535. return 0;
  536. }
  537. return $this->moderated_tag_count;
  538. }
  539. public function setModeratedTagCount($count)
  540. {
  541. $this->moderated_tag_count = $count;
  542. $this->updateBadCount();
  543. }
  544. public function addModeratedTagCount()
  545. {
  546. $this->setModeratedTagCount($this->getModeratedTagCount()+1);
  547. }
  548. public function getModeratedCommentCount()
  549. {
  550. if ($this->moderated_comment_count === null)
  551. {
  552. return 0;
  553. }
  554. return $this->moderated_comment_count;
  555. }
  556. public function setModeratedCommentCount($count)
  557. {
  558. $this->moderated_comment_count = $count;
  559. $this->updateBadCount();
  560. }
  561. public function addModeratedCommentCount()
  562. {
  563. $this->setModeratedCommentCount($this->getModeratedCommentCount()+1);
  564. }
  565. /*
  566. *
  567. *
  568. */
  569. public function getName()
  570. {
  571. return $this->getUsername();
  572. }
  573. // public function getLocalisationExploded()
  574. // {
  575. // $town = null;
  576. // $country = null;
  577. // if ($this->localisation)
  578. // {
  579. // if (($explode = explode(', ', $this->localisation)))
  580. // {
  581. // $town = $explode[0];
  582. // $country = $explode[1];
  583. // }
  584. // }
  585. // return array(
  586. // 'town' => $town,
  587. // 'country' => $country
  588. // );
  589. // }
  590. //
  591. // public function setLocalisationExploded($town, $country)
  592. // {
  593. // $town = str_replace(', ', '', $town);
  594. // $town = str_replace(',', '', $town);
  595. // $country = str_replace(', ', '', $country);
  596. // $country = str_replace(',', '', $country);
  597. //
  598. // $this->localisation = $town. ', ' .$country;
  599. // }
  600. // /**
  601. // * @ORM\PrePersist
  602. // */
  603. // public function setSlug()
  604. // {
  605. // if (!$this->slug)
  606. // {
  607. //
  608. // }
  609. // }
  610. //
  611. /**
  612. * Retourn si l'user_id transmis fait partis des enregistrements
  613. * followed de l'objet.
  614. *
  615. * @param int $user_id
  616. * @return boolean
  617. */
  618. public function isFollowingUser($user_id)
  619. {
  620. foreach ($this->followeds_users as $followed_user)
  621. {
  622. if ($followed_user->getFollowed()->getId() == $user_id)
  623. {
  624. return true;
  625. }
  626. }
  627. return false;
  628. }
  629. /**
  630. * Retourn si l'user_id transmis est l'un des User suivis
  631. *
  632. * @param Doctrine\Bundle\DoctrineBundle\Registry doctrine
  633. * @param int $user_id
  634. * @return boolean
  635. */
  636. public function isFollowingUserByQuery($doctrine, $user_id)
  637. {
  638. return $doctrine
  639. ->getRepository('MuzichCoreBundle:User')
  640. ->isFollowingUser($this->getId(), $user_id)
  641. ;
  642. }
  643. /**
  644. * Retourn si l'group_id transmis est l'un des groupe suivis
  645. *
  646. * @param Doctrine\Bundle\DoctrineBundle\Registry doctrine
  647. * @param int $user_id
  648. * @return boolean
  649. */
  650. public function isFollowingGroupByQuery($doctrine, $group_id)
  651. {
  652. return $doctrine
  653. ->getRepository('MuzichCoreBundle:User')
  654. ->isFollowingGroup($this->getId(), $group_id)
  655. ;
  656. }
  657. public function getPersonalHash($salt_context = null)
  658. {
  659. return hash('sha256', $this->getSalt().$this->getUsername().$salt_context);
  660. }
  661. /**
  662. * Ajoute a l'user les tags transmis (id) comme favoris.
  663. *
  664. * @param EntityManager $em
  665. * @param array $ids
  666. */
  667. public function updateTagsFavoritesById(EntityManager $em, $ids)
  668. {
  669. $ids = json_decode($ids);
  670. $ids_to_add = $ids;
  671. // Pour chacun des tags favoris
  672. foreach ($this->tags_favorites as $ii => $tag_favorite)
  673. {
  674. $trouve = false;
  675. foreach ($ids as $i => $id)
  676. {
  677. if ($id == $tag_favorite->getTag()->getId())
  678. {
  679. $trouve = true;
  680. // Si le tag était favoris déjà avant (et aussi maintenant)
  681. // il ne sera ni a ajouter, ni a supprimer.
  682. unset($ids_to_add[$i]);
  683. }
  684. }
  685. if (!$trouve)
  686. {
  687. // Si cet ancien tag n'est plus dans la liste, il faut le supprimer
  688. // (rappel: on supprime ici la relation, pas le tag)
  689. $em->remove($tag_favorite);
  690. }
  691. }
  692. if (count($ids_to_add))
  693. {
  694. $ids_to_add = array_merge($ids_to_add);
  695. $tag_favorite_position_max = $this->getTagFavoritePositionMax();
  696. $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids_to_add)->execute();
  697. // Pour les nouveaux ids restants
  698. foreach ($tags as $tag)
  699. {
  700. $tag_favorite = new UsersTagsFavorites();
  701. $tag_favorite->setUser($this);
  702. $tag_favorite->setTag($tag);
  703. $tag_favorite->setPosition($tag_favorite_position_max);
  704. $tag_favorite_position_max++;
  705. $this->addUsersTagsFavorites($tag_favorite);
  706. $em->persist($tag_favorite);
  707. }
  708. }
  709. $em->flush();
  710. }
  711. /**
  712. * Retourne un tableau contenant les ids des tags préférés de l'user
  713. *
  714. * @return type array
  715. */
  716. public function getTagFavoriteIds()
  717. {
  718. $ids = array();
  719. foreach ($this->tags_favorites as $tag_favorite)
  720. {
  721. $ids[$tag_favorite->getTag()->getId()] = $tag_favorite->getTag()->getId();
  722. }
  723. return $ids;
  724. }
  725. /**
  726. * Retourne la position max des tag favoris.
  727. *
  728. * @return int
  729. */
  730. public function getTagFavoritePositionMax()
  731. {
  732. $max = 0;
  733. foreach ($this->tags_favorites as $tag_favorite)
  734. {
  735. if ($tag_favorite->getPosition() > $max)
  736. {
  737. $max = $tag_favorite->getPosition();
  738. }
  739. }
  740. return $max;
  741. }
  742. /**
  743. * Set email_requested_datetime
  744. *
  745. * @param integer $emailRequestedDatetime
  746. */
  747. public function setEmailRequestedDatetime($emailRequestedDatetime)
  748. {
  749. $this->email_requested_datetime = $emailRequestedDatetime;
  750. }
  751. /**
  752. * Get email_requested_datetime
  753. *
  754. * @return integer
  755. */
  756. public function getEmailRequestedDatetime()
  757. {
  758. return $this->email_requested_datetime;
  759. }
  760. public function addLiveData($id, $data)
  761. {
  762. $this->live_datas[$id] = $data;
  763. }
  764. public function removeLiveData($id)
  765. {
  766. if (array_key_exists($id, $this->live_datas))
  767. {
  768. unset($this->live_datas[$id]);
  769. }
  770. }
  771. public function hasLiveData($id, $data = null)
  772. {
  773. if (array_key_exists($id, $this->live_datas))
  774. {
  775. if ($this->live_datas[$id] == $data)
  776. {
  777. return true;
  778. }
  779. }
  780. return false;
  781. }
  782. public function getTagsFavoritesQuick()
  783. {
  784. if ($this->tags_favorites_quick == null)
  785. {
  786. return array();
  787. }
  788. return json_decode($this->tags_favorites_quick, true);
  789. }
  790. /**
  791. *
  792. * @param array $tags_favorites_quick (id => name)
  793. */
  794. public function setTagsFavoritesQuick($tags_favorites_quick)
  795. {
  796. $this->tags_favorites_quick = json_encode($tags_favorites_quick);
  797. }
  798. /**
  799. *
  800. * @param \Muzich\CoreBundle\Entity\Tag $tag
  801. */
  802. public function addTagFavoriteQuick(Tag $tag)
  803. {
  804. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  805. if (!array_key_exists($tag->getId(), $tags_favorites_quick))
  806. {
  807. $tags_favorites_quick[$tag->getId()] = $tag->getName();
  808. }
  809. $this->setTagsFavoritesQuick($tags_favorites_quick);
  810. }
  811. /**
  812. *
  813. * @param \Muzich\CoreBundle\Entity\Tag $tag
  814. */
  815. public function removeTagFavoriteQuick(Tag $tag)
  816. {
  817. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  818. if (array_key_exists($tag->getId(), $tags_favorites_quick))
  819. {
  820. unset($tags_favorites_quick[$tag->getId()]);
  821. }
  822. $this->setTagsFavoritesQuick($tags_favorites_quick);
  823. }
  824. /**
  825. * Retourne vrai si le tag_id transmis fait partis des tags favoris de
  826. * l'utilisateur
  827. *
  828. * @param int $tag_id
  829. * @return boolean
  830. */
  831. public function haveTagsFavorite($tag_id)
  832. {
  833. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  834. if (array_key_exists($tag_id, $tags_favorites_quick))
  835. {
  836. return true;
  837. }
  838. return false;
  839. }
  840. /**
  841. *
  842. * @return type array
  843. */
  844. public function getDatas()
  845. {
  846. if ($this->datas === null)
  847. {
  848. return array();
  849. }
  850. return json_decode($this->datas, true);
  851. }
  852. /**
  853. *
  854. * @param string $data_id
  855. * @param ~ $default
  856. * @return all
  857. */
  858. public function getData($data_id, $default)
  859. {
  860. $datas = $this->getDatas();
  861. if (array_key_exists($data_id, $datas))
  862. {
  863. return $datas[$data_id];
  864. }
  865. return $default;
  866. }
  867. /**
  868. *
  869. * @param array $datas
  870. */
  871. public function setDatas($datas)
  872. {
  873. $this->datas = json_encode($datas);
  874. }
  875. /**
  876. *
  877. * @param string $data_id
  878. * @param all $data_value
  879. */
  880. public function setData($data_id, $data_value)
  881. {
  882. $datas = $this->getDatas();
  883. $datas[$data_id] = $data_value;
  884. $this->setDatas($datas);
  885. }
  886. public function getAvatarAbsolutePath()
  887. {
  888. return null === $this->avatar_path
  889. ? null
  890. : $this->getAvatarUploadRootDir().'/'.$this->avatar_path;
  891. }
  892. public function getAvatarWebPath()
  893. {
  894. return null === $this->avatar_path
  895. ? null
  896. : $this->getAvatarUploadDir().'/'.$this->avatar_path;
  897. }
  898. protected function getAvatarUploadRootDir()
  899. {
  900. return __DIR__.'/../../../../web/'.$this->getAvatarUploadDir();
  901. }
  902. protected function getAvatarUploadDir()
  903. {
  904. return 'files/avatars';
  905. }
  906. /**
  907. * @ORM\PrePersist()
  908. * @ORM\PreUpdate()
  909. */
  910. public function preUploadAvatar()
  911. {
  912. if (null !== $this->avatar) {
  913. $this->avatar_path = $this->getPersonalHash($this->avatar->getClientOriginalName()).'.'.$this->avatar->guessExtension();
  914. }
  915. }
  916. /**
  917. * @ORM\PostPersist()
  918. * @ORM\PostUpdate()
  919. */
  920. public function uploadAvatar()
  921. {
  922. if (null === $this->avatar) {
  923. return;
  924. }
  925. $this->avatar->move($this->getAvatarUploadRootDir(), $this->avatar_path);
  926. $this->avatar = null;
  927. }
  928. /**
  929. * @ORM\PostRemove()
  930. */
  931. public function removeUpload()
  932. {
  933. if ($file = $this->getAvatarAbsolutePath()) {
  934. unlink($file);
  935. }
  936. }
  937. public function getCguAccepted()
  938. {
  939. return $this->cgu_accepted;
  940. }
  941. public function setCguAccepted($accepted)
  942. {
  943. if ($accepted)
  944. $this->cgu_accepted = true;
  945. else
  946. $this->cgu_accepted = false;
  947. }
  948. public function getMailNewsletter()
  949. {
  950. return $this->mail_newsletter;
  951. }
  952. public function getMailPartner()
  953. {
  954. return $this->mail_partner;
  955. }
  956. public function getHelpTour()
  957. {
  958. return json_decode($this->help_tour, true);
  959. }
  960. public function setHelpTour($help_tour)
  961. {
  962. $this->help_tour = json_encode($help_tour);
  963. }
  964. public function wantSeeHelp($help_id)
  965. {
  966. $help_tour_status = $this->getHelpTour();
  967. if (array_key_exists($help_id, $help_tour_status))
  968. {
  969. return $help_tour_status[$help_id];
  970. }
  971. return false;
  972. }
  973. public function setSeeHelp($help_id, $boolean)
  974. {
  975. $help_tour_status = $this->getHelpTour();
  976. if (array_key_exists($help_id, $help_tour_status))
  977. {
  978. $help_tour_status[$help_id] = ($boolean)?true:false;
  979. }
  980. $this->setHelpTour($help_tour_status);
  981. }
  982. public function getBadCount()
  983. {
  984. if (is_null($this->bad_count))
  985. {
  986. return 0;
  987. }
  988. return $this->bad_count;
  989. }
  990. public function updateBadCount()
  991. {
  992. $this->bad_count = $this->getBadReportCount()
  993. + $this->getModeratedCommentCount()
  994. + $this->getModeratedElementCount()
  995. + $this->getModeratedTagCount()
  996. ;
  997. }
  998. public function setUsernameUpdatable($updatable)
  999. {
  1000. if ($updatable)
  1001. $this->username_updatable = true;
  1002. else
  1003. $this->username_updatable = false;
  1004. }
  1005. public function isUsernameUpdatable()
  1006. {
  1007. if ($this->username_updatable)
  1008. return true;
  1009. return false;
  1010. }
  1011. public function isEmailConfirmed()
  1012. {
  1013. return ($this->email_confirmed)?true:false;
  1014. }
  1015. public function setEmailConfirmed($confirmed)
  1016. {
  1017. $this->email_confirmed = ($confirmed)?true:false;
  1018. }
  1019. public function setEmailConfirmationSentTimestamp($timestamp)
  1020. {
  1021. $this->email_confirmation_sent_timestamp = $timestamp;
  1022. }
  1023. public function getEmailConfirmationSentTimestamp()
  1024. {
  1025. return $this->email_confirmation_sent_timestamp;
  1026. }
  1027. public function isPasswordSet()
  1028. {
  1029. return ($this->password_set)?true:false;
  1030. }
  1031. public function setPasswordSet($set)
  1032. {
  1033. $this->password_set = ($set)?true:false;
  1034. }
  1035. public function setPlainPassword($password)
  1036. {
  1037. parent::setPlainPassword($password);
  1038. $this->setPasswordSet(true);
  1039. }
  1040. /** @return void */
  1041. public function setFacebookId($facebook_id)
  1042. {
  1043. $this->facebook_id = $facebook_id;
  1044. $this->password_set = true;
  1045. $this->setEmailConfirmed(true);
  1046. }
  1047. /** @return string */
  1048. public function getFacebookId()
  1049. {
  1050. return $this->facebook_id;
  1051. }
  1052. /** @param Array */
  1053. public function setFBData($fbdata) // C'est dans cette méthode que vous ajouterez vos informations
  1054. {
  1055. if (isset($fbdata['id'])) {
  1056. $this->setFacebookId($fbdata['id']);
  1057. $this->addRole('ROLE_FACEBOOK');
  1058. }
  1059. if (isset($fbdata['email'])) {
  1060. $this->setEmail($fbdata['email']);
  1061. }
  1062. }
  1063. public function getUserPlaylistsPickeds()
  1064. {
  1065. return $this->user_playlists_pickeds;
  1066. }
  1067. public function setUserPlaylistsPickeds(Collection $user_playlists_pickeds)
  1068. {
  1069. $this->user_playlists_pickeds = $user_playlists_pickeds;
  1070. }
  1071. public function havePlaylistPicked(Playlist $playlist)
  1072. {
  1073. foreach ($this->getPickedsPlaylists() as $playlist_picked)
  1074. {
  1075. if ($playlist_picked->getId() == $playlist->getId())
  1076. {
  1077. return true;
  1078. }
  1079. }
  1080. return false;
  1081. }
  1082. public function getPickedsPlaylists()
  1083. {
  1084. $playlists = new ArrayCollection();
  1085. foreach ($this->user_playlists_pickeds as $user_playlist_picked)
  1086. {
  1087. $playlists->add($user_playlist_picked->getPlaylist());
  1088. }
  1089. return $playlists;
  1090. }
  1091. public function getPlaylistsOwneds()
  1092. {
  1093. return $this->playlists_owneds;
  1094. }
  1095. public function setPlaylistsOwneds(Collection $playlists_owneds)
  1096. {
  1097. $this->playlists_owneds = $playlists_owneds;
  1098. }
  1099. }