src/Entity/System/Employee.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use A4BGroup\A4bThemeBundle\Entity\UserInterface as A4BUserInterface;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\UploadedFile;
  6. /**
  7.  * Class Employee
  8.  *
  9.  * @ORM\Entity(repositoryClass="App\Repository\System\EmployeeRepository")
  10.  *
  11.  * @ORM\Table(name="ps_employee")
  12.  */
  13. class Employee implements A4BUserInterface
  14. {
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Id
  19.      *
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      *
  22.      * @ORM\Column(type="integer", name="id_employee", options={"unsigned":true})
  23.      */
  24.     private $id;
  25.     /**
  26.      * @var Profile
  27.      *
  28.      * @ORM\ManyToOne(targetEntity="Profile")
  29.      *
  30.      * @ORM\JoinColumn(name="id_profile", referencedColumnName="id_profile")
  31.      */
  32.     private $profile;
  33.     /**
  34.      * @var Language
  35.      *
  36.      * @ORM\ManyToOne(targetEntity="Language")
  37.      *
  38.      * @ORM\JoinColumn(name="id_lang", referencedColumnName="id_lang")
  39.      */
  40.     private $language;
  41.     /**
  42.      * @var string
  43.      *
  44.      * @ORM\Column(type="string", name="lastname", length=32)
  45.      */
  46.     private $lastname;
  47.     /**
  48.      * @var string
  49.      *
  50.      * @ORM\Column(type="string", name="firstname", length=32)
  51.      */
  52.     private $firstname;
  53.     /**
  54.      * @var string
  55.      *
  56.      * @ORM\Column(type="string", nullable=false, unique=true, length=128)
  57.      */
  58.     private $email;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @ORM\Column(type="string", name="passwd", length=128)
  63.      */
  64.     private $password;
  65.     /**
  66.      * @var \DateTime
  67.      *
  68.      * @ORM\Column(type="datetime", options={"default":"CURRENT_TIMESTAMP"}, name="last_passwd_gen")
  69.      */
  70.     private $passwordDate;
  71.     /**
  72.      * @ORM\Column(type="boolean", options={"unsigned":true, "default":0})
  73.      */
  74.     private bool $active false;
  75.     /**
  76.      * @ORM\Column(type="datetime", nullable=true)
  77.      */
  78.     private ?\DateTimeInterface $lastAccess null;
  79.     /**
  80.      * @ORM\Column(type="datetime", nullable=true)
  81.      */
  82.     private ?\DateTimeInterface $dateAdd;
  83.     /**
  84.      * @ORM\Column(type="datetime", nullable=true)
  85.      */
  86.     private ?\DateTimeInterface $dateUpd null;
  87.     /**
  88.      * @var string[]
  89.      *
  90.      * @ORM\Column(type="json", nullable=false)
  91.      */
  92.     protected $roles;
  93.     public function __construct()
  94.     {
  95.         $this->dateAdd = new \DateTime();
  96.         $this->passwordDate = new \DateTime();
  97.         $this->password '';
  98.         $this->roles = [];
  99.     }
  100.     public function getId(): int
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function setId(int $id): void
  105.     {
  106.         $this->id $id;
  107.     }
  108.     public function getProfile(): Profile
  109.     {
  110.         return $this->profile;
  111.     }
  112.     /**
  113.      * @param Profile $profile
  114.      */
  115.     public function setProfile(Profile $profile): void
  116.     {
  117.         $this->profile $profile;
  118.     }
  119.     public function getLanguage(): Language
  120.     {
  121.         return $this->language;
  122.     }
  123.     public function setLanguage(Language $language): self
  124.     {
  125.         $this->language $language;
  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.     /**
  138.      * @return string
  139.      */
  140.     public function getName(): string
  141.     {
  142.         return $this->firstname;
  143.     }
  144.     public function setName(string $firstname): self
  145.     {
  146.         $this->firstname $firstname;
  147.         return $this;
  148.     }
  149.     public function getEmail(): string
  150.     {
  151.         return $this->email;
  152.     }
  153.     public function setEmail(string $email): self
  154.     {
  155.         $this->email $email;
  156.         return $this;
  157.     }
  158.     public function getPassword(): string
  159.     {
  160.         return $this->password;
  161.     }
  162.     public function setPassword(string $password): self
  163.     {
  164.         $this->password $password;
  165.         return $this;
  166.     }
  167.     public function getPasswordDate(): \DateTime
  168.     {
  169.         return $this->passwordDate;
  170.     }
  171.     public function setPasswordDate(\DateTime $passwordDate): self
  172.     {
  173.         $this->passwordDate $passwordDate;
  174.         return $this;
  175.     }
  176.     public function isEnabled(): bool
  177.     {
  178.         return $this->active;
  179.     }
  180.     public function setEnabled(bool $active): self
  181.     {
  182.         $this->active $active;
  183.         return $this;
  184.     }
  185.     public function getRoles(): array
  186.     {
  187.         $roles $this->roles;
  188.         foreach ($this->getProfile()->getRoles() as $role) {
  189.             $roleName $role->getName();
  190.             if (!in_array($roleName$rolestrue)) {
  191.                 $roles[] = $role->getName();
  192.             }
  193.         }
  194.         $roles[] = self::ROLE_USER;
  195.         return \array_unique($roles);
  196.     }
  197.     public function getSalt(): ?string
  198.     {
  199.         return null;
  200.     }
  201.     public function getUsername(): string
  202.     {
  203.         return $this->email;
  204.     }
  205.     public function eraseCredentials(): A4BUserInterface
  206.     {
  207.         return $this;
  208.     }
  209.     public function getUserIdentifier(): string
  210.     {
  211.         return (string)$this->getId();
  212.     }
  213.     public function __toString(): string
  214.     {
  215.         return $this->firstname.' '.$this->lastname;
  216.     }
  217.     public function getLastAccess(): ?\DateTimeInterface
  218.     {
  219.         return $this->lastAccess;
  220.     }
  221.     public function setLastAccess(?\DateTimeInterface $lastAccess): Employee
  222.     {
  223.         $this->lastAccess $lastAccess;
  224.         return $this;
  225.     }
  226.     public function getAvatar(): ?string
  227.     {
  228.         return null;
  229.     }
  230.     public function setAvatar(?string $avatar): A4BUserInterface
  231.     {
  232.         return $this;
  233.     }
  234.     public function setUploadedFile(?UploadedFile $uploadedFile null): A4BUserInterface
  235.     {
  236.         return $this;
  237.     }
  238.     public function getUploadedFile(): ?UploadedFile
  239.     {
  240.         return null;
  241.     }
  242.     public function isEqualTo(A4BUserInterface $user): bool
  243.     {
  244.         return $this->email === $user->getEmail();
  245.     }
  246.     public function getDateAdd(): \DateTimeInterface
  247.     {
  248.         return $this->dateAdd;
  249.     }
  250.     public function setDateAdd(\DateTimeInterface $dateAdd): A4BUserInterface
  251.     {
  252.         $this->dateAdd $dateAdd;
  253.         return $this;
  254.     }
  255.     public function getDateUpd(): ?\DateTimeInterface
  256.     {
  257.         return $this->dateUpd;
  258.     }
  259.     public function setDateUpd(?\DateTimeInterface $dateUpd): A4BUserInterface
  260.     {
  261.         $this->dateUpd $dateUpd;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @param string[] $roles
  266.      */
  267.     public function setRoles(array $roles): A4BUserInterface
  268.     {
  269.         $this->roles $roles;
  270.         return $this;
  271.     }
  272.     /**
  273.      * @param string $role
  274.      */
  275.     public function addRole($role): A4BUserInterface
  276.     {
  277.         $role = \strtoupper((string)$role);
  278.         if (self::ROLE_DEFAULT === $role) {
  279.             return $this;
  280.         }
  281.         if (!\in_array($role$this->rolestrue)) {
  282.             $this->roles[] = $role;
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @param string $role
  288.      */
  289.     public function removeRole($role): A4BUserInterface
  290.     {
  291.         if (false !== $key = \array_search(\strtoupper((string)$role), $this->rolestrue)) {
  292.             unset($this->roles[$key]);
  293.             $this->roles = \array_values($this->roles);
  294.         }
  295.         return $this;
  296.     }
  297.     /**
  298.      * @param string $role
  299.      */
  300.     public function hasRole($role): bool
  301.     {
  302.         return \in_array(\strtoupper((string)$role), $this->getRoles(), true);
  303.     }
  304.     public function getPlainPassword(): ?string
  305.     {
  306.         return null;
  307.     }
  308.     public function setPlainPassword(string $plainPassword): A4BUserInterface
  309.     {
  310.         return $this;
  311.     }
  312.     public function isDeleted(): bool
  313.     {
  314.         return false;
  315.     }
  316.     public function setDeleted(bool $deleted): A4BUserInterface
  317.     {
  318.         return $this;
  319.     }
  320.     public function getLocale(): ?string
  321.     {
  322.         return $this->getLanguage()->getIsoCode();
  323.     }
  324.     public function setLocale(string $locale): A4BUserInterface
  325.     {
  326.         throw new \Exception('Use setLanguage instead');
  327.     }
  328.     public function setUsername(string $username): A4BUserInterface
  329.     {
  330.         $this->setEmail($username);
  331.         return $this;
  332.     }
  333. }