src/Entity/Employee.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EmployeeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassEmployeeRepository::class)]
  8. class Employee extends User
  9. {
  10.     use IdentifiableTrait;
  11.     private static array $rolesList = [
  12.         'ROLE_HISTORY',
  13.         'ROLE_STATISTICS',
  14.         'ROLE_BILLING',
  15.         'ROLE_PRESCRIPTION_PAD',
  16.         'ROLE_EMPLOYEE_VIEW',
  17.         'ROLE_EMPLOYEE_EDIT',
  18.         'ROLE_COMMERCIAL_VIEW',
  19.         'ROLE_COMMERCIAL_EDIT',
  20.         'ROLE_PRESCRIBER_CREATE',
  21.         'ROLE_PRESCRIBER_VIEW',
  22.         'ROLE_PRESCRIBER_EDIT',
  23.         'ROLE_PRESCRIBER_VALIDATION',
  24.         'ROLE_POINTS_MODIFICATION',
  25.         'ROLE_EXPORTS',
  26.         'ROLE_PARAMETERS',
  27.         'ROLE_INVOICE_DISSOCIATE',
  28.         'ROLE_ALLOWED_TO_SWITCH',
  29.         'ROLE_VISIT_REPORT',
  30.         'ROLE_BOOKING_EVENT',
  31.         'ROLE_CHOOSE_VISIT_REPORT_COMMERCIAL_ALLOWED',
  32.     ];
  33.     #[ORM\Column(length255nullabletrue)]
  34.     private ?string $lastname null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     private ?string $firstname null;
  37.     #[ORM\ManyToMany(targetEntityBookingEvent::class, mappedBy'allowedEmployees')]
  38.     private Collection $bookingEventsAllowed;
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?bool $isDisplayedInForms null;
  41.     public function __construct()
  42.     {
  43.         parent::__construct();
  44.         $this->bookingEventsAllowed = new ArrayCollection();
  45.     }
  46.     public function getFullName(): ?string
  47.     {
  48.         return $this->getLastname() . " " $this->getFirstname();
  49.     }
  50.     public function setHistoryRights(bool $historyRights): self
  51.     {
  52.         return $this->setRoleRights('ROLE_HISTORY'$historyRights);
  53.     }
  54.     public function hasHistoryRights(): bool
  55.     {
  56.         return in_array('ROLE_HISTORY'$this->rolestrue);
  57.     }
  58.     public function setInvoiceDissociateRights(bool $invoiceDissociateRights): self
  59.     {
  60.         return $this->setRoleRights('ROLE_INVOICE_DISSOCIATE'$invoiceDissociateRights);
  61.     }
  62.     public function hasInvoiceDissociateRights(): bool
  63.     {
  64.         return in_array('ROLE_INVOICE_DISSOCIATE'$this->rolestrue);
  65.     }
  66.     public function setPrescriberCreateRights(bool $prescriberCreateRights): self
  67.     {
  68.         return $this->setRoleRights('ROLE_PRESCRIBER_CREATE'$prescriberCreateRights);
  69.     }
  70.     public function prescriberCreateRights(): bool
  71.     {
  72.         return in_array('ROLE_PRESCRIBER_CREATE'$this->rolestrue);
  73.     }
  74.     public function setPrescriptionPadRights(bool $prescriptionPadRights): self
  75.     {
  76.         return $this->setRoleRights('ROLE_PRESCRIPTION_PAD'$prescriptionPadRights);
  77.     }
  78.     public function hasPrescriptionPadRights(): bool
  79.     {
  80.         return $this->hasRole('ROLE_PRESCRIPTION_PAD');
  81.     }
  82.     public function setStatisticsRights(bool $statisticsRights): self
  83.     {
  84.         return $this->setRoleRights('ROLE_STATISTICS'$statisticsRights);
  85.     }
  86.     public function hasStatisticsRights(): bool
  87.     {
  88.         return $this->hasRole('ROLE_STATISTICS');
  89.     }
  90.     public function setChooseVisitReportCommercialAllowedRights(bool $statisticsRights): self
  91.     {
  92.         return $this->setRoleRights('ROLE_CHOOSE_VISIT_REPORT_COMMERCIAL_ALLOWED'$statisticsRights);
  93.     }
  94.     public function hasChooseVisitReportCommercialAllowedRights(): bool
  95.     {
  96.         return $this->hasRole('ROLE_CHOOSE_VISIT_REPORT_COMMERCIAL_ALLOWED');
  97.     }
  98.     public function setBillingRights(bool $billingRights): self
  99.     {
  100.         return $this->setRoleRights('ROLE_BILLING'$billingRights);
  101.     }
  102.     public function hasBillingRights(): bool
  103.     {
  104.         return $this->hasRole('ROLE_BILLING');
  105.     }
  106.     public function setAllowedToSwitchRights(bool $allowedToSwitchRights): self
  107.     {
  108.         return $this->setRoleRights('ROLE_ALLOWED_TO_SWITCH'$allowedToSwitchRights);
  109.     }
  110.     public function hasAllowedToSwitchRights(): bool
  111.     {
  112.         return $this->hasRole('ROLE_ALLOWED_TO_SWITCH');
  113.     }
  114.     public function setParametersRights(bool $billingRights): self
  115.     {
  116.         return $this->setRoleRights('ROLE_PARAMETERS'$billingRights);
  117.     }
  118.     public function hasParametersRights(): bool
  119.     {
  120.         return $this->hasRole('ROLE_PARAMETERS');
  121.     }
  122.     public function setCommercialViewRights(bool $commercialViewRights): self
  123.     {
  124.         return $this->setRoleRights('ROLE_COMMERCIAL_VIEW'$commercialViewRights);
  125.     }
  126.     public function hasCommercialViewRights(): bool
  127.     {
  128.         return $this->hasRole('ROLE_COMMERCIAL_VIEW');
  129.     }
  130.     public function setCommercialEditRights(bool $commercialEditRights): self
  131.     {
  132.         return $this->setRoleRights('ROLE_COMMERCIAL_EDIT'$commercialEditRights);
  133.     }
  134.     public function hasCommercialEditRights(): bool
  135.     {
  136.         return $this->hasRole('ROLE_COMMERCIAL_EDIT');
  137.     }
  138.     public function setEmployeeViewRights(bool $employeeViewRights): self
  139.     {
  140.         return $this->setRoleRights('ROLE_EMPLOYEE_VIEW'$employeeViewRights);
  141.     }
  142.     public function hasEmployeeViewRights(): bool
  143.     {
  144.         return $this->hasRole('ROLE_EMPLOYEE_VIEW');
  145.     }
  146.     public function setEmployeeEditRights(bool $commercialEditRights): self
  147.     {
  148.         return $this->setRoleRights('ROLE_EMPLOYEE_EDIT'$commercialEditRights);
  149.     }
  150.     public function hasEmployeeEditRights(): bool
  151.     {
  152.         return $this->hasRole('ROLE_EMPLOYEE_EDIT');
  153.     }
  154.     public function setPrescriberViewRights(bool $prescriberViewRights): self
  155.     {
  156.         return $this->setRoleRights('ROLE_PRESCRIBER_VIEW'$prescriberViewRights);
  157.     }
  158.     public function hasPrescriberViewRights(): bool
  159.     {
  160.         return $this->hasRole('ROLE_PRESCRIBER_VIEW');
  161.     }
  162.     public function setPrescriberEditRights(bool $prescriberEditRights): self
  163.     {
  164.         return $this->setRoleRights('ROLE_PRESCRIBER_EDIT'$prescriberEditRights);
  165.     }
  166.     public function hasPrescriberEditRights(): bool
  167.     {
  168.         return $this->hasRole('ROLE_PRESCRIBER_EDIT');
  169.     }
  170.     public function setPrescriberValidationRights(bool $prescriberValidationRights): self
  171.     {
  172.         return $this->setRoleRights('ROLE_PRESCRIBER_VALIDATION'$prescriberValidationRights);
  173.     }
  174.     public function hasPrescriberValidationRights(): bool
  175.     {
  176.         return $this->hasRole('ROLE_PRESCRIBER_VALIDATION');
  177.     }
  178.     public function setVisitReportRights(bool $visitReportRights): self
  179.     {
  180.         return $this->setRoleRights('ROLE_VISIT_REPORT'$visitReportRights);
  181.     }
  182.     public function hasVisitReportRights(): bool
  183.     {
  184.         return $this->hasRole('ROLE_VISIT_REPORT');
  185.     }
  186.     public function setBookingEventRights(bool $BookingEventRights): self
  187.     {
  188.         return $this->setRoleRights('ROLE_BOOKING_EVENT'$BookingEventRights);
  189.     }
  190.     public function hasBookingEventRights(): bool
  191.     {
  192.         return $this->hasRole('ROLE_BOOKING_EVENT');
  193.     }
  194.     public function setPointsModificationRights(bool $pointsModificationRights): self
  195.     {
  196.         return $this->setRoleRights('ROLE_POINTS_MODIFICATION'$pointsModificationRights);
  197.     }
  198.     public function hasPointsModificationRights(): bool
  199.     {
  200.         return $this->hasRole('ROLE_POINTS_MODIFICATION');
  201.     }
  202.     public function setExportsRights(bool $exportsRights): self
  203.     {
  204.         return $this->setRoleRights('ROLE_EXPORTS'$exportsRights);
  205.     }
  206.     public function hasExportsRights(): bool
  207.     {
  208.         return $this->hasRole('ROLE_EXPORTS');
  209.     }
  210.     private function setRoleRights(string $rolebool $hasRights): self
  211.     {
  212.         if ($hasRights) {
  213.             if (!in_array($role$this->rolestrue)) {
  214.                 $this->roles[] = $role;
  215.             }
  216.         } else {
  217.             $this->roles array_diff($this->roles, [$role]);
  218.         }
  219.         return $this;
  220.     }
  221.     public function getRoles(): array
  222.     {
  223.         $roles parent::getRoles();
  224.         foreach (self::$rolesList as $role) {
  225.             if ($this->hasRole($role)) {
  226.                 $roles[] = $role;
  227.             }
  228.         }
  229.         return array_unique($roles);
  230.     }
  231.     public function setRoles(array $roles): self
  232.     {
  233.         $this->roles = ['ROLE_EMPLOYEE'];
  234.         foreach ($roles as $role) {
  235.             if (in_array($roleself::$rolesListtrue)) {
  236.                 $this->roles[] = $role;
  237.             }
  238.         }
  239.         return $this;
  240.     }
  241.     public function hasRole(string $role): bool
  242.     {
  243.         return in_array($role$this->rolestrue);
  244.     }
  245.     public function __toString(): string
  246.     {
  247.         return $this->getUserIdentifier();
  248.     }
  249.     public function getId(): ?int
  250.     {
  251.         return $this->id;
  252.     }
  253.     public function getLastname(): ?string
  254.     {
  255.         return $this->lastname;
  256.     }
  257.     public function setLastname(?string $lastname): static
  258.     {
  259.         $this->lastname $lastname;
  260.         return $this;
  261.     }
  262.     public function getFirstname(): ?string
  263.     {
  264.         return $this->firstname;
  265.     }
  266.     public function setFirstname(string $firstname): static
  267.     {
  268.         $this->firstname $firstname;
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return Collection<int, BookingEvent>
  273.      */
  274.     public function getBookingEventsAllowed(): Collection
  275.     {
  276.         return $this->bookingEventsAllowed;
  277.     }
  278.     public function addBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
  279.     {
  280.         if (!$this->bookingEventsAllowed->contains($bookingEventsAllowed)) {
  281.             $this->bookingEventsAllowed->add($bookingEventsAllowed);
  282.             $bookingEventsAllowed->addAllowedEmployee($this);
  283.         }
  284.         return $this;
  285.     }
  286.     public function removeBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
  287.     {
  288.         if ($this->bookingEventsAllowed->removeElement($bookingEventsAllowed)) {
  289.             $bookingEventsAllowed->removeAllowedEmployee($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function isIsDisplayedInForms(): ?bool
  294.     {
  295.         return $this->isDisplayedInForms;
  296.     }
  297.     public function setIsDisplayedInForms(?bool $isDisplayedInForms): static
  298.     {
  299.         $this->isDisplayedInForms $isDisplayedInForms;
  300.         return $this;
  301.     }
  302. }