HegreLand/src/Entity/Employee.php

275 lines
6.5 KiB
PHP

<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Repository\EmployeeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: EmployeeRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
class Employee implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180)]
private ?string $email = null;
#[ORM\Column(length: 30)]
private ?string $firstName = null;
#[ORM\Column(length: 30)]
private ?string $lastName = null;
#[ORM\Column]
private ?string $password = null;
#[ORM\Column]
private array $roles = [];
#[ORM\OneToMany(targetEntity: EmployeeSkill::class, mappedBy: 'employee')]
private Collection $employeeSkills;
//Changer en ManyToMany et pareil dans mission
#[ORM\ManyToOne(targetEntity: Mission::class, inversedBy: 'employee')]
private Collection $missions;
//Changer en OneToMany et inversement dans incident
#[ORM\ManyToOne(targetEntity: Incident::class, inversedBy: 'employee')]
private Collection $incidents;
#[ORM\OneToMany(targetEntity: Assignment::class, mappedBy: 'employee')]
private Collection $assignments;
#[ORM\OneToMany(targetEntity: Representation::class, mappedBy: 'employee')]
private Collection $representations;
public function __construct()
{
$this->assignments = new ArrayCollection();
$this->representations = new ArrayCollection();
$this->employeeSkills = new ArrayCollection();
}
public function getEmployeeSkills(): Collection
{
return $this->employeeSkills;
}
public function addEmployeeSkill(EmployeeSkill $employeeSkill): static
{
if(!$this->employeeSkills->contains($employeeSkill)) {
$this->employeeSkills->add($employeeSkill);
$employeeSkill->setEmployee($this);
}
return $this;
}
public function removeEmployeeSkill(EmployeeSkill $employeeSkill): static
{
if($this->employeeSkills->removeElement($employeeSkill)) {
if($employeeSkill->getEmployee() === $this) {
$employeeSkill->setEmployee(null);
}
}
return $this;
}
// public function getEmployeeMissions(): Collection
// {
// return $this->employeeMissions;
// }
//
// public function setEmployeeMissions(Collection $employeeMissions): void
// {
// $this->employeeMissions = $employeeMissions;
// }
// public function getEmployeeIncidents(): Collection
// {
// return $this->employeeIncidents;
// }
//
// public function setEmployeeIncidents(Collection $employeeIncidents): void
// {
// $this->employeeIncidents = $employeeIncidents;
// }
public function getAssignments(): Collection
{
return $this->assignments;
}
public function addAssigment(Assignment $assignment): static
{
if(!$this->assignments->contains($assignment)) {
$this->assignments->add($assignment);
$assignment->setEmployee($this);
}
return $this;
}
public function removeAssigment(Assignment $assignment): static
{
if($this->assignments->removeElement($assignment)) {
if($assignment->getEmployee() === $this) {
$assignment->setEmployee(null);
}
}
return $this;
}
public function getRepresentations(): Collection
{
return $this->representations;
}
public function addRepresentation(Representation $representation): static
{
if(!$this->representations->contains($representation)) {
$this->representations->add($representation);
$representation->setEmployee($this);
}
return $this;
}
public function removeRepresentation(Representation $representation): static
{
if($this->representations->removeElement($representation)) {
if($representation->getEmployee() === $this) {
$representation->setEmployee(null);
}
}
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): static
{
$this->id = $id;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): static
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getUserIdentifier(): string
{
return (string) $this->email;
}
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
public function getMissions(): ?Collection
{
return $this->missions;
}
public function setMissions(Collection $missions): void
{
$this->missions = $missions;
}
public function getIncidents(): ?Collection
{
return $this->incidents;
}
public function setIncidents(Collection $incidents): void
{
$this->incidents = $incidents;
}
public function __toString(): string
{
return $this->firstName . ' ' . $this->lastName;
}
}