<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity("username")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=180)
*/
private $surName;
/**
* @ORM\Column(type="string", length=255)
*/
private $organization;
/**
* @ORM\Column(type="string", length=180)
*/
private $phone;
/**
* @ORM\Column(type="string", length=180)
*/
private $email;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="datetime")
*/
private $dateCreated;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $isBioAuth;
/**
* @ORM\OneToMany(targetEntity=Suggestion::class, mappedBy="user")
*/
private $suggestions; //1 for yes 2 for no 0 for unsubscribed
/**
* Constructor
*/
public function __construct()
{
date_default_timezone_set('Africa/Douala');
$this->dateCreated = new \Datetime(); // default date
$this->suggestions = new ArrayCollection();
}
public function fullName(): ?string
{
return $this->getFirstName()." ".$this->getSurName();
}
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
public function getRoles(): ?array
{
return $this->roles;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
//$this->password = $password;
$options = ['cost' => 15];
$encoded = password_hash($password,PASSWORD_BCRYPT,$options);
$this->password = $encoded;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getSurName(): ?string
{
return $this->surName;
}
public function setSurName(string $surName): self
{
$this->surName = $surName;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getOrganization(): ?string
{
return $this->organization;
}
public function setOrganization(string $organization): self
{
$this->organization = $organization;
return $this;
}
public function getIsBioAuth(): ?int
{
return $this->isBioAuth;
}
public function setIsBioAuth(?int $isBioAuth): self
{
$this->isBioAuth = $isBioAuth;
return $this;
}
public function getDateCreated(): ?\DateTimeInterface
{
return $this->dateCreated;
}
public function setDateCreated(\DateTimeInterface $dateCreated): self
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* @return Collection<int, Suggestion>
*/
public function getSuggestions(): Collection
{
return $this->suggestions;
}
public function addSuggestion(Suggestion $suggestion): self
{
if (!$this->suggestions->contains($suggestion)) {
$this->suggestions[] = $suggestion;
$suggestion->setUser($this);
}
return $this;
}
public function removeSuggestion(Suggestion $suggestion): self
{
if ($this->suggestions->removeElement($suggestion)) {
// set the owning side to null (unless already changed)
if ($suggestion->getUser() === $this) {
$suggestion->setUser(null);
}
}
return $this;
}
}