<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: 'App\Repository\OrganizationRepository')]
class Organization
{
#[Groups(['LogService'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: 'App\Entity\Office', inversedBy: 'organizations')]
#[ORM\JoinColumn(nullable: false)]
private $office;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: 'App\Entity\User', inversedBy: 'organizations')]
private $user;
#[Groups(['LogService'])]
#[ORM\Column(type: 'string', length: 32, nullable: true)]
private $title;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: 'App\Entity\Department', inversedBy: 'organizations')]
private $department;
#[Groups(['LogService'])]
#[ORM\Column(type: 'boolean', nullable: true)]
private $isGroup;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: 'App\Entity\Organization', inversedBy: 'groupUsers')]
private $inGroup;
#[ORM\OneToMany(targetEntity: 'App\Entity\Organization', mappedBy: 'inGroup')]
private $groupUsers;
#[Groups(['LogService'])]
#[ORM\ManyToOne(targetEntity: 'App\Entity\Organization', inversedBy: 'supervisorChilds')]
private $supervisor;
#[ORM\OneToMany(targetEntity: 'App\Entity\Organization', mappedBy: 'supervisor')]
private $supervisorChilds;
#[Groups(['LogService'])]
#[ORM\Column(type: 'integer')]
private $ordering = 0;
#[ORM\Column(type: 'datetime', nullable: true)]
private $updatedAt;
public function __construct()
{
$this->groupUsers = new ArrayCollection();
$this->supervisorChilds = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getOffice(): ?Office
{
return $this->office;
}
public function setOffice(?Office $office): self
{
$this->office = $office;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getDepartment(): ?Department
{
return $this->department;
}
public function setDepartment(?Department $department): self
{
$this->department = $department;
return $this;
}
public function getIsGroup(): ?bool
{
return $this->isGroup;
}
public function setIsGroup(?bool $isGroup): self
{
$this->isGroup = $isGroup;
return $this;
}
public function getInGroup(): ?self
{
return $this->inGroup;
}
public function setInGroup(?self $inGroup): self
{
$this->inGroup = $inGroup;
return $this;
}
/**
* @return Collection|self[]
*/
public function getGroupUsers(): Collection
{
return $this->groupUsers;
}
public function addGroupUser(self $groupUser): self
{
if (!$this->groupUsers->contains($groupUser)) {
$this->groupUsers[] = $groupUser;
$groupUser->setInGroup($this);
}
return $this;
}
public function removeGroupUser(self $groupUser): self
{
if ($this->groupUsers->contains($groupUser)) {
$this->groupUsers->removeElement($groupUser);
// set the owning side to null (unless already changed)
if ($groupUser->getInGroup() === $this) {
$groupUser->setInGroup(null);
}
}
return $this;
}
public function getSupervisor(): ?self
{
return $this->supervisor;
}
public function setSupervisor(?self $supervisor): self
{
$this->supervisor = $supervisor;
return $this;
}
/**
* @return Collection|self[]
*/
public function getSupervisorChilds(): Collection
{
return $this->supervisorChilds;
}
public function addSupervisorChild(self $supervisorChild): self
{
if (!$this->supervisorChilds->contains($supervisorChild)) {
$this->supervisorChilds[] = $supervisorChild;
$supervisorChild->setSupervisor($this);
}
return $this;
}
public function removeSupervisorChild(self $supervisorChild): self
{
if ($this->supervisorChilds->contains($supervisorChild)) {
$this->supervisorChilds->removeElement($supervisorChild);
// set the owning side to null (unless already changed)
if ($supervisorChild->getSupervisor() === $this) {
$supervisorChild->setSupervisor(null);
}
}
return $this;
}
public function getOrdering(): ?int
{
return $this->ordering;
}
public function setOrdering(int $ordering): self
{
$this->ordering = $ordering;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function organizationTitle() {
if($this->user->getPersonalInfo()->getJobTitle() != null){ // For transitioning
return $this->user->getPersonalInfo()->getJobTitle();
} elseif ($this->title != null){
return $this->title;
} else {
return null;
}
}
}