<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Order;
use Doctrine\Common\Collections\Criteria;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\VirtualProperty;
use JMS\Serializer\Annotation\Accessor;
/**
* App\Entity\User
*
* @ORM\Table(name="users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ExclusionPolicy("all")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Expose
* @Groups({"single","rest","apiv1"})
*/
private $id;
/**
* @ORM\Column(type="string", length=25, unique=true)
* @Expose
* @Groups({"single","rest","apiv1"})
*/
private $username;
/**
* @ORM\Column(name="USERNAMEENCRIPTED", type="string", length=45)
*/
private $usernameencripted;
/**
* @ORM\Column(type="string", length=64)
*/
private $password;
/**
* @var string
*
* @ORM\Column( type="string", length=45, nullable=true)
* @Expose
* @Groups({"single","rest","apiv1"})
*/
private $name;
/**
* @var string
*
* @ORM\Column( type="string", length=45, nullable=true)
* @Expose
* @Groups({"single","rest","apiv1"})
*/
private $lastname;
/**
* @var string
*
* @ORM\Column(type="string", length=45, nullable=true)
*/
private $cellphone;
/**
* @var string
*
* @ORM\Column(type="string", length=45, nullable=true)
* @Expose
* @Groups({"single"})
*/
private $phone;
/**
* @ORM\Column(type="string", length=60, unique=true)
* @Expose
* @Groups({"single","rest"})
*/
private $email;
/**
* @var integer
*
* @ORM\Column(name="IDENTITYADMIN", type="integer", nullable=false)
*/
private $identityAdmin;
/**
* @ORM\Column(name="is_active", type="boolean")
* @Expose
* @Groups({"single"})
*/
private $isActive;
public function __construct()
{
$this->userRoles = new ArrayCollection();
$this->useraddress = new ArrayCollection();
$this->userattributes = new ArrayCollection();
$this->isActive = true;
}
/**
* @inheritDoc
*/
public function getUsername()
{
return $this->username;
}
/**
* @inheritDoc
*/
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
/**
* @inheritDoc
*/
public function getPassword()
{
return $this->password;
}
/**
* @inheritDoc
*/
public function eraseCredentials()
{
}
/**
* @see \Serializable::serialize()
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get id
*
* @return integer
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Set name
*
* @param string $name
* @return Usuario
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set lastname
*
* @param string $lastname
* @return Usuario
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set cellphone
*
* @param string $cellphone
* @return Usuario
*/
public function setCellphone($cellphone)
{
$this->cellphone = $cellphone;
return $this;
}
/**
* Get cellphone
*
* @return string
*/
public function getCellphone()
{
return $this->cellphone;
}
/**
* Set phone
*
* @param string $phone
* @return Usuario
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return User
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Get the formatted name to display (NAME Firstname or username)
*
* @param $separator: the separator between name and firstname (default: ' ')
* @return String
* @VirtualProperty
* @Groups({"single","rest","apiv1"})
*/
public function getNameComplete()
{
return $this->name . ' ' . $this->lastname ;
}
//-------------------------RELACIONES-------------------------------------------------//
/**
* @ORM\OneToMany(targetEntity="UserRole", mappedBy="user", cascade={"all"})
*/
private $userRoles;
public function getRoles()
{
$roles = array();
foreach ($this->userRoles as $userRole) {
$roles[] = $userRole->getRole();
}
return $roles;
}
/**
* @inheritDoc
*/
public function addUserRole(\App\Entity\UserRole $userrole)
{
$this->userRoles[] = $userrole;
return $this;
}
/**
* Remove userRoles
*
* @param \App\Entity\UserRole $userRoles
*/
public function removeUserRole(\App\Entity\UserRole $userRoles)
{
$this->userRoles->removeElement($userRoles);
}
/**
* Get userRoles
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUserRoles()
{
return $this->userRoles;
}
/**
* @ORM\OneToMany(targetEntity="Useraddress", mappedBy="user", cascade={"all"})
* @Expose
* @Groups({"rest","apiv1"})
* @Accessor(getter="getUserAddresactives")
* @ORM\OrderBy({"iduseraddress" = "DESC"})
*/
private $useraddress;
/**
* @ORM\OneToMany(targetEntity="Userattributes", mappedBy="user", cascade={"all"})
*/
private $userattributes;
public function getUserattributes()
{
return $this->userattributes;
}
public function getUserattributesbyname($name)
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("attributename", $name));
return $this->userattributes->matching($criteria);
}
public function setUserattributes($userattributes)
{
$this->userattributes = $userattributes;
return $this;
}
/**
* Add useraddress
*
* @param \App\Entity\Useraddress $useraddress
* @return User
*/
public function addUserAddress($useraddress)
{
$this->useraddress[] = $useraddress;
return $this;
}
/**
* Remove useraddress
*
* @param \App\Entity\Useraddress $useraddress
*/
public function removeUserAddress( $useraddress)
{
$this->useraddress->removeElement($useraddress);
}
/**
* Get useraddress
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUserAddress()
{
return $this->useraddress;
}
public function getUserAddresactives()
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("active", true));
return $this->useraddress->matching($criteria);
}
public function setUserAddress($useraddress)
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("active", true));
$this->useraddress = $this->useraddress->matching($criteria);
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\Order", mappedBy="user", cascade={"all"})
*/
private $userOrders;
public function addUserOrders(Order $userOrders)
{
$this->userOrders[] = $userOrders;
return $this;
}
public function removeUserOrders(Order $userOrders)
{
$this->userOrders->removeElement($userOrders);
}
public function getUserOrders()
{
return $this->userOrders;
}
/** @ORM\Column(name="SOCIALID", type="string", length=255, nullable=true) */
protected $social_id;
/** @ORM\Column(name="SOCIALACCESSTOKEN", type="string", length=255, nullable=true) */
protected $social_access_token;
public function getTypelogin() {
return $this->typelogin;
}
public function setTypelogin($typelogin) {
$this->typelogin = $typelogin;
return $this;
}
public function getSocialId() {
return $this->social_id;
}
public function setSocialId($social_id) {
$this->social_id = $social_id;
return $this;
}
public function getSocialAccessToken() {
return $this->social_access_token;
}
public function setSocialAccessToken($social_access_token) {
$this->social_access_token = $social_access_token;
return $this;
}
public function getIdentityAdmin() {
return $this->identityAdmin;
}
public function setIdentityAdmin($identityAdmin) {
$this->identityAdmin = $identityAdmin;
return $this;
}
/**
* @var boolean
*
* @ORM\Column(name="NOTIFICATIONEMAIL", type="boolean", nullable=true)
*/
private $notificationemail;
/**
* @var boolean
*
* @ORM\Column(name="NOTIFICATIONMOBILE", type="boolean", nullable=true)
*/
private $notificationmobile;
/** @ORM\Column(name="MOBILETOKEN", type="string", length=100, nullable=true) */
private $mobiletoken;
public function getNotificationemail() {
return $this->notificationemail;
}
public function setNotificationemail($notificationemail) {
$this->notificationemail = $notificationemail;
return $this;
}
public function getNotificationmobile() {
return $this->notificationmobile;
}
public function setNotificationmobile($notificationmobile) {
$this->notificationmobile = $notificationmobile;
return $this;
}
public function getMobiletoken() {
return $this->mobiletoken;
}
public function setMobiletoken($mobiletoken) {
$this->mobiletoken = $mobiletoken;
return $this;
}
/**
* @var \DateTime
*
* @ORM\Column(name="INSERTDATE", type="datetime", nullable=true)
*/
private $insertdate;
public function getInsertdate() {
return $this->insertdate;
}
public function setInsertdate(\DateTime $insertdate) {
$this->insertdate = $insertdate;
return $this;
}
public function getUsernameencripted() {
return $this->usernameencripted;
}
public function setUsernameencripted($usernameencripted) {
$this->usernameencripted = $usernameencripted;
return $this;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Usertypelogin", inversedBy="usertypeslogin", cascade={"all"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="IDUSERTYPELOGIN", referencedColumnName="IDUSERTYPELOGIN")
* })
* @Expose
* @Groups({"rest"})
*/
private $typelogin;
/**
* @var \Country
*
* @ORM\ManyToOne(targetEntity="Country")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="IDCOUNTRY", referencedColumnName="idcountry")
* })
* @Expose
* @Groups({"single","rest","apiv1"})
*/
private $country;
/**
* Add userOrder.
*
* @param \App\Entity\Order $userOrder
*
* @return User
*/
public function addUserOrder(\App\Entity\Order $userOrder)
{
$this->userOrders[] = $userOrder;
return $this;
}
/**
* Remove userOrder.
*
* @param \App\Entity\Order $userOrder
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeUserOrder(\App\Entity\Order $userOrder)
{
return $this->userOrders->removeElement($userOrder);
}
public function getCountry()
{
return $this->country;
}
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
}