src/Entity/Commercial.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommercialRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JetBrains\PhpStorm\Pure;
  9. #[ORM\Entity(repositoryClassCommercialRepository::class)]
  10. class Commercial extends User
  11. {
  12.     use IdentifiableTrait;
  13.     private static array $rolesList = [
  14.         'ROLE_VISIT_REPORT',
  15.         'ROLE_BOOKING_EVENT',
  16.     ];
  17.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  18.     private ?\DateTimeInterface $activityStartDate null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $firstname null;
  21.     #[ORM\Column(length255)]
  22.     private ?string $lastname null;
  23.     #[ORM\Column(length255)]
  24.     private ?string $address null;
  25.     #[ORM\Column(length255nullabletrue)]
  26.     private ?string $address2 null;
  27.     #[ORM\Column(length255)]
  28.     private ?string $postalCode null;
  29.     #[ORM\Column(length255)]
  30.     private ?string $city null;
  31.     #[ORM\Column(length255)]
  32.     private ?string $phone null;
  33.     #[ORM\Column(length255)]
  34.     private ?string $code null;
  35.     #[ORM\OneToMany(mappedBy'commercial'targetEntityPrescriber::class)]
  36.     private Collection $prescribers;
  37.     #[ORM\OneToMany(mappedBy'commercial'targetEntityInvoice::class)]
  38.     private Collection $invoices;
  39.     #[ORM\ManyToOne(inversedBy'commercials')]
  40.     #[ORM\JoinColumn(nullabletrue)]
  41.     private ?Country $country null;
  42.     #[ORM\ManyToMany(targetEntityCommercialSaleZone::class, inversedBy'commercials')]
  43.     private Collection $saleZones;
  44.     #[ORM\Column(nullabletrue)]
  45.     private ?\DateTimeImmutable $created_at null;
  46.     #[ORM\Column(nullabletrue)]
  47.     private ?\DateTimeImmutable $updated_at null;
  48.     #[ORM\Column(nullabletrue)]
  49.     private ?bool $archived null;
  50.     #[ORM\OneToMany(mappedBy'visitedBy'targetEntityVisitReport::class, orphanRemovaltrue)]
  51.     private Collection $visitReports;
  52.     #[ORM\ManyToOne(inversedBy'commercials')]
  53.     private ?BillingCenter $mainBillingCenter null;
  54.     #[ORM\ManyToMany(targetEntityBookingEvent::class, mappedBy'referents')]
  55.     private Collection $referentsBookingEvents;
  56.     #[ORM\ManyToMany(targetEntityBookingEvent::class, mappedBy'commercialSpeakers')]
  57.     private Collection $commercialSpeakersBookingEvents;
  58.     #[ORM\ManyToMany(targetEntityBookingEvent::class, mappedBy'allowedCommercials')]
  59.     private Collection $bookingEventsAllowed;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?bool $isDisplayedInForms null;
  62.     public function __construct()
  63.     {
  64.         parent::__construct();
  65.         $this->invoices      = new ArrayCollection();
  66.         $this->saleZones     = new ArrayCollection();
  67.         $this->visitReports  = new ArrayCollection();
  68.         $this->referentsBookingEvents = new ArrayCollection();
  69.         $this->commercialSpeakersBookingEvents = new ArrayCollection();
  70.         $this->bookingEventsAllowed = new ArrayCollection();
  71.     }
  72.     public function __toString(): string
  73.     {
  74.         return $this->getFullName();
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getActivityStartDate(): ?\DateTimeInterface
  81.     {
  82.         return $this->activityStartDate;
  83.     }
  84.     public function setActivityStartDate(\DateTimeInterface $activityStartDate): self
  85.     {
  86.         $this->activityStartDate $activityStartDate;
  87.         return $this;
  88.     }
  89.     public function getFirstname(): ?string
  90.     {
  91.         return $this->firstname;
  92.     }
  93.     public function setFirstname(string $firstname): self
  94.     {
  95.         $this->firstname $firstname;
  96.         return $this;
  97.     }
  98.     public function getLastname(): ?string
  99.     {
  100.         return $this->lastname;
  101.     }
  102.     public function setLastname(string $lastname): self
  103.     {
  104.         $this->lastname $lastname;
  105.         return $this;
  106.     }
  107.     public function getFullName(): ?string
  108.     {
  109.         return $this->getLastname() . " " $this->getFirstname();
  110.     }
  111.     public function getAddress(): ?string
  112.     {
  113.         return $this->address;
  114.     }
  115.     public function setAddress(string $address): self
  116.     {
  117.         $this->address $address;
  118.         return $this;
  119.     }
  120.     public function getAddress2(): ?string
  121.     {
  122.         return $this->address2;
  123.     }
  124.     public function setAddress2(?string $address2): self
  125.     {
  126.         $this->address2 $address2;
  127.         return $this;
  128.     }
  129.     public function getPostalCode(): ?string
  130.     {
  131.         return $this->postalCode;
  132.     }
  133.     public function setPostalCode(string $postalCode): self
  134.     {
  135.         $this->postalCode $postalCode;
  136.         return $this;
  137.     }
  138.     public function getCity(): ?string
  139.     {
  140.         return $this->city;
  141.     }
  142.     public function setCity(string $city): self
  143.     {
  144.         $this->city $city;
  145.         return $this;
  146.     }
  147.     public function getPhone(): ?string
  148.     {
  149.         return $this->phone;
  150.     }
  151.     public function setPhone(string $phone): self
  152.     {
  153.         $this->phone $phone;
  154.         return $this;
  155.     }
  156.     public function getCode(): ?string
  157.     {
  158.         return $this->code;
  159.     }
  160.     public function setCode(string $code): self
  161.     {
  162.         $this->code $code;
  163.         return $this;
  164.     }
  165.     /**
  166.      * @return Collection<int, Prescriber>
  167.      */
  168.     public function getPrescribers(): Collection
  169.     {
  170.         return $this->prescribers;
  171.     }
  172.     public function addPrescriber(Prescriber $prescriber): self
  173.     {
  174.         if (!$this->prescribers->contains($prescriber)) {
  175.             $this->prescribers->add($prescriber);
  176.             $prescriber->setCommercial($this);
  177.         }
  178.         return $this;
  179.     }
  180.     public function removePrescriber(Prescriber $prescriber): self
  181.     {
  182.         if ($this->prescribers->removeElement($prescriber)) {
  183.             // set the owning side to null (unless already changed)
  184.             if ($prescriber->getCommercial() === $this) {
  185.                 $prescriber->setCommercial(null);
  186.             }
  187.         }
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection<int, Invoice>
  192.      */
  193.     public function getInvoices(): Collection
  194.     {
  195.         return $this->invoices;
  196.     }
  197.     public function addInvoice(Invoice $invoice): self
  198.     {
  199.         if (!$this->invoices->contains($invoice)) {
  200.             $this->invoices->add($invoice);
  201.             $invoice->setCommercial($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeInvoice(Invoice $invoice): self
  206.     {
  207.         if ($this->invoices->removeElement($invoice)) {
  208.             // set the owning side to null (unless already changed)
  209.             if ($invoice->getCommercial() === $this) {
  210.                 $invoice->setCommercial(null);
  211.             }
  212.         }
  213.         return $this;
  214.     }
  215.     public function getCountry(): ?Country
  216.     {
  217.         return $this->country;
  218.     }
  219.     public function setCountry(?Country $country): self
  220.     {
  221.         $this->country $country;
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return Collection<int, CommercialSaleZone>
  226.      */
  227.     public function getSaleZones(): Collection
  228.     {
  229.         return $this->saleZones;
  230.     }
  231.     public function addSaleZone(CommercialSaleZone $saleZone): self
  232.     {
  233.         if (!$this->saleZones->contains($saleZone)) {
  234.             $this->saleZones->add($saleZone);
  235.         }
  236.         return $this;
  237.     }
  238.     public function removeSaleZone(CommercialSaleZone $saleZone): self
  239.     {
  240.         $this->saleZones->removeElement($saleZone);
  241.         return $this;
  242.     }
  243.     public function getCreatedAt(): ?\DateTimeImmutable
  244.     {
  245.         return $this->created_at;
  246.     }
  247.     public function setCreatedAt(?\DateTimeImmutable $created_at): self
  248.     {
  249.         $this->created_at $created_at;
  250.         return $this;
  251.     }
  252.     public function getUpdatedAt(): ?\DateTimeImmutable
  253.     {
  254.         return $this->updated_at;
  255.     }
  256.     public function setUpdatedAt(?\DateTimeImmutable $updated_at): self
  257.     {
  258.         $this->updated_at $updated_at;
  259.         return $this;
  260.     }
  261.     public function isArchived(): ?bool
  262.     {
  263.         return $this->archived;
  264.     }
  265.     public function setArchived(?bool $archived): static
  266.     {
  267.         $this->archived $archived;
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return Collection<int, VisitReport>
  272.      */
  273.     public function getVisitReports(): Collection
  274.     {
  275.         return $this->visitReports;
  276.     }
  277.     public function addVisitReport(VisitReport $visitReport): static
  278.     {
  279.         if (!$this->visitReports->contains($visitReport)) {
  280.             $this->visitReports->add($visitReport);
  281.             $visitReport->setVisitedBy($this);
  282.         }
  283.         return $this;
  284.     }
  285.     public function removeVisitReport(VisitReport $visitReport): static
  286.     {
  287.         if ($this->visitReports->removeElement($visitReport)) {
  288.             // set the owning side to null (unless already changed)
  289.             if ($visitReport->getVisitedBy() === $this) {
  290.                 $visitReport->setVisitedBy(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     public function getMainBillingCenter(): ?BillingCenter
  296.     {
  297.         return $this->mainBillingCenter;
  298.     }
  299.     public function setMainBillingCenter(?BillingCenter $mainBillingCenter): static
  300.     {
  301.         $this->mainBillingCenter $mainBillingCenter;
  302.         return $this;
  303.     }
  304.     public function setVisitReportRights(bool $visitReportRights): self
  305.     {
  306.         return $this->setRoleRights('ROLE_VISIT_REPORT'$visitReportRights);
  307.     }
  308.     public function hasVisitReportRights(): bool
  309.     {
  310.         return $this->hasRole('ROLE_VISIT_REPORT');
  311.     }
  312.     public function setBookingEventRights(bool $BookingEventRights): self
  313.     {
  314.         return $this->setRoleRights('ROLE_BOOKING_EVENT'$BookingEventRights);
  315.     }
  316.     public function hasBookingEventRights(): bool
  317.     {
  318.         return $this->hasRole('ROLE_BOOKING_EVENT');
  319.     }
  320.     private function setRoleRights(string $rolebool $hasRights): self
  321.     {
  322.         if ($hasRights) {
  323.             if (!in_array($role$this->rolestrue)) {
  324.                 $this->roles[] = $role;
  325.             }
  326.         } else {
  327.             $this->roles array_diff($this->roles, [$role]);
  328.         }
  329.         return $this;
  330.     }
  331.     public function getRoles(): array
  332.     {
  333.         $roles parent::getRoles();
  334.         foreach (self::$rolesList as $role) {
  335.             if ($this->hasRole($role)) {
  336.                 $roles[] = $role;
  337.             }
  338.         }
  339.         return array_unique($roles);
  340.     }
  341.     /**
  342.      * @return Collection<int, BookingEvent>
  343.      */
  344.     public function getPrescriberSpeakersBookingEvents(): Collection
  345.     {
  346.         return $this->referentsBookingEvents;
  347.     }
  348.     public function addBookingEvent(BookingEvent $referentsBookingEvents): static
  349.     {
  350.         if (!$this->referentsBookingEvents->contains($referentsBookingEvents)) {
  351.             $this->referentsBookingEvents->add($referentsBookingEvents);
  352.             $referentsBookingEvents->addCommercial($this); // Assurez-vous que cette opération ne crée pas une boucle infinie
  353.         }
  354.         return $this;
  355.     }
  356.     public function removeBookingEvent(BookingEvent $referentsBookingEvents): static
  357.     {
  358.         if ($this->referentsBookingEvents->removeElement($referentsBookingEvents)) {
  359.             $referentsBookingEvents->removeCommercial($this); // Assurez-vous que cette opération ne crée pas une boucle infinie
  360.         }
  361.         return $this;
  362.     }
  363.     /**
  364.      * @return Collection<int, BookingEvent>
  365.      */
  366.     public function getCommercialSpeakersBookingEvents(): Collection
  367.     {
  368.         return $this->commercialSpeakersBookingEvents;
  369.     }
  370.     public function addCommercialSpeakersBookingEvent(BookingEvent $commercialSpeakersBookingEvent): static
  371.     {
  372.         if (!$this->commercialSpeakersBookingEvents->contains($commercialSpeakersBookingEvent)) {
  373.             $this->commercialSpeakersBookingEvents->add($commercialSpeakersBookingEvent);
  374.             $commercialSpeakersBookingEvent->addCommercialSpeaker($this);
  375.         }
  376.         return $this;
  377.     }
  378.     public function removeCommercialSpeakersBookingEvent(BookingEvent $commercialSpeakersBookingEvent): static
  379.     {
  380.         if ($this->commercialSpeakersBookingEvents->removeElement($commercialSpeakersBookingEvent)) {
  381.             $commercialSpeakersBookingEvent->removeCommercialSpeaker($this);
  382.         }
  383.         return $this;
  384.     }
  385.     /**
  386.      * @return Collection<int, BookingEvent>
  387.      */
  388.     public function getBookingEventsAllowed(): Collection
  389.     {
  390.         return $this->bookingEventsAllowed;
  391.     }
  392.     public function addBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
  393.     {
  394.         if (!$this->bookingEventsAllowed->contains($bookingEventsAllowed)) {
  395.             $this->bookingEventsAllowed->add($bookingEventsAllowed);
  396.             $bookingEventsAllowed->addAllowedCommercial($this);
  397.         }
  398.         return $this;
  399.     }
  400.     public function removeBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
  401.     {
  402.         if ($this->bookingEventsAllowed->removeElement($bookingEventsAllowed)) {
  403.             $bookingEventsAllowed->removeAllowedCommercial($this);
  404.         }
  405.         return $this;
  406.     }
  407.     public function isIsDisplayedInForms(): ?bool
  408.     {
  409.         return $this->isDisplayedInForms;
  410.     }
  411.     public function setIsDisplayedInForms(?bool $isDisplayedInForms): static
  412.     {
  413.         $this->isDisplayedInForms $isDisplayedInForms;
  414.         return $this;
  415.     }
  416. }