<?php
namespace App\Entity;
use App\Repository\BranchesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=BranchesRepository::class)
* @ORM\Table(name="branches", uniqueConstraints={
* @UniqueConstraint(name="unique_branch_in_location", columns={"name", "branch_location_id"})
* })
* @UniqueEntity(
* fields={"name", "branch_location"},
* message="Branch already registered|Branch with combination (%s %s) is already registered"
* )
*/
class Branches
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "project.branches",
* "branches.base",
* "partner.selected.project",
* "worker.manage.joined.projects",
* "stakeholder.selected.core.project.manage",
* "worker.manage.selected.worker.in.project",
* "selected.partner.project.for.worker",
*
* "branch.base",
* "branch.core",
*
* "branch@core",
* "branch@base"
*
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({
* "project.branches",
* "branches.base",
* "partner.selected.project",
* "worker.manage.joined.projects",
* "stakeholder.selected.core.project.manage",
* "worker.manage.selected.worker.in.project",
* "selected.partner.project.for.worker",
* "worker.manage.base.timesheet.payments",
*
* "branch.base",
* "branch.core",
* "branch@core",
* "branch@base"
* })
*/
private $name;
/**
*
* ❌❌❌❌❌❌❌❌
* @deprecated use Connect to direct Project
* @ORM\OneToMany(targetEntity=ProjectBranches::class, mappedBy="branch")
*/
private $project_branches;
/**
* ✅✅✅✅✅✅✅✅
* @ORM\ManyToMany(targetEntity=Projects::class, mappedBy="branches")
*/
private $projects;
/**
* @ORM\ManyToOne(targetEntity=Locations::class, inversedBy="branches")
* @ORM\JoinColumn(nullable=false)
* @Groups({
* "project.branches",
* "branches.location.base",
* "partner.selected.project",
* "branch.location",
*
* "branch@location"
* })
*/
private $branch_location;
/**
* @ORM\OneToMany(targetEntity=ProjectOrders::class, mappedBy="order_branch")
*/
private $project_orders;
/**
* @ORM\OneToMany(targetEntity=BranchDepartments::class, mappedBy="branch", cascade={"persist", "remove"})
* @Groups({
* "branch.departments",
*
* "branch@departments"
* })
*/
private $branch_departments;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @Groups({
* "branch.core",
*
* "branch@core"
* })
*/
private $created_at;
/**
* @ORM\ManyToMany(targetEntity=WorkerInProject::class, mappedBy="branches")
* @Groups({
* "branch@worker_in_projects"
* })
*/
private $worker_in_projects;
/**
* @ORM\ManyToMany(targetEntity=WorkerInProject::class, mappedBy="project_branch_team_leader")
*/
private $worker_in_project_team_leader;
/**
* @ORM\OneToMany(targetEntity=ProjectOrderTaskFulfillment::class, mappedBy="branch")
*/
private $project_order_task_fulfillments;
public function __construct()
{
$this->project_branches = new ArrayCollection();
$this->project_orders = new ArrayCollection();
$this->branch_departments = new ArrayCollection();
$this->projects = new ArrayCollection();
$this->worker_in_projects = new ArrayCollection();
$this->worker_in_project_team_leader = new ArrayCollection();
$this->project_order_task_fulfillments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, ProjectBranches>
*/
public function getProjectBranches(): Collection
{
return $this->project_branches;
}
public function addProjectDependentBranch(ProjectBranches $projectDependentBranch): self
{
if (!$this->project_branches->contains($projectDependentBranch)) {
$this->project_branches[] = $projectDependentBranch;
$projectDependentBranch->setBranch($this);
}
return $this;
}
public function removeProjectDependentBranch(ProjectBranches $projectDependentBranch): self
{
if ($this->project_branches->removeElement($projectDependentBranch)) {
// set the owning side to null (unless already changed)
if ($projectDependentBranch->getBranch() === $this) {
$projectDependentBranch->setBranch(null);
}
}
return $this;
}
public function getBranchLocation(): ?Locations
{
return $this->branch_location;
}
public function setBranchLocation(?Locations $branch_location): self
{
$this->branch_location = $branch_location;
return $this;
}
/**
* @return Collection<int, ProjectOrders>
*/
public function getProjectOrders(): Collection
{
return $this->project_orders;
}
public function addProjectOrder(ProjectOrders $projectOrder): self
{
if (!$this->project_orders->contains($projectOrder)) {
$this->project_orders[] = $projectOrder;
$projectOrder->setOrderBranch($this);
}
return $this;
}
public function removeProjectOrder(ProjectOrders $projectOrder): self
{
if ($this->project_orders->removeElement($projectOrder)) {
// set the owning side to null (unless already changed)
if ($projectOrder->getOrderBranch() === $this) {
$projectOrder->setOrderBranch(null);
}
}
return $this;
}
/**
* @return Collection<int, BranchDepartments> & Selectable
*/
public function getBranchDepartments(): Collection
{
return $this->branch_departments;
}
public function addBranchDepartment(BranchDepartments $branchDepartment): self
{
if (!$this->branch_departments->contains($branchDepartment)) {
$this->branch_departments[] = $branchDepartment;
$branchDepartment->setBranch($this);
}
return $this;
}
public function removeBranchDepartment(BranchDepartments $branchDepartment): self
{
if ($this->branch_departments->removeElement($branchDepartment)) {
// set the owning side to null (unless already changed)
if ($branchDepartment->getBranch() === $this) {
$branchDepartment->setBranch(null);
}
}
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(?\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
/**
* @return Collection<int, Projects>
*/
public function getProjects(): Collection
{
return $this->projects;
}
public function addProject(Projects $project): self
{
if (!$this->projects->contains($project)) {
$this->projects[] = $project;
$project->addBranch($this);
}
return $this;
}
public function removeProject(Projects $project): self
{
if ($this->projects->removeElement($project)) {
$project->removeBranch($this);
}
return $this;
}
/**
* @return Collection<int, WorkerInProject>
*/
public function getWorkerInprojects(): Collection
{
return $this->worker_in_projects;
}
public function addWorkerInProject(WorkerInProject $workerInProject): self
{
if (!$this->worker_in_projects->contains($workerInProject)) {
$this->worker_in_projects[] = $workerInProject;
$workerInProject->addBranch($this);
}
return $this;
}
public function removeWorkerInProject(WorkerInProject $workerInProject): self
{
if ($this->worker_in_projects->removeElement($workerInProject)) {
$workerInProject->removeBranch($this);
}
return $this;
}
/**
* @return Collection<int, WorkerInProject>
*/
public function getWorkerInProjectTeamLeader(): Collection
{
return $this->worker_in_project_team_leader;
}
public function addWorkerInProjectTeamLeader(WorkerInProject $workerInProjectTeamLeader): self
{
if (!$this->worker_in_project_team_leader->contains($workerInProjectTeamLeader)) {
$this->worker_in_project_team_leader[] = $workerInProjectTeamLeader;
$workerInProjectTeamLeader->addProjectBranchTeamLeader($this);
}
return $this;
}
public function removeWorkerInProjectTeamLeader(WorkerInProject $workerInProjectTeamLeader): self
{
if ($this->worker_in_project_team_leader->removeElement($workerInProjectTeamLeader)) {
$workerInProjectTeamLeader->removeProjectBranchTeamLeader($this);
}
return $this;
}
/**
* @return Collection<int, ProjectOrderTaskFulfillment>
*/
public function getProjectOrderTaskFulfillments(): Collection
{
return $this->project_order_task_fulfillments;
}
public function addProjectOrderTaskFulfillment(ProjectOrderTaskFulfillment $projectOrderTaskFulfillment): self
{
if (!$this->project_order_task_fulfillments->contains($projectOrderTaskFulfillment)) {
$this->project_order_task_fulfillments[] = $projectOrderTaskFulfillment;
$projectOrderTaskFulfillment->setBranch($this);
}
return $this;
}
public function removeProjectOrderTaskFulfillment(ProjectOrderTaskFulfillment $projectOrderTaskFulfillment): self
{
if ($this->project_order_task_fulfillments->removeElement($projectOrderTaskFulfillment)) {
// set the owning side to null (unless already changed)
if ($projectOrderTaskFulfillment->getBranch() === $this) {
$projectOrderTaskFulfillment->setBranch(null);
}
}
return $this;
}
}