src/UserBundle/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace User\Entity;
  3. use Core\Entity\Traits\EntityTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="User\Repository\UserRepository")
  10.  * @ORM\Table(name="users_user")
  11.  */
  12. class User implements UserInterface, \Serializable
  13. {
  14.     use EntityTrait {
  15.         EntityTrait::__construct as private __entityConstruct;
  16.     }
  17.     /**
  18.      * @ORM\Column(type="integer", nullable=true)
  19.      */
  20.     private $account_type;
  21.     /**
  22.      * Référence unique de l'utilisateur
  23.      *
  24.      * @ORM\Column(type="string", length=255, unique=true)
  25.      */
  26.     private $reference;
  27.     /**
  28.      * Numéro de compte
  29.      *
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private $account_number;
  33.     /**
  34.      * Civilité (Monsieur, Madame, ...)
  35.      *
  36.      * @ORM\Column(type="integer", nullable=true)
  37.      */
  38.     private $title;
  39.     /**
  40.      * Nom
  41.      *
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $lastname;
  45.     /**
  46.      * Prénom
  47.      *
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $firstname;
  51.     /**
  52.      * Téléphone
  53.      *
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $phone;
  57.     /**
  58.      * Adresse e-mail
  59.      *
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $email;
  63.     /**
  64.      * Date de naissance
  65.      *
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private $birthday;
  69.     /**
  70.      * Adresse du site internet
  71.      *
  72.      * @ORM\Column(type="string", length=255, nullable=true)
  73.      */
  74.     private $website;
  75.     /**
  76.      * Société
  77.      *
  78.      * @ORM\Column(type="string", length=255, nullable=true)
  79.      */
  80.     private $company;
  81.     /**
  82.      * N° SIRET
  83.      *
  84.      * @ORM\Column(type="string", length=255, nullable=true)
  85.      */
  86.     private $siret;
  87.     /**
  88.      * N° TVA INTRACOMMUNAUTAIRE
  89.      *
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      */
  92.     private $tva_intracommunautaire;
  93.     /**
  94.      * N° APE
  95.      *
  96.      * @ORM\Column(type="string", length=255, nullable=true)
  97.      */
  98.     private $ape;
  99.     /**
  100.      * Notes
  101.      *
  102.      * @ORM\Column(type="text", nullable=true)
  103.      */
  104.     private $note;
  105.     /**
  106.      * Montant de crédit autorisé
  107.      *
  108.      * @ORM\Column(type="integer", nullable=true)
  109.      */
  110.     private $outstanding_allow_amount;
  111.     /**
  112.      * Mot de passe crypté de l'utilisateur
  113.      *
  114.      * @ORM\Column(type="string", length=255, nullable=true)
  115.      */
  116.     private $password;
  117.     /**
  118.      * TOKEN d'identification pour réinitialiser le mot de passe
  119.      *
  120.      * @ORM\Column(type="string", length=255, nullable=true)
  121.      */
  122.     private $forgot_token;
  123.     /**
  124.      * Date de la dernière demande de réinitialisation du mot de passe
  125.      *
  126.      * @ORM\Column(type="datetime", nullable=true)
  127.      */
  128.     private $forgot_time;
  129.     /**
  130.      * Inscription à la newsletter
  131.      *
  132.      * @ORM\Column(type="boolean", nullable=true)
  133.      */
  134.     private $use_newsletter;
  135.     /**
  136.      * Liste des adresses
  137.      *
  138.      * @ORM\OneToMany(targetEntity="UserAddress", mappedBy="user", cascade={"persist", "remove"})
  139.      */
  140.     private $address;
  141.     /**
  142.      * Liste des adresses
  143.      *
  144.      * @ORM\OneToMany(targetEntity="UserFavoris", mappedBy="user", cascade={"persist", "remove"})
  145.      */
  146.     private $favoris;
  147.     /**
  148.      *  Groupes utilisateurs
  149.      *
  150.      * @ORM\ManyToMany(targetEntity="UserGroup", mappedBy="users")
  151.      */
  152.     private $userGroups;
  153.     /**
  154.      * Rôles
  155.      * TODO - Relier les Rôles au Groupes utilisateurs
  156.      *
  157.      * @ORM\Column(name="roles", type="array")
  158.      */
  159.     private $roles = array();
  160.     /**
  161.      * Dernière visite
  162.      *
  163.      * @ORM\Column(type="datetime", nullable=true)
  164.      */
  165.     private $last_visit;
  166.     /**
  167.      * Liste des commandes de l'utilisateur
  168.      *
  169.      * @ORM\OneToMany(targetEntity="Shopping\Entity\Order", mappedBy="user")
  170.      */
  171.     private $orders;
  172.     /**
  173.      * @Assert\NotBlank()
  174.      * @Assert\Length(max=250)
  175.      */
  176.     private $plainPassword;
  177.     /**
  178.      * @ORM\OneToMany(targetEntity="Shopping\Entity\ProductSpecificPrice", mappedBy="user_group", cascade={"persist", "remove"}, orphanRemoval=true)
  179.      */
  180.     private $specific_prices;
  181.     private $collections = [
  182.         'specific_price'
  183.     ];
  184.     /**
  185.      * Constructeur
  186.      * @throws \Exception
  187.      */
  188.     public function __construct()
  189.     {
  190.         $this->__entityConstruct();
  191.         $datetime = new \Datetime();
  192.         $this->setLastVisit($datetime);
  193.         $this->setReference(uniqid());
  194.         $this->userGroups = new ArrayCollection();
  195.         $this->orders = new ArrayCollection();
  196.         $this->address = new ArrayCollection();
  197.         $this->favoris = new ArrayCollection();
  198.         $this->userGroups = new ArrayCollection();
  199.         $this->specific_prices = new ArrayCollection();
  200.     }
  201.     public function getCollections()
  202.     {
  203.         return $this->collections;
  204.     }
  205.     public function getReference()
  206.     {
  207.         return $this->reference;
  208.     }
  209.     public function setReference($reference)
  210.     {
  211.         $this->reference $reference;
  212.     }
  213.     /**
  214.      * @return mixed
  215.      */
  216.     public function getAccountNumber()
  217.     {
  218.         return $this->account_number;
  219.     }
  220.     /**
  221.      * @param mixed $account_number
  222.      */
  223.     public function setAccountNumber($account_number): void
  224.     {
  225.         $this->account_number $account_number;
  226.     }
  227.     /**
  228.      * Collection - Prix spécifiques
  229.      */
  230.     public function getSpecificPrices()
  231.     {
  232.         return $this->specific_prices;
  233.     }
  234.     public function setSpecificPrices($items)
  235.     {
  236.         $this->specific_prices $items;
  237.         return $this;
  238.     }
  239.     public function addSpecificPrice($item)
  240.     {
  241.         $this->specific_prices->add($item);
  242.         $item->setUser($this);
  243.         return $this;
  244.     }
  245.     public function removeSpecificPrice($item)
  246.     {
  247.         $this->specific_prices->removeElement($item);
  248.         return $this;
  249.     }
  250.     public function getUseNewsletter()
  251.     {
  252.         return $this->use_newsletter;
  253.     }
  254.     public function setUseNewsletter($use_newsletter): void
  255.     {
  256.         $this->use_newsletter $use_newsletter;
  257.     }
  258.     public function getAddress()
  259.     {
  260.         return $this->address;
  261.     }
  262.     public function addAddress($item)
  263.     {
  264.         $this->address->add($item);
  265.         $item->setUser($this);
  266.         return $this;
  267.     }
  268.     public function removeAddress($item)
  269.     {
  270.         $this->address->removeElement($item);
  271.         return $this;
  272.     }
  273.     public function getTitle()
  274.     {
  275.         return $this->title;
  276.     }
  277.     public function setTitle($title): void
  278.     {
  279.         $this->title $title;
  280.     }
  281.     public function getBirthday()
  282.     {
  283.         return $this->birthday;
  284.     }
  285.     public function setBirthday($birthday): void
  286.     {
  287.         $this->birthday $birthday;
  288.     }
  289.     public function getPhone()
  290.     {
  291.         return $this->phone;
  292.     }
  293.     public function setPhone($phone): void
  294.     {
  295.         $this->phone $phone;
  296.     }
  297.     public function getLastVisit()
  298.     {
  299.         return $this->last_visit;
  300.     }
  301.     public function setLastVisit($last_visit): void
  302.     {
  303.         $this->last_visit $last_visit;
  304.     }
  305.     public function getForgotToken()
  306.     {
  307.         return $this->forgot_token;
  308.     }
  309.     public function setForgotToken($forgot_token): void
  310.     {
  311.         $this->forgot_token $forgot_token;
  312.     }
  313.     public function getForgotTime()
  314.     {
  315.         return $this->forgot_time;
  316.     }
  317.     public function setForgotTime($forgot_time): void
  318.     {
  319.         $this->forgot_time $forgot_time;
  320.     }
  321.     public function getUserGroups()
  322.     {
  323.         return $this->userGroups;
  324.     }
  325.     public function addUserGroup(UserGroup $userGroup)
  326.     {
  327.         if ($this->userGroups->contains($userGroup)) {
  328.             return;
  329.         }
  330.         $this->userGroups->add($userGroup);
  331.     }
  332.     public function hasUserGroup($group_id){
  333.         foreach($this->userGroups as $group){
  334.             if($group->getId() == $group_id){
  335.                 return true;
  336.             }
  337.         }
  338.         return false;
  339.     }
  340.     public function clearUserGroups()
  341.     {
  342.         $this->userGroups = new ArrayCollection();
  343.         return $this->getUserGroups();
  344.     }
  345.     public function removeUserGroup(UserGroup $userGroup)
  346.     {
  347.         if (!$this->userGroups->contains($userGroup)) {
  348.             return;
  349.         }
  350.         $this->userGroups->removeElement($userGroup);
  351.     }
  352.     public function getTvaIntracommunautaire()
  353.     {
  354.         return $this->tva_intracommunautaire;
  355.     }
  356.     public function setTvaIntracommunautaire($tva_intracommunautaire)
  357.     {
  358.         $this->tva_intracommunautaire $tva_intracommunautaire;
  359.     }
  360.     public function getIdentity()
  361.     {
  362.         return trim((string)$this->getFirstname() . ' ' $this->getLastname());
  363.     }
  364.     public function getLastname()
  365.     {
  366.         return $this->lastname;
  367.     }
  368.     public function setLastname($lastname): void
  369.     {
  370.         $this->lastname $lastname;
  371.     }
  372.     /**
  373.      * @return mixed
  374.      */
  375.     public function getWebsite()
  376.     {
  377.         return $this->website;
  378.     }
  379.     /**
  380.      * @param mixed $website
  381.      */
  382.     public function setWebsite($website): void
  383.     {
  384.         $this->website $website;
  385.     }
  386.     /**
  387.      * @return mixed
  388.      */
  389.     public function getCompany()
  390.     {
  391.         return $this->company;
  392.     }
  393.     /**
  394.      * @param mixed $company
  395.      */
  396.     public function setCompany($company): void
  397.     {
  398.         $this->company $company;
  399.     }
  400.     /**
  401.      * @return mixed
  402.      */
  403.     public function getSiret()
  404.     {
  405.         return $this->siret;
  406.     }
  407.     /**
  408.      * @param mixed $siret
  409.      */
  410.     public function setSiret($siret): void
  411.     {
  412.         $this->siret $siret;
  413.     }
  414.     /**
  415.      * @return mixed
  416.      */
  417.     public function getApe()
  418.     {
  419.         return $this->ape;
  420.     }
  421.     /**
  422.      * @param mixed $ape
  423.      */
  424.     public function setApe($ape): void
  425.     {
  426.         $this->ape $ape;
  427.     }
  428.     /**
  429.      * @return mixed
  430.      */
  431.     public function getNote()
  432.     {
  433.         return $this->note;
  434.     }
  435.     /**
  436.      * @param mixed $note
  437.      */
  438.     public function setNote($note): void
  439.     {
  440.         $this->note $note;
  441.     }
  442.     /**
  443.      * @return mixed
  444.      */
  445.     public function getOutstandingAllowAmount()
  446.     {
  447.         return $this->outstanding_allow_amount;
  448.     }
  449.     /**
  450.      * @param mixed $outstanding_allow_amount
  451.      */
  452.     public function setOutstandingAllowAmount($outstanding_allow_amount): void
  453.     {
  454.         $this->outstanding_allow_amount $outstanding_allow_amount;
  455.     }
  456.     public function getFirstname()
  457.     {
  458.         return $this->firstname;
  459.     }
  460.     public function setFirstname($firstname): void
  461.     {
  462.         $this->firstname $firstname;
  463.     }
  464.     public function getUsername()
  465.     {
  466.         return $this->email;
  467.     }
  468.     public function getPassword()
  469.     {
  470.         return $this->password;
  471.     }
  472.     function setPassword($password)
  473.     {
  474.         $this->password $password;
  475.     }
  476.     public function getRoles()
  477.     {
  478.         if (empty($this->roles)) {
  479.             return ['ROLE_USER'];
  480.         }
  481.         return $this->roles;
  482.     }
  483.     function addRole($role)
  484.     {
  485.         $this->roles[] = $role;
  486.     }
  487.     public function removeRole($role)
  488.     {
  489.         foreach ($this->roles as $key => $value) {
  490.             if ($value == $role) {
  491.                 unset($this->roles[$key]);
  492.             }
  493.         }
  494.     }
  495.     /** @see \Serializable::serialize() */
  496.     public function serialize()
  497.     {
  498.         return json_encode([
  499.             'id' => $this->id,
  500.             'email' => $this->email,
  501.             'password' => $this->password,
  502.         ]);
  503.     }
  504.     /** @see \Serializable::unserialize() */
  505.     public function unserialize($serialized)
  506.     {
  507.         $params json_decode($serialized);
  508.         $this->id $params->id;
  509.         $this->email $params->email;
  510.         $this->password $params->password;
  511.         return $this;
  512.     }
  513.     function getEmail()
  514.     {
  515.         return $this->email;
  516.     }
  517.     function getPlainPassword()
  518.     {
  519.         return $this->plainPassword;
  520.     }
  521.     function setEmail($email)
  522.     {
  523.         $this->email $email;
  524.     }
  525.     function setPlainPassword($plainPassword)
  526.     {
  527.         $this->plainPassword $plainPassword;
  528.     }
  529.     public function __toString()
  530.     {
  531.         return $this->getIdentity();
  532.     }
  533.     public function getSalt()
  534.     {
  535.         // TODO: Implement getSalt() method.
  536.     }
  537.     public function eraseCredentials()
  538.     {
  539.         // TODO: Implement eraseCredentials() method.
  540.     }
  541.     public function getOrders()
  542.     {
  543.         return $this->orders;
  544.     }
  545.     public function addOrder($item)
  546.     {
  547.         $this->orders->add($item);
  548.         $item->setUser($this);
  549.         return $this;
  550.     }
  551.     public function removeOrder($item)
  552.     {
  553.         $this->orders->removeElement($item);
  554.         return $this;
  555.     }
  556.     public function getAccountType()
  557.     {
  558.         return $this->account_type;
  559.     }
  560.     public function setAccountType($account_type)
  561.     {
  562.         $this->account_type $account_type;
  563.     }
  564.     public function getFavoris()
  565.     {
  566.         return $this->favoris;
  567.     }
  568.     public function addFavoris($item)
  569.     {
  570.         $this->favoris->add($item);
  571.         $item->setUser($this);
  572.         return $this;
  573.     }
  574.     public function removeFavoris($item)
  575.     {
  576.         $this->favoris->removeElement($item);
  577.         return $this;
  578.     }
  579. }