src/Entity/User.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\UserInterface as SecurityUser;
  7. /**
  8.  * Class User
  9.  *
  10.  * @ORM\Table(name="user")
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  */
  13. class User implements SecurityUser\Serializable
  14. {
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Column(name="id", type="integer")
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @var string
  25.      *
  26.      * @ORM\Column(name="firstname", type="string")
  27.      */
  28.     public $firstname;
  29.     /**
  30.      * @var string
  31.      *
  32.      * @ORM\Column(name="lastname", type="string")
  33.      */
  34.     public $lastname;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @ORM\Column(name="password", type="string")
  39.      */
  40.     public $password;
  41.     /**
  42.      * @var string
  43.      *
  44.      * @ORM\Column(name="email", type="string")
  45.      */
  46.     public $email;
  47.     /**
  48.      * @var array
  49.      *
  50.      * @ORM\Column(name="roles", type="array")
  51.      */
  52.     public $roles;
  53.     /**
  54.      * @var string
  55.      *
  56.      * @ORM\Column(name="enabled", type="boolean")
  57.      */
  58.     public $enabled;
  59.     /**
  60.      * Many Users have Many Monnaies.
  61.      * @var ArrayCollection
  62.      * @ORM\ManyToMany(targetEntity="App\Entity\Monnaie", inversedBy="users")
  63.      * @ORM\JoinTable(name="users_monnaies")
  64.      */
  65.     private $monnaies;
  66.     /**
  67.      * @ORM\Column(type="datetime", nullable=true)
  68.      *
  69.      * @var DateTime
  70.      */
  71.     private $lastLogin;
  72.     /**
  73.      * User constructor.
  74.      */
  75.     public function __construct() {
  76.         $this->enabled true;
  77.         $this->roles[] = 'ROLE_USER';
  78.         $this->monnaies = new ArrayCollection();
  79.         $this->lastLogin = new DateTime();
  80.     }
  81.     /**
  82.      * Get id
  83.      *
  84.      * @return int
  85.      */
  86.     public function getId()
  87.     {
  88.         return $this->id;
  89.     }
  90.     /**
  91.      * @return string
  92.      */
  93.     public function getFirstname(): ?string {
  94.         return $this->firstname;
  95.     }
  96.     /**
  97.      * @param string $firstname
  98.      */
  99.     public function setFirstnamestring $firstname ): void {
  100.         $this->firstname $firstname;
  101.     }
  102.     /**
  103.      * @return string
  104.      */
  105.     public function getLastname(): ?string {
  106.         return $this->lastname;
  107.     }
  108.     /**
  109.      * @param string $lastname
  110.      */
  111.     public function setLastnamestring $lastname ): void {
  112.         $this->lastname $lastname;
  113.     }
  114.     /**
  115.      * @return string
  116.      */
  117.     public function getPassword(): ?string {
  118.         return $this->password;
  119.     }
  120.     /**
  121.      * @param string $password
  122.      */
  123.     public function setPasswordstring $password ): void {
  124.         $this->password $password;
  125.     }
  126.     /**
  127.      * @return string
  128.      */
  129.     public function getEmail(): ?string {
  130.         return $this->email;
  131.     }
  132.     /**
  133.      * @param string $email
  134.      */
  135.     public function setEmailstring $email ): void {
  136.         $this->email $email;
  137.     }
  138.     /**
  139.      * @return array
  140.      */
  141.     public function getRoles(): array {
  142.         return $this->roles;
  143.     }
  144.     /**
  145.      * @param array $roles
  146.      */
  147.     public function setRoles( array $roles ): void {
  148.         $this->roles $roles;
  149.     }
  150.     /**
  151.      * @return string
  152.      */
  153.     public function getEnabled(): string {
  154.         return $this->enabled;
  155.     }
  156.     /**
  157.      * @param string $enabled
  158.      */
  159.     public function setEnabledstring $enabled ): void {
  160.         $this->enabled $enabled;
  161.     }
  162.     /**
  163.      * {@inheritdoc}
  164.      */
  165.     public function updatePassword(string $passwordEncoded): void
  166.     {
  167.         $this->password $passwordEncoded;
  168.     }
  169.     /**
  170.      * {@inheritdoc}
  171.      */
  172.     public function enable(): void
  173.     {
  174.         $this->enabled true;
  175.     }
  176.     /**
  177.      * {@inheritdoc}
  178.      */
  179.     public function disable(): void
  180.     {
  181.         $this->enabled false;
  182.     }
  183.     /**
  184.      * {@inheritdoc}
  185.      *
  186.      * @codeCoverageIgnore
  187.      */
  188.     public function serialize()
  189.     {
  190.         return serialize([
  191.             $this->id,
  192.             $this->email,
  193.             $this->password,
  194.         ]);
  195.     }
  196.     /**
  197.      * {@inheritdoc}
  198.      *
  199.      * @codeCoverageIgnore
  200.      */
  201.     public function unserialize($serialized)
  202.     {
  203.         list(
  204.             $this->id,
  205.             $this->email,
  206.             $this->password
  207.             ) = unserialize($serialized);
  208.     }
  209.     /**
  210.      * {@inheritdoc}
  211.      *
  212.      * @codeCoverageIgnore
  213.      */
  214.     public function getSalt()
  215.     {
  216.         return;
  217.     }
  218.     /**
  219.      * {@inheritdoc}
  220.      *
  221.      * @codeCoverageIgnore
  222.      */
  223.     public function eraseCredentials()
  224.     {
  225.         return;
  226.     }
  227.     public function getUsername() {
  228.         return $this->email;
  229.     }
  230.     public function __toString()
  231.     {
  232.         return $this->firstname.' '.$this->lastname;
  233.     }
  234.     /**
  235.      * @return ArrayCollection
  236.      */
  237.     public function getMonnaies()
  238.     {
  239.         return $this->monnaies;
  240.     }
  241.     /**
  242.      * @param ArrayCollection $monnaies
  243.      */
  244.     public function setMonnaies(ArrayCollection $monnaies): void
  245.     {
  246.         $this->monnaies $monnaies;
  247.     }
  248.     /**
  249.      * @param Monnaie $monnay
  250.      */
  251.     public function addMonnay(Monnaie $monnay)
  252.     {
  253.         $this->monnaies[] = $monnay;
  254.     }
  255.     /**
  256.      * @param Monnaie $monnay
  257.      */
  258.     public function removeMonnay(Monnaie $monnay)
  259.     {
  260.         $this->monnaies->removeElement($monnay);
  261.     }
  262.     public function getNbMonnaies() {
  263.         return count($this->monnaies);
  264.     }
  265.     /**
  266.      * @return DateTime
  267.      */
  268.     public function getLastLogin(): ?DateTime
  269.     {
  270.         return $this->lastLogin;
  271.     }
  272.     /**
  273.      * @param DateTime $lastLogin
  274.      */
  275.     public function setLastLogin(DateTime $lastLogin): void
  276.     {
  277.         $this->lastLogin $lastLogin;
  278.     }
  279. }