<?php
namespace App\Entity;
use App\Entity\Task\MonitoringObjective;
use App\Entity\Task\Objective;
use App\Entity\Techcard\Techcard;
use App\Repository\ClientRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use function Clue\StreamFilter\fun;
/**
* @ORM\Entity(repositoryClass=ClientRepository::class)
*/
class Client
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text")
*/
private $region;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="clients")
*/
private $company;
/**
* @ORM\OneToMany(targetEntity=Field::class, mappedBy="client")
*/
private $fields;
/**
* @ORM\OneToMany(targetEntity=Techcard::class, mappedBy="client")
*/
private $techcards;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
*/
private $remove;
/**
* @ORM\OneToMany(targetEntity=Objective::class, mappedBy="client")
*/
private $objectives;
/**
* @ORM\OneToMany(targetEntity=MonitoringObjective::class, mappedBy="client")
*/
private $monitoringObjectives;
/**
* @ORM\OneToMany(targetEntity=ObjectGroup::class, mappedBy="subdivision")
*/
private $objectGroups;
/**
* @ORM\OneToMany(targetEntity=Location::class, mappedBy="subdivision")
*/
private $locations;
public function __construct()
{
if($this->id === null){
$this->remove = false;
}
$this->fields = new ArrayCollection();
$this->techcards = new ArrayCollection();
$this->objectives = new ArrayCollection();
$this->monitoringObjectives = new ArrayCollection();
$this->objectGroups = new ArrayCollection();
$this->locations = 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 getRegion(): ?string
{
return $this->region;
}
public function setRegion(string $region): self
{
$this->region = $region;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection|Field[]
*/
public function getFields($remove = false): Collection
{
if($remove){
return $this->fields;
} else {
return $this->fields->filter(function ($item){
/** @var Field $item */
if(!$item->isRemoved()){
return $item;
}
return null;
});
}
}
public function addField(Field $field): self
{
if (!$this->fields->contains($field)) {
$this->fields[] = $field;
$field->setClient($this);
}
return $this;
}
public function removeField(Field $field): self
{
if ($this->fields->removeElement($field)) {
// set the owning side to null (unless already changed)
if ($field->getClient() === $this) {
$field->setClient(null);
}
}
return $this;
}
public function getSize(): float
{
$arrayFieldSize = $this->getFields()->map(function ($item) {
return (float)(str_replace(" ",'',$item->getSize()));
})->toArray();
return array_sum($arrayFieldSize);
}
public function getFieldsCount(): float
{
return $this->getFields()->count();
}
/**
* @return Collection|Techcard[]
*/
public function getTechcards(): Collection
{
return $this->techcards;
}
public function addTechcard(Techcard $techcard): self
{
if (!$this->techcards->contains($techcard)) {
$this->techcards[] = $techcard;
$techcard->setClient($this);
}
return $this;
}
public function removeTechcard(Techcard $techcard): self
{
if ($this->techcards->removeElement($techcard)) {
// set the owning side to null (unless already changed)
if ($techcard->getClient() === $this) {
$techcard->setClient(null);
}
}
return $this;
}
public function removeAllTechcard()
{
$list = $this->getTechcards();
if($list->count()){
foreach ($list as $item){
$this->removeTechcard($item);
}
}
}
public function getEmployees()
{
$response = new ArrayCollection();
if($this->getFields()->count()){
$this->getFields()->filter(function ($field) use (&$response){
/** @var Field $field */
if($field->getEmployees()->count()){
$field->getEmployees()->filter(function ($employee) use (&$response){
if(!$response->contains($employee)){
$response->add($employee);
}
});
}
});
}
return $response;
}
public function isRemove(): ?bool
{
return $this->remove;
}
public function setRemove(?bool $remove): self
{
$this->remove = $remove;
return $this;
}
/**
* @return Collection<int, Objective>
*/
public function getObjectives(): Collection
{
return $this->objectives;
}
public function addObjective(Objective $objective): self
{
if (!$this->objectives->contains($objective)) {
$this->objectives[] = $objective;
$objective->setClient($this);
}
return $this;
}
public function removeObjective(Objective $objective): self
{
if ($this->objectives->removeElement($objective)) {
// set the owning side to null (unless already changed)
if ($objective->getClient() === $this) {
$objective->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, MonitoringObjective>
*/
public function getMonitoringObjectives(): Collection
{
return $this->monitoringObjectives;
}
public function addMonitoringObjective(MonitoringObjective $monitoringObjective): self
{
if (!$this->monitoringObjectives->contains($monitoringObjective)) {
$this->monitoringObjectives[] = $monitoringObjective;
$monitoringObjective->setClient($this);
}
return $this;
}
public function removeMonitoringObjective(MonitoringObjective $monitoringObjective): self
{
if ($this->monitoringObjectives->removeElement($monitoringObjective)) {
// set the owning side to null (unless already changed)
if ($monitoringObjective->getClient() === $this) {
$monitoringObjective->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, ObjectGroup>
*/
public function getObjectGroups(): Collection
{
return $this->objectGroups;
}
public function addObjectGroup(ObjectGroup $objectGroup): self
{
if (!$this->objectGroups->contains($objectGroup)) {
$this->objectGroups[] = $objectGroup;
$objectGroup->setSubdivision($this);
}
return $this;
}
public function removeObjectGroup(ObjectGroup $objectGroup): self
{
if ($this->objectGroups->removeElement($objectGroup)) {
// set the owning side to null (unless already changed)
if ($objectGroup->getSubdivision() === $this) {
$objectGroup->setSubdivision(null);
}
}
return $this;
}
/**
* @return Collection<int, Location>
*/
public function getLocations(): Collection
{
return $this->locations;
}
public function addLocation(Location $location): self
{
if (!$this->locations->contains($location)) {
$this->locations[] = $location;
$location->setSubdivision($this);
}
return $this;
}
public function removeLocation(Location $location): self
{
if ($this->locations->removeElement($location)) {
// set the owning side to null (unless already changed)
if ($location->getSubdivision() === $this) {
$location->setSubdivision(null);
}
}
return $this;
}
}