src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. /**
  8.  * @ORM\Table(name="users")
  9.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  10.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  11.  */
  12. class User implements UserInterface , \JsonSerializable
  13. {
  14.     /**
  15.      * @ORM\Id()
  16.      * @ORM\GeneratedValue()
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=180, unique=true)
  22.      */
  23.     private $email;
  24.     /**
  25.      * @var string
  26.      *
  27.      * @ORM\Column(type="string", nullable=true)
  28.      */
  29.     private $numberPhone;
  30.     /**
  31.      * @var string
  32.      *
  33.      * @ORM\Column(name="first_name", type="string", length=180, nullable=false)
  34.      */
  35.     private $firstName;
  36.     /**
  37.      * @var string|null
  38.      *
  39.      * @ORM\Column(name="last_name", type="string", length=180, nullable=false)
  40.      */
  41.     private $lastName;
  42.     /**
  43.      * @var string|null
  44.      * @ORM\Column(name="civility", type="string", length=40, nullable=false)
  45.      */
  46.     private $civility;
  47.     /**
  48.      * @var string|null
  49.      *
  50.      * @ORM\Column(name="profile_pic", type="string", length=255, nullable=true)
  51.      */
  52.     private $profilePic;
  53.     /**
  54.      * @ORM\Column(type="json")
  55.      */
  56.     private $roles = [];
  57.     /**
  58.      * @var string The hashed password
  59.      * @ORM\Column(type="string")
  60.      */
  61.     private $password;
  62.     /**
  63.      * @ORM\Column(type="string", length=255)
  64.      */
  65.     private $status;
  66.     /**
  67.      * @ORM\Column(type="datetime")
  68.      */
  69.     private $created_at;
  70.     /**
  71.      * @ORM\Column(type="datetime")
  72.      */
  73.     private $updated_at;
  74.     /**
  75.      * @ORM\Column(type="datetime", nullable=true)
  76.      */
  77.     private $deleted_at;
  78.     /**
  79.      * Many Users have Many Groups.
  80.      * @ORM\ManyToMany(targetEntity="Group", inversedBy="users", fetch="EAGER")
  81.      * @ORM\JoinTable(name="users_groups",
  82.      *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
  83.      *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
  84.      *      )
  85.      */
  86.     private $groups;
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="Comment", mappedBy="user", cascade={"remove"})
  89.      */
  90.     private $comments;
  91.     /**
  92.      * Many Users have Many conversation.
  93.      * @ORM\ManyToMany(targetEntity="Conversation", inversedBy="users")
  94.      * @ORM\JoinTable(name="conversations_users")
  95.      */
  96.     private $conversations;
  97.     /**
  98.      * One product has many features. This is the inverse side.
  99.      * @ORM\OneToMany(targetEntity="Message", mappedBy="user", cascade={"remove"})
  100.      */
  101.     private $messages;
  102.     /**
  103.      * @ORM\Column(type="boolean")
  104.      */
  105.     private $isActive;
  106.     /**
  107.      * @ORM\Column(type="string", length=255,unique=true)
  108.      */
  109.     private $uuid;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity="Notification", mappedBy="user")
  112.      */
  113.     private $notifications;
  114.     /**
  115.      * @var string|null
  116.      * @ORM\Column(type="string", length=255, nullable=true)
  117.      */
  118.     private $reset_token;
  119.     /**
  120.      * @var string|null
  121.      * @ORM\Column(type="string", length=5, nullable=false)
  122.      */
  123.     private $locale;
  124.     /**
  125.      * @ORM\Column(type="boolean", nullable=true)
  126.      */
  127.     private $is_verified;
  128.     /**
  129.      * @ORM\Column(type="string", length=10, nullable=true)
  130.      */
  131.     private $otp_code;
  132.     /**
  133.      * @ORM\Column(type="boolean", nullable=true)
  134.      */
  135.     private $is_otp_expired;
  136.     /**
  137.      * User constructor.
  138.      */
  139.     public function __construct() {
  140.         $this->isActive false;
  141.         $this->groups = new ArrayCollection();
  142.         $this->conversations = new ArrayCollection();
  143.         $this->comments = new ArrayCollection();
  144.         $this->notifications = new ArrayCollection();
  145.         $this->locale $this->getLocale();
  146.     }
  147.     public function getId(): ?int
  148.     {
  149.         return $this->id;
  150.     }
  151.     public function getEmail(): ?string
  152.     {
  153.         return $this->email;
  154.     }
  155.     public function setEmail(string $email): self
  156.     {
  157.         $this->email $email;
  158.         return $this;
  159.     }
  160.     public function getNumberPhone(): ?string
  161.     {
  162.         return $this->numberPhone;
  163.     }
  164.     public function setNumberPhone(string $numberPhone): self
  165.     {
  166.         $this->numberPhone $numberPhone;
  167.         return $this;
  168.     }
  169.     public function getFirstName(): ?string
  170.     {
  171.         return $this->firstName;
  172.     }
  173.     public function setFirstName(string $firstName): self
  174.     {
  175.         $this->firstName $firstName;
  176.         return $this;
  177.     }
  178.     public function getLastName(): ?string
  179.     {
  180.         return $this->lastName;
  181.     }
  182.     public function setLastName(?string $lastName): self
  183.     {
  184.         $this->lastName $lastName;
  185.         return $this;
  186.     }
  187.     public function getCivility(): ?string
  188.     {
  189.         return $this->civility;
  190.     }
  191.     public function setCivility(?string $civility): self
  192.     {
  193.         $this->civility $civility;
  194.         return $this;
  195.     }
  196.     public function getProfilePic(): ?string
  197.     {
  198.         if ($this->profilePic == null) {
  199.             return '/assets/media/users/default.jpg';
  200.         }
  201.         return '/assets/media/users/' $this->profilePic;
  202.     }
  203.     public function setProfilePic(?string $profilePic): self
  204.     {
  205.         $this->profilePic $profilePic;
  206.         return $this;
  207.     }
  208.     /**
  209.      *  full Name User
  210.      *
  211.      */
  212.     public function fullName() : string {
  213.         return (string) sprintf('%s %s'$this->firstName $this->lastName);
  214.     }
  215.     /**
  216.      * A visual identifier that represents this user.
  217.      *
  218.      * @see UserInterface
  219.      */
  220.     public function getUsername(): string
  221.     {
  222.         return (string) $this->email;
  223.     }
  224.     /**
  225.      * @see UserInterface
  226.      */
  227.     public function getRoles(): array
  228.     {
  229.         $roles $this->roles;
  230.         // guarantee every user at least has ROLE_USER
  231.         $roles[] = 'ROLE_USER';
  232.         return array_unique($roles);
  233.     }
  234.     public function getRoleDescription(){
  235.         if($this->getRoles()[0] =='ROLE_ADMIN'){
  236.             return 'Administrateur';
  237.         }elseif ($this->getRoles()[0] =='ROLE_ADMIN_ASSISTANT'){
  238.             return 'Assistant Administrateur';
  239.         }elseif ($this->getRoles()[0] =='ROLE_PILOTE'){
  240.             return 'Pilote';
  241.         }elseif ($this->getRoles()[0] =='ROLE_MEMBRE'){
  242.             return 'Membre';
  243.         };
  244.     }
  245.     public function setRoles(array $roles): self
  246.     {
  247.         $this->roles $roles;
  248.         return $this;
  249.     }
  250.     /**
  251.      * @see UserInterface
  252.      */
  253.     public function getPassword(): string
  254.     {
  255.         return (string) $this->password;
  256.     }
  257.     public function setPassword(string $password): self
  258.     {
  259.         $this->password $password;
  260.         return $this;
  261.     }
  262.     public function getStatus(): ?string
  263.     {
  264.         return $this->status;
  265.     }
  266.     public function setStatus(string $status): self
  267.     {
  268.         $this->status $status;
  269.         return $this;
  270.     }
  271.     public function getCreatedAt(): ?\DateTimeInterface
  272.     {
  273.         return $this->created_at;
  274.     }
  275.     public function setCreatedAt(\DateTimeInterface $created_at): self
  276.     {
  277.         $this->created_at $created_at;
  278.         return $this;
  279.     }
  280.     public function getUpdatedAt(): ?\DateTimeInterface
  281.     {
  282.         return $this->updated_at;
  283.     }
  284.     public function setUpdatedAt(\DateTimeInterface $updated_at): self
  285.     {
  286.         $this->updated_at $updated_at;
  287.         return $this;
  288.     }
  289.     public function getDeletedAt(): ?\DateTimeInterface
  290.     {
  291.         return $this->deleted_at;
  292.     }
  293.     public function setDeletedAt(\DateTimeInterface $deleted_at): self
  294.     {
  295.         $this->deleted_at $deleted_at;
  296.         return $this;
  297.     }
  298.     /**
  299.      * @see UserInterface
  300.      */
  301.     public function getSalt()
  302.     {
  303.         // not needed when using the "bcrypt" algorithm in security.yaml
  304.     }
  305.     /**
  306.      * @see UserInterface
  307.      */
  308.     public function eraseCredentials()
  309.     {
  310.         // If you store any temporary, sensitive data on the user, clear it here
  311.         // $this->plainPassword = null;
  312.     }
  313.     public function getGroups()
  314.     {
  315.         return $this->groups;
  316.     }
  317.     public function setGroups($groups): self
  318.     {
  319.         $this->groups $groups;
  320.         return $this;
  321.     }
  322.     public function addGroup(Group $group)
  323.     {
  324.         $this->groups[] = $group;
  325.     }
  326.     public function IsActive(): ?bool
  327.     {
  328.         return $this->isActive;
  329.     }
  330.     public function setIsActive(bool $isActive): self
  331.     {
  332.         $this->isActive $isActive;
  333.         return $this;
  334.     }
  335.     public function getComments()
  336.     {
  337.         return $this->comments;
  338.     }
  339.     public function setComments($comments): self
  340.     {
  341.         $this->comments $comments;
  342.         return $this;
  343.     }
  344.     public function getConversations()
  345.     {
  346.         return $this->conversations;
  347.     }
  348.     public function setConversations($conversations): self{
  349.         $this->conversations $conversations;
  350.         return $this;
  351.     }
  352.     public function addConversation(Conversation $conversation){
  353.         $this->conversations[] = $conversation;
  354.     }
  355.     public function getMessages(){
  356.         return $this->messages;
  357.     }
  358.     public function setMessages($messages): self{
  359.         $this->messages $messages;
  360.         return $this;
  361.     }
  362.     public function getNotifications(){
  363.         return $this->notifications;
  364.     }
  365.     public function setNotifications($notifications): self{
  366.         $this->notifications $notifications;
  367.         return $this;
  368.     }
  369.     public function addNotifications(Notification $notification){
  370.         $this->notifications[] = $notification;
  371.     }
  372.     public function toArray(){
  373.         return [
  374.             'id' => $this->getId(),
  375.             'firstName' => $this->getFirstName(),
  376.             'lastName' => $this->getLastName(),
  377.             'fullName' => $this->fullName(),
  378.             'email' => $this->getEmail(),
  379.             'numberPhone' => $this->getNumberPhone(),
  380.             'civility'=>$this->getCivility(),
  381.             'profilePic'=>$this->getProfilePic(),
  382.             'isActive'=>$this->isActive(),
  383.             'uuid'=> $this->getUuid()
  384.         ];
  385.     }
  386.     /**
  387.      * Specify data which should be serialized to JSON
  388.      * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
  389.      * @return mixed data which can be serialized by <b>json_encode</b>,
  390.      * which is a value of any type other than a resource.
  391.      * @since 5.4.0
  392.      */
  393.     public function jsonSerialize(){
  394.         return [
  395.             'id' => $this->getId(),
  396.             'firstName' => $this->getFirstName(),
  397.             'lastName' => $this->getLastName(),
  398.             'fullName' => $this->fullName(),
  399.             'email' => $this->getEmail(),
  400.             'roles'=> $this->getRoles(),
  401.             'numberPhone' => $this->getNumberPhone(),
  402.             'civility'=>$this->getCivility(),
  403.             'groups' => $this->getGroups()->toArray(),
  404.             'profilePic'=>$this->getProfilePic(),
  405.             'isActive'=>$this->isActive(),
  406.             'uuid'=> $this->getUuid()
  407.         ];
  408.     }
  409.     public function getUuid(): ?string
  410.     {
  411.         return $this->uuid;
  412.     }
  413.     public function setUuid(string $uuid): self
  414.     {
  415.         $this->uuid $uuid;
  416.         return $this;
  417.     }
  418.     public function getChannel(): array{
  419.         $channels = [];
  420.         foreach ($this->conversations as $conversation)
  421.         {
  422.             $channels[] = $conversation->getUuid();
  423.         }
  424.         return $channels;
  425.     }
  426.     public function getResetToken(): ?string
  427.     {
  428.         return $this->reset_token;
  429.     }
  430.     public function setResetToken(?string $reset_token): self
  431.     {
  432.         $this->reset_token $reset_token;
  433.         return $this;
  434.     }
  435.     public function getLocale(): ?string
  436.     {
  437.         return $this->locale;
  438.     }
  439.     public function setLocale(?string $locale): self
  440.     {
  441.         $this->locale $locale;
  442.         return $this;
  443.     }
  444.     public function getIsVerified(): ?bool
  445.     {
  446.         return $this->is_verified;
  447.     }
  448.     public function setIsVerified(?bool $is_verified): self
  449.     {
  450.         $this->is_verified $is_verified;
  451.         return $this;
  452.     }
  453.     public function getOtpCode(): ?string
  454.     {
  455.         return $this->otp_code;
  456.     }
  457.     public function setOtpCode(?string $otp_code): self
  458.     {
  459.         $this->otp_code $otp_code;
  460.         return $this;
  461.     }
  462.     public function getIsOtpExpired(): ?bool
  463.     {
  464.         return $this->is_otp_expired;
  465.     }
  466.     public function setIsOtpExpired(?bool $is_otp_expired): self
  467.     {
  468.         $this->is_otp_expired $is_otp_expired;
  469.         return $this;
  470.     }
  471. }