src/Entity/Admin.php line 18

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\AdminRepository;
  5. use App\Traits\TimeStampTrait;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. #[ORM\Table(name'admin')]
  12. #[ORM\Entity(repositoryClassAdminRepository::class)]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Admin implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     use TimeStampTrait;
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     private $id;
  21.     #[ORM\Column(type'string'length100uniquetrue)]
  22.     private $username;
  23.     #[ORM\ManyToOne(targetEntity'Roles'inversedBy'admins')]
  24.     private $role;
  25.     /**
  26.      * @var string The hashed password
  27.      */
  28.     #[ORM\Column(type'string')]
  29.     private $password;
  30.     #[ORM\Column(type'string'length50)]
  31.     private $name;
  32.     #[ORM\Column(type'string'length50)]
  33.     private $lastname;
  34.     #[ORM\Column(type'string'length100)]
  35.     private $email;
  36.     #[ORM\Column(length100nullabletrue)]
  37.     private ?string $code null;
  38.     #[ORM\Column(length25nullabletrue)]
  39.     private ?string $phone null;
  40.     #[ORM\Column(length25nullabletrue)]
  41.     private ?string $sexe null;
  42.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'admins')]
  43.     private ?self $admin null;
  44.     #[ORM\OneToMany(mappedBy'admin'targetEntityself::class)]
  45.     private Collection $admins;
  46.     #[ORM\Column(nullabletrue)]
  47.     private ?bool $status null;
  48.     public function __construct()
  49.     {
  50.         $this->admins = new ArrayCollection();
  51.     }
  52.     public function getId()
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function setId($id): self
  57.     {
  58.         $this->id $id;
  59.         return $this;
  60.     }
  61.     /**
  62.      * A visual identifier that represents this user.
  63.      *
  64.      * @see UserInterface
  65.      */
  66.     public function getUserIdentifier(): string
  67.     {
  68.         return (string) $this->username;
  69.     }
  70.     public function getUsername(): string
  71.     {
  72.         return (string) $this->username;
  73.     }
  74.     public function setUsername(string $username): self
  75.     {
  76.         $this->username $username;
  77.         return $this;
  78.     }
  79.     public function getRole()
  80.     {
  81.         return $this->role;
  82.     }
  83.     public function setRole($role): void
  84.     {
  85.         $this->role $role;
  86.     }
  87.     /**
  88.      * @see UserInterface
  89.      */
  90.     public function getRoles(): array
  91.     {
  92.         return [$this->role->getRole()];
  93.     }
  94.     /**
  95.      * @see UserInterface
  96.      */
  97.     public function getPassword(): string
  98.     {
  99.         return (string) $this->password;
  100.     }
  101.     public function setPassword(string $password): self
  102.     {
  103.         $this->password $password;
  104.         return $this;
  105.     }
  106.     /**
  107.      * @see UserInterface
  108.      */
  109.     public function eraseCredentials(): void
  110.     {
  111.         // If you store any temporary, sensitive data on the user, clear it here
  112.         // $this->plainPassword = null;
  113.     }
  114.     public function setName(?string $name): static
  115.     {
  116.         $this->name $name;
  117.         return $this;
  118.     }
  119.     public function getName(): ?string
  120.     {
  121.         return $this->name;
  122.     }
  123.     public function setFirstname(string $name): self
  124.     {
  125.         $this->name $name;
  126.         return $this;
  127.     }
  128.     public function getLastname(): ?string
  129.     {
  130.         return $this->lastname;
  131.     }
  132.     public function setLastname(string $lastname): self
  133.     {
  134.         $this->lastname $lastname;
  135.         return $this;
  136.     }
  137.     public function getEmail(): ?string
  138.     {
  139.         return $this->email;
  140.     }
  141.     public function setEmail(string $email): self
  142.     {
  143.         $this->email $email;
  144.         return $this;
  145.     }
  146.     public function getCode(): ?string
  147.     {
  148.         return $this->code;
  149.     }
  150.     public function setCode(?string $code): static
  151.     {
  152.         $this->code $code;
  153.         return $this;
  154.     }
  155.     public function getPhone(): ?string
  156.     {
  157.         return $this->phone;
  158.     }
  159.     public function setPhone(?string $phone): static
  160.     {
  161.         $this->phone $phone;
  162.         return $this;
  163.     }
  164.     public function getSexe(): ?string
  165.     {
  166.         return $this->sexe;
  167.     }
  168.     public function setSexe(?string $sexe): static
  169.     {
  170.         $this->sexe $sexe;
  171.         return $this;
  172.     }
  173.     public function getAdmin(): ?self
  174.     {
  175.         return $this->admin;
  176.     }
  177.     public function setAdmin(?self $admin): static
  178.     {
  179.         $this->admin $admin;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return Collection<int, self>
  184.      */
  185.     public function getAdmins(): Collection
  186.     {
  187.         return $this->admins;
  188.     }
  189.     public function addAdmin(self $admin): static
  190.     {
  191.         if (!$this->admins->contains($admin)) {
  192.             $this->admins->add($admin);
  193.             $admin->setAdmin($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeAdmin(self $admin): static
  198.     {
  199.         if ($this->admins->removeElement($admin)) {
  200.             // set the owning side to null (unless already changed)
  201.             if ($admin->getAdmin() === $this) {
  202.                 $admin->setAdmin(null);
  203.             }
  204.         }
  205.         return $this;
  206.     }
  207.     public function isStatus(): ?bool
  208.     {
  209.         return $this->status;
  210.     }
  211.     public function setStatus(?bool $status): static
  212.     {
  213.         $this->status $status;
  214.         return $this;
  215.     }
  216. }