<?php
namespace User\Entity;
use Core\Entity\Traits\EntityTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="User\Repository\UserRepository")
* @ORM\Table(name="users_user")
*/
class User implements UserInterface, \Serializable
{
use EntityTrait {
EntityTrait::__construct as private __entityConstruct;
}
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $account_type;
/**
* Référence unique de l'utilisateur
*
* @ORM\Column(type="string", length=255, unique=true)
*/
private $reference;
/**
* Numéro de compte
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $account_number;
/**
* Civilité (Monsieur, Madame, ...)
*
* @ORM\Column(type="integer", nullable=true)
*/
private $title;
/**
* Nom
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastname;
/**
* Prénom
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstname;
/**
* Téléphone
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* Adresse e-mail
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;
/**
* Date de naissance
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $birthday;
/**
* Adresse du site internet
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $website;
/**
* Société
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $company;
/**
* N° SIRET
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $siret;
/**
* N° TVA INTRACOMMUNAUTAIRE
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tva_intracommunautaire;
/**
* N° APE
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $ape;
/**
* Notes
*
* @ORM\Column(type="text", nullable=true)
*/
private $note;
/**
* Montant de crédit autorisé
*
* @ORM\Column(type="integer", nullable=true)
*/
private $outstanding_allow_amount;
/**
* Mot de passe crypté de l'utilisateur
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $password;
/**
* TOKEN d'identification pour réinitialiser le mot de passe
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $forgot_token;
/**
* Date de la dernière demande de réinitialisation du mot de passe
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $forgot_time;
/**
* Inscription à la newsletter
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $use_newsletter;
/**
* Liste des adresses
*
* @ORM\OneToMany(targetEntity="UserAddress", mappedBy="user", cascade={"persist", "remove"})
*/
private $address;
/**
* Liste des adresses
*
* @ORM\OneToMany(targetEntity="UserFavoris", mappedBy="user", cascade={"persist", "remove"})
*/
private $favoris;
/**
* Groupes utilisateurs
*
* @ORM\ManyToMany(targetEntity="UserGroup", mappedBy="users")
*/
private $userGroups;
/**
* Rôles
* TODO - Relier les Rôles au Groupes utilisateurs
*
* @ORM\Column(name="roles", type="array")
*/
private $roles = array();
/**
* Dernière visite
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $last_visit;
/**
* Liste des commandes de l'utilisateur
*
* @ORM\OneToMany(targetEntity="Shopping\Entity\Order", mappedBy="user")
*/
private $orders;
/**
* @Assert\NotBlank()
* @Assert\Length(max=250)
*/
private $plainPassword;
/**
* @ORM\OneToMany(targetEntity="Shopping\Entity\ProductSpecificPrice", mappedBy="user_group", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $specific_prices;
private $collections = [
'specific_price'
];
/**
* Constructeur
* @throws \Exception
*/
public function __construct()
{
$this->__entityConstruct();
$datetime = new \Datetime();
$this->setLastVisit($datetime);
$this->setReference(uniqid());
$this->userGroups = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->address = new ArrayCollection();
$this->favoris = new ArrayCollection();
$this->userGroups = new ArrayCollection();
$this->specific_prices = new ArrayCollection();
}
public function getCollections()
{
return $this->collections;
}
public function getReference()
{
return $this->reference;
}
public function setReference($reference)
{
$this->reference = $reference;
}
/**
* @return mixed
*/
public function getAccountNumber()
{
return $this->account_number;
}
/**
* @param mixed $account_number
*/
public function setAccountNumber($account_number): void
{
$this->account_number = $account_number;
}
/**
* Collection - Prix spécifiques
*/
public function getSpecificPrices()
{
return $this->specific_prices;
}
public function setSpecificPrices($items)
{
$this->specific_prices = $items;
return $this;
}
public function addSpecificPrice($item)
{
$this->specific_prices->add($item);
$item->setUser($this);
return $this;
}
public function removeSpecificPrice($item)
{
$this->specific_prices->removeElement($item);
return $this;
}
public function getUseNewsletter()
{
return $this->use_newsletter;
}
public function setUseNewsletter($use_newsletter): void
{
$this->use_newsletter = $use_newsletter;
}
public function getAddress()
{
return $this->address;
}
public function addAddress($item)
{
$this->address->add($item);
$item->setUser($this);
return $this;
}
public function removeAddress($item)
{
$this->address->removeElement($item);
return $this;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title): void
{
$this->title = $title;
}
public function getBirthday()
{
return $this->birthday;
}
public function setBirthday($birthday): void
{
$this->birthday = $birthday;
}
public function getPhone()
{
return $this->phone;
}
public function setPhone($phone): void
{
$this->phone = $phone;
}
public function getLastVisit()
{
return $this->last_visit;
}
public function setLastVisit($last_visit): void
{
$this->last_visit = $last_visit;
}
public function getForgotToken()
{
return $this->forgot_token;
}
public function setForgotToken($forgot_token): void
{
$this->forgot_token = $forgot_token;
}
public function getForgotTime()
{
return $this->forgot_time;
}
public function setForgotTime($forgot_time): void
{
$this->forgot_time = $forgot_time;
}
public function getUserGroups()
{
return $this->userGroups;
}
public function addUserGroup(UserGroup $userGroup)
{
if ($this->userGroups->contains($userGroup)) {
return;
}
$this->userGroups->add($userGroup);
}
public function hasUserGroup($group_id){
foreach($this->userGroups as $group){
if($group->getId() == $group_id){
return true;
}
}
return false;
}
public function clearUserGroups()
{
$this->userGroups = new ArrayCollection();
return $this->getUserGroups();
}
public function removeUserGroup(UserGroup $userGroup)
{
if (!$this->userGroups->contains($userGroup)) {
return;
}
$this->userGroups->removeElement($userGroup);
}
public function getTvaIntracommunautaire()
{
return $this->tva_intracommunautaire;
}
public function setTvaIntracommunautaire($tva_intracommunautaire)
{
$this->tva_intracommunautaire = $tva_intracommunautaire;
}
public function getIdentity()
{
return trim((string)$this->getFirstname() . ' ' . $this->getLastname());
}
public function getLastname()
{
return $this->lastname;
}
public function setLastname($lastname): void
{
$this->lastname = $lastname;
}
/**
* @return mixed
*/
public function getWebsite()
{
return $this->website;
}
/**
* @param mixed $website
*/
public function setWebsite($website): void
{
$this->website = $website;
}
/**
* @return mixed
*/
public function getCompany()
{
return $this->company;
}
/**
* @param mixed $company
*/
public function setCompany($company): void
{
$this->company = $company;
}
/**
* @return mixed
*/
public function getSiret()
{
return $this->siret;
}
/**
* @param mixed $siret
*/
public function setSiret($siret): void
{
$this->siret = $siret;
}
/**
* @return mixed
*/
public function getApe()
{
return $this->ape;
}
/**
* @param mixed $ape
*/
public function setApe($ape): void
{
$this->ape = $ape;
}
/**
* @return mixed
*/
public function getNote()
{
return $this->note;
}
/**
* @param mixed $note
*/
public function setNote($note): void
{
$this->note = $note;
}
/**
* @return mixed
*/
public function getOutstandingAllowAmount()
{
return $this->outstanding_allow_amount;
}
/**
* @param mixed $outstanding_allow_amount
*/
public function setOutstandingAllowAmount($outstanding_allow_amount): void
{
$this->outstanding_allow_amount = $outstanding_allow_amount;
}
public function getFirstname()
{
return $this->firstname;
}
public function setFirstname($firstname): void
{
$this->firstname = $firstname;
}
public function getUsername()
{
return $this->email;
}
public function getPassword()
{
return $this->password;
}
function setPassword($password)
{
$this->password = $password;
}
public function getRoles()
{
if (empty($this->roles)) {
return ['ROLE_USER'];
}
return $this->roles;
}
function addRole($role)
{
$this->roles[] = $role;
}
public function removeRole($role)
{
foreach ($this->roles as $key => $value) {
if ($value == $role) {
unset($this->roles[$key]);
}
}
}
/** @see \Serializable::serialize() */
public function serialize()
{
return json_encode([
'id' => $this->id,
'email' => $this->email,
'password' => $this->password,
]);
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
$params = json_decode($serialized);
$this->id = $params->id;
$this->email = $params->email;
$this->password = $params->password;
return $this;
}
function getEmail()
{
return $this->email;
}
function getPlainPassword()
{
return $this->plainPassword;
}
function setEmail($email)
{
$this->email = $email;
}
function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
}
public function __toString()
{
return $this->getIdentity();
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getOrders()
{
return $this->orders;
}
public function addOrder($item)
{
$this->orders->add($item);
$item->setUser($this);
return $this;
}
public function removeOrder($item)
{
$this->orders->removeElement($item);
return $this;
}
public function getAccountType()
{
return $this->account_type;
}
public function setAccountType($account_type)
{
$this->account_type = $account_type;
}
public function getFavoris()
{
return $this->favoris;
}
public function addFavoris($item)
{
$this->favoris->add($item);
$item->setUser($this);
return $this;
}
public function removeFavoris($item)
{
$this->favoris->removeElement($item);
return $this;
}
}