src/Entity/System/Employee.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use A4BGroup\A4bThemeBundle\Entity\UserInterface as A4BUserInterface;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\UploadedFile;
  7. /**
  8.  * Class Employee
  9.  *
  10.  * @ORM\Entity(repositoryClass="App\Repository\System\EmployeeRepository")
  11.  *
  12.  * @ORM\Table(name="ps_employee")
  13.  */
  14. class Employee implements A4BUserInterface
  15. {
  16.     /**
  17.      * @var int
  18.      *
  19.      * @ORM\Id
  20.      *
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      *
  23.      * @ORM\Column(type="integer", name="id_employee", options={"unsigned":true})
  24.      */
  25.     private $id;
  26.     /**
  27.      * @var Profile
  28.      *
  29.      * @deprecated
  30.      *
  31.      * @ORM\ManyToOne(targetEntity="Profile")
  32.      *
  33.      * @ORM\JoinColumn(name="id_profile", referencedColumnName="id_profile", nullable=false)
  34.      */
  35.     private $profile;
  36.     /**
  37.      * @var Language
  38.      *
  39.      * @ORM\ManyToOne(targetEntity="Language")
  40.      *
  41.      * @ORM\JoinColumn(name="id_lang", referencedColumnName="id_lang")
  42.      */
  43.     private $language;
  44.     /**
  45.      * @var string
  46.      *
  47.      * @ORM\Column(type="string", name="lastname", length=32)
  48.      */
  49.     private $lastname;
  50.     /**
  51.      * @var string
  52.      *
  53.      * @ORM\Column(type="string", name="firstname", length=32)
  54.      */
  55.     private $firstname;
  56.     /**
  57.      * @var string
  58.      *
  59.      * @ORM\Column(type="string", nullable=false, unique=true, length=128)
  60.      */
  61.     private $email;
  62.     /**
  63.      * @var string
  64.      *
  65.      * @ORM\Column(type="string", name="passwd", length=128)
  66.      */
  67.     private $password;
  68.     /**
  69.      * @var \DateTime
  70.      *
  71.      * @ORM\Column(type="datetime", options={"default":"CURRENT_TIMESTAMP"}, name="last_passwd_gen")
  72.      */
  73.     private $passwordDate;
  74.     /**
  75.      * @var ArrayCollection<int, AdminAcl>|AdminAcl[]
  76.      *
  77.      * @ORM\ManyToMany(targetEntity="AdminAcl", inversedBy="employees")
  78.      *
  79.      * @ORM\JoinTable(name="employee_admin_acl",
  80.      *      joinColumns={@ORM\JoinColumn(name="employee_id", referencedColumnName="id_employee")},
  81.      *      inverseJoinColumns={@ORM\JoinColumn(name="admin_acl_id", referencedColumnName="id")}
  82.      *   )
  83.      */
  84.     private $routes;
  85.     /**
  86.      * @ORM\Column(type="boolean", options={"unsigned":true, "default":0})
  87.      */
  88.     private bool $active false;
  89.     /**
  90.      * @ORM\Column(type="datetime", nullable=true)
  91.      */
  92.     private ?\DateTimeInterface $lastAccess null;
  93.     /**
  94.      * @ORM\Column(type="datetime", nullable=true)
  95.      */
  96.     private ?\DateTimeInterface $dateAdd;
  97.     /**
  98.      * @ORM\Column(type="datetime", nullable=true)
  99.      */
  100.     private ?\DateTimeInterface $dateUpd null;
  101.     /**
  102.      * @var string[]
  103.      *
  104.      * @ORM\Column(type="json", nullable=false)
  105.      */
  106.     protected $roles;
  107.     /**
  108.      * @var ArrayCollection<int, SynchronisedShopConfiguration>|SynchronisedShopConfiguration[]
  109.      *
  110.      * @ORM\OneToMany(targetEntity="App\Entity\System\SynchronisedShopConfiguration", mappedBy="employee")
  111.      */
  112.     private $syncronisedShopConfiguration;
  113.     /**
  114.      * @var Role[]|ArrayCollection<int, Role>
  115.      *
  116.      * @ORM\ManyToMany(targetEntity="App\Entity\System\Role", inversedBy="employees")
  117.      *
  118.      * @ORM\JoinTable(name="employee_role",
  119.      *  joinColumns={@ORM\JoinColumn(name="employee_id", referencedColumnName="id_employee")},
  120.      *     inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id_role")}
  121.      * )
  122.      */
  123.     private $roleCollection;
  124.     public function __construct()
  125.     {
  126.         $this->dateAdd = new \DateTime();
  127.         $this->passwordDate = new \DateTime();
  128.         $this->password '';
  129.         $this->roles = [];
  130.         $this->syncronisedShopConfiguration = new ArrayCollection();
  131.         $this->roleCollection = new ArrayCollection();
  132.     }
  133.     public function getId(): int
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function setId(int $id): void
  138.     {
  139.         $this->id $id;
  140.     }
  141.     /**
  142.      * @return Profile
  143.      *
  144.      * @deprecated use employee_role instead
  145.      */
  146.     public function getProfile(): Profile
  147.     {
  148.         return $this->profile;
  149.     }
  150.     /**
  151.      * @deprecated
  152.      *
  153.      * @param Profile $profile
  154.      */
  155.     public function setProfile(Profile $profile): void
  156.     {
  157.         $this->profile $profile;
  158.     }
  159.     public function getLanguage(): Language
  160.     {
  161.         return $this->language;
  162.     }
  163.     public function setLanguage(Language $language): self
  164.     {
  165.         $this->language $language;
  166.         return $this;
  167.     }
  168.     public function getLastname(): string
  169.     {
  170.         return $this->lastname;
  171.     }
  172.     public function setLastname(string $lastname): self
  173.     {
  174.         $this->lastname $lastname;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return string
  179.      */
  180.     public function getName(): string
  181.     {
  182.         return $this->firstname;
  183.     }
  184.     public function setName(string $firstname): self
  185.     {
  186.         $this->firstname $firstname;
  187.         return $this;
  188.     }
  189.     public function getEmail(): string
  190.     {
  191.         return $this->email;
  192.     }
  193.     public function setEmail(string $email): self
  194.     {
  195.         $this->email $email;
  196.         return $this;
  197.     }
  198.     public function getPassword(): string
  199.     {
  200.         return $this->password;
  201.     }
  202.     public function setPassword(string $password): self
  203.     {
  204.         $this->password $password;
  205.         return $this;
  206.     }
  207.     public function getPasswordDate(): \DateTime
  208.     {
  209.         return $this->passwordDate;
  210.     }
  211.     public function setPasswordDate(\DateTime $passwordDate): self
  212.     {
  213.         $this->passwordDate $passwordDate;
  214.         return $this;
  215.     }
  216.     public function isEnabled(): bool
  217.     {
  218.         return $this->active;
  219.     }
  220.     public function setEnabled(bool $active): self
  221.     {
  222.         $this->active $active;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Role[]|ArrayCollection<int, Role>
  227.      */
  228.     public function getRoleCollection()
  229.     {
  230.         return $this->roleCollection;
  231.     }
  232.     /**
  233.      * @param Role[]|ArrayCollection<int, Role> $roles
  234.      */
  235.     public function setRoleCollection($roles): Employee
  236.     {
  237.         $this->roleCollection $roles;
  238.         return $this;
  239.     }
  240.     public function getRoles(): array
  241.     {
  242.         $roles $this->roles;
  243.         foreach ($this->getRoleCollection() as $role) {
  244.             $roleName $role->getName();
  245.             if ($role->isEmployee() && !in_array($roleName$rolestrue)) {
  246.                 $roles[] = $roleName;
  247.             }
  248.         }
  249.         $roles[] = Role::ROLE_EMPLOYEE;
  250.         return \array_unique($roles);
  251.     }
  252.     public function getSalt(): ?string
  253.     {
  254.         return null;
  255.     }
  256.     public function getUsername(): string
  257.     {
  258.         return $this->email;
  259.     }
  260.     public function eraseCredentials(): A4BUserInterface
  261.     {
  262.         return $this;
  263.     }
  264.     public function getUserIdentifier(): string
  265.     {
  266.         return (string)$this->getId();
  267.     }
  268.     public function __toString(): string
  269.     {
  270.         return $this->firstname.' '.$this->lastname;
  271.     }
  272.     public function getLastAccess(): ?\DateTimeInterface
  273.     {
  274.         return $this->lastAccess;
  275.     }
  276.     public function setLastAccess(?\DateTimeInterface $lastAccess): Employee
  277.     {
  278.         $this->lastAccess $lastAccess;
  279.         return $this;
  280.     }
  281.     public function getAvatar(): ?string
  282.     {
  283.         return null;
  284.     }
  285.     public function setAvatar(?string $avatar): A4BUserInterface
  286.     {
  287.         return $this;
  288.     }
  289.     public function setUploadedFile(?UploadedFile $uploadedFile null): A4BUserInterface
  290.     {
  291.         return $this;
  292.     }
  293.     public function getUploadedFile(): ?UploadedFile
  294.     {
  295.         return null;
  296.     }
  297.     public function isEqualTo(A4BUserInterface $user): bool
  298.     {
  299.         return $this->email === $user->getEmail();
  300.     }
  301.     public function getDateAdd(): \DateTimeInterface
  302.     {
  303.         return $this->dateAdd;
  304.     }
  305.     public function setDateAdd(\DateTimeInterface $dateAdd): A4BUserInterface
  306.     {
  307.         $this->dateAdd $dateAdd;
  308.         return $this;
  309.     }
  310.     public function getDateUpd(): ?\DateTimeInterface
  311.     {
  312.         return $this->dateUpd;
  313.     }
  314.     public function setDateUpd(?\DateTimeInterface $dateUpd): A4BUserInterface
  315.     {
  316.         $this->dateUpd $dateUpd;
  317.         return $this;
  318.     }
  319.     /**
  320.      * @param string[] $roles
  321.      */
  322.     public function setRoles(array $roles): A4BUserInterface
  323.     {
  324.         $this->roles $roles;
  325.         return $this;
  326.     }
  327.     /**
  328.      * @param string $role
  329.      */
  330.     public function addRole($role): A4BUserInterface
  331.     {
  332.         $role = \strtoupper((string)$role);
  333.         if (Role::ROLE_EMPLOYEE === $role) {
  334.             return $this;
  335.         }
  336.         if (!\in_array($role$this->rolestrue)) {
  337.             $this->roles[] = $role;
  338.         }
  339.         return $this;
  340.     }
  341.     /**
  342.      * @param string $role
  343.      */
  344.     public function removeRole($role): A4BUserInterface
  345.     {
  346.         if (false !== $key = \array_search(\strtoupper((string)$role), $this->rolestrue)) {
  347.             unset($this->roles[$key]);
  348.             $this->roles = \array_values($this->roles);
  349.         }
  350.         return $this;
  351.     }
  352.     /**
  353.      * @param string $role
  354.      */
  355.     public function hasRole($role): bool
  356.     {
  357.         return \in_array(\strtoupper((string)$role), $this->getRoles(), true);
  358.     }
  359.     public function getPlainPassword(): ?string
  360.     {
  361.         return null;
  362.     }
  363.     public function setPlainPassword(string $plainPassword): A4BUserInterface
  364.     {
  365.         return $this;
  366.     }
  367.     public function isDeleted(): bool
  368.     {
  369.         return false;
  370.     }
  371.     public function setDeleted(bool $deleted): A4BUserInterface
  372.     {
  373.         return $this;
  374.     }
  375.     public function getLocale(): ?string
  376.     {
  377.         return $this->getLanguage()->getIsoCode();
  378.     }
  379.     public function setLocale(string $locale): A4BUserInterface
  380.     {
  381.         throw new \Exception('Use setLanguage instead');
  382.     }
  383.     public function setUsername(string $username): A4BUserInterface
  384.     {
  385.         $this->setEmail($username);
  386.         return $this;
  387.     }
  388.     /**
  389.      * @return AdminAcl[]|ArrayCollection<int, AdminAcl>
  390.      */
  391.     public function getRoutes()
  392.     {
  393.         return $this->routes;
  394.     }
  395.     /**
  396.      * @param AdminAcl[]|ArrayCollection<int, AdminAcl> $routes
  397.      */
  398.     public function setRoutes($routes): Employee
  399.     {
  400.         $this->routes $routes;
  401.         return $this;
  402.     }
  403.     /**
  404.      * @return ArrayCollection<int, SynchronisedShopConfiguration>|SynchronisedShopConfiguration[]
  405.      */
  406.     public function getSyncronisedShopConfiguration()
  407.     {
  408.         return $this->syncronisedShopConfiguration;
  409.     }
  410. }