src/Entity/Client.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Task\MonitoringObjective;
  4. use App\Entity\Task\Objective;
  5. use App\Entity\Techcard\Techcard;
  6. use App\Repository\ClientRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use function Clue\StreamFilter\fun;
  11. /**
  12.  * @ORM\Entity(repositoryClass=ClientRepository::class)
  13.  */
  14. class Client
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="text")
  28.      */
  29.     private $region;
  30.     /**
  31.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="clients")
  32.      */
  33.     private $company;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity=Field::class, mappedBy="client")
  36.      */
  37.     private $fields;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity=Techcard::class, mappedBy="client")
  40.      */
  41.     private $techcards;
  42.     /**
  43.      * @ORM\Column(type="boolean", nullable=true, options={"default": false})
  44.      */
  45.     private $remove;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity=Objective::class, mappedBy="client")
  48.      */
  49.     private $objectives;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity=MonitoringObjective::class, mappedBy="client")
  52.      */
  53.     private $monitoringObjectives;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity=ObjectGroup::class, mappedBy="subdivision")
  56.      */
  57.     private $objectGroups;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity=Location::class, mappedBy="subdivision")
  60.      */
  61.     private $locations;
  62.     public function __construct()
  63.     {
  64.         if($this->id === null){
  65.             $this->remove false;
  66.         }
  67.         $this->fields = new ArrayCollection();
  68.         $this->techcards = new ArrayCollection();
  69.         $this->objectives = new ArrayCollection();
  70.         $this->monitoringObjectives = new ArrayCollection();
  71.         $this->objectGroups = new ArrayCollection();
  72.         $this->locations = new ArrayCollection();
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     public function getRegion(): ?string
  88.     {
  89.         return $this->region;
  90.     }
  91.     public function setRegion(string $region): self
  92.     {
  93.         $this->region $region;
  94.         return $this;
  95.     }
  96.     public function getCompany(): ?Company
  97.     {
  98.         return $this->company;
  99.     }
  100.     public function setCompany(?Company $company): self
  101.     {
  102.         $this->company $company;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection|Field[]
  107.      */
  108.     public function getFields($remove false): Collection
  109.     {
  110.         if($remove){
  111.             return $this->fields;
  112.         } else {
  113.             return $this->fields->filter(function ($item){
  114.                 /** @var Field $item */
  115.                 if(!$item->isRemoved()){
  116.                     return $item;
  117.                 }
  118.                 return null;
  119.             });
  120.         }
  121.     }
  122.     public function addField(Field $field): self
  123.     {
  124.         if (!$this->fields->contains($field)) {
  125.             $this->fields[] = $field;
  126.             $field->setClient($this);
  127.         }
  128.         return $this;
  129.     }
  130.     public function removeField(Field $field): self
  131.     {
  132.         if ($this->fields->removeElement($field)) {
  133.             // set the owning side to null (unless already changed)
  134.             if ($field->getClient() === $this) {
  135.                 $field->setClient(null);
  136.             }
  137.         }
  138.         return $this;
  139.     }
  140.     public function getSize(): float
  141.     {
  142.         $arrayFieldSize $this->getFields()->map(function ($item) {
  143.             return (float)(str_replace(" ",'',$item->getSize()));
  144.         })->toArray();
  145.         return array_sum($arrayFieldSize);
  146.     }
  147.     public function getFieldsCount(): float
  148.     {
  149.         return $this->getFields()->count();
  150.     }
  151.     /**
  152.      * @return Collection|Techcard[]
  153.      */
  154.     public function getTechcards(): Collection
  155.     {
  156.         return $this->techcards;
  157.     }
  158.     public function addTechcard(Techcard $techcard): self
  159.     {
  160.         if (!$this->techcards->contains($techcard)) {
  161.             $this->techcards[] = $techcard;
  162.             $techcard->setClient($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeTechcard(Techcard $techcard): self
  167.     {
  168.         if ($this->techcards->removeElement($techcard)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($techcard->getClient() === $this) {
  171.                 $techcard->setClient(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176.     public function removeAllTechcard()
  177.     {
  178.         $list $this->getTechcards();
  179.         if($list->count()){
  180.             foreach ($list as $item){
  181.                 $this->removeTechcard($item);
  182.             }
  183.         }
  184.     }
  185.     public function getEmployees()
  186.     {
  187.         $response = new ArrayCollection();
  188.         if($this->getFields()->count()){
  189.             $this->getFields()->filter(function ($field) use (&$response){
  190.                 /** @var Field $field */
  191.                 if($field->getEmployees()->count()){
  192.                     $field->getEmployees()->filter(function ($employee) use (&$response){
  193.                         if(!$response->contains($employee)){
  194.                             $response->add($employee);
  195.                         }
  196.                     });
  197.                 }
  198.             });
  199.         }
  200.      return $response;
  201.     }
  202.     public function isRemove(): ?bool
  203.     {
  204.         return $this->remove;
  205.     }
  206.     public function setRemove(?bool $remove): self
  207.     {
  208.         $this->remove $remove;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return Collection<int, Objective>
  213.      */
  214.     public function getObjectives(): Collection
  215.     {
  216.         return $this->objectives;
  217.     }
  218.     public function addObjective(Objective $objective): self
  219.     {
  220.         if (!$this->objectives->contains($objective)) {
  221.             $this->objectives[] = $objective;
  222.             $objective->setClient($this);
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeObjective(Objective $objective): self
  227.     {
  228.         if ($this->objectives->removeElement($objective)) {
  229.             // set the owning side to null (unless already changed)
  230.             if ($objective->getClient() === $this) {
  231.                 $objective->setClient(null);
  232.             }
  233.         }
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection<int, MonitoringObjective>
  238.      */
  239.     public function getMonitoringObjectives(): Collection
  240.     {
  241.         return $this->monitoringObjectives;
  242.     }
  243.     public function addMonitoringObjective(MonitoringObjective $monitoringObjective): self
  244.     {
  245.         if (!$this->monitoringObjectives->contains($monitoringObjective)) {
  246.             $this->monitoringObjectives[] = $monitoringObjective;
  247.             $monitoringObjective->setClient($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeMonitoringObjective(MonitoringObjective $monitoringObjective): self
  252.     {
  253.         if ($this->monitoringObjectives->removeElement($monitoringObjective)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($monitoringObjective->getClient() === $this) {
  256.                 $monitoringObjective->setClient(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return Collection<int, ObjectGroup>
  263.      */
  264.     public function getObjectGroups(): Collection
  265.     {
  266.         return $this->objectGroups;
  267.     }
  268.     public function addObjectGroup(ObjectGroup $objectGroup): self
  269.     {
  270.         if (!$this->objectGroups->contains($objectGroup)) {
  271.             $this->objectGroups[] = $objectGroup;
  272.             $objectGroup->setSubdivision($this);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removeObjectGroup(ObjectGroup $objectGroup): self
  277.     {
  278.         if ($this->objectGroups->removeElement($objectGroup)) {
  279.             // set the owning side to null (unless already changed)
  280.             if ($objectGroup->getSubdivision() === $this) {
  281.                 $objectGroup->setSubdivision(null);
  282.             }
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return Collection<int, Location>
  288.      */
  289.     public function getLocations(): Collection
  290.     {
  291.         return $this->locations;
  292.     }
  293.     public function addLocation(Location $location): self
  294.     {
  295.         if (!$this->locations->contains($location)) {
  296.             $this->locations[] = $location;
  297.             $location->setSubdivision($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeLocation(Location $location): self
  302.     {
  303.         if ($this->locations->removeElement($location)) {
  304.             // set the owning side to null (unless already changed)
  305.             if ($location->getSubdivision() === $this) {
  306.                 $location->setSubdivision(null);
  307.             }
  308.         }
  309.         return $this;
  310.     }
  311. }