User.php 24KB

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