<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Table(name="users")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface , \JsonSerializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
private $numberPhone;
/**
* @var string
*
* @ORM\Column(name="first_name", type="string", length=180, nullable=false)
*/
private $firstName;
/**
* @var string|null
*
* @ORM\Column(name="last_name", type="string", length=180, nullable=false)
*/
private $lastName;
/**
* @var string|null
* @ORM\Column(name="civility", type="string", length=40, nullable=false)
*/
private $civility;
/**
* @var string|null
*
* @ORM\Column(name="profile_pic", type="string", length=255, nullable=true)
*/
private $profilePic;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
*/
private $status;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="datetime")
*/
private $updated_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deleted_at;
/**
* Many Users have Many Groups.
* @ORM\ManyToMany(targetEntity="Group", inversedBy="users", fetch="EAGER")
* @ORM\JoinTable(name="users_groups",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
private $groups;
/**
* @ORM\OneToMany(targetEntity="Comment", mappedBy="user", cascade={"remove"})
*/
private $comments;
/**
* Many Users have Many conversation.
* @ORM\ManyToMany(targetEntity="Conversation", inversedBy="users")
* @ORM\JoinTable(name="conversations_users")
*/
private $conversations;
/**
* One product has many features. This is the inverse side.
* @ORM\OneToMany(targetEntity="Message", mappedBy="user", cascade={"remove"})
*/
private $messages;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="string", length=255,unique=true)
*/
private $uuid;
/**
* @ORM\OneToMany(targetEntity="Notification", mappedBy="user")
*/
private $notifications;
/**
* @var string|null
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $reset_token;
/**
* @var string|null
* @ORM\Column(type="string", length=5, nullable=false)
*/
private $locale;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $is_verified;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $otp_code;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $is_otp_expired;
/**
* User constructor.
*/
public function __construct() {
$this->isActive = false;
$this->groups = new ArrayCollection();
$this->conversations = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->locale = $this->getLocale();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getNumberPhone(): ?string
{
return $this->numberPhone;
}
public function setNumberPhone(string $numberPhone): self
{
$this->numberPhone = $numberPhone;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getCivility(): ?string
{
return $this->civility;
}
public function setCivility(?string $civility): self
{
$this->civility = $civility;
return $this;
}
public function getProfilePic(): ?string
{
if ($this->profilePic == null) {
return '/assets/media/users/default.jpg';
}
return '/assets/media/users/' . $this->profilePic;
}
public function setProfilePic(?string $profilePic): self
{
$this->profilePic = $profilePic;
return $this;
}
/**
* full Name User
*
*/
public function fullName() : string {
return (string) sprintf('%s %s', $this->firstName , $this->lastName);
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function getRoleDescription(){
if($this->getRoles()[0] =='ROLE_ADMIN'){
return 'Administrateur';
}elseif ($this->getRoles()[0] =='ROLE_ADMIN_ASSISTANT'){
return 'Assistant Administrateur';
}elseif ($this->getRoles()[0] =='ROLE_PILOTE'){
return 'Pilote';
}elseif ($this->getRoles()[0] =='ROLE_MEMBRE'){
return 'Membre';
};
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deleted_at;
}
public function setDeletedAt(\DateTimeInterface $deleted_at): self
{
$this->deleted_at = $deleted_at;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getGroups()
{
return $this->groups;
}
public function setGroups($groups): self
{
$this->groups = $groups;
return $this;
}
public function addGroup(Group $group)
{
$this->groups[] = $group;
}
public function IsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getComments()
{
return $this->comments;
}
public function setComments($comments): self
{
$this->comments = $comments;
return $this;
}
public function getConversations()
{
return $this->conversations;
}
public function setConversations($conversations): self{
$this->conversations = $conversations;
return $this;
}
public function addConversation(Conversation $conversation){
$this->conversations[] = $conversation;
}
public function getMessages(){
return $this->messages;
}
public function setMessages($messages): self{
$this->messages = $messages;
return $this;
}
public function getNotifications(){
return $this->notifications;
}
public function setNotifications($notifications): self{
$this->notifications = $notifications;
return $this;
}
public function addNotifications(Notification $notification){
$this->notifications[] = $notification;
}
public function toArray(){
return [
'id' => $this->getId(),
'firstName' => $this->getFirstName(),
'lastName' => $this->getLastName(),
'fullName' => $this->fullName(),
'email' => $this->getEmail(),
'numberPhone' => $this->getNumberPhone(),
'civility'=>$this->getCivility(),
'profilePic'=>$this->getProfilePic(),
'isActive'=>$this->isActive(),
'uuid'=> $this->getUuid()
];
}
/**
* Specify data which should be serialized to JSON
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize(){
return [
'id' => $this->getId(),
'firstName' => $this->getFirstName(),
'lastName' => $this->getLastName(),
'fullName' => $this->fullName(),
'email' => $this->getEmail(),
'roles'=> $this->getRoles(),
'numberPhone' => $this->getNumberPhone(),
'civility'=>$this->getCivility(),
'groups' => $this->getGroups()->toArray(),
'profilePic'=>$this->getProfilePic(),
'isActive'=>$this->isActive(),
'uuid'=> $this->getUuid()
];
}
public function getUuid(): ?string
{
return $this->uuid;
}
public function setUuid(string $uuid): self
{
$this->uuid = $uuid;
return $this;
}
public function getChannel(): array{
$channels = [];
foreach ($this->conversations as $conversation)
{
$channels[] = $conversation->getUuid();
}
return $channels;
}
public function getResetToken(): ?string
{
return $this->reset_token;
}
public function setResetToken(?string $reset_token): self
{
$this->reset_token = $reset_token;
return $this;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
public function getIsVerified(): ?bool
{
return $this->is_verified;
}
public function setIsVerified(?bool $is_verified): self
{
$this->is_verified = $is_verified;
return $this;
}
public function getOtpCode(): ?string
{
return $this->otp_code;
}
public function setOtpCode(?string $otp_code): self
{
$this->otp_code = $otp_code;
return $this;
}
public function getIsOtpExpired(): ?bool
{
return $this->is_otp_expired;
}
public function setIsOtpExpired(?bool $is_otp_expired): self
{
$this->is_otp_expired = $is_otp_expired;
return $this;
}
}