<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
//use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\Countries;
/**
* User
*
* @ORM\Table(name="tam_users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\HasLifecycleCallbacks
*/
class User implements UserInterface, EquatableInterface, EncoderAwareInterface, \Serializable
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="string_confirm_email", type="string", length=255, nullable=true)
*/
private $stringConfirmEmail;
/**
* @var string
*
* @ORM\Column(name="string_confirm_recovery", type="string", length=255, nullable=true)
*/
private $stringConfirmRecovery;
/**
* @var string
*
* @ORM\Column(name="provider", type="string", length=250, nullable=false)
*/
private $provider;
/**
* @var string
*
* @ORM\Column(name="provider_client_id", type="string", length=255, nullable=true)
*/
private $providerClientId;
/**
* @var string
*
* @ORM\Column(name="access_token", type="string", length=250, nullable=true)
*/
private $accessToken;
/**
* @var string
*
* @ORM\Column(name="refresh_token", type="string", length=250, nullable=true)
*/
private $refreshToken;
/**
* @var string
*
* @ORM\Column(name="token_secret", type="string", length=250, nullable=true)
*/
private $tokenSecret;
/**
* @var string
*
* @ORM\Column(name="expires_in", type="string", length=250, nullable=true)
*/
private $expiresIn;
/**
* @var string
*
* @ORM\Column(name="civility", type="string", length=255, nullable=true)
*/
private $civility;
/**
* @var string
*
* @ORM\Column(name="nickname", type="string", length=255, nullable=true)
*/
private $nickname;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=255, nullable=true)
*/
private $lastname;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=true)
*/
private $firstname;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255, nullable=true)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="oldpassword", type="string", length=255, nullable=true)
*/
private $oldPassword;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=255, nullable=true)
*/
private $salt;
/**
* @var text
*
* @ORM\Column(name="roles", type="text", options={"default": "ROLE_USER"})
*/
private $roles;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=255, nullable=true)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="zipcode", type="string", length=255, nullable=true)
*/
private $zipcode;
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=255, nullable=true)
*/
private $city;
/**
* @var string
*
* @ORM\Column(name="country", type="string", length=255, options={"default": "FR"})
*/
private $country;
/**
* @var string
*
* @ORM\Column(name="lat", type="decimal", precision=14, scale=10, nullable=true)
*/
private $lat;
/**
* @var string
*
* @ORM\Column(name="lng", type="decimal", precision=14, scale=10, nullable=true)
*/
private $lng;
/**
* @var geography
*
* @ORM\Column(name="coordinates", type="geography", nullable=true, options={"geometry_type"="POINT", "srid"=4326})
*/
private $coordinates;
/**
* @var boolean
*
* @ORM\Column(name="connected", type="boolean", options={"default": FALSE})
*/
private $connected;
/**
* @var \DateTime
*
* @ORM\Column(name="date_last_connected", type="datetime", nullable=true)
*/
private $dateLastConnected;
/**
* @var string
*
* @ORM\Column(name="last_connect_mode", type="string", length=255, nullable=true)
*/
private $lastConnectMode;
/**
* @var string
*
* @ORM\Column(name="smartphone_type", type="string", length=255, nullable=true)
*/
private $smartphoneType;
/**
* @var string
*
* @ORM\Column(name="smartphone_os_version", type="string", length=255, nullable=true)
*/
private $smartphoneOsVersion;
/**
* @var string
*
* @ORM\Column(name="smartphone_resolution", type="string", length=255, nullable=true)
*/
private $smartphoneResolution;
/**
* @var \App\Entity\AppVersion
*
* @ORM\ManyToOne(targetEntity="\App\Entity\AppVersion", fetch="EAGER", inversedBy="users")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="smartphone_app_version", referencedColumnName="id", onDelete="SET NULL")
* })
*/
private $smartphoneAppVersion;
/**
* @var string
*
* @ORM\Column(name="device_tokens", type="text", nullable=true)
*/
private $deviceTokens;
/**
* @var \DateTime
*
* @ORM\Column(name="date_created", type="datetime", nullable=false)
*/
private $dateCreated;
/**
* @var \DateTime
*
* @ORM\Column(name="date_updated", type="datetime", nullable=true)
*/
private $dateUpdated;
/**
* @var boolean
*
* @ORM\Column(name="active", type="boolean", options={"default": FALSE})
*/
private $active;
/**
* @var boolean
*
* @ORM\Column(name="email_validate", type="boolean", options={"default": FALSE})
*/
private $emailValidate;
/**
* @var boolean
*
* @ORM\Column(name="deleted", type="boolean", options={"default": FALSE})
*/
private $deleted;
/**
* @var \DateTime
*
* @ORM\Column(name="date_deleted", type="datetime", nullable=true)
*/
private $dateDeleted;
/**
* @var string
*
* @ORM\Column(name="vat_number", type="string", length=255, nullable=true)
*/
private $vatNumber;
/**
* @var integer
*
* @ORM\Column(name="old_id", type="integer", options={"default": 0}, nullable=true)
*/
private $oldId;
/**
* @ORM\OneToOne(targetEntity="\App\Entity\Player\Player", mappedBy="user", cascade={"persist", "remove"})
*/
private $player;
/**
* @ORM\OneToOne(targetEntity="\App\Entity\Club\Club", mappedBy="user", cascade={"persist", "remove"})
*/
private $club;
/**
* @ORM\OneToOne(targetEntity="\App\Entity\Pro\Pro", mappedBy="user", cascade={"persist", "remove"})
*/
private $pro;
/**
* @ORM\OneToOne(targetEntity="\App\Entity\League\League", mappedBy="user", cascade={"persist", "remove"})
*/
private $league;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="\App\Entity\Feed\FeedElement", mappedBy="user", cascade={"persist", "remove"})
* @ORM\OrderBy({"dateCreated" = "desc"})
*/
private $feedElements;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="\App\Entity\Feed\FeedMessage", mappedBy="sender", cascade={"persist", "remove"})
*/
private $feedMessages;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="\App\Entity\Message\Message", mappedBy="sender", cascade={"persist", "remove"})
*/
private $sendedMessages;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="\App\Entity\Message\Message", mappedBy="recipient", cascade={"persist", "remove"})
*/
private $receivedMessages;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="\App\Entity\Log\LogUser", mappedBy="user", cascade={"persist", "remove"})
*/
private $connectionLogs;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Friend", mappedBy="user", cascade={"persist", "remove"})
*/
private $friends;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="\App\Entity\Friend", mappedBy="friend", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $friendRequests;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\UserFollow", mappedBy="user", cascade={"persist", "remove"})
*/
private $followUsers;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\UserFollow", mappedBy="userFollowed", cascade={"persist", "remove"})
*/
private $followers;
/**
* @var string
*
* @ORM\Column(name="avatar", type="string", length=255, nullable=true)
*/
private $avatar;
/**
* @var string
*
* @ORM\Column(name="url_avatar_provider", type="text", nullable=true)
*/
private $urlAvatarForProvider;
/**
* Image avatarFile
*
* @var File
*
* @Assert\File(
* maxSize = "5M",
* mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/tiff"},
* maxSizeMessage = "The maxmimum allowed file size is 5MB.",
* mimeTypesMessage = "Only the filetypes image are allowed."
* )
*/
protected $avatarFile;
/**
* @var float
*
*/
private $distance;
public function __construct()
{
$this->active = true;
$this->emailValidate = false;
$this->deleted = false;
$this->dateCreated = new \DateTime();
$this->dateUpdated = new \DateTime();
$this->roles = 'ROLE_USER';
$this->avatarFile = null;
$this->connected = false;
$this->feedElements = new ArrayCollection();
$this->feedMessages = new ArrayCollection();
$this->distance = 0;
$this->friends = new ArrayCollection();
$this->friendRequests = new ArrayCollection();
$this->followUsers = new ArrayCollection();
$this->followers = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set stringConfirmEmail
*
* @param string $stringConfirmEmail
*
* @return User
*/
public function setStringConfirmEmail($stringConfirmEmail)
{
$this->stringConfirmEmail = $stringConfirmEmail;
return $this;
}
/**
* Get stringConfirmEmail
*
* @return string
*/
public function getStringConfirmEmail()
{
return $this->stringConfirmEmail;
}
/**
* Set stringConfirmRecovery
*
* @param string $stringConfirmRecovery
*
* @return User
*/
public function setStringConfirmRecovery($stringConfirmRecovery)
{
$this->stringConfirmRecovery = $stringConfirmRecovery;
return $this;
}
/**
* Get stringConfirmRecovery
*
* @return string
*/
public function getStringConfirmRecovery()
{
return $this->stringConfirmRecovery;
}
/**
* Set provider
*
* @param string $provider
*
* @return User
*/
public function setProvider($provider)
{
$this->provider = $provider;
return $this;
}
/**
* Get provider
*
* @return string
*/
public function getProvider()
{
return $this->provider;
}
/**
* Set providerClientId
*
* @param string $providerClientId
*
* @return User
*/
public function setProviderClientId($providerClientId)
{
$this->providerClientId = $providerClientId;
return $this;
}
/**
* Get providerClientId
*
* @return string
*/
public function getProviderClientId()
{
return $this->providerClientId;
}
/**
* Set accessToken
*
* @param string $accessToken
*
* @return User
*/
public function setAccessToken($accessToken)
{
$this->accessToken = $accessToken;
return $this;
}
/**
* Get accessToken
*
* @return string
*/
public function getAccessToken()
{
return $this->accessToken;
}
/**
* Set refreshToken
*
* @param string $refreshToken
*
* @return User
*/
public function setRefreshToken($refreshToken)
{
$this->refreshToken = $refreshToken;
return $this;
}
/**
* Get refreshToken
*
* @return string
*/
public function getRefreshToken()
{
return $this->refreshToken;
}
/**
* Set tokenSecret
*
* @param string $tokenSecret
*
* @return User
*/
public function setTokenSecret($tokenSecret)
{
$this->tokenSecret = $tokenSecret;
return $this;
}
/**
* Get tokenSecret
*
* @return string
*/
public function getTokenSecret()
{
return $this->tokenSecret;
}
/**
* Set expiresIn
*
* @param string $expiresIn
*
* @return User
*/
public function setExpiresIn($expiresIn)
{
$this->expiresIn = $expiresIn;
return $this;
}
/**
* Get expiresIn
*
* @return string
*/
public function getExpiresIn()
{
return $this->expiresIn;
}
/**
* Set civility
*
* @param string $civility
*
* @return User
*/
public function setCivility($civility)
{
$this->civility = $civility;
return $this;
}
/**
* Get civility
*
* @return string
*/
public function getCivility()
{
return $this->civility;
}
/**
* Set nickname
*
* @param string $nickname
*
* @return User
*/
public function setNickname($nickname)
{
$this->nickname = $nickname;
return $this;
}
/**
* Get nickname
*
* @return string
*/
public function getNickname()
{
if($this->getPlayer() && $this->nickname == ""){
//return strtoupper($this->getLastname())." ".substr($this->firstname, 0, 1).".";
if($this->getLastname() != ""){
return strtoupper($this->getLastname());
}else{
return "Tam nickname undefined";
}
}
return $this->nickname;
}
/**
* Set lastname
*
* @param string $lastname
*
* @return User
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set firstname
*
* @param string $firstname
*
* @return Administrator
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email)
{
$this->email = strtolower($email);
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* @param string $password
*
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
//return $this->password;
return null === $this->password ? $this->oldPassword : $this->password;
}
/**
* Set oldPassword
*
* @param string $password
*
* @return User
*/
public function setOldPassword($oldPassword)
{
$this->oldPassword = $oldPassword;
return $this;
}
/**
* Get oldPassword
*
* @return string
*/
public function getOldPassword()
{
return $this->oldPassword;
}
/**
* Set roles
*
* @param string $roles
*
* @return User
*/
public function setRoles($roles)
{
$this->roles = $roles;
return $this;
}
/**
* Get roles
*
* @return string
*/
public function getRoles()
{
return array($this->roles);
}
/**
* Set salt
*
* @param string $salt
*
* @return User
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
//return null;
//return "TEST";
return $this->salt;
}
/**
* Set address
*
* @param string $address
*
* @return User
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set zipcode
*
* @param string $zipcode
*
* @return User
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
return $this;
}
/**
* Get zipcode
*
* @return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set city
*
* @param string $city
*
* @return User
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set country
*
* @param string $country
*
* @return User
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set lat
*
* @param string $lat
* @return User
*/
public function setLat($lat)
{
$this->lat = $lat;
return $this;
}
/**
* Get lat
*
* @return string
*/
public function getLat()
{
return $this->lat;
}
/**
* Set lng
*
* @param string $lng
* @return User
*/
public function setLng($lng)
{
$this->lng = $lng;
return $this;
}
/**
* Get lng
*
* @return string
*/
public function getLng()
{
return $this->lng;
}
/**
* Set coordinates
*
* @param string $coordinates
* @return User
*/
public function setCoordinates($coordinates)
{
$this->coordinates = $coordinates;
return $this;
}
/**
* Get coordinates
*
* @return \geography
*/
public function getCoordinates()
{
return $this->coordinates;
}
/**
* Set connected
*
* @param boolean $connected
*
* @return User
*/
public function setConnected($connected)
{
$this->connected = $connected;
return $this;
}
/**
* Get connected
*
* @return boolean
*/
public function getConnected()
{
return $this->connected;
}
/**
* Set dateLastConnected
*
* @param \DateTime $dateLastConnected
*
* @return User
*/
public function setDateLastConnected($dateLastConnected)
{
$this->dateLastConnected = $dateLastConnected;
return $this;
}
/**
* Get dateLastConnected
*
* @return \DateTime
*/
public function getDateLastConnected()
{
return $this->dateLastConnected;
}
/**
* Set lastConnectMode
*
* @param string $lastConnectMode
*
* @return User
*/
public function setLastConnectMode($lastConnectMode)
{
$this->lastConnectMode = $lastConnectMode;
return $this;
}
/**
* Get lastConnectMode
*
* @return string
*/
public function getLastConnectMode()
{
return $this->lastConnectMode;
}
/**
* Set smartphoneType
*
* @param string $smartphoneType
*
* @return User
*/
public function setSmartphoneType($smartphoneType)
{
$this->smartphoneType = $smartphoneType;
return $this;
}
/**
* Get smartphoneType
*
* @return string
*/
public function getSmartphoneType()
{
return $this->smartphoneType;
}
/**
* Set smartphoneOsVersion
*
* @param string $smartphoneOsVersion
*
* @return User
*/
public function setSmartphoneOsVersion($smartphoneOsVersion)
{
$this->smartphoneOsVersion = $smartphoneOsVersion;
return $this;
}
/**
* Get smartphoneOsVersion
*
* @return string
*/
public function getSmartphoneOsVersion()
{
return $this->smartphoneOsVersion;
}
/**
* Set smartphoneResolution
*
* @param string $smartphoneResolution
*
* @return User
*/
public function setSmartphoneResolution($smartphoneResolution)
{
$this->smartphoneResolution = $smartphoneResolution;
return $this;
}
/**
* Get smartphoneResolution
*
* @return string
*/
public function getSmartphoneResolution()
{
return $this->smartphoneResolution;
}
/**
* Set smartphoneAppVersion
*
* @param RankingSystem $smartphoneAppVersion
*
* @return user
*/
public function setSmartphoneAppVersion($smartphoneAppVersion)
{
$this->smartphoneAppVersion = $smartphoneAppVersion;
return $this;
}
/**
* Get smartphoneAppVersion
*
* @return AppVersion
*/
public function getSmartphoneAppVersion()
{
return $this->smartphoneAppVersion;
}
/**
* Set deviceTokens
*
* @param string $deviceTokens
*
* @return User
*/
public function setDeviceTokens($deviceTokens)
{
$this->deviceTokens = $deviceTokens;
return $this;
}
/**
* Get deviceTokens
*
* @return string
*/
public function getDeviceTokens()
{
return $this->deviceTokens;
}
/**
* Set dateCreated
*
* @param \DateTime $dateCreated
*
* @return User
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* @return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
/**
* Set dateUpdated
*
* @param \DateTime $dateUpdated
*
* @return User
*/
public function setDateUpdated($dateUpdated)
{
$this->dateUpdated = $dateUpdated;
return $this;
}
/**
* Get dateUpdated
*
* @return \DateTime
*/
public function getDateUpdated()
{
return $this->dateUpdated;
}
/**
* Set active
*
* @param boolean $active
*
* @return User
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set emailValidate
*
* @param boolean $emailValidate
*
* @return User
*/
public function setEmailValidate($emailValidate)
{
$this->emailValidate = $emailValidate;
return $this;
}
/**
* Get emailValidate
*
* @return boolean
*/
public function getEmailValidate()
{
return $this->emailValidate;
}
/**
* Set dateActive
*
* @param \DateTime $dateActive
*
* @return User
*/
public function setDateActive($dateActive)
{
$this->dateActive = $dateActive;
return $this;
}
/**
* Get dateActive
*
* @return \DateTime
*/
public function getDateActive()
{
return $this->dateActive;
}
/**
* Set deleted
*
* @param boolean $deleted
*
* @return User
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
return $this;
}
/**
* Get deleted
*
* @return boolean
*/
public function getDeleted()
{
return $this->deleted;
}
/**
* Set dateDeleted
*
* @param \DateTime $dateDeleted
*
* @return User
*/
public function setDateDeleted($datedeleted)
{
$this->dateDeleted = $datedeleted;
return $this;
}
/**
* Get dateDeleted
*
* @return \DateTime
*/
public function getDateDeleted()
{
return $this->dateDeleted;
}
/**
* Set vatNumber
*
* @param string $vatNumber
*
* @return User
*/
public function setVatNumber($vatNumber)
{
$this->vatNumber = $vatNumber;
return $this;
}
/**
* Get vatNumber
*
* @return string
*/
public function getVatNumber()
{
return $this->vatNumber;
}
/**
* Set oldId
*
* @param integer $oldId
*
* @return User
*/
public function setOldId($oldId)
{
$this->oldId = $oldId;
return $this;
}
/**
* Get oldId
*
* @return integer
*/
public function getOldId()
{
return $this->oldId;
}
/**
* Set Player
*
* @param \App\Entity\Player\Player $player
*
* @return User
*/
public function setPlayer(\App\Entity\Player\Player $player)
{
//$player->setUser($this);
$this->player = $player;
return $this;
}
/**
* Get player
*
* @return \App\Entity\Player\Player
*/
public function getPlayer()
{
return $this->player;
}
/**
* Set Club
*
* @param \App\Entity\Club\Club $club
*
* @return User
*/
public function setClub(\App\Entity\Club\Club $club)
{
$this->club = $club;
return $this;
}
/**
* Get club
*
* @return \App\Entity\Club\Club
*/
public function getClub()
{
return $this->club;
}
/**
* Set Pro
*
* @param \App\Entity\Pro\Pro $pro
*
* @return User
*/
public function setPro(\App\Entity\Pro\Pro $pro)
{
$this->pro = $pro;
return $this;
}
/**
* Get pro
*
* @return \App\Entity\Pro\Pro
*/
public function getPro()
{
return $this->pro;
}
/**
* Set league
*
* @param \App\Entity\League\League $league
*
* @return User
*/
public function setLeague(\App\Entity\League\League $league)
{
$this->league = $league;
return $this;
}
/**
* Get league
*
* @return \App\Entity\League\League
*/
public function getLeague()
{
return $this->league;
}
/**
* Add feedElement
*
* @param \App\Entity\Feed\FeedElement $feedElement
*
* @return User
*/
public function addFeedElement(\App\Entity\Feed\FeedElement $feedElement)
{
$this->feedElements[] = $feedElement;
return $this;
}
/**
* Remove feedElement
*
* @param \App\Entity\Feed\FeedElement $feedElement
*/
public function removeFeedElement(\App\Entity\Feed\FeedElement $feedElement)
{
$this->feedElements->removeElement($feedElement);
}
/**
* Get feedElements
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFeedElements()
{
return $this->feedElements;
}
/**
* Add feedMessage
*
* @param \App\Entity\Feed\FeedMessage $feedMesage
*
* @return User
*/
public function addFeedMessage(\App\Entity\Feed\FeedMessage $feedMessage)
{
$this->feedMessages[] = $feedMessage;
return $this;
}
/**
* Remove feedMessage
*
* @param \App\Entity\Feed\FeedMessage $feedMessage
*/
public function removeFeedMessage(\App\Entity\Feed\FeedMessage $feedMessage)
{
$this->feedMessages->removeElement($feedMessage);
}
/**
* Get feedMessages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFeedMessages()
{
return $this->feedMessages;
}
/**
* Add message
*
* @param \App\Entity\Message\Message $message
*
* @return User
*/
public function addSendedMessage(\App\Entity\Message\Message $message)
{
$this->sendedMessages[] = $message;
return $this;
}
/**
* Remove message
*
* @param \App\Entity\Message\Message $message
*/
public function removeSendedMessage(\App\Entity\Message\Message $message)
{
$this->sendedMessages->removeElement($message);
}
/**
* Get sendedMessages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSendedMessages()
{
return $this->sendedMessages;
}
/**
* Add receivedMessage
*
* @param \App\Entity\Message\Message $message
*
* @return User
*/
public function addReceivedMessage(\App\Entity\Message\Message $message)
{
$this->receivedMessages[] = $message;
return $this;
}
/**
* Remove receivedMessage
*
* @param \App\Entity\Message\Message $message
*/
public function removeReceivedMessage(\App\Entity\Message\Message $message)
{
$this->receivedMessages->removeElement($message);
}
/**
* Get receivedMessages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getReceivedMessages()
{
return $this->receivedMessages;
}
/**
* Add connectionLog
*
* @param \App\Entity\Log\LogUser $connectionLog
*
* @return User
*/
public function addConnectionLog(\App\Entity\Log\LogUser $connectionLog)
{
$this->connectionLogs[] = $connectionLog;
return $this;
}
/**
* Remove connectionLog
*
* @param \App\Entity\Log\LogUser $connectionLog
*/
public function removeConnectionLog(\App\Entity\Log\LogUser $connectionLog)
{
$this->connectionLogs->removeElement($connectionLog);
}
/**
* Get connectionLogs
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getConnectionLogs()
{
return $this->connectionLogs;
}
/**
* Add friend
*
* @param \App\Entity\Friend $friend
*
* @return User
*/
public function addFriend(\App\Entity\Friend $friend)
{
$friend->setUser($this);
$this->friends[] = $friend;
return $this;
}
/**
* Remove friend
*
* @param \App\Entity\Friend $friend
*/
public function removeFriend(\App\Entity\Friend $friend)
{
$this->friends->removeElement($friend);
}
/**
* Get friends
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFriends()
{
return $this->friends;
}
/**
* Add friendRequest
*
* @param \App\Entity\Friend $friendRequest
*
* @return User
*/
public function addFriendRequest(\App\Entity\Friend $friendRequest)
{
$this->friendRequests[] = $friendRequest;
return $this;
}
/**
* Remove friendRequest
*
* @param \App\Entity\Friend $friendRequest
*/
public function removeFriendRequest(\App\Entity\Friend $friendRequest)
{
$this->friendRequests->removeElement($friendRequest);
}
/**
* Get friendRequests
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFriendRequests()
{
return $this->friendRequests;
}
/**
* Add followUser
*
* @param \App\Entity\UserFollow $followUser
*
* @return User
*/
public function addFollowUser(\App\Entity\UserFollow $followUser)
{
$this->followUsers[] = $followUser;
return $this;
}
/**
* Remove followUser
*
* @param \App\Entity\UserFollow $followUser
*/
public function removeFollowUser(\App\Entity\UserFollow $followUser)
{
$this->followUsers->removeElement($followUser);
}
/**
* Get followUsers
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFollowUsers()
{
return $this->followUsers;
}
/**
* Add follower
*
* @param \App\Entity\UserFollow $follower
*
* @return User
*/
public function addFollower(\App\Entity\UserFollow $follower)
{
$this->followers[] = $follower;
return $this;
}
/**
* Remove follower
*
* @param \App\Entity\UserFollow $follower
*/
public function removeFollower(\App\Entity\UserFollow $follower)
{
$this->followers->removeElement($follower);
}
/**
* Get followers
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFollowers()
{
return $this->followers;
}
/********************************
EncoderAwareInterface
********************************/
/**
* Tells whether user uses the legacy password encoding or the new one
*
* @return boolean
*/
public function hasLegacyPassword()
{
return null !== $this->oldPassword;
}
/**
* {@inheritDoc}
*/
public function getEncoderName()
{
if ($this->hasLegacyPassword()) {
// User is configured with a legacy password, make use of the legacy encoder
// configured in security.yml
return 'legacy_encoder';
}
// User is configured with the default password system, make use of the default encoder
return null;
}
/********************************
SERIALIZE
*********************************/
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
$this->nickname,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->email,
$this->password,
$this->nickname,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
public function eraseCredentials()
{
}
public function getUsername()
{
return $this->email;
}
/**
* Set avatar
*
* @param string $avatar
*
* @return User
*/
public function setAvatar($avatar)
{
$this->avatar = $avatar;
return $this;
}
/**
* Get avatar
*
* @return string
*/
public function getAvatar()
{
return $this->avatar;
}
/**
* Set urlAvatarForProvider
*
* @param string $urlAvatarForProvider
*
* @return User
*/
public function setUrlAvatarForProvider($urlAvatarForProvider)
{
$this->urlAvatarForProvider = $urlAvatarForProvider;
return $this;
}
/**
* Get urlAvatarForProvider
*
* @return string
*/
public function getUrlAvatarForProvider()
{
return $this->urlAvatarForProvider;
}
public function getLinkAvatar()
{
if($this->provider == 'facebook'){
if($this->getUrlAvatarForProvider())
return $this->getUrlAvatarForProvider();
}else{
if($this->getAvatar()){
if(file_exists($this->getUploadAvatarRootDir().$this->getAvatar()))
return $this->getAvatarDir().$this->getAvatar();
}
}
if($this->player)
return '/assets/images/common/defaultAvatar.png';
else if($this->club)
return '/assets/images/common/defaultAvatarClub.png';
else if($this->pro)
return '/assets/images/common/defaultAvatarPro.png';
return '/assets/images/common/defaultAvatar.png';
}
public function getAbsolutePathAvatar()
{
if($this->getAvatar()){
if(file_exists($this->getUploadAvatarRootDir().$this->getAvatar()))
return $this->getUploadAvatarRootDir().$this->getAvatarPath();
else
return null;
}else{
return null;
}
}
/**
* Sets avatarFile.
*
* @param UploadedFile $file
*/
public function setAvatarFile(UploadedFile $file = null)
{
$this->avatarFile = $file;
$this->setDateUpdated(new \DateTime());
}
/**
* Get avatarFile.
*
* @return UploadedFile
*/
public function getAvatarFile()
{
return $this->avatarFile;
}
/**
* Set distance
*
* @param float $distance
*
* @return User
*/
public function setDistance($distance)
{
$this->distance = str_replace(",", ".", $distance);
return $this;
}
/**
* Get distance
*
* @return float
*/
public function getDistance()
{
return $this->distance;
}
/**
* Get stringDistance
*
* @return string
*/
public function getStringDistance()
{
if($this->distance > 1000){
return sprintf("%0.2f km", $this->distance/1000);
}else{
return sprintf("%0.2f m", $this->distance);
}
}
public function isEqualTo(UserInterface $user)
{
/*if (!$user instanceof Users) {
return false;
}*/
if ($this->id !== $user->getId()) {
return false;
}
if ($this->email !== $user->getEmail()) {
return false;
}
/*if ($this->provider=='email' && $this->password !== $user->getPassword()) {
return false;
}*/
return true;
}
/***********************
* Lifecycle Callbacks
***********************/
/**
*
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpdate()
{
$this->setDateUpdated(new \DateTime());
if($this->getLng() && $this->getLat())
$this->setCoordinates('SRID=4326;POINT(' . $this->getLng() . ' ' . $this->getLat() . ')');
}
/**
* Called before saving the entity
*
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if (null !== $this->avatarFile) {
// do whatever you want to generate a unique name
$filename = sha1(uniqid(mt_rand(), true));
//$this->avatar = $filename.'.'.$this->avatarFile->guessExtension();
$this->avatar = $filename.'.'.$this->avatarFile->getClientOriginalExtension();
$this->setDateUpdated(new \DateTime());
}
}
/**
* Called before entity removal
*
* @ORM\PreRemove()
*/
public function removeUpload()
{
if ($file = $this->getAbsolutePathAvatar()) {
unlink($file);
}
}
/**
* Called after entity persistence
*
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload()
{
// The file property can be empty if the field is not required
if (null === $this->avatarFile) {
return;
}
// Use the original file name here but you should
// sanitize it at least to avoid any security issues
// move takes the target directory and then the
// target filename to move to
$this->avatarFile->move(
$this->getUploadAvatarRootDir(),
$this->avatar
);
// Set the path property to the filename where you've saved the file
//$this->path = $this->file->getClientOriginalName();
// Clean up the file property as you won't need it anymore
$this->avatarFile = null;
}
/***********************
* OTHER FUNCTION
***********************/
public function isFriend(User $target){
foreach($this->getFriends() as $friend){
if($friend->getFriend()->getId() == $target->getId()){
if($friend->getDateAccept())
return true;
}
}
foreach($this->getFriendRequests() as $friend){
if($friend->getUser()->getId() == $target->getId()){
if($friend->getDateAccept())
return true;
}
}
return false;
}
public function isFriendRequestSent(User $target){
foreach($this->getFriends() as $friend){
if($friend->getFriend()->getId() == $target->getId()){
if(!$friend->getDateAccept())
return true;
}
}
return false;
}
public function isFriendRequestReceived(User $target){
foreach($this->getFriendRequests() as $friend){
if($friend->getUser()->getId() == $target->getId()){
if(!$friend->getDateAccept())
return $friend->getId();
}
}
return false;
}
public function getFriendRequestReceived(User $target){
foreach($this->getFriendRequests() as $friend){
if($friend->getUser()->getId() == $target->getId()){
if(!$friend->getDateAccept())
return $friend;
}
}
return false;
}
public function nbRequestFriend(){
$nb = 0;
foreach($this->getFriendRequests() as $friend){
if(!$friend->getDateAccept())
$nb++;
}
return $nb;
}
public function getRequestFriend(){
$arrayReturn = array();
foreach($this->getFriendRequests() as $friend){
if(!$friend->getDateAccept())
$arrayReturn[] = $friend;
}
return $arrayReturn;
}
public function getAllFriends(){
$arrayReturn = array();
foreach($this->getFriendRequests() as $friend){
if($friend->getDateAccept())
$arrayReturn[] = $friend->getUser();
}
foreach($this->getFriends() as $friend){
if($friend->getDateAccept())
$arrayReturn[] = $friend->getFriend();
}
return $arrayReturn;
}
public function getAllUsersInvitationSent(){
$arrayReturn = array();
foreach($this->getFriends() as $friend){
if(!$friend->getDateAccept())
$arrayReturn[] = $friend->getFriend();
}
return $arrayReturn;
}
public function getNbUnreadMessageForUserInteract(User $userInteract){
$nb = 0;
foreach($this->getReceivedMessages() as $message){
if($message->getSender()->getId() == $userInteract->getId() && $message->getRead() == FALSE){
$nb++;
}
}
return $nb;
}
public function isFollowed(User $target){
foreach($this->getFollowUsers() as $followUser){
if($followUser->getUserFollowed()->getId() == $target->getId()){
return true;
}
}
return false;
}
public function getAllUsersFollowed(){
$arrayReturn = array();
foreach($this->getFollowUsers() as $followUser){
$arrayReturn[] = $followUser->getUserFollowed();
}
return $arrayReturn;
}
public function getListIdFriends()
{
$listFriendId = array();
foreach($this->getAllFriends() as $friend){
$listFriendId[] = $friend->getId();
}
return $listFriendId;
}
public function getListIdFollowed()
{
$listIds = array();
foreach($this->getAllUsersFollowed() as $userFollowed){
$listIds[] = $userFollowed->getId();
}
return $listIds;
}
public function getListIdFriendsAndFollowed()
{
$listIds = array();
foreach($this->getAllFriends() as $friend){
$listIds[] = $friend->getId();
}
foreach($this->getAllUsersFollowed() as $userFollowed){
$listIds[] = $userFollowed->getId();
}
return $listIds;
}
public function getUploadAvatarRootDir(){
$logoDir = __DIR__ . '/../../public/assets/profiles/'.$this->getId().'/avatar/';
$fs = new Filesystem();
if ($fs->exists($logoDir) == false) {
$fs->mkdir($logoDir);
}
return $logoDir;
}
public function getAvatarDir()
{
return '/assets/profiles/'.$this->getId().'/avatar/';
}
public function getCountryName(){
//return Intl::getRegionBundle()->getCountryName($this->getCountry());
if(!$this->getCountry() || $this->getCountry() == "" || $this->getCountry() == "ITN")
return "";
return Countries::getName($this->getCountry());
}
public function getSimpleWithTypeArrayForJson($schemeAndBaseURL, $userTools = null, $currentUser = null){
$array = $this->getSimpleArrayForJson($schemeAndBaseURL);
if($this->getPlayer()){
$array['player'] = $this->getPlayer()->getArrayForJson($userTools, $currentUser);
}else if($this->getClub()){
$array['club'] = $this->getClub()->getArrayForJson();
}else if($this->getPro()){
$array['pro'] = $this->getPro()->getArrayForJson();
}
return $array;
}
public function hasInvoice(){
if($this->getFeedElements()){
foreach($this->getFeedElements() as $feed){
if($feed->getTransaction()){
return true;
}
}
}
return false;
}
public function getCustomerCode(){
return "TAM".sprintf("%05d", $this->getId());
}
public function getSimpleArrayForJson($schemeAndBaseURL, $userTools = null, $currentUser = null){
$array = array();
$array['id'] = $this->getId();
$array['civility'] = $this->getCivility();
if($this->getNickname())
$array['nickname'] = $this->getNickname();
else
$array['nickname'] = "Not defined";
$array['lastname'] = $this->getLastname();
$array['firstname'] = $this->getFirstname();
$array['email'] = $this->getEmail();
$array['address'] = $this->getAddress();
$array['zipcode'] = $this->getZipcode();
$array['city'] = $this->getCity();
$array['country'] = $this->getCountry();
$array['countryName'] = $this->getCountryName();
$array['lat'] = $this->getLat();
$array['lng'] = $this->getLng();
$array['distance'] = $this->getDistance();
$array['distanceLabel'] = $this->getStringDistance();
if($this->getAvatar()){
if($this->getProvider() == 'email')
$array['avatarURL'] = $schemeAndBaseURL.$this->getLinkAvatar();
else
$array['avatarURL'] = $this->getLinkAvatar();
}
$array['isPlayer'] = $this->getPlayer() ? true : false;
$array['isClub'] = $this->getClub() ? true : false;
$array['isPro'] = $this->getPro() ? true : false;
return $array;
}
public function getArrayForJson($schemeAndBaseURL, $userTools = null, $currentUser = null, $friend = false){
$array = array();
$array['id'] = $this->getId();
$array['civility'] = $this->getCivility();
$array['nickname'] = $this->getNickname();
$array['lastname'] = $this->getLastname();
$array['firstname'] = $this->getFirstname();
$array['email'] = $this->getEmail();
$array['address'] = $this->getAddress();
$array['zipcode'] = $this->getZipcode();
$array['city'] = $this->getCity();
$array['country'] = $this->getCountry();
$array['countryName'] = $this->getCountryName();
$array['lat'] = $this->getLat();
$array['lng'] = $this->getLng();
if($this->getAvatar()){
if($this->getProvider() == 'email')
$array['avatarURL'] = $schemeAndBaseURL.$this->getLinkAvatar();
else
$array['avatarURL'] = $this->getLinkAvatar();
}
if($this->getPlayer()){
$array['player'] = $this->getPlayer()->getArrayForJson($userTools, $currentUser);
if($this->getAllFriends() && $friend === false){
$array['NBfriends'] = count($this->getAllFriends());
foreach($this->getAllFriends() as $friend){
$array['friends'][] = $friend->getSimpleWithTypeArrayForJson($schemeAndBaseURL, $userTools, $currentUser, true);
}
}
if($this->getAllUsersInvitationSent()){
$array['NBInvitationsSent'] = count($this->getAllUsersInvitationSent());
foreach($this->getAllUsersInvitationSent() as $friend){
$array['invitationSent'][] = $friend->getSimpleWithTypeArrayForJson($schemeAndBaseURL, $userTools, $currentUser, true);
}
}
if($this->getRequestFriend()){
$array['NBRequestFriendReceived'] = count($this->getRequestFriend());
foreach($this->getRequestFriend() as $request){
$array['requestFriendReceived'][] = $request->getUser()->getSimpleWithTypeArrayForJson($schemeAndBaseURL, $userTools, $currentUser, true);
}
}
}
if($this->getClub() || $this->getPro()){
if($this->getClub())
$array['club'] = $this->getClub()->getArrayForJson();
if($this->getPro())
$array['pro'] = $this->getPro()->getArrayForJson();
if($this->getFollowers()){
$array['NBFollowers'] = count($this->getFollowers());
foreach($this->getFollowers() as $follower){
$array['followers'][] = $follower->getUser()->getSimpleWithTypeArrayForJson($schemeAndBaseURL, $userTools, $currentUser, true);
}
}
}
if($this->getAllUsersFollowed()){
$array['NBFollowUsers'] = count($this->getAllUsersFollowed());
foreach($this->getAllUsersFollowed() as $followUser){
$array['followUsers'][] = $followUser->getSimpleArrayForJson($schemeAndBaseURL, $userTools, $currentUser, true);
}
}
$array['isPlayer'] = $this->getPlayer() ? true : false;
$array['isClub'] = $this->getClub() ? true : false;
$array['isPro'] = $this->getPro() ? true : false;
return $array;
}
public function getJsonData(){
return json_encode($this->getArrayForJson());
}
public function getFriendInfoArrayForJson($schemeAndBaseURL){
$array = array();
$array['id'] = $this->getId();
$array['civility'] = $this->getCivility();
$array['nickname'] = $this->getNickname();
$array['lastname'] = $this->getLastname();
$array['firstname'] = $this->getFirstname();
$array['email'] = $this->getEmail();
$array['address'] = $this->getAddress();
$array['zipcode'] = $this->getZipcode();
$array['city'] = $this->getCity();
$array['country'] = $this->getCountry();
$array['countryName'] = $this->getCountryName();
$array['lat'] = $this->getLat();
$array['lng'] = $this->getLng();
if($this->getAvatar()){
if($this->getProvider() == 'email')
$array['avatarURL'] = $schemeAndBaseURL.$this->getLinkAvatar();
else
$array['avatarURL'] = $this->getLinkAvatar();
}
if($this->getTams()){
foreach($this->getTams() as $tam){
$array['tams'][] = $tam->getArrayForJson($schemeAndBaseURL);
}
}
$array['isPlayer'] = $this->getPlayer() ? true : false;
$array['isClub'] = $this->getClub() ? true : false;
$array['isPro'] = $this->getPro() ? true : false;
return $array;
}
public function updateFromJson($jsonObject){
$this->setNickname($jsonObject->nickname);
$this->setLastname($jsonObject->lastname);
$this->setFirstname($jsonObject->firstname);
$this->setEmail($jsonObject->email);
$this->setAddress($jsonObject->address);
$this->setZipcode($jsonObject->zipcode);
$this->setCity($jsonObject->city);
$this->setCountry(strtoupper($jsonObject->country));
}
}