src/Entity/Employees/Employee.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Employees;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use App\Entity\Departments;
  6. use App\Entity\Location;
  7. use App\Entity\Positions\Position;
  8. use App\Entity\User;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. /**
  15.  * Employees.
  16.  *
  17.  * @ApiResource(
  18.  *     collectionOperations={
  19.  *          "get", "post"
  20.  *     },
  21.  *     itemOperations={
  22.  *          "get", "patch", "delete"
  23.  *     },
  24.  *     normalizationContext={"groups"={"employee:read"}},
  25.  *     denormalizationContext={"groups"={"employee:write"}},
  26.  *     forceEager=false,
  27.  * )
  28.  * @ORM\Entity
  29.  * @Vich\Uploadable
  30.  */
  31. class Employee extends User
  32. {
  33.     /**
  34.      * @ApiSubresource()
  35.      * @ORM\OneToMany(targetEntity="App\Entity\Employees\EmployeePosition", mappedBy="employee", orphanRemoval=true)
  36.      */
  37.     #[Groups(['employee:read''employee:write'])]
  38.     private $employeePositions;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity="App\Entity\Employees\EmployeeEmploymentDate",mappedBy="employee", orphanRemoval=true)
  41.      */
  42.     #[Groups(['employee:write''employee:read'])]
  43.     private $employeeEmploymentDates;
  44.     /**
  45.      * @ORM\Column(type="string", length=20, nullable=true)
  46.      */
  47.     #[Groups(['employee:read''employee:write'])]
  48.     private $gender;
  49.     /**
  50.      * @ORM\Column(type="string", length=255, nullable=true)
  51.      */
  52.     #[Groups(['employee:read''employee:write'])]
  53.     private $education;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      */
  57.     #[Groups(['employee:read''employee:write'])]
  58.     private $manager;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=Location::class, inversedBy="employees")
  61.      */
  62.     #[Groups(['employee:read''employee:write'])]
  63.     private $location;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=Departments::class, inversedBy="employees", fetch="EAGER")
  66.      */
  67.     #[Groups(['employee:read''employee:write'])]
  68.     private $department;
  69.     /**
  70.      * @ORM\Column(type="boolean", options={"default":"0"})
  71.      */
  72.     private $active;
  73.     /** @var string */
  74.     private $currentPosition;
  75.     /** @var \DateTime */
  76.     private $startDate;
  77.     public function __construct()
  78.     {
  79.         $this->employeePositions = new ArrayCollection();
  80.         $this->employeeEmploymentDates = new ArrayCollection();
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->getDisplayName();
  85.     }
  86.     /**
  87.      * @return Collection|EmployeePosition[]
  88.      */
  89.     public function getEmployeePositions(): Collection
  90.     {
  91.         return $this->employeePositions;
  92.     }
  93.     public function addEmployeePositions(EmployeePosition $employeePosition): self
  94.     {
  95.         if (!$this->employeePositions->contains($employeePosition)) {
  96.             $this->employeePositions[] = $employeePosition;
  97.             $employeePosition->setEmployee($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removeEmployeePosition(EmployeePosition $employeePosition): self
  102.     {
  103.         if ($this->employeePositions->contains($employeePosition)) {
  104.             $this->employeePositions->removeElement($employeePosition);
  105.             // set the owning side to null (unless already changed)
  106.             if ($employeePosition->getEmployee() === $this) {
  107.                 $employeePosition->setEmployee(null);
  108.             }
  109.         }
  110.         return $this;
  111.     }
  112.     public function getEmployeeEmploymentDates(): Collection
  113.     {
  114.         return $this->employeeEmploymentDates;
  115.     }
  116.     public function addEmployeeEmploymentDates(EmployeeEmploymentDate $employeeEmploymentDate): self
  117.     {
  118.         if (!$this->employeeEmploymentDates->contains($employeeEmploymentDate)) {
  119.             $this->employeeEmploymentDates[] = $employeeEmploymentDate;
  120.             $employeeEmploymentDate->setEmployee($this);
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeEmployeeEmploymentDate(EmployeeEmploymentDate $employeeEmploymentDate): self
  125.     {
  126.         if ($this->employeeEmploymentDates->contains($employeeEmploymentDate)) {
  127.             $this->employeeEmploymentDates->removeElement($employeeEmploymentDate);
  128.             // set the owning side to null (unless already changed)
  129.             if ($employeeEmploymentDate->getEmployee() === $this) {
  130.                 $employeeEmploymentDate->setEmployee(null);
  131.             }
  132.         }
  133.         return $this;
  134.     }
  135.     public function __toString()
  136.     {
  137.         return $this->getId()->toString();
  138.     }
  139.     public function getGender(): ?string
  140.     {
  141.         return $this->gender;
  142.     }
  143.     public function setGender(?string $gender): self
  144.     {
  145.         $this->gender $gender;
  146.         return $this;
  147.     }
  148.     public function getEducation(): ?string
  149.     {
  150.         return $this->education;
  151.     }
  152.     public function setEducation(?string $education): self
  153.     {
  154.         $this->education $education;
  155.         return $this;
  156.     }
  157.     public function getManager(): ?string
  158.     {
  159.         return $this->manager;
  160.     }
  161.     public function setManager(?string $manager): self
  162.     {
  163.         $this->manager $manager;
  164.         return $this;
  165.     }
  166.     public function getLocation(): ?Location
  167.     {
  168.         return $this->location;
  169.     }
  170.     public function setLocation(?Location $location): self
  171.     {
  172.         $this->location $location;
  173.         return $this;
  174.     }
  175.     public function getDepartment(): ?Departments
  176.     {
  177.         return $this->department;
  178.     }
  179.     public function setDepartment(?Departments $department): self
  180.     {
  181.         $this->department $department;
  182.         return $this;
  183.     }
  184.     public function getCurrentPositionTitle()
  185.     {
  186.         if (count($this->employeePositions)) {
  187.             return $this->employeePositions[0]->getPosition()->getName();
  188.         }
  189.     }
  190.     public function getActive(): ?bool
  191.     {
  192.         return $this->active;
  193.     }
  194.     public function setActive(bool $active): self
  195.     {
  196.         $this->active $active;
  197.         return $this;
  198.     }
  199.     public function getStartDate(): \DateTime
  200.     {
  201.         return $this->startDate;
  202.     }
  203.     /**
  204.      * @param \DateTime $startDate
  205.      * @return Employee
  206.      */
  207.     public function setStartDate(\DateTime $startDate)
  208.     {
  209.         $this->startDate $startDate;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return string|null
  214.      */
  215.     public function getCurrentPosition(): ?string
  216.     {
  217.         return $this->currentPosition;
  218.     }
  219.     /**
  220.      * @param string $currentPosition     *
  221.      * @return Employee
  222.      */
  223.     public function setCurrentPosition(string $currentPosition): self
  224.     {
  225.         $this->currentPosition $currentPosition;
  226.         return $this;
  227.     }
  228.     public function getRoles(): array
  229.     {
  230.         return array_unique(array_merge(parent::getRoles(), ['ROLE_EMPLOYEE']));;
  231.     }
  232.     public function getEntityType(): string
  233.     {
  234.         return 'employee';
  235.     }
  236. }