src/Entity/Company.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\CompanyRepository;
  6. use DateTimeImmutable;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. #[ORM\Entity(repositoryClassCompanyRepository::class)]
  10. class Company
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length100)]
  17.     private ?string $name null;
  18.     #[ORM\ManyToOne(inversedBy'companies')]
  19.     #[ORM\JoinColumn(nullabletrue)]
  20.     private ?Accompanist $accompanist null;
  21.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyMember::class)]
  22.     private Collection $companyMembers;
  23.     #[ORM\OneToMany(mappedBy'company'targetEntityEvaluation::class, orphanRemovaltruefetch"EAGER")]
  24.     private Collection $evaluations;
  25.     #[ORM\Column(typeTypes::DATE_IMMUTABLEnullabletrue)]
  26.     private ?\DateTimeImmutable $enterProgram null;
  27.     #[ORM\OneToMany(mappedBy'company'targetEntityObjective::class, orphanRemovaltrue)]
  28.     private Collection $objectives;
  29.     #[ORM\Column(nullabletrue)]
  30.     private ?\DateTimeImmutable $updatedAt null;
  31.     #[ORM\ManyToOne]
  32.     #[ORM\JoinColumn(nullabletrue)]
  33.     private ?User $lastUpdator null;
  34.     #[ORM\Column(length255nullabletrue)]
  35.     private ?string $logo null;
  36.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyQuestionnaire::class, orphanRemovaltruefetch"EAGER")]
  37.     private Collection $companyQuestionnaires;
  38.     private ?array $activeQuestionnaires null;
  39.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyIndicatorThematic::class, orphanRemovaltrue)]
  40.     private Collection $companyIndicatorThematics;
  41.     #[ORM\OneToMany(mappedBy'company'targetEntityMembership::class, orphanRemovaltruefetch"EAGER")]
  42.     private Collection $memberships;
  43.     private ?Membership $lastMembership null;
  44.     #[ORM\OneToMany(mappedBy'company'targetEntityBCCompany::class, orphanRemovaltruefetch"EAGER")]
  45.     private Collection $BCCompanies;
  46.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyLabelNR::class, orphanRemovaltrue)]
  47.     private Collection $companyLabelNR;
  48.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyAuditNR::class, orphanRemovaltrue)]
  49.     private Collection $companyAuditNR;
  50.     #[ORM\Column]
  51.     private ?bool $labelNR null;
  52.     #[ORM\Column]
  53.     private ?bool $bilanCarbone null;
  54.     #[ORM\Column]
  55.     private ?bool $auditNR null;
  56.     #[ORM\Column]
  57.     private ?bool $training null;
  58.     public function __construct()
  59.     {
  60.         $this->companyMembers = new ArrayCollection();
  61.         $this->objectives = new ArrayCollection();
  62.         $this->enterProgram = new DateTimeImmutable();
  63.         $this->companyQuestionnaires = new ArrayCollection();
  64.         $this->companyIndicatorThematics = new ArrayCollection();
  65.         $this->memberships = new ArrayCollection();
  66.         $this->BCCompanies = new ArrayCollection();
  67.         $this->companyLabelNR = new ArrayCollection();
  68.         $this->companyAuditNR = new ArrayCollection();
  69.     }
  70.     public function __toString()
  71.     {
  72.         return $this->name;
  73.     }
  74.     public function getMemberCount()
  75.     {
  76.         return count($this->companyMembers);
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getActiveQuestionnaires(): ?array
  83.     {
  84.         return $this->activeQuestionnaires;
  85.     }
  86.     public function setActiveQuestionnaires(array $activeQuestionnaires): self
  87.     {
  88.         $this->activeQuestionnaires $activeQuestionnaires;
  89.         return $this;
  90.     }
  91.     public function getName(): ?string
  92.     {
  93.         return $this->name;
  94.     }
  95.     public function setName(string $name): self
  96.     {
  97.         $this->name $name;
  98.         return $this;
  99.     }
  100.     public function getAccompanist(): ?Accompanist
  101.     {
  102.         return $this->accompanist;
  103.     }
  104.     public function setAccompanist(?Accompanist $accompanist): self
  105.     {
  106.         $this->accompanist $accompanist;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return Collection<int, CompanyMember>
  111.      */
  112.     public function getCompanyMembers(): Collection
  113.     {
  114.         return $this->companyMembers;
  115.     }
  116.     public function addCompanyMember(CompanyMember $companyMember): self
  117.     {
  118.         if (!$this->companyMembers->contains($companyMember)) {
  119.             $this->companyMembers->add($companyMember);
  120.             $companyMember->setCompany($this);
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeCompanyMember(CompanyMember $companyMember): self
  125.     {
  126.         if ($this->companyMembers->removeElement($companyMember)) {
  127.             // set the owning side to null (unless already changed)
  128.             if ($companyMember->getCompany() === $this) {
  129.                 $companyMember->setCompany(null);
  130.             }
  131.         }
  132.         return $this;
  133.     }
  134.     public function getEnterProgram(): ?\DateTimeImmutable
  135.     {
  136.         return $this->enterProgram;
  137.     }
  138.     public function setEnterProgram(\DateTimeImmutable $enterProgram): self
  139.     {
  140.         $this->enterProgram $enterProgram;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection<int, Evaluation>
  145.      */
  146.     public function getEvaluations(): Collection
  147.     {
  148.         return $this->evaluations;
  149.     }
  150.     public function addEvaluation(Evaluation $evaluation): self
  151.     {
  152.         if (!$this->evaluations->contains($evaluation)) {
  153.             $this->evaluations->add($evaluation);
  154.             $evaluation->setCompany($this);
  155.         }
  156.         return $this;
  157.     }
  158.     public function removeEvaluation(Evaluation $evaluation): self
  159.     {
  160.         if ($this->evaluations->removeElement($evaluation)) {
  161.             // set the owning side to null (unless already changed)
  162.             if ($evaluation->getCompany() === $this) {
  163.                 $evaluation->setCompany(null);
  164.             }
  165.         }
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return Collection<int, Objective>
  170.      */
  171.     public function getObjectives(): Collection
  172.     {
  173.         return $this->objectives;
  174.     }
  175.     public function addObjective(Objective $objective): self
  176.     {
  177.         if (!$this->objectives->contains($objective)) {
  178.             $this->objectives->add($objective);
  179.             $objective->setCompany($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeObjective(Objective $objective): self
  184.     {
  185.         if ($this->objectives->removeElement($objective)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($objective->getCompany() === $this) {
  188.                 $objective->setCompany(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     public function getObjectivesOngoing(): array
  194.     {
  195.         $objectives = [];
  196.         $now = new DateTimeImmutable();
  197.         foreach ($this->objectives as $key => $objective) {
  198.             if ($objective->getStatus()["status"] == "ongoing") {
  199.                 $objectives[] = $objective;
  200.             }
  201.         }
  202.         return $objectives;
  203.     }
  204.     public function getObjectivesLate(): array
  205.     {
  206.         $objectives = [];
  207.         $now = new DateTimeImmutable();
  208.         foreach ($this->objectives as $key => $objective) {
  209.             if ($objective->getStatus()["status"] == "late") {
  210.                 $objectives[] = $objective;
  211.             }
  212.         }
  213.         return $objectives;
  214.     }
  215.     public function getObjectivesTerminated(): array
  216.     {
  217.         $objectives = [];
  218.         foreach ($this->objectives as $key => $objective) {
  219.             if ($objective->getStatus()["status"] == "terminated") {
  220.                 $objectives[] = $objective;
  221.             }
  222.         }
  223.         return $objectives;
  224.     }
  225.     public function getObjectivesPaused(): array
  226.     {
  227.         $objectives = [];
  228.         foreach ($this->objectives as $key => $objective) {
  229.             if ($objective->getStatus()["status"] == "paused") {
  230.                 $objectives[] = $objective;
  231.             }
  232.         }
  233.         return $objectives;
  234.     }
  235.     public function getObjectivesNotStarted(): array
  236.     {
  237.         $objectives = [];
  238.         foreach ($this->objectives as $key => $objective) {
  239.             if ($objective->getStatus()["status"] == "notstarted") {
  240.                 $objectives[] = $objective;
  241.             }
  242.         }
  243.         return $objectives;
  244.     }
  245.     public function getUpdatedAt(): ?\DateTimeImmutable
  246.     {
  247.         return $this->updatedAt;
  248.     }
  249.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  250.     {
  251.         $this->updatedAt $updatedAt;
  252.         return $this;
  253.     }
  254.     public function getLastUpdator(): ?User
  255.     {
  256.         return $this->lastUpdator;
  257.     }
  258.     public function setLastUpdator(?User $lastUpdator): self
  259.     {
  260.         $this->lastUpdator $lastUpdator;
  261.         return $this;
  262.     }
  263.     public function getLastEvaluationStrategy()
  264.     {
  265.         foreach (array_reverse($this->evaluations->toArray()) as $key => $evaluation) {
  266.             if ($evaluation->getQuestionnaire()->getName() == "Stratégie") {
  267.                 return $evaluation;
  268.             }
  269.         }
  270.         return null;
  271.     }
  272.     public function getLastEvaluationIT4Green()
  273.     {
  274.         foreach (array_reverse($this->evaluations->toArray()) as $key => $evaluation) {
  275.             if ($evaluation->getQuestionnaire()->getName() == "IT4Green") {
  276.                 return $evaluation;
  277.             }
  278.         }
  279.         return null;
  280.     }
  281.     public function getLastEvaluationIT4Good()
  282.     {
  283.         foreach (array_reverse($this->evaluations->toArray()) as $key => $evaluation) {
  284.             if ($evaluation->getQuestionnaire()->getName() == "IT4Good") {
  285.                 return $evaluation;
  286.             }
  287.         }
  288.         return null;
  289.     }
  290.     public function getLogo(): ?string
  291.     {
  292.         return $this->logo;
  293.     }
  294.     public function setLogo(?string $logo): self
  295.     {
  296.         $this->logo $logo;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return Collection<int, CompanyQuestionnaire>
  301.      */
  302.     public function getCompanyQuestionnaires(): Collection
  303.     {
  304.         return $this->companyQuestionnaires;
  305.     }
  306.     public function addCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
  307.     {
  308.         if (!$this->companyQuestionnaires->contains($companyQuestionnaire)) {
  309.             $this->companyQuestionnaires->add($companyQuestionnaire);
  310.             $companyQuestionnaire->setCompany($this);
  311.         }
  312.         return $this;
  313.     }
  314.     public function removeCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
  315.     {
  316.         if ($this->companyQuestionnaires->removeElement($companyQuestionnaire)) {
  317.             // set the owning side to null (unless already changed)
  318.             if ($companyQuestionnaire->getCompany() === $this) {
  319.                 $companyQuestionnaire->setCompany(null);
  320.             }
  321.         }
  322.         return $this;
  323.     }
  324.     // public function getLabelNRType(): ?string
  325.     // {
  326.     //     if (!$this->getCompanyLabelNR()) {
  327.     //         return "";
  328.     //     } else {
  329.     //         return $this->getCompanyLabelNR()->getType();
  330.     //     }
  331.     // }
  332.     /**
  333.      * @return Collection<int, CompanyIndicatorThematic>
  334.      */
  335.     public function getCompanyIndicatorThematics(): Collection
  336.     {
  337.         return $this->companyIndicatorThematics;
  338.     }
  339.     public function addCompanyIndicatorThematic(CompanyIndicatorThematic $companyIndicatorThematic): self
  340.     {
  341.         if (!$this->companyIndicatorThematics->contains($companyIndicatorThematic)) {
  342.             $this->companyIndicatorThematics->add($companyIndicatorThematic);
  343.             $companyIndicatorThematic->setCompany($this);
  344.         }
  345.         return $this;
  346.     }
  347.     public function removeCompanyIndicatorThematic(CompanyIndicatorThematic $companyIndicatorThematic): self
  348.     {
  349.         if ($this->companyIndicatorThematics->removeElement($companyIndicatorThematic)) {
  350.             // set the owning side to null (unless already changed)
  351.             if ($companyIndicatorThematic->getCompany() === $this) {
  352.                 $companyIndicatorThematic->setCompany(null);
  353.             }
  354.         }
  355.         return $this;
  356.     }
  357.     /**
  358.      * @return Collection<int, Membership>
  359.      */
  360.     public function getMemberships(): Collection
  361.     {
  362.         return $this->memberships;
  363.     }
  364.     public function addMembership(Membership $membership): self
  365.     {
  366.         if (!$this->memberships->contains($membership)) {
  367.             $this->memberships->add($membership);
  368.             $membership->setCompany($this);
  369.         }
  370.         return $this;
  371.     }
  372.     public function removeMembership(Membership $membership): self
  373.     {
  374.         if ($this->memberships->removeElement($membership)) {
  375.             // set the owning side to null (unless already changed)
  376.             if ($membership->getCompany() === $this) {
  377.                 $membership->setCompany(null);
  378.             }
  379.         }
  380.         return $this;
  381.     }
  382.     public function hasMemberShip(): ?bool
  383.     {
  384.         $now = new DateTimeImmutable();
  385.         $memberships array_reverse($this->memberships->toArray());
  386.         if (count($memberships) > 0) {
  387.             $this->setLastMembership($memberships[0]);
  388.         }
  389.         foreach (array_reverse($this->memberships->toArray()) as $key => $membership) {
  390.             if ($membership->isActive() && $membership->getStartedAt() < $now && $membership->getEndAt() > $now) {
  391.                 return true;
  392.             }
  393.         }
  394.         return false;
  395.     }
  396.     public function getLastMembership(): ?Membership
  397.     {
  398.         return $this->lastMembership;
  399.     }
  400.     public function setLastMembership(?Membership $lastMembership): self
  401.     {
  402.         $this->lastMembership $lastMembership;
  403.         return $this;
  404.     }
  405.     /**
  406.      * @return Collection<int, BCCompany>
  407.      */
  408.     public function getBCCompanies(): Collection
  409.     {
  410.         return $this->BCCompanies;
  411.     }
  412.     public function addBCCompany(BCCompany $bCCompany): self
  413.     {
  414.         if (!$this->BCCompanies->contains($bCCompany)) {
  415.             $this->BCCompanies->add($bCCompany);
  416.             $bCCompany->setCompany($this);
  417.         }
  418.         return $this;
  419.     }
  420.     public function removeBCCompany(BCCompany $bCCompany): self
  421.     {
  422.         if ($this->BCCompanies->removeElement($bCCompany)) {
  423.             // set the owning side to null (unless already changed)
  424.             if ($bCCompany->getCompany() === $this) {
  425.                 $bCCompany->setCompany(null);
  426.             }
  427.         }
  428.         return $this;
  429.     }
  430.     public function getCompanyMembersWithRoles(): array
  431.     {
  432.         $membersCdP = [];
  433.         $membersNormal = [];
  434.         foreach ($this->companyMembers as $key => $member) {
  435.             if (
  436.                 in_array("ROLE_COMPANY_PILOT"$member->getUser()->getRoles())
  437.             ) {
  438.                 $membersCdP[] = $member->getName() . " (CdP)";
  439.             } else {
  440.                 $membersNormal[] = $member->getName();
  441.             }
  442.         }
  443.         $members array_merge($membersCdP$membersNormal);
  444.         return $members;
  445.     }
  446.     /**
  447.      * @return Collection<int, CompanyLabelNR>
  448.      */
  449.     public function getCompanyLabelNR(): Collection
  450.     {
  451.         return $this->companyLabelNR;
  452.     }
  453.     public function addCompanyLabelNR(CompanyLabelNR $companyLabelNR): static
  454.     {
  455.         if (!$this->companyLabelNR->contains($companyLabelNR)) {
  456.             $this->companyLabelNR->add($companyLabelNR);
  457.             $companyLabelNR->setCompany($this);
  458.         }
  459.         return $this;
  460.     }
  461.     public function removeCompanyLabelNR(CompanyLabelNR $companyLabelNR): static
  462.     {
  463.         if ($this->companyLabelNR->removeElement($companyLabelNR)) {
  464.             // set the owning side to null (unless already changed)
  465.             if ($companyLabelNR->getCompany() === $this) {
  466.                 $companyLabelNR->setCompany(null);
  467.             }
  468.         }
  469.         return $this;
  470.     }
  471.     /**
  472.      * @return Collection<int, CompanyAuditNR>
  473.      */
  474.     public function getCompanyAuditNR(): Collection
  475.     {
  476.         return $this->companyAuditNR;
  477.     }
  478.     public function addCompanyAuditNR(CompanyAuditNR $companyAuditNR): static
  479.     {
  480.         if (!$this->companyAuditNR->contains($companyAuditNR)) {
  481.             $this->companyAuditNR->add($companyAuditNR);
  482.             $companyAuditNR->setCompany($this);
  483.         }
  484.         return $this;
  485.     }
  486.     public function removeCompanyAuditNR(CompanyAuditNR $companyAuditNR): static
  487.     {
  488.         if ($this->companyAuditNR->removeElement($companyAuditNR)) {
  489.             // set the owning side to null (unless already changed)
  490.             if ($companyAuditNR->getCompany() === $this) {
  491.                 $companyAuditNR->setCompany(null);
  492.             }
  493.         }
  494.         return $this;
  495.     }
  496.     public function isLabelNR(): ?bool
  497.     {
  498.         return $this->labelNR;
  499.     }
  500.     public function setLabelNR(bool $labelNR): static
  501.     {
  502.         $this->labelNR $labelNR;
  503.         return $this;
  504.     }
  505.     public function isBilanCarbone(): ?bool
  506.     {
  507.         return $this->bilanCarbone;
  508.     }
  509.     public function setBilanCarbone(bool $bilanCarbone): static
  510.     {
  511.         $this->bilanCarbone $bilanCarbone;
  512.         return $this;
  513.     }
  514.     public function isAuditNR(): ?bool
  515.     {
  516.         return $this->auditNR;
  517.     }
  518.     public function setAuditNR(bool $auditNR): static
  519.     {
  520.         $this->auditNR $auditNR;
  521.         return $this;
  522.     }
  523.     public function getRoadmapFilters(): array
  524.     {
  525.         $filters = [];
  526.         if ($this->isAuditNR()) {
  527.             $filters[] = [
  528.                 "value" =>  "audit_nr",
  529.                 "label" =>   "Audit NR"
  530.             ];
  531.         }
  532.         if ($this->isLabelNR()) {
  533.             $filters[] = [
  534.                 "value" =>  "label_nr",
  535.                 "label" =>   "Label NR"
  536.             ];
  537.         }
  538.         if ($this->isBilanCarbone()) {
  539.             $filters[] = [
  540.                 "value" =>  "bilan_carbone",
  541.                 "label" =>   "Bilan Carbone"
  542.             ];
  543.         }
  544.         $filters array_merge($filters, [
  545.             [
  546.                 "value" =>  "other",
  547.                 "label" =>   "Autre"
  548.             ]
  549.         ]);
  550.         return $filters;
  551.     }
  552.     public function getLabelNRInfos(): ?array
  553.     {
  554.         $array = [];
  555.         foreach ($this->companyLabelNR as $key => $lnr) {
  556.             $typeLabel $lnr->getType() == "Classique" : ($lnr->getType() == "ESN" "Collectivité");
  557.             $infos $lnr->getLabelNR()->getName()  . " - " $typeLabel " - " $lnr->getCreatedAt()->format('d/m/Y');
  558.             $array[] = [
  559.                 "infos" =>  $infos,
  560.                 "id" => $lnr->getId(),
  561.             ];
  562.         }
  563.         return $array;
  564.     }
  565.     public function getAuditNRInfos(): ?array
  566.     {
  567.         $array = [];
  568.         foreach ($this->companyAuditNR as $key => $lnr) {
  569.             $typeLabel $lnr->getType() == "Classique" : ($lnr->getType() == "ESN" "Collectivité");
  570.             $infos $lnr->getLabelNR()->getName() . " - " $typeLabel " - " $lnr->getCreatedAt()->format('d/m/Y');
  571.             $array[] = [
  572.                 "infos" =>  $infos,
  573.                 "id" => $lnr->getId(),
  574.             ];
  575.         }
  576.         return $array;
  577.     }
  578.     public function getCompanyQuestionnairesInfos(): ?array
  579.     {
  580.         $array = [];
  581.         foreach ($this->companyQuestionnaires as $key => $cq) {
  582.             $array[] = [
  583.                 "questionnaire" => $cq->getQuestionnaire()->getId(),
  584.                 "thematic" => $cq->getThematic()->getId(),
  585.             ];
  586.         }
  587.         return $array;
  588.     }
  589.     public function getCompanyIndicatorThematicsInfos(): ?array
  590.     {
  591.         $array = [];
  592.         foreach ($this->companyIndicatorThematics as $key => $companyIndicatorThematic) {
  593.             if ($companyIndicatorThematic->isActive()) {
  594.                 $array[] = $companyIndicatorThematic->getThematic()->getId();
  595.             }
  596.         }
  597.         return $array;
  598.     }
  599.     public function isTraining(): ?bool
  600.     {
  601.         return $this->training;
  602.     }
  603.     public function setTraining(bool $training): static
  604.     {
  605.         $this->training $training;
  606.         return $this;
  607.     }
  608. }