User.php 25KB

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