src/Entity/Employee.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Task\MonitoringObjective;
  4. use App\Repository\EmployeeRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=EmployeeRepository::class)
  10.  */
  11. class Employee
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $role;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $phone;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      */
  34.     private $email;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $image;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $comment;
  43.     /**
  44.      * @ORM\Column(type="string", length=255, nullable=true)
  45.      */
  46.     private $lastName;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=Position::class)
  49.      */
  50.     private $position;
  51.     /**
  52.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="employee", cascade={"persist", "remove"})
  53.      */
  54.     private $user;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $password;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="employees")
  61.      */
  62.     private $company;
  63.     /**
  64.      * @ORM\ManyToMany(targetEntity=Field::class, mappedBy="employees")
  65.      */
  66.     private $fields;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity=MonitoringObjective::class, mappedBy="viewer")
  69.      */
  70.     private $monitoringObjectives;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="employees")
  73.      */
  74.     private $creator;
  75.     public function __construct()
  76.     {
  77.         $this->fields = new ArrayCollection();
  78.         $this->monitoringObjectives = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getName(): ?string
  85.     {
  86.         return $this->name;
  87.     }
  88.     public function setName(string $name): self
  89.     {
  90.         $this->name $name;
  91.         return $this;
  92.     }
  93.     public function getLastDateConnect(): ?\DateTimeInterface
  94.     {
  95. //        if($this->getUser()) {
  96. //            return $this->getUser()->getLastConnect();
  97. //        }
  98.         return null;
  99.     }
  100.     public function getRole(): ?string
  101.     {
  102.         return $this->role;
  103.     }
  104.     public function getRoleName(string $role): ?string
  105.     {
  106.         if($role === Role::ADMIN){
  107.             return 'admin';
  108.         }
  109.         return 'scout';
  110.     }
  111.     public function setRole(string $role): self
  112.     {
  113.         $this->role $role;
  114.         return $this;
  115.     }
  116.     
  117.     public function getPhone(): ?string
  118.     {
  119.         return $this->phone;
  120.     }
  121.     public function setPhone(string $phone): self
  122.     {
  123.         $this->phone $phone;
  124.         return $this;
  125.     }
  126.     public function getEmail(): ?string
  127.     {
  128.         return $this->email;
  129.     }
  130.     public function setEmail(string $email): self
  131.     {
  132.         $this->email $email;
  133.         return $this;
  134.     }
  135.     public function getAccess(): ?string
  136.     {
  137.        if($this->role === Role::ADMIN){
  138.            return 'full';
  139.        }
  140.        return 'scout';
  141.     }
  142.     public function getImage(): ?string
  143.     {
  144.         return $this->image;
  145.     }
  146.     public function setImage(?string $image): self
  147.     {
  148.         $this->image $image;
  149.         return $this;
  150.     }
  151.     public function getComment(): ?string
  152.     {
  153.         return $this->comment;
  154.     }
  155.     public function setComment(string $comment): self
  156.     {
  157.         $this->comment $comment;
  158.         return $this;
  159.     }
  160.     public function getLastName(): ?string
  161.     {
  162.         return $this->lastName;
  163.     }
  164.     public function setLastName(?string $lastName): self
  165.     {
  166.         $this->lastName $lastName;
  167.         return $this;
  168.     }
  169.     public function getPosition(): ?Position
  170.     {
  171.         return $this->position;
  172.     }
  173.     public function setPosition(?Position $position): self
  174.     {
  175.         $this->position $position;
  176.         return $this;
  177.     }
  178.     public function getUser(): ?User
  179.     {
  180.         return $this->user;
  181.     }
  182.     public function setUser(?User $user): self
  183.     {
  184.         $this->user $user;
  185.         return $this;
  186.     }
  187.     public function getClients()
  188.     {
  189.         $response = [];
  190.         if($this->getFields()->count()){
  191.             foreach ($this->getFields() as $field) {
  192.                 $response[$field->getClient()->getId()] = $field->getClient();
  193.             }
  194.         }
  195.         return $response;
  196.     }
  197.     public function getClientIds()
  198.     {
  199.         $response = [];
  200.         $clients $this->getClients();
  201. //        if(!empty($clients)){
  202. //            foreach ($clients as $client) {
  203. //                $response[$client->getId()] = $client->getId();
  204. //            }
  205. //        }
  206.         if($this->getCompany()){
  207.             if($this->getCompany()->getCompanyGroup()){
  208.                 if($this->getCompany()->getCompanyGroup()->getCompanies()->count() > 0){
  209.                     /** @var Company $company */
  210.                     foreach ($this->getCompany()->getCompanyGroup()->getCompanies() as $company) {
  211.                         foreach ($company->getClients() as $client) {
  212.                             $response[$client->getId()] = $client->getId();
  213.                         }
  214.                     }
  215.                 }
  216.             }
  217.         }
  218.         return $response;
  219.     }
  220.     public function getFieldIds()
  221.     {
  222.         $response = [];
  223.         if($this->getFields()->count()){
  224.             foreach ($this->getFields() as $field) {
  225.                 $response[] = $field->getId();
  226.             }
  227.         }
  228.         return $response;
  229.     }
  230.     public function getFieldsClient()
  231.     {
  232.         $response = [];
  233.         if($this->getFields()->count()){
  234.             foreach ($this->getFields() as $field) {
  235.                 $response[$field->getClient()->getName()][] = $field;
  236.             }
  237.         }
  238.         return $response;
  239.     }
  240.     public function getFieldsClientIds(): array
  241.     {
  242.         $response = [];
  243.         if($this->getFields()->count() > 0){
  244.             foreach ($this->getFields() as $field) {
  245.                 if(!in_array($field->getClient()->getId(),$response) && !$field->isRemoved()){
  246.                     $response[] = $field->getClient()->getId();
  247.                 }
  248.             }
  249.         }
  250.         return array_unique($response);
  251.     }
  252.     public function getFieldsTechcardIds(): array
  253.     {
  254.         $response = [];
  255.         if($this->getFields()->count()){
  256.             foreach ($this->getFields() as $field) {
  257.                 if(!empty($field->getTechcard()) && !in_array($field->getTechcard()->getId(),$response) && !$field->isRemoved()){
  258.                     $response[] = $field->getTechcard()->getId();
  259.                 }
  260.             }
  261.         }
  262.         return $response;
  263.     }
  264.     public function getFullName(): string
  265.     {
  266.         $fullName $this->name ' ' $this->lastName;
  267.         if(empty($fullName)){
  268.             $fullName $this->email;
  269.         }
  270.         return $fullName;
  271.     }
  272.     public function getPassword(): ?string
  273.     {
  274.         return $this->password;
  275.     }
  276.     public function setPassword(?string $password): self
  277.     {
  278.         $this->password $password;
  279.         return $this;
  280.     }
  281.     public function getCompany(): ?Company
  282.     {
  283.         return $this->company;
  284.     }
  285.     public function setCompany(?Company $company): self
  286.     {
  287.         $this->company $company;
  288.         return $this;
  289.     }
  290.     /**
  291.      * @return Collection|Field[]
  292.      */
  293.     public function getFields($removed false): Collection
  294.     {
  295.         if($removed) {
  296.             return $this->fields;
  297.         } else {
  298.             return $this->fields->filter(function ($field){
  299.                 /** @var Field $field */
  300.                 /** @var Client $client */
  301.                 $client $field->getClient();
  302.                 if(!empty($client) && !$client->isRemove()) {
  303.                     /** @var Company $company */
  304.                     $company $client->getCompany();
  305.                     if (!empty($company) && !$company->isRemove()) {
  306.                         /** @var CompanyGroup $companyGroup */
  307.                         $companyGroup $company->getCompanyGroup();
  308.                         if (!empty($companyGroup) && !$companyGroup->isRemove()) {
  309.                             return $field;
  310.                         }
  311.                     }
  312.                 }
  313.                 return null;
  314.             });
  315.         }
  316.     }
  317.     public function addField(Field $field): self
  318.     {
  319.         if (!$this->fields->contains($field)) {
  320.             $this->fields[] = $field;
  321.             $field->addEmployee($this);
  322.         }
  323.         return $this;
  324.     }
  325.     public function removeField(Field $field): self
  326.     {
  327.         if ($this->fields->removeElement($field)) {
  328.             $field->removeEmployee($this);
  329.         }
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return Collection<int, MonitoringObjective>
  334.      */
  335.     public function getMonitoringObjectives(): Collection
  336.     {
  337.         return $this->monitoringObjectives;
  338.     }
  339.     public function addMonitoringObjective(MonitoringObjective $monitoringObjective): self
  340.     {
  341.         if (!$this->monitoringObjectives->contains($monitoringObjective)) {
  342.             $this->monitoringObjectives[] = $monitoringObjective;
  343.             $monitoringObjective->setViewer($this);
  344.         }
  345.         return $this;
  346.     }
  347.     public function removeMonitoringObjective(MonitoringObjective $monitoringObjective): self
  348.     {
  349.         if ($this->monitoringObjectives->removeElement($monitoringObjective)) {
  350.             // set the owning side to null (unless already changed)
  351.             if ($monitoringObjective->getViewer() === $this) {
  352.                 $monitoringObjective->setViewer(null);
  353.             }
  354.         }
  355.         return $this;
  356.     }
  357.     public function getCompanyGroupId()
  358.     {
  359.         if(!empty($this->getCompany())
  360.             && !empty($this->getCompany()->getCompanyGroup())
  361.         ){
  362.             return $this->getCompany()->getCompanyGroup()->getId();
  363.         }
  364.         return null;
  365.     }
  366.     public function getCreator(): ?User
  367.     {
  368.         return $this->creator;
  369.     }
  370.     public function setCreator(?User $creator): self
  371.     {
  372.         $this->creator $creator;
  373.         return $this;
  374.     }
  375. }