User.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. /**
  44. * @ORM\Id
  45. * @ORM\Column(type="integer")
  46. * @ORM\generatedValue(strategy="AUTO")
  47. */
  48. protected $id;
  49. /**
  50. * @Gedmo\Slug(fields={"username"})
  51. * @ORM\Column(length=128, unique=true)
  52. */
  53. protected $slug;
  54. /**
  55. * @ORM\Column(type="text", nullable=true)
  56. * @ORM\Column(length=256)
  57. */
  58. protected $email_requested;
  59. /**
  60. * @ORM\Column(type="integer", nullable=true)
  61. */
  62. protected $email_requested_datetime;
  63. /**
  64. * Cet attribut contient les enregistrements UsersTagsFavorites lié
  65. * a cet utilisateur dans le cadre des Tags Favoris.
  66. *
  67. * @ORM\OneToMany(targetEntity="UsersTagsFavorites", mappedBy="user")
  68. */
  69. protected $tags_favorites;
  70. /**
  71. * Cet attribut contient les enregistrements UsersElementsFavorites lié
  72. * a cet utilisateur dans le cadre des éléments Favoris.
  73. *
  74. * @ORM\OneToMany(targetEntity="UsersElementsFavorites", mappedBy="user")
  75. */
  76. protected $elements_favorites;
  77. /**
  78. * Liste des Elements appartenant a cet utilisateur.
  79. *
  80. * @ORM\OneToMany(targetEntity="Element", mappedBy="owner")
  81. */
  82. protected $elements;
  83. /**
  84. * Liste des propositions de tags effectués par cet utilisateur
  85. *
  86. * @ORM\OneToMany(targetEntity="ElementTagsProposition", mappedBy="user")
  87. */
  88. protected $element_tags_propositions;
  89. /**
  90. * Users que cet utilisateur suit.
  91. *
  92. * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="follower")
  93. */
  94. protected $followeds_users;
  95. /**
  96. * Users qui suivent cet utilisateur.
  97. *
  98. * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="followed")
  99. */
  100. protected $followers_users;
  101. /**
  102. * Cet attribut contient les enregistrements FollowGroup lié
  103. * a cet utilisateur dans le cadre des groupes suivis.
  104. *
  105. * @ORM\OneToMany(targetEntity="FollowGroup", mappedBy="follower")
  106. */
  107. protected $followed_groups;
  108. /**
  109. * Liste des Groupes appartenant a cet utilisateur.
  110. *
  111. * @ORM\OneToMany(targetEntity="Group", mappedBy="owner")
  112. */
  113. protected $groups_owned;
  114. /**
  115. * Compteur de signalements inutiles
  116. *
  117. * @ORM\Column(type="integer", nullable=true)
  118. * @var int
  119. */
  120. protected $bad_report_count;
  121. /**
  122. * Compteur de contenus refusés par la modération
  123. *
  124. * @ORM\Column(type="integer", nullable=true)
  125. * @var int
  126. */
  127. protected $moderated_element_count;
  128. /**
  129. * Compteur de contenus refusés par la modération
  130. *
  131. * @ORM\Column(type="integer", nullable=true)
  132. * @var int
  133. */
  134. protected $moderated_tag_count;
  135. /**
  136. * Compteur de contenus refusés par la modération
  137. *
  138. * @ORM\Column(type="integer", nullable=true)
  139. * @var int
  140. */
  141. protected $moderated_comment_count;
  142. /**
  143. * @ORM\Column(type="text", nullable=true)
  144. * @ORM\Column(length=256)
  145. */
  146. protected $town;
  147. /**
  148. * @ORM\Column(type="text", nullable=true)
  149. * @ORM\Column(length=128)
  150. */
  151. protected $country;
  152. /**
  153. * Reputation
  154. *
  155. * @ORM\Column(type="integer", nullable=true)
  156. * @var int
  157. */
  158. protected $reputation;
  159. /**
  160. * Liste des Events appartenant a cet utilisateur.
  161. *
  162. * @ORM\OneToMany(targetEntity="Event", mappedBy="user")
  163. */
  164. protected $events;
  165. /**
  166. * Contient des données pratique pour par exemple influencer l'affichange dans twig.
  167. *
  168. * @var array
  169. */
  170. protected $live_datas = array();
  171. /**
  172. * Contient des données pratique, comme l'ordre des tags de sa page favoris etc.
  173. *
  174. * @ORM\Column(type="text", nullable=true)
  175. * @var type string
  176. */
  177. protected $datas = null;
  178. /**
  179. * Tableau contenant les id => name des tags favoris
  180. * de l'user. Ces donnée sont faites pour optimiser les calculs.
  181. * Ce chamsp est mis ajour a chaque fois qu'un UsersTagsFavorite est manipulé.
  182. *
  183. * @ORM\Column(type="text", unique=false, nullable=true)
  184. * @var array
  185. */
  186. private $tags_favorites_quick;
  187. /**
  188. *
  189. */
  190. public function __construct()
  191. {
  192. $this->tags_favorites = new ArrayCollection();
  193. $this->elements = new ArrayCollection();
  194. $this->elements_favorites = new ArrayCollection();
  195. $this->followeds_users = new ArrayCollection();
  196. $this->followers_users = new ArrayCollection();
  197. $this->followed_groups = new ArrayCollection();
  198. $this->groups = new ArrayCollection();
  199. $this->groups_owned = new ArrayCollection();
  200. parent::__construct();
  201. }
  202. public function __toString()
  203. {
  204. return $this->getName();
  205. }
  206. /**
  207. * Get id
  208. *
  209. * @return integer
  210. */
  211. public function getId()
  212. {
  213. return $this->id;
  214. }
  215. /**
  216. * Get tags_favorites
  217. *
  218. * @return Doctrine\Common\Collections\Collection
  219. */
  220. public function getTagsFavorites()
  221. {
  222. return $this->tags_favorites;
  223. }
  224. /**
  225. * Add tags_favorites
  226. *
  227. * @param UsersTagsFavorites $tagsFavorites
  228. */
  229. public function addUsersTagsFavorites(UsersTagsFavorites $tagsFavorites)
  230. {
  231. $this->tags_favorites[] = $tagsFavorites;
  232. }
  233. /**
  234. * Add elements_favorites
  235. *
  236. * @param UsersElementsFavorites $elementsFavorites
  237. */
  238. public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
  239. {
  240. $this->elements_favorites[] = $elementsFavorites;
  241. }
  242. /**
  243. * Get elements_favorites
  244. *
  245. * @return Doctrine\Common\Collections\Collection
  246. */
  247. public function getElementsFavorites()
  248. {
  249. return $this->elements_favorites;
  250. }
  251. /**
  252. * Add elements
  253. *
  254. * @param Element $elements
  255. */
  256. public function addElement(Element $elements)
  257. {
  258. $this->elements[] = $elements;
  259. }
  260. /**
  261. * Get elements
  262. *
  263. * @return Doctrine\Common\Collections\Collection
  264. */
  265. public function getElements()
  266. {
  267. return $this->elements;
  268. }
  269. /**
  270. * Add elements
  271. *
  272. * @param Element $elements
  273. */
  274. public function addElementTagsProposition(ElementTagsProposition $proposition)
  275. {
  276. $this->element_tags_propositions[] = $proposition;
  277. }
  278. /**
  279. * Get elements
  280. *
  281. * @return Doctrine\Common\Collections\Collection
  282. */
  283. public function getElementTagsPropositions()
  284. {
  285. return $this->element_tags_propositions;
  286. }
  287. /**
  288. * Add followeds_users
  289. *
  290. * @param FollowUser $followedsUsers
  291. */
  292. public function addFollowUser(FollowUser $followedsUsers)
  293. {
  294. $this->followeds_users[] = $followedsUsers;
  295. }
  296. /**
  297. * Get followeds_users
  298. *
  299. * @return Doctrine\Common\Collections\Collection
  300. */
  301. public function getFollowedsUsers()
  302. {
  303. $users = array();
  304. foreach ($this->followeds_users as $follow_user)
  305. {
  306. $users[] = $follow_user->getFollowed();
  307. }
  308. return $users;
  309. }
  310. /**
  311. * Get followers_users
  312. *
  313. * @return Doctrine\Common\Collections\Collection
  314. */
  315. public function getFollowersUsers()
  316. {
  317. $users = array();
  318. foreach ($this->followers_users as $follow_user)
  319. {
  320. $users[] = $follow_user->getFollower();
  321. }
  322. return $users;
  323. }
  324. /**
  325. * Add followed_groups
  326. *
  327. * @param FollowGroup $followedGroups
  328. */
  329. public function addFollowGroup(FollowGroup $followedGroups)
  330. {
  331. $this->followed_groups[] = $followedGroups;
  332. }
  333. /**
  334. * Get followed_groups
  335. *
  336. * @return Doctrine\Common\Collections\Collection
  337. */
  338. public function getFollowedGroups()
  339. {
  340. $groups = array();
  341. foreach ($this->followed_groups as $follow_group)
  342. {
  343. $groups[] = $follow_group->getGroup();
  344. }
  345. return $groups;
  346. }
  347. /**
  348. * Add groups
  349. *
  350. * @param Group $groups
  351. */
  352. public function addGroupOwned(Group $groups)
  353. {
  354. $this->groups[] = $groups;
  355. }
  356. /**
  357. * Get groups
  358. *
  359. * @return Doctrine\Common\Collections\Collection
  360. */
  361. public function getGroupsOwned()
  362. {
  363. return $this->groups_owned;
  364. }
  365. /**
  366. * Get groups in array (id => name)
  367. *
  368. * @return Doctrine\Common\Collections\Collection
  369. */
  370. public function getGroupsOwnedArray()
  371. {
  372. $groups = array();
  373. foreach ($this->groups_owned as $group)
  374. {
  375. $groups[$group->getId()] = $group->getName();
  376. }
  377. return $groups;
  378. }
  379. public function getSlug()
  380. {
  381. return $this->slug;
  382. }
  383. public function setSlug($slug)
  384. {
  385. $this->slug = $slug;
  386. }
  387. public function getEmailRequested()
  388. {
  389. return $this->email_requested;
  390. }
  391. public function setEmailRequested($email_requested)
  392. {
  393. $this->email_requested = $email_requested;
  394. }
  395. public function getBadReportCount()
  396. {
  397. return $this->bad_report_count;
  398. }
  399. public function setBadReportCount($count)
  400. {
  401. $this->bad_report_count = $count;
  402. }
  403. public function addBadReport()
  404. {
  405. $this->setBadReportCount($this->getBadReportCount()+1);
  406. }
  407. public function getTown()
  408. {
  409. return $this->town;
  410. }
  411. public function setTown($town)
  412. {
  413. $this->town = $town;
  414. }
  415. public function getCountry()
  416. {
  417. return $this->country;
  418. }
  419. public function setCountry($country)
  420. {
  421. $this->country = $country;
  422. }
  423. public function setReputation($reputation)
  424. {
  425. $this->reputation = $reputation;
  426. }
  427. public function getReputation()
  428. {
  429. if ($this->reputation === null)
  430. {
  431. return 0;
  432. }
  433. return $this->reputation;
  434. }
  435. public function getEvents()
  436. {
  437. return $this->events;
  438. }
  439. public function setEvents($events)
  440. {
  441. $this->events = $events;
  442. }
  443. public function getModeratedElementCount()
  444. {
  445. if ($this->moderated_element_count === null)
  446. {
  447. return 0;
  448. }
  449. return $this->moderated_element_count;
  450. }
  451. public function setModeratedElementCount($count)
  452. {
  453. $this->moderated_element_count = $count;
  454. }
  455. public function addModeratedElementCount()
  456. {
  457. $this->setModeratedElementCount($this->getModeratedElementCount()+1);
  458. }
  459. public function getModeratedTagCount()
  460. {
  461. if ($this->moderated_tag_count === null)
  462. {
  463. return 0;
  464. }
  465. return $this->moderated_tag_count;
  466. }
  467. public function setModeratedTagCount($count)
  468. {
  469. $this->moderated_tag_count = $count;
  470. }
  471. public function addModeratedTagCount()
  472. {
  473. $this->setModeratedTagCount($this->getModeratedTagCount()+1);
  474. }
  475. public function getModeratedCommentCount()
  476. {
  477. if ($this->moderated_comment_count === null)
  478. {
  479. return 0;
  480. }
  481. return $this->moderated_comment_count;
  482. }
  483. public function setModeratedCommentCount($count)
  484. {
  485. $this->moderated_comment_count = $count;
  486. }
  487. public function addModeratedCommentCount()
  488. {
  489. $this->setModeratedCommentCount($this->getModeratedCommentCount()+1);
  490. }
  491. /*
  492. *
  493. *
  494. */
  495. public function getName()
  496. {
  497. return $this->getUsername();
  498. }
  499. // public function getLocalisationExploded()
  500. // {
  501. // $town = null;
  502. // $country = null;
  503. // if ($this->localisation)
  504. // {
  505. // if (($explode = explode(', ', $this->localisation)))
  506. // {
  507. // $town = $explode[0];
  508. // $country = $explode[1];
  509. // }
  510. // }
  511. // return array(
  512. // 'town' => $town,
  513. // 'country' => $country
  514. // );
  515. // }
  516. //
  517. // public function setLocalisationExploded($town, $country)
  518. // {
  519. // $town = str_replace(', ', '', $town);
  520. // $town = str_replace(',', '', $town);
  521. // $country = str_replace(', ', '', $country);
  522. // $country = str_replace(',', '', $country);
  523. //
  524. // $this->localisation = $town. ', ' .$country;
  525. // }
  526. // /**
  527. // * @ORM\prePersist
  528. // */
  529. // public function setSlug()
  530. // {
  531. // if (!$this->slug)
  532. // {
  533. //
  534. // }
  535. // }
  536. //
  537. /**
  538. * Retourn si l'user_id transmis fait partis des enregistrements
  539. * followed de l'objet.
  540. *
  541. * @param int $user_id
  542. * @return boolean
  543. */
  544. public function isFollowingUser($user_id)
  545. {
  546. foreach ($this->followeds_users as $followed_user)
  547. {
  548. if ($followed_user->getFollowed()->getId() == $user_id)
  549. {
  550. return true;
  551. }
  552. }
  553. return false;
  554. }
  555. /**
  556. * Retourn si l'user_id transmis est l'un des User suivis
  557. *
  558. * @param Symfony\Bundle\DoctrineBundle\Registry doctrine
  559. * @param int $user_id
  560. * @return boolean
  561. */
  562. public function isFollowingUserByQuery($doctrine, $user_id)
  563. {
  564. return $doctrine
  565. ->getRepository('MuzichCoreBundle:User')
  566. ->isFollowingUser($this->getId(), $user_id)
  567. ;
  568. }
  569. /**
  570. * Retourn si l'group_id transmis est l'un des groupe suivis
  571. *
  572. * @param Symfony\Bundle\DoctrineBundle\Registry doctrine
  573. * @param int $user_id
  574. * @return boolean
  575. */
  576. public function isFollowingGroupByQuery($doctrine, $group_id)
  577. {
  578. return $doctrine
  579. ->getRepository('MuzichCoreBundle:User')
  580. ->isFollowingGroup($this->getId(), $group_id)
  581. ;
  582. }
  583. public function getPersonalHash($salt_context = null)
  584. {
  585. return hash('sha256', $this->getSalt().$this->getUsername().$salt_context);
  586. }
  587. /**
  588. * Ajoute a l'user les tags transmis (id) comme favoris.
  589. *
  590. * @param EntityManager $em
  591. * @param array $ids
  592. */
  593. public function updateTagsFavoritesById(EntityManager $em, $ids)
  594. {
  595. $ids = json_decode($ids);
  596. $ids_to_add = $ids;
  597. // Pour chacun des tags favoris
  598. foreach ($this->tags_favorites as $ii => $tag_favorite)
  599. {
  600. $trouve = false;
  601. foreach ($ids as $i => $id)
  602. {
  603. if ($id == $tag_favorite->getTag()->getId())
  604. {
  605. $trouve = true;
  606. // Si le tag était favoris déjà avant (et aussi maintenant)
  607. // il ne sera ni a ajouter, ni a supprimer.
  608. unset($ids_to_add[$i]);
  609. }
  610. }
  611. if (!$trouve)
  612. {
  613. // Si cet ancien tag n'est plus dans la liste, il faut le supprimer
  614. // (rappel: on supprime ici la relation, pas le tag)
  615. $em->remove($tag_favorite);
  616. }
  617. }
  618. if (count($ids_to_add))
  619. {
  620. $ids_to_add = array_merge($ids_to_add);
  621. $tag_favorite_position_max = $this->getTagFavoritePositionMax();
  622. $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids_to_add)->execute();
  623. // Pour les nouveaux ids restants
  624. foreach ($tags as $tag)
  625. {
  626. $tag_favorite = new UsersTagsFavorites();
  627. $tag_favorite->setUser($this);
  628. $tag_favorite->setTag($tag);
  629. $tag_favorite->setPosition($tag_favorite_position_max);
  630. $tag_favorite_position_max++;
  631. $this->addUsersTagsFavorites($tag_favorite);
  632. $em->persist($tag_favorite);
  633. }
  634. }
  635. $em->flush();
  636. }
  637. /**
  638. * Retourne un tableau contenant les ids des tags préférés de l'user
  639. *
  640. * @return type array
  641. */
  642. public function getTagFavoriteIds()
  643. {
  644. $ids = array();
  645. foreach ($this->tags_favorites as $tag_favorite)
  646. {
  647. $ids[$tag_favorite->getTag()->getId()] = $tag_favorite->getTag()->getId();
  648. }
  649. return $ids;
  650. }
  651. /**
  652. * Retourne la position max des tag favoris.
  653. *
  654. * @return int
  655. */
  656. public function getTagFavoritePositionMax()
  657. {
  658. $max = 0;
  659. foreach ($this->tags_favorites as $tag_favorite)
  660. {
  661. if ($tag_favorite->getPosition() > $max)
  662. {
  663. $max = $tag_favorite->getPosition();
  664. }
  665. }
  666. return $max;
  667. }
  668. /**
  669. * Set email_requested_datetime
  670. *
  671. * @param integer $emailRequestedDatetime
  672. */
  673. public function setEmailRequestedDatetime($emailRequestedDatetime)
  674. {
  675. $this->email_requested_datetime = $emailRequestedDatetime;
  676. }
  677. /**
  678. * Get email_requested_datetime
  679. *
  680. * @return integer
  681. */
  682. public function getEmailRequestedDatetime()
  683. {
  684. return $this->email_requested_datetime;
  685. }
  686. public function addLiveData($id, $data)
  687. {
  688. $this->live_datas[$id] = $data;
  689. }
  690. public function removeLiveData($id)
  691. {
  692. if (array_key_exists($id, $this->live_datas))
  693. {
  694. unset($this->live_datas[$id]);
  695. }
  696. }
  697. public function hasLiveData($id, $data = null)
  698. {
  699. if (array_key_exists($id, $this->live_datas))
  700. {
  701. if ($this->live_datas[$id] == $data)
  702. {
  703. return true;
  704. }
  705. }
  706. return false;
  707. }
  708. public function getTagsFavoritesQuick()
  709. {
  710. if ($this->tags_favorites_quick == null)
  711. {
  712. return array();
  713. }
  714. return json_decode($this->tags_favorites_quick, true);
  715. }
  716. /**
  717. *
  718. * @param array $tags_favorites_quick (id => name)
  719. */
  720. public function setTagsFavoritesQuick($tags_favorites_quick)
  721. {
  722. $this->tags_favorites_quick = json_encode($tags_favorites_quick);
  723. }
  724. /**
  725. *
  726. * @param \Muzich\CoreBundle\Entity\Tag $tag
  727. */
  728. public function addTagFavoriteQuick(Tag $tag)
  729. {
  730. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  731. if (!array_key_exists($tag->getId(), $tags_favorites_quick))
  732. {
  733. $tags_favorites_quick[$tag->getId()] = $tag->getName();
  734. }
  735. $this->setTagsFavoritesQuick($tags_favorites_quick);
  736. }
  737. /**
  738. *
  739. * @param \Muzich\CoreBundle\Entity\Tag $tag
  740. */
  741. public function removeTagFavoriteQuick(Tag $tag)
  742. {
  743. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  744. if (array_key_exists($tag->getId(), $tags_favorites_quick))
  745. {
  746. unset($tags_favorites_quick[$tag->getId()]);
  747. }
  748. $this->setTagsFavoritesQuick($tags_favorites_quick);
  749. }
  750. /**
  751. * Retourne vrai si le tag_id transmis fait partis des tags favoris de
  752. * l'utilisateur
  753. *
  754. * @param int $tag_id
  755. * @return boolean
  756. */
  757. public function haveTagsFavorite($tag_id)
  758. {
  759. $tags_favorites_quick = $this->getTagsFavoritesQuick();
  760. if (array_key_exists($tag_id, $tags_favorites_quick))
  761. {
  762. return true;
  763. }
  764. return false;
  765. }
  766. /**
  767. *
  768. * @return type array
  769. */
  770. public function getDatas()
  771. {
  772. if ($this->datas === null)
  773. {
  774. return array();
  775. }
  776. return json_decode($this->datas, true);
  777. }
  778. /**
  779. *
  780. * @param string $data_id
  781. * @param ~ $default
  782. * @return all
  783. */
  784. public function getData($data_id, $default)
  785. {
  786. $datas = $this->getDatas();
  787. if (array_key_exists($data_id, $datas))
  788. {
  789. return $datas[$data_id];
  790. }
  791. return $default;
  792. }
  793. /**
  794. *
  795. * @param array $datas
  796. */
  797. public function setDatas($datas)
  798. {
  799. $this->datas = json_encode($datas);
  800. }
  801. /**
  802. *
  803. * @param string $data_id
  804. * @param all $data_value
  805. */
  806. public function setData($data_id, $data_value)
  807. {
  808. $datas = $this->getDatas();
  809. $datas[$data_id] = $data_value;
  810. $this->setDatas($datas);
  811. }
  812. }