src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  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\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity("username")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180)
  25.      */
  26.     private $firstName;
  27.     /**
  28.      * @ORM\Column(type="string", length=180)
  29.      */
  30.     private $surName;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      */
  34.     private $organization;
  35.     
  36.     /**
  37.      * @ORM\Column(type="string", length=180)
  38.      */
  39.     private $phone;
  40.     /**
  41.      * @ORM\Column(type="string", length=180)
  42.      */
  43.     private $email;
  44.     /**
  45.      * @ORM\Column(type="string", length=180, unique=true)
  46.      */
  47.     private $username;
  48.     /**
  49.      * @ORM\Column(type="json")
  50.      */
  51.     private $roles = [];
  52.     /**
  53.      * @var string The hashed password
  54.      * @ORM\Column(type="string")
  55.      */
  56.     private $password;
  57.     
  58.     /**
  59.      * @ORM\Column(type="datetime")
  60.      */
  61.     private $dateCreated;
  62.     /**
  63.      * @ORM\Column(type="integer", nullable=true)
  64.      */
  65.     private $isBioAuth;
  66.     /**
  67.      * @ORM\OneToMany(targetEntity=Suggestion::class, mappedBy="user")
  68.      */
  69.     private $suggestions//1 for yes 2 for no 0 for unsubscribed
  70.     /**
  71.      * Constructor
  72.      */
  73.     public function __construct()
  74.     {
  75.         date_default_timezone_set('Africa/Douala');
  76.         $this->dateCreated = new \Datetime(); // default date
  77.         $this->suggestions = new ArrayCollection();
  78.     }
  79.     
  80.     public function fullName(): ?string
  81.     {
  82.         return $this->getFirstName()." ".$this->getSurName();
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getUsername(): ?string
  89.     {
  90.         return $this->username;
  91.     }
  92.     public function setUsername(string $username): self
  93.     {
  94.         $this->username $username;
  95.         return $this;
  96.     }
  97.     /**
  98.      * A visual identifier that represents this user.
  99.      *
  100.      * @see UserInterface
  101.      */
  102.     public function getUserIdentifier(): string
  103.     {
  104.         return (string) $this->username;
  105.     }
  106.     public function getRoles(): ?array
  107.     {
  108.         return $this->roles;
  109.     }
  110.     public function setRoles(array $roles): self
  111.     {
  112.         $this->roles $roles;
  113.         return $this;
  114.     }
  115.     public function getPassword(): ?string
  116.     {
  117.         return $this->password;
  118.     }
  119.     public function setPassword(string $password): self
  120.     {
  121.         //$this->password = $password;
  122.         $options = ['cost' => 15];
  123.         $encoded password_hash($password,PASSWORD_BCRYPT,$options);
  124.         $this->password $encoded;
  125.         return $this;
  126.     }
  127.     /**
  128.      * Returning a salt is only needed, if you are not using a modern
  129.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  130.      *
  131.      * @see UserInterface
  132.      */
  133.     public function getSalt(): ?string
  134.     {
  135.         return null;
  136.     }
  137.     /**
  138.      * @see UserInterface
  139.      */
  140.     public function eraseCredentials()
  141.     {
  142.         // If you store any temporary, sensitive data on the user, clear it here
  143.         // $this->plainPassword = null;
  144.     }
  145.     public function getFirstName(): ?string
  146.     {
  147.         return $this->firstName;
  148.     }
  149.     public function setFirstName(string $firstName): self
  150.     {
  151.         $this->firstName $firstName;
  152.         return $this;
  153.     }
  154.     public function getSurName(): ?string
  155.     {
  156.         return $this->surName;
  157.     }
  158.     public function setSurName(string $surName): self
  159.     {
  160.         $this->surName $surName;
  161.         return $this;
  162.     }
  163.     public function getPhone(): ?string
  164.     {
  165.         return $this->phone;
  166.     }
  167.     public function setPhone(string $phone): self
  168.     {
  169.         $this->phone $phone;
  170.         return $this;
  171.     }
  172.     public function getEmail(): ?string
  173.     {
  174.         return $this->email;
  175.     }
  176.     public function setEmail(string $email): self
  177.     {
  178.         $this->email $email;
  179.         return $this;
  180.     }
  181.     public function getOrganization(): ?string
  182.     {
  183.         return $this->organization;
  184.     }
  185.     public function setOrganization(string $organization): self
  186.     {
  187.         $this->organization $organization;
  188.         
  189.         return $this;
  190.     }
  191.     public function getIsBioAuth(): ?int
  192.     {
  193.         return $this->isBioAuth;
  194.     }
  195.     public function setIsBioAuth(?int $isBioAuth): self
  196.     {
  197.         $this->isBioAuth $isBioAuth;
  198.         return $this;
  199.     }
  200.     public function getDateCreated(): ?\DateTimeInterface
  201.     {
  202.         return $this->dateCreated;
  203.     }
  204.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  205.     {
  206.         $this->dateCreated $dateCreated;
  207.         return $this;
  208.     }
  209.     /**
  210.      * @return Collection<int, Suggestion>
  211.      */
  212.     public function getSuggestions(): Collection
  213.     {
  214.         return $this->suggestions;
  215.     }
  216.     public function addSuggestion(Suggestion $suggestion): self
  217.     {
  218.         if (!$this->suggestions->contains($suggestion)) {
  219.             $this->suggestions[] = $suggestion;
  220.             $suggestion->setUser($this);
  221.         }
  222.         return $this;
  223.     }
  224.     public function removeSuggestion(Suggestion $suggestion): self
  225.     {
  226.         if ($this->suggestions->removeElement($suggestion)) {
  227.             // set the owning side to null (unless already changed)
  228.             if ($suggestion->getUser() === $this) {
  229.                 $suggestion->setUser(null);
  230.             }
  231.         }
  232.         return $this;
  233.     }
  234. }