src/Entity/Users/User/User.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Users\User;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Validator\Validatortext\Email;
  5. use App\Validator\Validatortext\Taillemin;
  6. use App\Validator\Validatortext\Taillemax;
  7. use App\Validator\Validatortext\Password;
  8. use App\Service\Servicetext\GeneralServicetext;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use App\Repository\Users\User\UserRepository;
  12. /**
  13.  * User
  14.  *
  15.  * @ORM\Table("user")
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  * @UniqueEntity(fields="username", message="Ce  mail existe déjà.")
  18.  ** @ORM\HasLifecycleCallbacks
  19.  */
  20. class User implements UserInterface
  21. {
  22.     /**
  23.      * @var integer
  24.      *
  25.      * @ORM\Column(name="id", type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     private $id;
  30.     /**
  31.      * @var string
  32.      *
  33.      * @ORM\Column(name="nom", type="string", length=255)
  34.     */
  35.     private $nom;
  36.     
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="prenom", type="string", length=255)
  41.     */
  42.     private $prenom;
  43.     
  44.     /**
  45.      * @var string
  46.      *
  47.      * @ORM\Column(name="username", type="string", length=255, unique=true)
  48.      * @Email()
  49.     */
  50.     private $username;
  51.     /**
  52.      * @var string
  53.      *
  54.      * @ORM\Column(name="password", type="string", length=255)
  55.      */
  56.     private $password;
  57.     
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(name="salt", type="string", length=255, nullable=true)
  62.      */
  63.     private $salt;
  64.     
  65.     /**
  66.      * @var array
  67.      *
  68.      * @ORM\Column(name="roles", type="array")
  69.      */
  70.     private $roles;
  71.     /**
  72.      * @var \DateTime
  73.      *
  74.      * @ORM\Column(name="dateins", type="datetime")
  75.      */
  76.     private $dateins;
  77.     
  78.     private $servicetext;
  79.     
  80.     public function __construct(GeneralServicetext $service)
  81.     {
  82.         $this->servicetext $service;
  83.         $this->dateins = new \Datetime();
  84.         $this->roles = array('ROLE_USER');
  85.     }
  86.     
  87.     public function getServicetext()
  88.     {
  89.         return $this->servicetext;
  90.     }
  91.     
  92.     public function setServicetext(GeneralServicetext $service)
  93.     {
  94.         $this->servicetext $service;
  95.     }
  96.     /**
  97.      * Get id
  98.      *
  99.      * @return integer 
  100.      */
  101.     public function getId()
  102.     {
  103.         return $this->id;
  104.     }
  105.     /**
  106.      * Set nom
  107.      *
  108.      * @param string $nom
  109.      * @return User
  110.      */
  111.     public function setNom($nom)
  112.     {
  113.         $this->nom $nom;
  114.         return $this;
  115.     }
  116.     /**
  117.      * Get nom
  118.      *
  119.      * @return string 
  120.      */
  121.     public function getNom()
  122.     {
  123.         return $this->nom;
  124.     }
  125.     /**
  126.      * Set password
  127.      *
  128.      * @param string $password
  129.      * @return User
  130.      */
  131.     public function setPassword($password)
  132.     {
  133.         $this->password $password;
  134.         return $this;
  135.     }
  136.     /**
  137.      * Get password
  138.      *
  139.      * @return string 
  140.      */
  141.     public function getPassword()
  142.     {
  143.         return $this->password;
  144.     }
  145.     /**
  146.      * Set dateins
  147.      *
  148.      * @param \DateTime $dateins
  149.      * @return User
  150.      */
  151.     public function setDateins($dateins)
  152.     {
  153.         $this->dateins $dateins;
  154.         return $this;
  155.     }
  156.     /**
  157.      * Get dateins
  158.      *
  159.      * @return \DateTime 
  160.      */
  161.     public function getDateins()
  162.     {
  163.         return $this->dateins;
  164.     }
  165.     
  166.     /**
  167.      * @ORM\PrePersist()
  168.      */
  169.     public function premajuscule()
  170.     {
  171.         $text1 $this->servicetext->retireAccent($this->nom);
  172.         $text1 strtolower($text1);
  173.         $this->nom ucwords($text1);
  174.     }
  175.     
  176.      /**
  177.      * Set roles
  178.      *
  179.      * @param array $roles
  180.      * @return User
  181.      */
  182.     public function setRoles($roles)
  183.     {
  184.         $this->roles $roles;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get roles
  189.      *
  190.      * @return array 
  191.      */
  192.     public function getRoles()
  193.     {
  194.         return $this->roles;
  195.     }
  196.     
  197.     public function addRole($role)
  198.     {
  199.         if (!in_array($role$this->roles)) {
  200.             $this->roles[] = $role;
  201.         }
  202.         return $this;
  203.     }
  204.     public function removeRole($role)
  205.     {
  206.         if (false !== $key array_search(strtoupper($role), $this->rolestrue)) {
  207.             unset($this->roles[$key]);
  208.             $this->roles array_values($this->roles);
  209.         }
  210.         return $this;
  211.     }
  212.     
  213.     /**
  214.      * Set salt
  215.      *
  216.      * @param string $salt
  217.      * @return User
  218.      */
  219.     public function setSalt($salt)
  220.     {
  221.         $this->salt $salt;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Get salt
  226.      *
  227.      * @return string 
  228.      */
  229.     public function getSalt()
  230.     {
  231.         return $this->salt;
  232.     }
  233.     
  234.     /**
  235.      * Set username
  236.      *
  237.      * @param string $username
  238.      * @return User
  239.      */
  240.     public function setUsername($username)
  241.     {
  242.         $this->username $username;
  243.         return $this;
  244.     }
  245.     /**
  246.      * Get username
  247.      *
  248.      * @return string 
  249.      */
  250.     public function getUsername()
  251.     {
  252.         return $this->username;
  253.     }
  254.     
  255.     public function eraseCredentials()
  256.     {
  257.     
  258.     }
  259.     
  260.     public function name($tail)
  261.     {
  262.         $allname $this->nom.' '.$this->prenom;
  263.         if(strlen($allname) <= $tail)
  264.         {
  265.             return $allname;
  266.         }else{
  267.             $text wordwrap($allname,$tail,'~',true);
  268.             $tab explode('~',$text);
  269.             $text $tab[0];
  270.             return $text.'...';
  271.         }
  272.     }
  273.     /**
  274.      * Set prenom
  275.      *
  276.      * @param string $prenom
  277.      * @return User
  278.      */
  279.     public function setPrenom($prenom)
  280.     {
  281.         $this->prenom $prenom;
  282.         return $this;
  283.     }
  284.     /**
  285.      * Get prenom
  286.      *
  287.      * @return string 
  288.      */
  289.     public function getPrenom()
  290.     {
  291.         return $this->prenom;
  292.     }
  293. }