<?php
namespace App\Entity;
use App\Repository\EmployeeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: EmployeeRepository::class)]
class Employee extends User
{
use IdentifiableTrait;
private static array $rolesList = [
'ROLE_HISTORY',
'ROLE_STATISTICS',
'ROLE_BILLING',
'ROLE_PRESCRIPTION_PAD',
'ROLE_EMPLOYEE_VIEW',
'ROLE_EMPLOYEE_EDIT',
'ROLE_COMMERCIAL_VIEW',
'ROLE_COMMERCIAL_EDIT',
'ROLE_PRESCRIBER_CREATE',
'ROLE_PRESCRIBER_VIEW',
'ROLE_PRESCRIBER_EDIT',
'ROLE_PRESCRIBER_VALIDATION',
'ROLE_POINTS_MODIFICATION',
'ROLE_EXPORTS',
'ROLE_PARAMETERS',
'ROLE_INVOICE_DISSOCIATE',
'ROLE_ALLOWED_TO_SWITCH',
'ROLE_VISIT_REPORT',
'ROLE_BOOKING_EVENT',
'ROLE_CHOOSE_VISIT_REPORT_COMMERCIAL_ALLOWED',
];
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastname = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $firstname = null;
#[ORM\ManyToMany(targetEntity: BookingEvent::class, mappedBy: 'allowedEmployees')]
private Collection $bookingEventsAllowed;
#[ORM\Column(nullable: true)]
private ?bool $isDisplayedInForms = null;
public function __construct()
{
parent::__construct();
$this->bookingEventsAllowed = new ArrayCollection();
}
public function getFullName(): ?string
{
return $this->getLastname() . " " . $this->getFirstname();
}
public function setHistoryRights(bool $historyRights): self
{
return $this->setRoleRights('ROLE_HISTORY', $historyRights);
}
public function hasHistoryRights(): bool
{
return in_array('ROLE_HISTORY', $this->roles, true);
}
public function setInvoiceDissociateRights(bool $invoiceDissociateRights): self
{
return $this->setRoleRights('ROLE_INVOICE_DISSOCIATE', $invoiceDissociateRights);
}
public function hasInvoiceDissociateRights(): bool
{
return in_array('ROLE_INVOICE_DISSOCIATE', $this->roles, true);
}
public function setPrescriberCreateRights(bool $prescriberCreateRights): self
{
return $this->setRoleRights('ROLE_PRESCRIBER_CREATE', $prescriberCreateRights);
}
public function prescriberCreateRights(): bool
{
return in_array('ROLE_PRESCRIBER_CREATE', $this->roles, true);
}
public function setPrescriptionPadRights(bool $prescriptionPadRights): self
{
return $this->setRoleRights('ROLE_PRESCRIPTION_PAD', $prescriptionPadRights);
}
public function hasPrescriptionPadRights(): bool
{
return $this->hasRole('ROLE_PRESCRIPTION_PAD');
}
public function setStatisticsRights(bool $statisticsRights): self
{
return $this->setRoleRights('ROLE_STATISTICS', $statisticsRights);
}
public function hasStatisticsRights(): bool
{
return $this->hasRole('ROLE_STATISTICS');
}
public function setChooseVisitReportCommercialAllowedRights(bool $statisticsRights): self
{
return $this->setRoleRights('ROLE_CHOOSE_VISIT_REPORT_COMMERCIAL_ALLOWED', $statisticsRights);
}
public function hasChooseVisitReportCommercialAllowedRights(): bool
{
return $this->hasRole('ROLE_CHOOSE_VISIT_REPORT_COMMERCIAL_ALLOWED');
}
public function setBillingRights(bool $billingRights): self
{
return $this->setRoleRights('ROLE_BILLING', $billingRights);
}
public function hasBillingRights(): bool
{
return $this->hasRole('ROLE_BILLING');
}
public function setAllowedToSwitchRights(bool $allowedToSwitchRights): self
{
return $this->setRoleRights('ROLE_ALLOWED_TO_SWITCH', $allowedToSwitchRights);
}
public function hasAllowedToSwitchRights(): bool
{
return $this->hasRole('ROLE_ALLOWED_TO_SWITCH');
}
public function setParametersRights(bool $billingRights): self
{
return $this->setRoleRights('ROLE_PARAMETERS', $billingRights);
}
public function hasParametersRights(): bool
{
return $this->hasRole('ROLE_PARAMETERS');
}
public function setCommercialViewRights(bool $commercialViewRights): self
{
return $this->setRoleRights('ROLE_COMMERCIAL_VIEW', $commercialViewRights);
}
public function hasCommercialViewRights(): bool
{
return $this->hasRole('ROLE_COMMERCIAL_VIEW');
}
public function setCommercialEditRights(bool $commercialEditRights): self
{
return $this->setRoleRights('ROLE_COMMERCIAL_EDIT', $commercialEditRights);
}
public function hasCommercialEditRights(): bool
{
return $this->hasRole('ROLE_COMMERCIAL_EDIT');
}
public function setEmployeeViewRights(bool $employeeViewRights): self
{
return $this->setRoleRights('ROLE_EMPLOYEE_VIEW', $employeeViewRights);
}
public function hasEmployeeViewRights(): bool
{
return $this->hasRole('ROLE_EMPLOYEE_VIEW');
}
public function setEmployeeEditRights(bool $commercialEditRights): self
{
return $this->setRoleRights('ROLE_EMPLOYEE_EDIT', $commercialEditRights);
}
public function hasEmployeeEditRights(): bool
{
return $this->hasRole('ROLE_EMPLOYEE_EDIT');
}
public function setPrescriberViewRights(bool $prescriberViewRights): self
{
return $this->setRoleRights('ROLE_PRESCRIBER_VIEW', $prescriberViewRights);
}
public function hasPrescriberViewRights(): bool
{
return $this->hasRole('ROLE_PRESCRIBER_VIEW');
}
public function setPrescriberEditRights(bool $prescriberEditRights): self
{
return $this->setRoleRights('ROLE_PRESCRIBER_EDIT', $prescriberEditRights);
}
public function hasPrescriberEditRights(): bool
{
return $this->hasRole('ROLE_PRESCRIBER_EDIT');
}
public function setPrescriberValidationRights(bool $prescriberValidationRights): self
{
return $this->setRoleRights('ROLE_PRESCRIBER_VALIDATION', $prescriberValidationRights);
}
public function hasPrescriberValidationRights(): bool
{
return $this->hasRole('ROLE_PRESCRIBER_VALIDATION');
}
public function setVisitReportRights(bool $visitReportRights): self
{
return $this->setRoleRights('ROLE_VISIT_REPORT', $visitReportRights);
}
public function hasVisitReportRights(): bool
{
return $this->hasRole('ROLE_VISIT_REPORT');
}
public function setBookingEventRights(bool $BookingEventRights): self
{
return $this->setRoleRights('ROLE_BOOKING_EVENT', $BookingEventRights);
}
public function hasBookingEventRights(): bool
{
return $this->hasRole('ROLE_BOOKING_EVENT');
}
public function setPointsModificationRights(bool $pointsModificationRights): self
{
return $this->setRoleRights('ROLE_POINTS_MODIFICATION', $pointsModificationRights);
}
public function hasPointsModificationRights(): bool
{
return $this->hasRole('ROLE_POINTS_MODIFICATION');
}
public function setExportsRights(bool $exportsRights): self
{
return $this->setRoleRights('ROLE_EXPORTS', $exportsRights);
}
public function hasExportsRights(): bool
{
return $this->hasRole('ROLE_EXPORTS');
}
private function setRoleRights(string $role, bool $hasRights): self
{
if ($hasRights) {
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
} else {
$this->roles = array_diff($this->roles, [$role]);
}
return $this;
}
public function getRoles(): array
{
$roles = parent::getRoles();
foreach (self::$rolesList as $role) {
if ($this->hasRole($role)) {
$roles[] = $role;
}
}
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = ['ROLE_EMPLOYEE'];
foreach ($roles as $role) {
if (in_array($role, self::$rolesList, true)) {
$this->roles[] = $role;
}
}
return $this;
}
public function hasRole(string $role): bool
{
return in_array($role, $this->roles, true);
}
public function __toString(): string
{
return $this->getUserIdentifier();
}
public function getId(): ?int
{
return $this->id;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(?string $lastname): static
{
$this->lastname = $lastname;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): static
{
$this->firstname = $firstname;
return $this;
}
/**
* @return Collection<int, BookingEvent>
*/
public function getBookingEventsAllowed(): Collection
{
return $this->bookingEventsAllowed;
}
public function addBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
{
if (!$this->bookingEventsAllowed->contains($bookingEventsAllowed)) {
$this->bookingEventsAllowed->add($bookingEventsAllowed);
$bookingEventsAllowed->addAllowedEmployee($this);
}
return $this;
}
public function removeBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
{
if ($this->bookingEventsAllowed->removeElement($bookingEventsAllowed)) {
$bookingEventsAllowed->removeAllowedEmployee($this);
}
return $this;
}
public function isIsDisplayedInForms(): ?bool
{
return $this->isDisplayedInForms;
}
public function setIsDisplayedInForms(?bool $isDisplayedInForms): static
{
$this->isDisplayedInForms = $isDisplayedInForms;
return $this;
}
}