src/Entity/User.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\RandomGenerator;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  * @UniqueEntity(
  13.  *     fields =  {"email", "token"},
  14.  *     message = "L'email que vous avez indiquez est déjà utilisé"
  15.  *
  16.  * )
  17.  */
  18. class User implements UserInterface
  19. {
  20.     /**
  21.      * @ORM\Id()
  22.      * @ORM\GeneratedValue()
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      * @Assert\Email()
  29.      */
  30.     private $email;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $society;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $full_name;
  39.     /**
  40.      * @ORM\Column(type="string", length=255)
  41.      * @Assert\Length(
  42.      *      min = 8,
  43.      *      minMessage = "Your password must be at least {{ limit }} characters long"
  44.      * )
  45.      */
  46.     private $password;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      */
  50.     private $confirmationToken null;
  51.     /**
  52.      * @var bool
  53.      *
  54.      * @ORM\Column(type="boolean")
  55.      */
  56.     private $isAlreadyRequested false;
  57.     /**
  58.      * @return mixed
  59.      */
  60.     public function getSociety()
  61.     {
  62.         return $this->society;
  63.     }
  64.     /**
  65.      * @param mixed $society
  66.      */
  67.     public function setSociety($society): void
  68.     {
  69.         $this->society $society;
  70.     }
  71.     /**
  72.      * @return bool
  73.      */
  74.     public function isCatering(): bool
  75.     {
  76.         return $this->catering;
  77.     }
  78.     /**
  79.      * @param bool $catering
  80.      */
  81.     public function setCatering(bool $catering): void
  82.     {
  83.         $this->catering $catering;
  84.     }
  85.     /**
  86.      * @var bool
  87.      *
  88.      * @ORM\Column(type="boolean")
  89.      */
  90.     private $catering false;
  91.     /**
  92.      * @ORM\Column(type="datetime")
  93.      */
  94.     private $createAt;
  95.     /**
  96.      * @ORM\Column(type="datetime", nullable=true)
  97.      */
  98.     private $dateRequestPassword;
  99.     /**
  100.      * User constructor.
  101.      */
  102.     public function __construct()
  103.     {
  104.         //$this->createdAt = new \DateTime("now");
  105.         $this->setCreateAt(new \DateTime("now"));
  106.         $this->members = new ArrayCollection();
  107.         $randomGenrator = new RandomGenerator();
  108.         $this->token $randomGenrator->random();
  109.     }
  110.     /**
  111.      * @return mixed
  112.      */
  113.     public function getCreateAt()
  114.     {
  115.         return $this->createAt;
  116.     }
  117.     /**
  118.      * @param mixed $createAt
  119.      */
  120.     public function setCreateAt($createAt): void
  121.     {
  122.         $this->createAt $createAt;
  123.     }
  124.     /**
  125.      * @return mixed
  126.      */
  127.     public function getDateRequestPassword()
  128.     {
  129.         return $this->dateRequestPassword;
  130.     }
  131.     /**
  132.      * @param mixed $dateRequestPassword
  133.      */
  134.     public function setDateRequestPassword($dateRequestPassword): void
  135.     {
  136.         $this->dateRequestPassword $dateRequestPassword;
  137.     }
  138.     /**
  139.      * @return mixed
  140.      */
  141.     public function getFullName()
  142.     {
  143.         return $this->full_name;
  144.     }
  145.     /**
  146.      * @param mixed $full_name
  147.      */
  148.     public function setFullName($full_name): void
  149.     {
  150.         $this->full_name $full_name;
  151.     }
  152.     /**
  153.     * @Assert\EqualTo(
  154.     *      propertyPath = "password",
  155.      *     message= "Vous n'avez pas tapé le même mot de passe"
  156.     * )
  157.     */
  158.     public $confirm_password;
  159.     /**
  160.      * @var array
  161.      *
  162.      * @ORM\Column(name="roles", type="array")
  163.      */
  164.     private $roles = [];
  165.     /**
  166.      * @ORM\ManyToOne(targetEntity="CategoryUser", inversedBy="user")
  167.      */
  168.     private $categoryUser;
  169.     /**
  170.      * @ORM\OneToMany(targetEntity="App\Entity\Members", mappedBy="user", orphanRemoval=true)
  171.      */
  172.     private $members;
  173.     /**
  174.      * @ORM\Column(type="string", length=255, unique=true)
  175.      */
  176.     private $token;
  177.     public function getId()
  178.     {
  179.         return $this->id;
  180.     }
  181.     public function getEmail(): ?string
  182.     {
  183.         return $this->email;
  184.     }
  185.     public function setEmail(string $email): self
  186.     {
  187.         $this->email $email;
  188.         return $this;
  189.     }
  190.     public function getUsername(): ?string
  191.     {
  192.         return $this->email;
  193.     }
  194.     public function getPassword(): ?string
  195.     {
  196.         return $this->password;
  197.     }
  198.     public function setPassword(string $password): self
  199.     {
  200.         $this->password $password;
  201.         return $this;
  202.     }
  203.     public function eraseCredentials()
  204.     {
  205.         // TODO: Implement eraseCredentials() method.
  206.     }
  207.     public function getSalt()
  208.     {
  209.         // TODO: Implement getSalt() method.
  210.     }
  211.     /**
  212.      * Retourne les rôles de l'user
  213.      */
  214.     public function getRoles(): array
  215.     {
  216.         if (empty($this->roles)) {
  217.             return ['ROLE_USER'];
  218.         }
  219.         return $this->roles;
  220.     }
  221.     function addRole($role) {
  222.         $this->roles[] = $role;
  223.     }
  224.     /**
  225.      * {@inheritdoc}
  226.      */
  227.     public function serialize(): string
  228.     {
  229.         return serialize([$this->id$this->email$this->password]);
  230.     }
  231.     /**
  232.      * {@inheritdoc}
  233.      */
  234.     public function unserialize($serialized): void
  235.     {
  236.         [$this->id$this->email$this->password] = unserialize($serialized, ['allowed_classes' => false]);
  237.     }
  238.     public function getConfirmationToken()
  239.     {
  240.         return $this->confirmationToken;
  241.     }
  242.     public function getIsAlreadyRequested()
  243.     {
  244.         return $this->isAlreadyRequested;
  245.     }
  246.     public function setConfirmationToken($confirmationToken)
  247.     {
  248.         $this->confirmationToken $confirmationToken;
  249.     }
  250.     public function setIsAlreadyRequested($isAlreadyRequested)
  251.     {
  252.         $this->isAlreadyRequested $isAlreadyRequested;
  253.     }
  254.     public function getCategoryUser(): ?CategoryUser
  255.     {
  256.         return $this->categoryUser;
  257.     }
  258.     public function setCategoryUser(?CategoryUser $categoryUser): self
  259.     {
  260.         $this->categoryUser $categoryUser;
  261.         return $this;
  262.     }
  263.     /**
  264.      * @return Collection|Members[]
  265.      */
  266.     public function getMembers(): Collection
  267.     {
  268.         return $this->members;
  269.     }
  270.     public function addMember(Members $member): self
  271.     {
  272.         if (!$this->members->contains($member)) {
  273.             $this->members[] = $member;
  274.             $member->setUser($this);
  275.         }
  276.         return $this;
  277.     }
  278.     public function removeMember(Members $member): self
  279.     {
  280.         if ($this->members->contains($member)) {
  281.             $this->members->removeElement($member);
  282.             // set the owning side to null (unless already changed)
  283.             if ($member->getUser() === $this) {
  284.                 $member->setUser(null);
  285.             }
  286.         }
  287.         return $this;
  288.     }
  289.     public function getToken(): ?string
  290.     {
  291.         return $this->token;
  292.     }
  293.     public function setToken(string $token): self
  294.     {
  295.         $this->token $token;
  296.         return $this;
  297.     }
  298. }