12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310 |
- <?php
-
- namespace Muzich\CoreBundle\Entity;
-
- use FOS\UserBundle\Entity\User as BaseUser;
- use Doctrine\ORM\Mapping as ORM;
- use \Doctrine\Common\Collections\ArrayCollection;
- use \Doctrine\Common\Collections\Collection;
- use Gedmo\Mapping\Annotation as Gedmo;
- use Doctrine\ORM\EntityManager;
- use Muzich\CoreBundle\Entity\UsersTagsFavorites;
- use Symfony\Component\Validator\Constraints as Assert;
- use Muzich\CoreBundle\Entity\ElementTagsProposition;
- use Muzich\CoreBundle\Entity\Tag;
- use Muzich\CoreBundle\Managers\UserPrivacy as PrivacyManager;
-
- /**
- * Cet entité est l'utilisateur ayant effectué la requête.
- *
- * @ORM\Entity
- * @ORM\Table(name="m_user")
- * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\UserRepository")
- * @ORM\HasLifecycleCallbacks()
- */
- class User extends BaseUser
- {
-
- const DATA_FAV_UPDATED = "data_fav_updated";
- const DATA_DIFF_UPDATED = "data_diff_updated";
- const DATA_PLAY_UPDATED = "data_play_updated";
-
- const HELP_TOUR_HOME = "home";
-
- /**
- * @ORM\Id
- * @ORM\Column(type="integer")
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- protected $id;
-
- /**
- * @Gedmo\Slug(fields={"username"})
- * @ORM\Column(length=128, unique=true)
- */
- protected $slug;
-
- /**
- * @ORM\Column(type="text", nullable=true)
- * @ORM\Column(length=256)
- */
- protected $email_requested;
-
- /**
- * @ORM\Column(type="integer", nullable=true)
- */
- protected $email_requested_datetime;
-
- /**
- * Cet attribut contient les enregistrements UsersTagsFavorites lié
- * a cet utilisateur dans le cadre des Tags Favoris.
- *
- * @ORM\OneToMany(targetEntity="UsersTagsFavorites", mappedBy="user")
- */
- protected $tags_favorites;
-
- /**
- * @ORM\OneToMany(targetEntity="UserPlaylistPicked", mappedBy="user")
- */
- protected $user_playlists_pickeds;
-
- /**
- * Cet attribut contient les enregistrements UsersElementsFavorites lié
- * a cet utilisateur dans le cadre des éléments Favoris.
- *
- * @ORM\OneToMany(targetEntity="UsersElementsFavorites", mappedBy="user")
- */
- protected $elements_favorites;
-
- /**
- * Liste des Elements appartenant a cet utilisateur.
- *
- * @ORM\OneToMany(targetEntity="Element", mappedBy="owner")
- */
- protected $elements;
-
- /**
- * Liste des propositions de tags effectués par cet utilisateur
- *
- * @ORM\OneToMany(targetEntity="ElementTagsProposition", mappedBy="user")
- */
- protected $element_tags_propositions;
-
- /**
- * Users que cet utilisateur suit.
- *
- * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="follower")
- */
- protected $followeds_users;
-
- /**
- * Users qui suivent cet utilisateur.
- *
- * @ORM\OneToMany(targetEntity="FollowUser", mappedBy="followed")
- */
- protected $followers_users;
-
- /**
- * Cet attribut contient les enregistrements FollowGroup lié
- * a cet utilisateur dans le cadre des groupes suivis.
- *
- * @ORM\OneToMany(targetEntity="FollowGroup", mappedBy="follower")
- */
- protected $followed_groups;
-
- /**
- * Liste des Groupes appartenant a cet utilisateur.
- *
- * @ORM\OneToMany(targetEntity="Group", mappedBy="owner")
- */
- protected $groups_owned;
-
- /**
- * @ORM\OneToMany(targetEntity="Playlist", mappedBy="owner")
- */
- protected $playlists_owneds;
-
- /**
- * @ORM\Column(type="integer", nullable=true)
- * @var int
- */
- protected $bad_count;
-
- /**
- * Compteur de signalements inutiles
- *
- * @ORM\Column(type="integer", nullable=true)
- * @var int
- */
- protected $bad_report_count;
-
- /**
- * Compteur de contenus refusés par la modération
- *
- * @ORM\Column(type="integer", nullable=true)
- * @var int
- */
- protected $moderated_element_count;
-
- /**
- * Compteur de contenus refusés par la modération
- *
- * @ORM\Column(type="integer", nullable=true)
- * @var int
- */
- protected $moderated_tag_count;
-
- /**
- * Compteur de contenus refusés par la modération
- *
- * @ORM\Column(type="integer", nullable=true)
- * @var int
- */
- protected $moderated_comment_count;
-
- /**
- * @ORM\Column(type="text", nullable=true)
- * @ORM\Column(length=256)
- */
- protected $town;
-
- /**
- * @ORM\Column(type="text", nullable=true)
- * @ORM\Column(length=128)
- */
- protected $country;
-
- /**
- * Reputation
- *
- * @ORM\Column(type="integer", nullable=true)
- * @var int
- */
- protected $reputation;
-
- /**
- * Liste des Events appartenant a cet utilisateur.
- *
- * @ORM\OneToMany(targetEntity="Event", mappedBy="user")
- */
- protected $events;
-
- /**
- * Contient des données pratique pour par exemple influencer l'affichange dans twig.
- *
- * @var array
- */
- protected $live_datas = array();
-
- /**
- * Contient des données pratique, comme l'ordre des tags de sa page favoris etc.
- *
- * @ORM\Column(type="text", nullable=true)
- * @var type string
- */
- protected $datas = null;
-
- /**
- * Tableau contenant les id => name des tags favoris
- * de l'user. Ces donnée sont faites pour optimiser les calculs.
- * Ce chamsp est mis ajour a chaque fois qu'un UsersTagsFavorite est manipulé.
- *
- * @ORM\Column(type="text", unique=false, nullable=true)
- * @var array
- */
- private $tags_favorites_quick;
-
- /**
- * @Assert\Image(maxSize="6000000")
- */
- public $avatar;
-
- /**
- * @ORM\Column(type="text", length=255, nullable=true)
- */
- public $avatar_path;
-
- /**
- * @ORM\Column(type="text", unique=false, nullable=true)
- * @var array
- */
- private $help_tour;
-
- /**
- * @ORM\Column(type="boolean")
- * @Assert\NotBlank()
- * @var type boolean
- */
- public $cgu_accepted = false;
-
- /**
- * @ORM\Column(type="boolean")
- * @var type boolean
- */
- public $mail_newsletter = true;
-
- /**
- * @ORM\Column(type="boolean")
- * @var type boolean
- */
- public $mail_partner = true;
-
- /**
- * @ORM\Column(type="boolean", nullable=true)
- * @var type boolean
- */
- private $username_updatable = false;
-
- /**
- * @ORM\Column(type="boolean", nullable=false)
- * @var type boolean
- */
- private $email_confirmed = true;
-
- /**
- * @ORM\Column(type="integer")
- */
- protected $email_confirmation_sent_timestamp = 0;
-
- /**
- * @ORM\Column(type="boolean", nullable=false)
- * @var type boolean
- */
- private $password_set = true;
-
- /** @ORM\Column(name="facebook_id", type="string", length=255, nullable=true) */
- protected $facebook_id;
-
- /**
- * @ORM\Column(type="text", unique=false, nullable=true)
- */
- protected $privacy;
-
- /**
- *
- */
- public function __construct()
- {
- $this->tags_favorites = new ArrayCollection();
- $this->elements = new ArrayCollection();
- $this->elements_favorites = new ArrayCollection();
- $this->followeds_users = new ArrayCollection();
- $this->followers_users = new ArrayCollection();
- $this->followed_groups = new ArrayCollection();
- $this->groups = new ArrayCollection();
- $this->groups_owned = new ArrayCollection();
- $this->user_playlists_pickeds = new ArrayCollection();
- $this->playlists_owneds = new ArrayCollection();
- $this->help_tour = json_encode(array(
- self::HELP_TOUR_HOME => true
- ));
- parent::__construct();
- }
-
- public function __toString()
- {
- return $this->getName();
- }
-
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * Get tags_favorites
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getTagsFavorites()
- {
- return $this->tags_favorites;
- }
-
- /**
- * Add tags_favorites
- *
- * @param UsersTagsFavorites $tagsFavorites
- */
- public function addUsersTagsFavorites(UsersTagsFavorites $tagsFavorites)
- {
- $this->tags_favorites[] = $tagsFavorites;
- }
-
- /**
- * Add elements_favorites
- *
- * @param UsersElementsFavorites $elementsFavorites
- */
- public function addUsersElementsFavorites(UsersElementsFavorites $elementsFavorites)
- {
- $this->elements_favorites[] = $elementsFavorites;
- }
-
- /**
- * Get elements_favorites
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getElementsFavorites()
- {
- return $this->elements_favorites;
- }
-
- public function getElementsFavoritesElements()
- {
- if (!$this->elements_favorites)
- return new ArrayCollection();
-
- $elements = array();
- foreach ($this->elements_favorites as $element_favorite)
- {
- $elements[] = $element_favorite->getElement();
- }
-
- return $elements;
- }
-
- /**
- * Add elements
- *
- * @param Element $elements
- */
- public function addElement(Element $elements)
- {
- $this->elements[] = $elements;
- }
-
- /**
- * Get elements
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getElements()
- {
- return $this->elements;
- }
-
- /**
- * Add elements
- *
- * @param Element $elements
- */
- public function addElementTagsProposition(ElementTagsProposition $proposition)
- {
- $this->element_tags_propositions[] = $proposition;
- }
-
- /**
- * Get elements
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getElementTagsPropositions()
- {
- return $this->element_tags_propositions;
- }
-
- /**
- * Add followeds_users
- *
- * @param FollowUser $followedsUsers
- */
- public function addFollowUser(FollowUser $followedsUsers)
- {
- $this->followeds_users[] = $followedsUsers;
- }
-
- /**
- * Get followeds_users
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getFollowedsUsers()
- {
- $users = array();
- foreach ($this->followeds_users as $follow_user)
- {
- $users[] = $follow_user->getFollowed();
- }
- return $users;
- }
-
- /**
- * Get followers_users
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getFollowersUsers()
- {
- $users = array();
- foreach ($this->followers_users as $follow_user)
- {
- $users[] = $follow_user->getFollower();
- }
- return $users;
- }
-
- /**
- * Add followed_groups
- *
- * @param FollowGroup $followedGroups
- */
- public function addFollowGroup(FollowGroup $followedGroups)
- {
- $this->followed_groups[] = $followedGroups;
- }
-
- /**
- * Get followed_groups
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getFollowedGroups()
- {
- $groups = array();
- foreach ($this->followed_groups as $follow_group)
- {
- $groups[] = $follow_group->getGroup();
- }
- return $groups;
- }
-
- /**
- * Add groups
- *
- * @param Group $groups
- */
- public function addGroupOwned(Group $groups)
- {
- $this->groups[] = $groups;
- }
-
- /**
- * Get groups
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getGroupsOwned()
- {
- return $this->groups_owned;
- }
-
- /**
- * Get groups in array (id => name)
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getGroupsOwnedArray()
- {
- $groups = array();
- foreach ($this->groups_owned as $group)
- {
- $groups[$group->getId()] = $group->getName();
- }
- return $groups;
- }
-
- public function getSlug()
- {
- return $this->slug;
- }
-
- public function setSlug($slug)
- {
- $this->slug = $slug;
- }
-
- public function getEmailRequested()
- {
- return $this->email_requested;
- }
-
- public function setEmailRequested($email_requested)
- {
- $this->email_requested = $email_requested;
- }
-
- public function getBadReportCount()
- {
- return $this->bad_report_count;
- }
-
- public function setBadReportCount($count)
- {
- $this->bad_report_count = $count;
- $this->updateBadCount();
- }
-
- public function addBadReport()
- {
- $this->setBadReportCount($this->getBadReportCount()+1);
- }
-
- public function getTown()
- {
- return $this->town;
- }
-
- public function setTown($town)
- {
- $this->town = $town;
- }
-
- public function getCountry()
- {
- return $this->country;
- }
-
- public function setCountry($country)
- {
- $this->country = $country;
- }
-
- public function setReputation($reputation)
- {
- $this->reputation = $reputation;
- }
-
- public function getReputation()
- {
- if ($this->reputation === null)
- {
- return 0;
- }
- return $this->reputation;
- }
-
- public function getEvents()
- {
- return $this->events;
- }
-
- public function setEvents($events)
- {
- $this->events = $events;
- }
-
- public function getModeratedElementCount()
- {
- if ($this->moderated_element_count === null)
- {
- return 0;
- }
- return $this->moderated_element_count;
- }
-
- public function setModeratedElementCount($count)
- {
- $this->moderated_element_count = $count;
- $this->updateBadCount();
- }
-
- public function addModeratedElementCount()
- {
- $this->setModeratedElementCount($this->getModeratedElementCount()+1);
- }
-
- public function getModeratedTagCount()
- {
- if ($this->moderated_tag_count === null)
- {
- return 0;
- }
- return $this->moderated_tag_count;
- }
-
- public function setModeratedTagCount($count)
- {
- $this->moderated_tag_count = $count;
- $this->updateBadCount();
- }
-
- public function addModeratedTagCount()
- {
- $this->setModeratedTagCount($this->getModeratedTagCount()+1);
- }
-
- public function getModeratedCommentCount()
- {
- if ($this->moderated_comment_count === null)
- {
- return 0;
- }
- return $this->moderated_comment_count;
- }
-
- public function setModeratedCommentCount($count)
- {
- $this->moderated_comment_count = $count;
- $this->updateBadCount();
- }
-
- public function addModeratedCommentCount()
- {
- $this->setModeratedCommentCount($this->getModeratedCommentCount()+1);
- }
-
- /*
- *
- *
- */
-
- public function getName()
- {
- return $this->getUsername();
- }
-
- // public function getLocalisationExploded()
- // {
- // $town = null;
- // $country = null;
- // if ($this->localisation)
- // {
- // if (($explode = explode(', ', $this->localisation)))
- // {
- // $town = $explode[0];
- // $country = $explode[1];
- // }
- // }
- // return array(
- // 'town' => $town,
- // 'country' => $country
- // );
- // }
- //
- // public function setLocalisationExploded($town, $country)
- // {
- // $town = str_replace(', ', '', $town);
- // $town = str_replace(',', '', $town);
- // $country = str_replace(', ', '', $country);
- // $country = str_replace(',', '', $country);
- //
- // $this->localisation = $town. ', ' .$country;
- // }
-
- // /**
- // * @ORM\PrePersist
- // */
- // public function setSlug()
- // {
- // if (!$this->slug)
- // {
- //
- // }
- // }
- //
- /**
- * Retourn si l'user_id transmis fait partis des enregistrements
- * followed de l'objet.
- *
- * @param int $user_id
- * @return boolean
- */
- public function isFollowingUser($user_id)
- {
- foreach ($this->followeds_users as $followed_user)
- {
- if ($followed_user->getFollowed()->getId() == $user_id)
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Retourn si l'user_id transmis est l'un des User suivis
- *
- * @param Doctrine\Bundle\DoctrineBundle\Registry doctrine
- * @param int $user_id
- * @return boolean
- */
- public function isFollowingUserByQuery($doctrine, $user_id)
- {
- return $doctrine
- ->getRepository('MuzichCoreBundle:User')
- ->isFollowingUser($this->getId(), $user_id)
- ;
- }
-
- /**
- * Retourn si l'group_id transmis est l'un des groupe suivis
- *
- * @param Doctrine\Bundle\DoctrineBundle\Registry doctrine
- * @param int $user_id
- * @return boolean
- */
- public function isFollowingGroupByQuery($doctrine, $group_id)
- {
- return $doctrine
- ->getRepository('MuzichCoreBundle:User')
- ->isFollowingGroup($this->getId(), $group_id)
- ;
- }
-
- public function getPersonalHash($salt_context = null)
- {
- return hash('sha256', $this->getSalt().$this->getUsername().$salt_context);
- }
-
- /**
- * Ajoute a l'user les tags transmis (id) comme favoris.
- *
- * @param EntityManager $em
- * @param array $ids
- */
- public function updateTagsFavoritesById(EntityManager $em, $ids)
- {
- $ids = json_decode($ids);
- $ids_to_add = $ids;
-
- // Pour chacun des tags favoris
- foreach ($this->tags_favorites as $ii => $tag_favorite)
- {
- $trouve = false;
- foreach ($ids as $i => $id)
- {
- if ($id == $tag_favorite->getTag()->getId())
- {
- $trouve = true;
- // Si le tag était favoris déjà avant (et aussi maintenant)
- // il ne sera ni a ajouter, ni a supprimer.
- unset($ids_to_add[$i]);
- }
- }
-
- if (!$trouve)
- {
- // Si cet ancien tag n'est plus dans la liste, il faut le supprimer
- // (rappel: on supprime ici la relation, pas le tag)
- $em->remove($tag_favorite);
- }
- }
-
- if (count($ids_to_add))
- {
- $ids_to_add = array_merge($ids_to_add);
- $tag_favorite_position_max = $this->getTagFavoritePositionMax();
- $tags = $em->getRepository('MuzichCoreBundle:Tag')->findByIds($ids_to_add)->execute();
-
- // Pour les nouveaux ids restants
- foreach ($tags as $tag)
- {
- $tag_favorite = new UsersTagsFavorites();
- $tag_favorite->setUser($this);
- $tag_favorite->setTag($tag);
- $tag_favorite->setPosition($tag_favorite_position_max);
- $tag_favorite_position_max++;
-
- $this->addUsersTagsFavorites($tag_favorite);
- $em->persist($tag_favorite);
- }
- }
-
- $em->flush();
- }
-
- /**
- * Retourne un tableau contenant les ids des tags préférés de l'user
- *
- * @return type array
- */
- public function getTagFavoriteIds()
- {
- $ids = array();
- foreach ($this->tags_favorites as $tag_favorite)
- {
- $ids[$tag_favorite->getTag()->getId()] = $tag_favorite->getTag()->getId();
- }
- return $ids;
- }
-
- /**
- * Retourne la position max des tag favoris.
- *
- * @return int
- */
- public function getTagFavoritePositionMax()
- {
- $max = 0;
- foreach ($this->tags_favorites as $tag_favorite)
- {
- if ($tag_favorite->getPosition() > $max)
- {
- $max = $tag_favorite->getPosition();
- }
- }
- return $max;
- }
-
- /**
- * Set email_requested_datetime
- *
- * @param integer $emailRequestedDatetime
- */
- public function setEmailRequestedDatetime($emailRequestedDatetime)
- {
- $this->email_requested_datetime = $emailRequestedDatetime;
- }
-
- /**
- * Get email_requested_datetime
- *
- * @return integer
- */
- public function getEmailRequestedDatetime()
- {
- return $this->email_requested_datetime;
- }
-
- public function addLiveData($id, $data)
- {
- $this->live_datas[$id] = $data;
- }
-
- public function removeLiveData($id)
- {
- if (array_key_exists($id, $this->live_datas))
- {
- unset($this->live_datas[$id]);
- }
- }
-
- public function hasLiveData($id, $data = null)
- {
- if (array_key_exists($id, $this->live_datas))
- {
- if ($this->live_datas[$id] == $data)
- {
- return true;
- }
- }
- return false;
- }
-
- public function getTagsFavoritesQuick()
- {
- if ($this->tags_favorites_quick == null)
- {
- return array();
- }
-
- return json_decode($this->tags_favorites_quick, true);
- }
-
- public function getTagsFavoritesQuickIds()
- {
- $tags_favorites_ids = array();
- $tags_favorites_data = $this->getTagsFavoritesQuick();
-
- foreach ($tags_favorites_data as $tag_id => $tag_name)
- {
- $tags_favorites_ids[] = $tag_id;
- }
-
- return $tags_favorites_ids;
- }
-
- /**
- *
- * @param array $tags_favorites_quick (id => name)
- */
- public function setTagsFavoritesQuick($tags_favorites_quick)
- {
- $this->tags_favorites_quick = json_encode($tags_favorites_quick);
- }
-
- /**
- *
- * @param \Muzich\CoreBundle\Entity\Tag $tag
- */
- public function addTagFavoriteQuick(Tag $tag)
- {
- $tags_favorites_quick = $this->getTagsFavoritesQuick();
- if (!array_key_exists($tag->getId(), $tags_favorites_quick))
- {
- $tags_favorites_quick[$tag->getId()] = $tag->getName();
- }
- $this->setTagsFavoritesQuick($tags_favorites_quick);
- }
-
- /**
- *
- * @param \Muzich\CoreBundle\Entity\Tag $tag
- */
- public function removeTagFavoriteQuick(Tag $tag)
- {
- $tags_favorites_quick = $this->getTagsFavoritesQuick();
- if (array_key_exists($tag->getId(), $tags_favorites_quick))
- {
- unset($tags_favorites_quick[$tag->getId()]);
- }
- $this->setTagsFavoritesQuick($tags_favorites_quick);
- }
-
- /**
- * Retourne vrai si le tag_id transmis fait partis des tags favoris de
- * l'utilisateur
- *
- * @param int $tag_id
- * @return boolean
- */
- public function haveTagsFavorite($tag_id)
- {
- $tags_favorites_quick = $this->getTagsFavoritesQuick();
- if (array_key_exists($tag_id, $tags_favorites_quick))
- {
- return true;
- }
-
- return false;
- }
-
- /**
- *
- * @return type array
- */
- public function getDatas()
- {
- if ($this->datas === null)
- {
- return array();
- }
- return json_decode($this->datas, true);
- }
-
- /**
- *
- * @param string $data_id
- * @param ~ $default
- * @return all
- */
- public function getData($data_id, $default)
- {
- $datas = $this->getDatas();
- if (array_key_exists($data_id, $datas))
- {
- return $datas[$data_id];
- }
-
- return $default;
- }
-
-
- /**
- *
- * @param array $datas
- */
- public function setDatas($datas)
- {
- $this->datas = json_encode($datas);
- }
-
- /**
- *
- * @param string $data_id
- * @param all $data_value
- */
- public function setData($data_id, $data_value)
- {
- $datas = $this->getDatas();
- $datas[$data_id] = $data_value;
- $this->setDatas($datas);
- }
-
- public function getAvatarAbsolutePath()
- {
- return null === $this->avatar_path
- ? null
- : $this->getAvatarUploadRootDir().'/'.$this->avatar_path;
- }
-
- public function getAvatarWebPath()
- {
- return null === $this->avatar_path
- ? null
- : $this->getAvatarUploadDir().'/'.$this->avatar_path;
- }
-
- protected function getAvatarUploadRootDir()
- {
- return __DIR__.'/../../../../web/'.$this->getAvatarUploadDir();
- }
-
- protected function getAvatarUploadDir()
- {
- return 'files/avatars';
- }
-
- /**
- * @ORM\PrePersist()
- * @ORM\PreUpdate()
- */
- public function preUploadAvatar()
- {
- if (null !== $this->avatar) {
- $this->avatar_path = $this->getPersonalHash($this->avatar->getClientOriginalName()).'.'.$this->avatar->guessExtension();
- }
- }
-
- /**
- * @ORM\PostPersist()
- * @ORM\PostUpdate()
- */
- public function uploadAvatar()
- {
- if (null === $this->avatar) {
- return;
- }
-
- $this->avatar->move($this->getAvatarUploadRootDir(), $this->avatar_path);
- $this->avatar = null;
- }
-
- /**
- * @ORM\PostRemove()
- */
- public function removeUpload()
- {
- if ($file = $this->getAvatarAbsolutePath()) {
- unlink($file);
- }
- }
-
- public function getCguAccepted()
- {
- return $this->cgu_accepted;
- }
-
- public function setCguAccepted($accepted)
- {
- if ($accepted)
- $this->cgu_accepted = true;
- else
- $this->cgu_accepted = false;
- }
-
- public function getMailNewsletter()
- {
- return $this->mail_newsletter;
- }
-
- public function getMailPartner()
- {
- return $this->mail_partner;
- }
-
- public function getHelpTour()
- {
- return json_decode($this->help_tour, true);
- }
-
- public function setHelpTour($help_tour)
- {
- $this->help_tour = json_encode($help_tour);
- }
-
- public function wantSeeHelp($help_id)
- {
- $help_tour_status = $this->getHelpTour();
- if (array_key_exists($help_id, $help_tour_status))
- {
- return $help_tour_status[$help_id];
- }
- return false;
- }
-
- public function setSeeHelp($help_id, $boolean)
- {
- $help_tour_status = $this->getHelpTour();
- if (array_key_exists($help_id, $help_tour_status))
- {
- $help_tour_status[$help_id] = ($boolean)?true:false;
- }
- $this->setHelpTour($help_tour_status);
- }
-
- public function getBadCount()
- {
- if (is_null($this->bad_count))
- {
- return 0;
- }
-
- return $this->bad_count;
- }
-
- public function updateBadCount()
- {
- $this->bad_count = $this->getBadReportCount()
- + $this->getModeratedCommentCount()
- + $this->getModeratedElementCount()
- + $this->getModeratedTagCount()
- ;
- }
-
- public function setUsernameUpdatable($updatable)
- {
- if ($updatable)
- $this->username_updatable = true;
- else
- $this->username_updatable = false;
- }
-
- public function isUsernameUpdatable()
- {
- if ($this->username_updatable)
- return true;
- return false;
- }
-
- public function isEmailConfirmed()
- {
- return ($this->email_confirmed)?true:false;
- }
-
- public function setEmailConfirmed($confirmed)
- {
- $this->email_confirmed = ($confirmed)?true:false;
- }
-
- public function setEmailConfirmationSentTimestamp($timestamp)
- {
- $this->email_confirmation_sent_timestamp = $timestamp;
- }
-
- public function getEmailConfirmationSentTimestamp()
- {
- return $this->email_confirmation_sent_timestamp;
- }
-
- public function isPasswordSet()
- {
- return ($this->password_set)?true:false;
- }
-
- public function setPasswordSet($set)
- {
- $this->password_set = ($set)?true:false;
- }
-
- public function setPlainPassword($password)
- {
- parent::setPlainPassword($password);
- $this->setPasswordSet(true);
- }
-
- /** @return void */
- public function setFacebookId($facebook_id)
- {
- $this->facebook_id = $facebook_id;
- $this->password_set = true;
- $this->setEmailConfirmed(true);
- }
-
- /** @return string */
- public function getFacebookId()
- {
- return $this->facebook_id;
- }
-
- /** @param Array */
- public function setFBData($fbdata) // C'est dans cette méthode que vous ajouterez vos informations
- {
- if (isset($fbdata['id'])) {
- $this->setFacebookId($fbdata['id']);
- $this->addRole('ROLE_FACEBOOK');
- }
- if (isset($fbdata['email'])) {
- $this->setEmail($fbdata['email']);
- }
- }
-
- public function getUserPlaylistsPickeds()
- {
- return $this->user_playlists_pickeds;
- }
-
- public function setUserPlaylistsPickeds(Collection $user_playlists_pickeds)
- {
- $this->user_playlists_pickeds = $user_playlists_pickeds;
- }
-
- public function havePlaylistPicked(Playlist $playlist)
- {
- foreach ($this->getPickedsPlaylists() as $playlist_picked)
- {
- if ($playlist_picked->getId() == $playlist->getId())
- {
- return true;
- }
- }
-
- return false;
- }
-
- public function getPickedsPlaylists()
- {
- $playlists = new ArrayCollection();
- foreach ($this->user_playlists_pickeds as $user_playlist_picked)
- {
- $playlists->add($user_playlist_picked->getPlaylist());
- }
-
- return $playlists;
- }
-
- public function getPlaylistsOwneds()
- {
- return $this->playlists_owneds;
- }
-
- public function setPlaylistsOwneds(Collection $playlists_owneds)
- {
- $this->playlists_owneds = $playlists_owneds;
- }
-
- public function getPrivacy()
- {
- return json_decode($this->privacy, true);
- }
-
- public function setPrivacy($privacy)
- {
- $this->privacy = json_encode($privacy);
- }
-
- public function isFavoritesPublics()
- {
- $privacy_manager = new PrivacyManager($this);
- return $privacy_manager->get(PrivacyManager::CONF_FAVORITES_PUBLIC);
- }
-
- public function setFavoritesPublics($public)
- {
- $privacy_manager = new PrivacyManager($this);
- return $privacy_manager->set(PrivacyManager::CONF_FAVORITES_PUBLIC, $public);
- }
-
- public function setDataFavoriteNoMoreUpdated()
- {
- $this->setData(self::DATA_FAV_UPDATED, false);
- }
-
- public function setDataDiffusionsNoMoreUpdated()
- {
- $this->setData(self::DATA_DIFF_UPDATED, false);
- }
-
- public function setDataPlaylistNoMoreUpdated()
- {
- $this->setData(self::DATA_PLAY_UPDATED, false);
- }
-
- }
|