<?php
namespace App\Entity;
use App\Repository\WorkerInProjectRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use phpDocumentor\Reflection\Types\This;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints\Date;
/**
* @ORM\Entity(repositoryClass=WorkerInProjectRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class WorkerInProject
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "customer.joined.projects.assigned.team.leaders",
* "worker.manage.joined.projects",
* "worker.manage.selectable.stakeholder.projects",
* "worker.manage.selected.worker.in.project",
*
*
* "worker.in.project.base"
*
* })
*/
private $id;
/**
* /// TODO Remove this prop
* @deprecated
* over worker_activity
* @ORM\ManyToOne(targetEntity=Worker::class, inversedBy="workerInProjects")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @MaxDepth(2)
* "timesheet.for.stakeholder",
* "timesheet.for.customer"
* Groups({
* "customer.joined.projects.assigned.team.leaders",
* })
*/
private $worker;
/**
* Stakeholder Level
* Info: Assigned to Project Stakeholder -> StakeHolder assigned to Project
* @ORM\ManyToOne(targetEntity=ProjectStakeholders::class, inversedBy="workerInProjects")
* @ORM\JoinColumn(nullable=false, options={"comment": "Project StakeholderId"}, onDelete="CASCADE")
* @MaxDepth(2)
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selectable.stakeholder.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $project;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $start_at;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $end_at;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created_at;
/**
* ----------------------------------------------------------------------------------------------------------------
* This is custom column not associated to table
* Event Listener Prop
* This prop Update during event.listener
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selectable.stakeholder.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $status;
/**
* Event Listener Prop
* This prop Update during event.listener
* @param array $status
*/
public function setStatus( array $status ): void {
$this->status = $status;
}
/** * Event Listener Prop */
public function getStatus(){
return $this->status;
}
// ----------------------------------------------------------------------------------------------------------------
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $forcibly_completed;
/**
* @ORM\ManyToMany(targetEntity=Qualification::class, inversedBy="workerInProjects")
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $assigned_qualifications;
/**
* @ORM\Column(type="decimal", precision=7, scale=2, nullable=true)
* @Groups({"worker.manage.selected.worker.in.project", "worker.manage.joined.projects"})
*/
private $cost_per_hour;
/**
* @ORM\Column(type="boolean", nullable=true, options={"comment": "Worker for App Check-In/Out anywhere without coords just for joined project"})
* @Groups({"worker.manage.selected.worker.in.project"})
*/
private $can_app_check_anywhere;
/**
* @ORM\ManyToMany(targetEntity=ProjectBranches::class, inversedBy="workerInProjects")
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selected.worker.in.project",
* "customer.selected.project",
*
* "worker.in.project.assigned.project.branches"
* })
*/
private $assigned_project_branches;
/**
* If you change the name of table, this is a important risk for data, will lost all
* Before you replace the name of table should backup!!
* @ORM\ManyToMany(targetEntity=ProjectBranches::class, inversedBy="project_branch_team_leaders")
* ORM\JoinTable(name="worker_in_project_project_branches_team_leaders",
* joinColumns={@ORM\JoinColumn(name="worker_in_project_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="project_branch_id", referencedColumnName="id")}
* )
* @ORM\JoinTable(name="worker_in_project_project_branches_team_leaders")
* @Groups({
* "worker.manage.joined.projects",
* "worker.manage.selected.worker.in.project"
* })
*/
private $project_branches_team_leader;
/**
* @ORM\ManyToOne(targetEntity=WorkerActivities::class, inversedBy="worker_in_projects")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
* @MaxDepth(2)
* @Groups({
* "customer.joined.projects.assigned.team.leaders",
* "timesheet.for.stakeholder",
* "timesheet.for.customer",
* "customer.selected.project",
*
*
* "worker.in.project.worker.activity"
* })
*/
private $worker_activity;
public function __construct()
{
$this->assigned_qualifications = new ArrayCollection();
$this->assigned_project_branches = new ArrayCollection();
$this->project_branches_team_leader = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**@deprecated
* Fetch over WorkerActivity*/
public function getWorker(): ?Worker
{
return $this->worker;
}
/**@deprecated
* Fetch over WorkerActivity*/
public function setWorker(?Worker $worker): self
{
$this->worker = $worker;
return $this;
}
public function getProject(): ?ProjectStakeholders
{
return $this->project;
}
public function setProject(?ProjectStakeholders $project): self
{
$this->project = $project;
return $this;
}
public function getStartAt(): ?\DateTimeImmutable
{
return $this->start_at;
}
public function setStartAt(?\DateTimeImmutable $start_at): self
{
$this->start_at = $start_at;
return $this;
}
public function getEndAt(): ?\DateTimeImmutable
{
return $this->end_at;
}
public function setEndAt(?\DateTimeImmutable $end_at): self
{
$this->end_at = $end_at;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getCustomName(){
$this->customName = $this->getId();
}
public function getForciblyCompleted(): ?bool
{
return $this->forcibly_completed;
}
public function setForciblyCompleted(?bool $forcibly_completed): self
{
$this->forcibly_completed = $forcibly_completed;
return $this;
}
/**
* @return Collection<int, Qualification>
*/
public function getAssignedQualifications(): Collection
{
// use this
return new ArrayCollection( $this->assigned_qualifications->map( function ( /**@var $qualification Qualification*/ $qualification ){
return $qualification;
})->getValues() );
// Instead of this
// return $this->assigned_qualifications;
// Info: If Assigned Q empty selected return, error for required field, if select again any value collection returned as associative array instead indexed
}
public function addAssignedQualification(Qualification $assignedQualification): self
{
if (!$this->assigned_qualifications->contains($assignedQualification)) {
$this->assigned_qualifications[] = $assignedQualification;
}
return $this;
}
public function removeAssignedQualification(Qualification $assignedQualification): self
{
$this->assigned_qualifications->removeElement($assignedQualification);
return $this;
}
public function getCostPerHour(): ?float
{
return $this->cost_per_hour;// ?? $this->getWorker()->getCostPerHour();
}
public function setCostPerHour(?string $cost_per_hour): self
{
$this->cost_per_hour = $cost_per_hour;
return $this;
}
public function isCanAppCheckAnywhere(): ?bool
{
return $this->can_app_check_anywhere;
}
public function setCanAppCheckAnywhere(?bool $can_app_check_anywhere): self
{
$this->can_app_check_anywhere = $can_app_check_anywhere;
return $this;
}
/**
* @return Collection<int, ProjectBranches>
*/
public function getAssignedProjectBranches(): Collection
{
return $this->assigned_project_branches;
}
public function addAssignedProjectBranch(ProjectBranches $assignedProjectBranch): self
{
if (!$this->assigned_project_branches->contains($assignedProjectBranch)) {
$this->assigned_project_branches[] = $assignedProjectBranch;
}
return $this;
}
public function removeAssignedProjectBranch(ProjectBranches $assignedProjectBranch): self
{
$this->assigned_project_branches->removeElement($assignedProjectBranch);
return $this;
}
/**
* @return Collection<int, ProjectBranches>
*/
public function getProjectBranchesTeamLeader(): Collection
{
return $this->project_branches_team_leader;
}
public function addProjectBranchesTeamLeader(ProjectBranches $workerInProjectProjectBranchesTeamLeader): self
{
if (!$this->project_branches_team_leader->contains($workerInProjectProjectBranchesTeamLeader)) {
$this->project_branches_team_leader[] = $workerInProjectProjectBranchesTeamLeader;
}
return $this;
}
public function removeProjectBranchesTeamLeader(ProjectBranches $workerInProjectProjectBranchesTeamLeader): self
{
$this->project_branches_team_leader->removeElement($workerInProjectProjectBranchesTeamLeader);
return $this;
}
public function getWorkerActivity(): ?WorkerActivities
{
return $this->worker_activity;
}
public function setWorkerActivity(?WorkerActivities $workerActivity): self
{
$this->worker_activity = $workerActivity;
return $this;
}
}