src/Entity/Company.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Techcard\Techcard;
  4. use App\Repository\CompanyRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CompanyRepository::class)
  10.  */
  11. class Company
  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, nullable=true)
  25.      */
  26.     private $email;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, options={"default": "ROLE_ADMIN"})
  29.      */
  30.     private $role;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity=Client::class, mappedBy="company")
  33.      */
  34.     private $clients;
  35.     /**
  36.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="company")
  37.      */
  38.     private $user;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity=Techcard::class, mappedBy="company")
  41.      */
  42.     private $techcards;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=Employee::class, mappedBy="company")
  45.      */
  46.     private $employees;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=CompanyGroup::class, inversedBy="companies")
  49.      */
  50.     private $companyGroup;
  51.     /**
  52.      * @ORM\Column(type="boolean", nullable=true, options={"default": false})
  53.      */
  54.     private $remove;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true)
  57.      */
  58.     private $cropWiseToken;
  59.     /**
  60.      * @ORM\Column(type="boolean", nullable=true, options={"default": false})
  61.      */
  62.     private $downloadCropWiseReport;
  63.     /**
  64.      * @ORM\Column(type="boolean", nullable=true, options={"default": false})
  65.      */
  66.     private $uploadCereraReport;
  67.     public function __construct()
  68.     {
  69.         if(is_null($this->id)){
  70.             $this->role 'ROLE_ADMIN';
  71.             $this->remove false;
  72.         }
  73.         $this->clients = new ArrayCollection();
  74.         $this->user = new ArrayCollection();
  75.         $this->techcards = new ArrayCollection();
  76.         $this->employees = new ArrayCollection();
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->name;
  85.     }
  86.     public function setName(?string $name): self
  87.     {
  88.         $this->name $name;
  89.         return $this;
  90.     }
  91.     public function getEmail(): ?string
  92.     {
  93.         return $this->email;
  94.     }
  95.     public function setEmail(string $email): self
  96.     {
  97.         $this->email $email;
  98.         return $this;
  99.     }
  100.     
  101.     /**
  102.      * @return mixed
  103.      */
  104.     public function getRole()
  105.     {
  106.         return $this->role;
  107.     }
  108.     /**
  109.      * @param mixed $role
  110.      */
  111.     public function setRole($role): void
  112.     {
  113.         $this->role $role;
  114.     }
  115.     /**
  116.      * @return Collection|Client[]
  117.      */
  118.     public function getClients($displayRemoved false): Collection
  119.     {
  120.         if(!$displayRemoved) {
  121.             return $this->clients->filter(function ($item) {
  122.                     if(!$item->isRemove()){
  123.                         return $item;
  124.                     }
  125.                     return null;
  126.             });
  127.         } else {
  128.             return $this->clients;
  129.         }
  130.     }
  131.     public function addClient(Client $client): self
  132.     {
  133.         if (!$this->clients->contains($client)) {
  134.             $this->clients[] = $client;
  135.             $client->setCompany($this);
  136.         }
  137.         return $this;
  138.     }
  139.     public function removeClient(Client $client): self
  140.     {
  141.         if ($this->clients->removeElement($client)) {
  142.             // set the owning side to null (unless already changed)
  143.             if ($client->getCompany() === $this) {
  144.                 $client->setCompany(null);
  145.             }
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeAllClient(): self
  150.     {
  151.        $clients $this->getClients();
  152.        if($clients){
  153.            foreach ($clients as $client){
  154.                $this->removeClient($client);
  155.            }
  156.        }
  157.         return $this;
  158.     }
  159.     public function removeAllEmployee()
  160.     {
  161.         $employees $this->getAllEmployees();
  162.         if($employees->count()) {
  163.             foreach ($employees as $employee) {
  164.                 $this->removeEmployee($employee);
  165.             }
  166.         }
  167.     }
  168.     /**
  169.      * @return Collection|User[]
  170.      */
  171.     public function getUser(): Collection
  172.     {
  173.         return $this->user;
  174.     }
  175.     public function addUser(User $user): self
  176.     {
  177.         if (!$this->user->contains($user)) {
  178.             $this->user[] = $user;
  179.             $user->setCompany($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeUser(User $user): self
  184.     {
  185.         if ($this->user->removeElement($user)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($user->getCompany() === $this) {
  188.                 $user->setCompany(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     public function removeAllUser()
  194.     {
  195.         $users $this->getUser();
  196.         if($users) {
  197.             foreach ($users as $user) {
  198.                 $this->removeUser($user);
  199.             }
  200.         }
  201.     }
  202.     /**
  203.      * @return mixed
  204.      */
  205.     public function getDownloadCropWiseReport()
  206.     {
  207.         return $this->downloadCropWiseReport;
  208.     }
  209.     /**
  210.      * @param mixed $downloadCropWiseReport
  211.      */
  212.     public function setDownloadCropWiseReport($downloadCropWiseReport): void
  213.     {
  214.         $this->downloadCropWiseReport $downloadCropWiseReport;
  215.     }
  216.     /**
  217.      * @return mixed
  218.      */
  219.     public function getUploadCereraReport()
  220.     {
  221.         return $this->uploadCereraReport;
  222.     }
  223.     /**
  224.      * @param mixed $uploadCereraReport
  225.      */
  226.     public function setUploadCereraReport($uploadCereraReport): void
  227.     {
  228.         $this->uploadCereraReport $uploadCereraReport;
  229.     }
  230.     public function getFields(): ArrayCollection
  231.     {
  232.         $fields = [];
  233.         $clients $this->getClients()->toArray();
  234.         array_walk($clients,function ($item) use (&$fields){
  235.             $fields array_merge($fields,$item->getFields()->toArray());
  236.         });
  237.         return new ArrayCollection($fields);
  238.     }
  239.     /**
  240.      * @return Collection|Techcard[]
  241.      */
  242.     public function getTechcards(): Collection
  243.     {
  244.         return $this->techcards;
  245.     }
  246.     public function addTechcard(Techcard $techcard): self
  247.     {
  248.         if (!$this->techcards->contains($techcard)) {
  249.             $this->techcards[] = $techcard;
  250.             $techcard->setCompany($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removeTechcard(Techcard $techcard): self
  255.     {
  256.         if ($this->techcards->removeElement($techcard)) {
  257.             // set the owning side to null (unless already changed)
  258.             if ($techcard->getCompany() === $this) {
  259.                 $techcard->setCompany(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeAllTechcard()
  265.     {
  266.         $techcards $this->getTechcards();
  267.         if($techcards) {
  268.             foreach ($techcards as $techcard) {
  269.                 $this->removeTechcard($techcard);
  270.             }
  271.         }
  272.     }
  273.     public function getEmployees()
  274.     {
  275.         $response = new ArrayCollection();
  276.         if($this->getClients()->count()){
  277.             $this->getClients()->filter(function ($client) use (&$response){
  278.                 if($client->getFields()->count()){
  279.                     $client->getFields()->filter(function ($field) use (&$response){
  280.                         /** @var Field $field */
  281.                         if($field->getEmployees()->count()){
  282.                             $field->getEmployees()->filter(function ($employee) use (&$response){
  283.                                 if(!$response->contains($employee)){
  284.                                     $response->add($employee);
  285.                                 }
  286.                             });
  287.                         }
  288.                     });
  289.                 }
  290.             });
  291.         }
  292.         return $response;
  293.     }
  294.     public function __toString()
  295.     {
  296.         return $this->name;
  297.     }
  298.     public function getAllEmployees()
  299.     {
  300.         return $this->employees;
  301.     }
  302.     public function addEmployee(Employee $employee): self
  303.     {
  304.         if (!$this->employees->contains($employee)) {
  305.             $this->employees[] = $employee;
  306.             $employee->setCompancompany($this);
  307.         }
  308.         return $this;
  309.     }
  310.     public function removeEmployee(Employee $employee): self
  311.     {
  312.         if ($this->employees->removeElement($employee)) {
  313.             // set the owning side to null (unless already changed)
  314.             if ($employee->getCompancompany() === $this) {
  315.                 $employee->setCompancompany(null);
  316.             }
  317.         }
  318.         return $this;
  319.     }
  320.     public function getCompanyGroup(): ?CompanyGroup
  321.     {
  322.         return $this->companyGroup;
  323.     }
  324.     public function setCompanyGroup(?CompanyGroup $companyGroup): self
  325.     {
  326.         $this->companyGroup $companyGroup;
  327.         return $this;
  328.     }
  329.     public function isRemove(): ?bool
  330.     {
  331.         return $this->remove;
  332.     }
  333.     public function setRemove(?bool $remove): self
  334.     {
  335.         $this->remove $remove;
  336.         return $this;
  337.     }
  338.     public function getCropWiseToken(): ?string
  339.     {
  340.         return $this->cropWiseToken;
  341.     }
  342.     public function setCropWiseToken(?string $cropWiseToken): self
  343.     {
  344.         $this->cropWiseToken $cropWiseToken;
  345.         return $this;
  346.     }
  347. }