<?php
namespace App\Entity\Employees;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use App\Entity\Departments;
use App\Entity\Location;
use App\Entity\Positions\Position;
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Employees.
*
* @ApiResource(
* collectionOperations={
* "get", "post"
* },
* itemOperations={
* "get", "patch", "delete"
* },
* normalizationContext={"groups"={"employee:read"}},
* denormalizationContext={"groups"={"employee:write"}},
* forceEager=false,
* )
* @ORM\Entity
* @Vich\Uploadable
*/
class Employee extends User
{
/**
* @ApiSubresource()
* @ORM\OneToMany(targetEntity="App\Entity\Employees\EmployeePosition", mappedBy="employee", orphanRemoval=true)
*/
#[Groups(['employee:read', 'employee:write'])]
private $employeePositions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Employees\EmployeeEmploymentDate",mappedBy="employee", orphanRemoval=true)
*/
#[Groups(['employee:write', 'employee:read'])]
private $employeeEmploymentDates;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
#[Groups(['employee:read', 'employee:write'])]
private $gender;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
#[Groups(['employee:read', 'employee:write'])]
private $education;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
#[Groups(['employee:read', 'employee:write'])]
private $manager;
/**
* @ORM\ManyToOne(targetEntity=Location::class, inversedBy="employees")
*/
#[Groups(['employee:read', 'employee:write'])]
private $location;
/**
* @ORM\ManyToOne(targetEntity=Departments::class, inversedBy="employees", fetch="EAGER")
*/
#[Groups(['employee:read', 'employee:write'])]
private $department;
/**
* @ORM\Column(type="boolean", options={"default":"0"})
*/
private $active;
/** @var string */
private $currentPosition;
/** @var \DateTime */
private $startDate;
public function __construct()
{
$this->employeePositions = new ArrayCollection();
$this->employeeEmploymentDates = new ArrayCollection();
}
public function getName(): ?string
{
return $this->getDisplayName();
}
/**
* @return Collection|EmployeePosition[]
*/
public function getEmployeePositions(): Collection
{
return $this->employeePositions;
}
public function addEmployeePositions(EmployeePosition $employeePosition): self
{
if (!$this->employeePositions->contains($employeePosition)) {
$this->employeePositions[] = $employeePosition;
$employeePosition->setEmployee($this);
}
return $this;
}
public function removeEmployeePosition(EmployeePosition $employeePosition): self
{
if ($this->employeePositions->contains($employeePosition)) {
$this->employeePositions->removeElement($employeePosition);
// set the owning side to null (unless already changed)
if ($employeePosition->getEmployee() === $this) {
$employeePosition->setEmployee(null);
}
}
return $this;
}
public function getEmployeeEmploymentDates(): Collection
{
return $this->employeeEmploymentDates;
}
public function addEmployeeEmploymentDates(EmployeeEmploymentDate $employeeEmploymentDate): self
{
if (!$this->employeeEmploymentDates->contains($employeeEmploymentDate)) {
$this->employeeEmploymentDates[] = $employeeEmploymentDate;
$employeeEmploymentDate->setEmployee($this);
}
return $this;
}
public function removeEmployeeEmploymentDate(EmployeeEmploymentDate $employeeEmploymentDate): self
{
if ($this->employeeEmploymentDates->contains($employeeEmploymentDate)) {
$this->employeeEmploymentDates->removeElement($employeeEmploymentDate);
// set the owning side to null (unless already changed)
if ($employeeEmploymentDate->getEmployee() === $this) {
$employeeEmploymentDate->setEmployee(null);
}
}
return $this;
}
public function __toString()
{
return $this->getId()->toString();
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getEducation(): ?string
{
return $this->education;
}
public function setEducation(?string $education): self
{
$this->education = $education;
return $this;
}
public function getManager(): ?string
{
return $this->manager;
}
public function setManager(?string $manager): self
{
$this->manager = $manager;
return $this;
}
public function getLocation(): ?Location
{
return $this->location;
}
public function setLocation(?Location $location): self
{
$this->location = $location;
return $this;
}
public function getDepartment(): ?Departments
{
return $this->department;
}
public function setDepartment(?Departments $department): self
{
$this->department = $department;
return $this;
}
public function getCurrentPositionTitle()
{
if (count($this->employeePositions)) {
return $this->employeePositions[0]->getPosition()->getName();
}
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getStartDate(): \DateTime
{
return $this->startDate;
}
/**
* @param \DateTime $startDate
* @return Employee
*/
public function setStartDate(\DateTime $startDate)
{
$this->startDate = $startDate;
return $this;
}
/**
* @return string|null
*/
public function getCurrentPosition(): ?string
{
return $this->currentPosition;
}
/**
* @param string $currentPosition *
* @return Employee
*/
public function setCurrentPosition(string $currentPosition): self
{
$this->currentPosition = $currentPosition;
return $this;
}
public function getRoles(): array
{
return array_unique(array_merge(parent::getRoles(), ['ROLE_EMPLOYEE']));;
}
public function getEntityType(): string
{
return 'employee';
}
}