<?php
namespace App\Entity;
use App\Repository\OrganizationUnitRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Ignore;
/**
* @ORM\Entity(repositoryClass=OrganizationUnitRepository::class)
*/
class OrganizationUnit
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Organization::class, inversedBy="organizationUnits")
* @ORM\JoinColumn(nullable=false)
*/
private $organization;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $acronym;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $head;
/**
* @ORM\ManyToOne(targetEntity=OrganizationUnit::class)
*/
private $reportsTo;
/**
* @ORM\OneToMany(targetEntity=Project::class, mappedBy="unit")
* @Ignore()
*/
private $projects;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="unit")
* @Ignore()
*/
private $users;
public function __construct()
{
$this->projects = new ArrayCollection();
$this->users = 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;
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): self
{
$this->organization = $organization;
return $this;
}
public function getAcronym(): ?string
{
return $this->acronym;
}
public function setAcronym(?string $acronym): self
{
$this->acronym = $acronym;
return $this;
}
public function getHead(): ?User
{
return $this->head;
}
public function setHead(?User $head): self
{
$this->head = $head;
return $this;
}
public function getReportsTo(): ?self
{
return $this->reportsTo;
}
public function setReportsTo(?self $reportsTo): self
{
$this->reportsTo = $reportsTo;
return $this;
}
public function __toString()
{
return $this->name;
}
/**
* @return Collection|Project[]
*/
public function getProjects(): Collection
{
return $this->projects;
}
public function addProject(Project $project): self
{
if (!$this->projects->contains($project)) {
$this->projects[] = $project;
$project->setUnit($this);
}
return $this;
}
public function removeProject(Project $project): self
{
if ($this->projects->removeElement($project)) {
// set the owning side to null (unless already changed)
if ($project->getUnit() === $this) {
$project->setUnit(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setUnit($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getUnit() === $this) {
$user->setUnit(null);
}
}
return $this;
}
}