User.php 24KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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 = false;
  232. /**
  233. * @ORM\Column(type="integer")
  234. */
  235. protected $email_confirmation_sent_timestamp = 0;
  236. /**
  237. *
  238. */
  239. public function __construct()
  240. {
  241. $this->tags_favorites = new ArrayCollection();
  242. $this->elements = new ArrayCollection();
  243. $this->elements_favorites = new ArrayCollection();
  244. $this->followeds_users = new ArrayCollection();
  245. $this->followers_users = new ArrayCollection();
  246. $this->followed_groups = new ArrayCollection();
  247. $this->groups = new ArrayCollection();
  248. $this->groups_owned = new ArrayCollection();
  249. $this->help_tour = json_encode(array(
  250. self::HELP_TOUR_HOME => true
  251. ));
  252. parent::__construct();
  253. }
  254. public function __toString()
  255. {
  256. return $this->getName();
  257. }
  258. /**
  259. * Get id
  260. *
  261. * @return integer
  262. */
  263. public function getId()
  264. {
  265. return $this->id;
  266. }
  267. /**
  268. * Get tags_favorites
  269. *
  270. * @return Doctrine\Common\Collections\Collection
  271. */
  272. public function getTagsFavorites()
  273. {
  274. return $this->tags_favorites;
  275. }
  276. /**
  277. * Add tags_favorites
  278. *
  279. * @param UsersTagsFavorites $tagsFavorites
  280. */
  281. public function addUsersTagsFavorites(UsersTagsFavorites $tagsFavorites)
  282. {
  283. $this->tags_favorites[] = $tagsFavorites;
  284. }
  285. /**
  286. * Add elements_favorites
  287. *
  288. * @param UsersElementsFavorites $elementsFavorites
  289. */
  290. public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
  291. {
  292. $this->elements_favorites[] = $elementsFavorites;
  293. }
  294. /**
  295. * Get elements_favorites
  296. *
  297. * @return Doctrine\Common\Collections\Collection
  298. */
  299. public function getElementsFavorites()
  300. {
  301. return $this->elements_favorites;
  302. }
  303. /**
  304. * Add elements
  305. *
  306. * @param Element $elements
  307. */
  308. public function addElement(Element $elements)
  309. {
  310. $this->elements[] = $elements;
  311. }
  312. /**
  313. * Get elements
  314. *
  315. * @return Doctrine\Common\Collections\Collection
  316. */
  317. public function getElements()
  318. {
  319. return $this->elements;
  320. }
  321. /**
  322. * Add elements
  323. *
  324. * @param Element $elements
  325. */
  326. public function addElementTagsProposition(ElementTagsProposition $proposition)
  327. {
  328. $this->element_tags_propositions[] = $proposition;
  329. }
  330. /**
  331. * Get elements
  332. *
  333. * @return Doctrine\Common\Collections\Collection
  334. */
  335. public function getElementTagsPropositions()
  336. {
  337. return $this->element_tags_propositions;
  338. }
  339. /**
  340. * Add followeds_users
  341. *
  342. * @param FollowUser $followedsUsers
  343. */
  344. public function addFollowUser(FollowUser $followedsUsers)
  345. {
  346. $this->followeds_users[] = $followedsUsers;
  347. }
  348. /**
  349. * Get followeds_users
  350. *
  351. * @return Doctrine\Common\Collections\Collection
  352. */
  353. public function getFollowedsUsers()
  354. {
  355. $users = array();
  356. foreach ($this->followeds_users as $follow_user)
  357. {
  358. $users[] = $follow_user->getFollowed();
  359. }
  360. return $users;
  361. }
  362. /**
  363. * Get followers_users
  364. *
  365. * @return Doctrine\Common\Collections\Collection
  366. */
  367. public function getFollowersUsers()
  368. {
  369. $users = array();
  370. foreach ($this->followers_users as $follow_user)
  371. {
  372. $users[] = $follow_user->getFollower();
  373. }
  374. return $users;
  375. }
  376. /**
  377. * Add followed_groups
  378. *
  379. * @param FollowGroup $followedGroups
  380. */
  381. public function addFollowGroup(FollowGroup $followedGroups)
  382. {
  383. $this->followed_groups[] = $followedGroups;
  384. }
  385. /**
  386. * Get followed_groups
  387. *
  388. * @return Doctrine\Common\Collections\Collection
  389. */
  390. public function getFollowedGroups()
  391. {
  392. $groups = array();
  393. foreach ($this->followed_groups as $follow_group)
  394. {
  395. $groups[] = $follow_group->getGroup();
  396. }
  397. return $groups;
  398. }
  399. /**
  400. * Add groups
  401. *
  402. * @param Group $groups
  403. */
  404. public function addGroupOwned(Group $groups)
  405. {
  406. $this->groups[] = $groups;
  407. }
  408. /**
  409. * Get groups
  410. *
  411. * @return Doctrine\Common\Collections\Collection
  412. */
  413. public function getGroupsOwned()
  414. {
  415. return $this->groups_owned;
  416. }
  417. /**
  418. * Get groups in array (id => name)
  419. *
  420. * @return Doctrine\Common\Collections\Collection
  421. */
  422. public function getGroupsOwnedArray()
  423. {
  424. $groups = array();
  425. foreach ($this->groups_owned as $group)
  426. {
  427. $groups[$group->getId()] = $group->getName();
  428. }
  429. return $groups;
  430. }
  431. public function getSlug()
  432. {
  433. return $this->slug;
  434. }
  435. public function setSlug($slug)
  436. {
  437. $this->slug = $slug;
  438. }
  439. public function getEmailRequested()
  440. {
  441. return $this->email_requested;
  442. }
  443. public function setEmailRequested($email_requested)
  444. {
  445. $this->email_requested = $email_requested;
  446. }
  447. public function getBadReportCount()
  448. {
  449. return $this->bad_report_count;
  450. }
  451. public function setBadReportCount($count)
  452. {
  453. $this->bad_report_count = $count;
  454. $this->updateBadCount();
  455. }
  456. public function addBadReport()
  457. {
  458. $this->setBadReportCount($this->getBadReportCount()+1);
  459. }
  460. public function getTown()
  461. {
  462. return $this->town;
  463. }
  464. public function setTown($town)
  465. {
  466. $this->town = $town;
  467. }
  468. public function getCountry()
  469. {
  470. return $this->country;
  471. }
  472. public function setCountry($country)
  473. {
  474. $this->country = $country;
  475. }
  476. public function setReputation($reputation)
  477. {
  478. $this->reputation = $reputation;
  479. }
  480. public function getReputation()
  481. {
  482. if ($this->reputation === null)
  483. {
  484. return 0;
  485. }
  486. return $this->reputation;
  487. }
  488. public function getEvents()
  489. {
  490. return $this->events;
  491. }
  492. public function setEvents($events)
  493. {
  494. $this->events = $events;
  495. }
  496. public function getModeratedElementCount()
  497. {
  498. if ($this->moderated_element_count === null)
  499. {
  500. return 0;
  501. }
  502. return $this->moderated_element_count;
  503. }
  504. public function setModeratedElementCount($count)
  505. {
  506. $this->moderated_element_count = $count;
  507. $this->updateBadCount();
  508. }
  509. public function addModeratedElementCount()
  510. {
  511. $this->setModeratedElementCount($this->getModeratedElementCount()+1);
  512. }
  513. public function getModeratedTagCount()
  514. {
  515. if ($this->moderated_tag_count === null)
  516. {
  517. return 0;
  518. }
  519. return $this->moderated_tag_count;
  520. }
  521. public function setModeratedTagCount($count)
  522. {
  523. $this->moderated_tag_count = $count;
  524. $this->updateBadCount();
  525. }
  526. public function addModeratedTagCount()
  527. {
  528. $this->setModeratedTagCount($this->getModeratedTagCount()+1);
  529. }
  530. public function getModeratedCommentCount()
  531. {
  532. if ($this->moderated_comment_count === null)
  533. {
  534. return 0;
  535. }
  536. return $this->moderated_comment_count;
  537. }
  538. public function setModeratedCommentCount($count)
  539. {
  540. $this->moderated_comment_count = $count;
  541. $this->updateBadCount();
  542. }
  543. public function addModeratedCommentCount()
  544. {
  545. $this->setModeratedCommentCount($this->getModeratedCommentCount()+1);
  546. }
  547. /*
  548. *
  549. *
  550. */
  551. public function getName()
  552. {
  553. return $this->getUsername();
  554. }
  555. // public function getLocalisationExploded()
  556. // {
  557. // $town = null;
  558. // $country = null;
  559. // if ($this->localisation)
  560. // {
  561. // if (($explode = explode(', ', $this->localisation)))
  562. // {
  563. // $town = $explode[0];
  564. // $country = $explode[1];
  565. // }
  566. // }
  567. // return array(
  568. // 'town' => $town,
  569. // 'country' => $country
  570. // );
  571. // }
  572. //
  573. // public function setLocalisationExploded($town, $country)
  574. // {
  575. // $town = str_replace(', ', '', $town);
  576. // $town = str_replace(',', '', $town);
  577. // $country = str_replace(', ', '', $country);
  578. // $country = str_replace(',', '', $country);
  579. //
  580. // $this->localisation = $town. ', ' .$country;
  581. // }
  582. // /**
  583. // * @ORM\PrePersist
  584. // */
  585. // public function setSlug()
  586. // {
  587. // if (!$this->slug)
  588. // {
  589. //
  590. // }
  591. // }
  592. //
  593. /**
  594. * Retourn si l'user_id transmis fait partis des enregistrements
  595. * followed de l'objet.
  596. *
  597. * @param int $user_id
  598. * @return boolean
  599. */
  600. public function isFollowingUser($user_id)
  601. {
  602. foreach ($this->followeds_users as $followed_user)
  603. {
  604. if ($followed_user->getFollowed()->getId() == $user_id)
  605. {
  606. return true;
  607. }
  608. }
  609. return false;
  610. }
  611. /**
  612. * Retourn si l'user_id transmis est l'un des User suivis
  613. *
  614. * @param Doctrine\Bundle\DoctrineBundle\Registry doctrine
  615. * @param int $user_id
  616. * @return boolean
  617. */
  618. public function isFollowingUserByQuery($doctrine, $user_id)
  619. {
  620. return $doctrine
  621. ->getRepository('MuzichCoreBundle:User')
  622. ->isFollowingUser($this->getId(), $user_id)
  623. ;
  624. }
  625. /**
  626. * Retourn si l'group_id transmis est l'un des groupe suivis
  627. *
  628. * @param Doctrine\Bundle\DoctrineBundle\Registry doctrine
  629. * @param int $user_id
  630. * @return boolean
  631. */
  632. public function isFollowingGroupByQuery($doctrine, $group_id)
  633. {
  634. return $doctrine
  635. ->getRepository('MuzichCoreBundle:User')
  636. ->isFollowingGroup($this->getId(), $group_id)
  637. ;
  638. }
  639. public function getPersonalHash($salt_context = null)
  640. {
  641. return hash('sha256', $this->getSalt().$this->getUsername().$salt_context);
  642. }
  643. /**
  644. * Ajoute a l'user les tags transmis (id) comme favoris.
  645. *
  646. * @param EntityManager $em
  647. * @param array $ids
  648. */
  649. public function updateTagsFavoritesById(EntityManager $em, $ids)
  650. {
  651. $ids = json_decode($ids);
  652. $ids_to_add = $ids;
  653. // Pour chacun des tags favoris
  654. foreach ($this->tags_favorites as $ii => $tag_favorite)
  655. {
  656. $trouve = false;
  657. foreach ($ids as $i => $id)
  658. {
  659. if ($id == $tag_favorite->getTag()->getId())
  660. {
  661. $trouve = true;
  662. // Si le tag était favoris déjà avant (et aussi maintenant)
  663. // il ne sera ni a ajouter, ni a supprimer.
  664. unset($ids_to_add[$i]);
  665. }
  666. }
  667. if (!$trouve)
  668. {
  669. // Si cet ancien tag n'est plus dans la liste, il faut le supprimer
  670. // (rappel: on supprime ici la relation, pas le tag)
  671. $em->remove($tag_favorite);
  672. }
  673. }
  674. if (count($ids_to_add))
  675. {
  676. $ids_to_add = array_merge($ids_to_add);
  677. $tag_favorite_position_max = $this->getTagFavoritePositionMax();
  678. $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids_to_add)->execute();
  679. // Pour les nouveaux ids restants
  680. foreach ($tags as $tag)
  681. {
  682. $tag_favorite = new UsersTagsFavorites();
  683. $tag_favorite->setUser($this);
  684. $tag_favorite->setTag($tag);
  685. $tag_favorite->setPosition($tag_favorite_position_max);
  686. $tag_favorite_position_max++;
  687. $this->addUsersTagsFavorites($tag_favorite);
  688. $em->persist($tag_favorite);
  689. }
  690. }
  691. $em->flush();
  692. }
  693. /**
  694. * Retourne un tableau contenant les ids des tags préférés de l'user
  695. *
  696. * @return type array
  697. */
  698. public function getTagFavoriteIds()
  699. {
  700. $ids = array();
  701. foreach ($this->tags_favorites as $tag_favorite)
  702. {
  703. $ids[$tag_favorite->getTag()->getId()] = $tag_favorite->getTag()->getId();
  704. }
  705. return $ids;
  706. }
  707. /**
  708. * Retourne la position max des tag favoris.
  709. *
  710. * @return int
  711. */
  712. public function getTagFavoritePositionMax()
  713. {
  714. $max = 0;
  715. foreach ($this->tags_favorites as $tag_favorite)
  716. {
  717. if ($tag_favorite->getPosition() > $max)
  718. {
  719. $max = $tag_favorite->getPosition();
  720. }
  721. }
  722. return $max;
  723. }
  724. /**
  725. * Set email_requested_datetime
  726. *
  727. * @param integer $emailRequestedDatetime
  728. */
  729. public function setEmailRequestedDatetime($emailRequestedDatetime)
  730. {
  731. $this->email_requested_datetime = $emailRequestedDatetime;
  732. }
  733. /**
  734. * Get email_requested_datetime
  735. *
  736. * @return integer
  737. */
  738. public function getEmailRequestedDatetime()
  739. {
  740. return $this->email_requested_datetime;
  741. }
  742. public function addLiveData($id, $data)
  743. {
  744. $this->live_datas[$id] = $data;
  745. }
  746. public function removeLiveData($id)
  747. {
  748. if (array_key_exists($id, $this->live_datas))
  749. {
  750. unset($this->live_datas[$id]);
  751. }
  752. }
  753. public function hasLiveData($id, $data = null)
  754. {
  755. if (array_key_exists($id, $this->live_datas))
  756. {
  757. if ($this->live_datas[$id] == $data)
  758. {
  759. return true;
  760. }
  761. }
  762. return false;
  763. }
  764. public function getTagsFavoritesQuick()
  765. {
  766. if ($this->tags_favorites_quick == null)
  767. {
  768. return array();
  769. }
  770. return json_decode($this->tags_favorites_quick, true);
  771. }
  772. /**
  773. *
  774. * @param array $tags_favorites_quick (id => name)
  775. */
  776. public function setTagsFavoritesQuick($tags_favorites_quick)
  777. {
  778. $this->tags_favorites_quick = json_encode($tags_favorites_quick);
  779. }
  780. /**
  781. *
  782. * @param \Muzich\CoreBundle\Entity\Tag $tag
  783. */
  784. public function addTagFavoriteQuick(Tag $tag)
  785. {
  786. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  787. if (!array_key_exists($tag->getId(), $tags_favorites_quick))
  788. {
  789. $tags_favorites_quick[$tag->getId()] = $tag->getName();
  790. }
  791. $this->setTagsFavoritesQuick($tags_favorites_quick);
  792. }
  793. /**
  794. *
  795. * @param \Muzich\CoreBundle\Entity\Tag $tag
  796. */
  797. public function removeTagFavoriteQuick(Tag $tag)
  798. {
  799. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  800. if (array_key_exists($tag->getId(), $tags_favorites_quick))
  801. {
  802. unset($tags_favorites_quick[$tag->getId()]);
  803. }
  804. $this->setTagsFavoritesQuick($tags_favorites_quick);
  805. }
  806. /**
  807. * Retourne vrai si le tag_id transmis fait partis des tags favoris de
  808. * l'utilisateur
  809. *
  810. * @param int $tag_id
  811. * @return boolean
  812. */
  813. public function haveTagsFavorite($tag_id)
  814. {
  815. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  816. if (array_key_exists($tag_id, $tags_favorites_quick))
  817. {
  818. return true;
  819. }
  820. return false;
  821. }
  822. /**
  823. *
  824. * @return type array
  825. */
  826. public function getDatas()
  827. {
  828. if ($this->datas === null)
  829. {
  830. return array();
  831. }
  832. return json_decode($this->datas, true);
  833. }
  834. /**
  835. *
  836. * @param string $data_id
  837. * @param ~ $default
  838. * @return all
  839. */
  840. public function getData($data_id, $default)
  841. {
  842. $datas = $this->getDatas();
  843. if (array_key_exists($data_id, $datas))
  844. {
  845. return $datas[$data_id];
  846. }
  847. return $default;
  848. }
  849. /**
  850. *
  851. * @param array $datas
  852. */
  853. public function setDatas($datas)
  854. {
  855. $this->datas = json_encode($datas);
  856. }
  857. /**
  858. *
  859. * @param string $data_id
  860. * @param all $data_value
  861. */
  862. public function setData($data_id, $data_value)
  863. {
  864. $datas = $this->getDatas();
  865. $datas[$data_id] = $data_value;
  866. $this->setDatas($datas);
  867. }
  868. public function getAvatarAbsolutePath()
  869. {
  870. return null === $this->avatar_path
  871. ? null
  872. : $this->getAvatarUploadRootDir().'/'.$this->avatar_path;
  873. }
  874. public function getAvatarWebPath()
  875. {
  876. return null === $this->avatar_path
  877. ? null
  878. : $this->getAvatarUploadDir().'/'.$this->avatar_path;
  879. }
  880. protected function getAvatarUploadRootDir()
  881. {
  882. return __DIR__.'/../../../../web/'.$this->getAvatarUploadDir();
  883. }
  884. protected function getAvatarUploadDir()
  885. {
  886. return 'files/avatars';
  887. }
  888. /**
  889. * @ORM\PrePersist()
  890. * @ORM\PreUpdate()
  891. */
  892. public function preUploadAvatar()
  893. {
  894. if (null !== $this->avatar) {
  895. $this->avatar_path = $this->getPersonalHash($this->avatar->getClientOriginalName()).'.'.$this->avatar->guessExtension();
  896. }
  897. }
  898. /**
  899. * @ORM\PostPersist()
  900. * @ORM\PostUpdate()
  901. */
  902. public function uploadAvatar()
  903. {
  904. if (null === $this->avatar) {
  905. return;
  906. }
  907. $this->avatar->move($this->getAvatarUploadRootDir(), $this->avatar_path);
  908. $this->avatar = null;
  909. }
  910. /**
  911. * @ORM\PostRemove()
  912. */
  913. public function removeUpload()
  914. {
  915. if ($file = $this->getAvatarAbsolutePath()) {
  916. unlink($file);
  917. }
  918. }
  919. public function getCguAccepted()
  920. {
  921. return $this->cgu_accepted;
  922. }
  923. public function setCguAccepted($accepted)
  924. {
  925. if ($accepted)
  926. $this->cgu_accepted = true;
  927. else
  928. $this->cgu_accepted = false;
  929. }
  930. public function getMailNewsletter()
  931. {
  932. return $this->mail_newsletter;
  933. }
  934. public function getMailPartner()
  935. {
  936. return $this->mail_partner;
  937. }
  938. public function getHelpTour()
  939. {
  940. return json_decode($this->help_tour, true);
  941. }
  942. public function setHelpTour($help_tour)
  943. {
  944. $this->help_tour = json_encode($help_tour);
  945. }
  946. public function wantSeeHelp($help_id)
  947. {
  948. $help_tour_status = $this->getHelpTour();
  949. if (array_key_exists($help_id, $help_tour_status))
  950. {
  951. return $help_tour_status[$help_id];
  952. }
  953. return false;
  954. }
  955. public function setSeeHelp($help_id, $boolean)
  956. {
  957. $help_tour_status = $this->getHelpTour();
  958. if (array_key_exists($help_id, $help_tour_status))
  959. {
  960. $help_tour_status[$help_id] = ($boolean)?true:false;
  961. }
  962. $this->setHelpTour($help_tour_status);
  963. }
  964. public function getBadCount()
  965. {
  966. if (is_null($this->bad_count))
  967. {
  968. return 0;
  969. }
  970. return $this->bad_count;
  971. }
  972. public function updateBadCount()
  973. {
  974. $this->bad_count = $this->getBadReportCount()
  975. + $this->getModeratedCommentCount()
  976. + $this->getModeratedElementCount()
  977. + $this->getModeratedTagCount()
  978. ;
  979. }
  980. public function setUsernameUpdatable($updatable)
  981. {
  982. if ($updatable)
  983. $this->username_updatable = true;
  984. else
  985. $this->username_updatable = false;
  986. }
  987. public function isUsernameUpdatable()
  988. {
  989. if ($this->username_updatable)
  990. return true;
  991. return false;
  992. }
  993. public function isEmailConfirmed()
  994. {
  995. return ($this->email_confirmed)?true:false;
  996. }
  997. public function setEmailConfirmed($confirmed)
  998. {
  999. $this->email_confirmed = ($confirmed)?true:false;
  1000. }
  1001. public function setEmailConfirmationSentTimestamp($timestamp)
  1002. {
  1003. $this->email_confirmation_sent_timestamp = $timestamp;
  1004. }
  1005. public function getEmailConfirmationSentTimestamp()
  1006. {
  1007. return $this->email_confirmation_sent_timestamp;
  1008. }
  1009. }