src/Entity/Company.php line 13
<?php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CompanyRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
#[ORM\Entity(repositoryClass: CompanyRepository::class)]
class Company
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 100)]
private ?string $name = null;
#[ORM\ManyToOne(inversedBy: 'companies')]
#[ORM\JoinColumn(nullable: true)]
private ?Accompanist $accompanist = null;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: CompanyMember::class)]
private Collection $companyMembers;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: Evaluation::class, orphanRemoval: true, fetch: "EAGER")]
private Collection $evaluations;
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $enterProgram = null;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: Objective::class, orphanRemoval: true)]
private Collection $objectives;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
private ?User $lastUpdator = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $logo = null;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: CompanyQuestionnaire::class, orphanRemoval: true, fetch: "EAGER")]
private Collection $companyQuestionnaires;
private ?array $activeQuestionnaires = null;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: CompanyIndicatorThematic::class, orphanRemoval: true)]
private Collection $companyIndicatorThematics;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: Membership::class, orphanRemoval: true, fetch: "EAGER")]
private Collection $memberships;
private ?Membership $lastMembership = null;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: BCCompany::class, orphanRemoval: true, fetch: "EAGER")]
private Collection $BCCompanies;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: CompanyLabelNR::class, orphanRemoval: true)]
private Collection $companyLabelNR;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: CompanyAuditNR::class, orphanRemoval: true)]
private Collection $companyAuditNR;
#[ORM\Column]
private ?bool $labelNR = null;
#[ORM\Column]
private ?bool $bilanCarbone = null;
#[ORM\Column]
private ?bool $auditNR = null;
#[ORM\Column]
private ?bool $training = null;
public function __construct()
{
$this->companyMembers = new ArrayCollection();
$this->objectives = new ArrayCollection();
$this->enterProgram = new DateTimeImmutable();
$this->companyQuestionnaires = new ArrayCollection();
$this->companyIndicatorThematics = new ArrayCollection();
$this->memberships = new ArrayCollection();
$this->BCCompanies = new ArrayCollection();
$this->companyLabelNR = new ArrayCollection();
$this->companyAuditNR = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getMemberCount()
{
return count($this->companyMembers);
}
public function getId(): ?int
{
return $this->id;
}
public function getActiveQuestionnaires(): ?array
{
return $this->activeQuestionnaires;
}
public function setActiveQuestionnaires(array $activeQuestionnaires): self
{
$this->activeQuestionnaires = $activeQuestionnaires;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getAccompanist(): ?Accompanist
{
return $this->accompanist;
}
public function setAccompanist(?Accompanist $accompanist): self
{
$this->accompanist = $accompanist;
return $this;
}
/**
* @return Collection<int, CompanyMember>
*/
public function getCompanyMembers(): Collection
{
return $this->companyMembers;
}
public function addCompanyMember(CompanyMember $companyMember): self
{
if (!$this->companyMembers->contains($companyMember)) {
$this->companyMembers->add($companyMember);
$companyMember->setCompany($this);
}
return $this;
}
public function removeCompanyMember(CompanyMember $companyMember): self
{
if ($this->companyMembers->removeElement($companyMember)) {
// set the owning side to null (unless already changed)
if ($companyMember->getCompany() === $this) {
$companyMember->setCompany(null);
}
}
return $this;
}
public function getEnterProgram(): ?\DateTimeImmutable
{
return $this->enterProgram;
}
public function setEnterProgram(\DateTimeImmutable $enterProgram): self
{
$this->enterProgram = $enterProgram;
return $this;
}
/**
* @return Collection<int, Evaluation>
*/
public function getEvaluations(): Collection
{
return $this->evaluations;
}
public function addEvaluation(Evaluation $evaluation): self
{
if (!$this->evaluations->contains($evaluation)) {
$this->evaluations->add($evaluation);
$evaluation->setCompany($this);
}
return $this;
}
public function removeEvaluation(Evaluation $evaluation): self
{
if ($this->evaluations->removeElement($evaluation)) {
// set the owning side to null (unless already changed)
if ($evaluation->getCompany() === $this) {
$evaluation->setCompany(null);
}
}
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->add($objective);
$objective->setCompany($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->getCompany() === $this) {
$objective->setCompany(null);
}
}
return $this;
}
public function getObjectivesOngoing(): array
{
$objectives = [];
$now = new DateTimeImmutable();
foreach ($this->objectives as $key => $objective) {
if ($objective->getStatus()["status"] == "ongoing") {
$objectives[] = $objective;
}
}
return $objectives;
}
public function getObjectivesLate(): array
{
$objectives = [];
$now = new DateTimeImmutable();
foreach ($this->objectives as $key => $objective) {
if ($objective->getStatus()["status"] == "late") {
$objectives[] = $objective;
}
}
return $objectives;
}
public function getObjectivesTerminated(): array
{
$objectives = [];
foreach ($this->objectives as $key => $objective) {
if ($objective->getStatus()["status"] == "terminated") {
$objectives[] = $objective;
}
}
return $objectives;
}
public function getObjectivesPaused(): array
{
$objectives = [];
foreach ($this->objectives as $key => $objective) {
if ($objective->getStatus()["status"] == "paused") {
$objectives[] = $objective;
}
}
return $objectives;
}
public function getObjectivesNotStarted(): array
{
$objectives = [];
foreach ($this->objectives as $key => $objective) {
if ($objective->getStatus()["status"] == "notstarted") {
$objectives[] = $objective;
}
}
return $objectives;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getLastUpdator(): ?User
{
return $this->lastUpdator;
}
public function setLastUpdator(?User $lastUpdator): self
{
$this->lastUpdator = $lastUpdator;
return $this;
}
public function getLastEvaluationStrategy()
{
foreach (array_reverse($this->evaluations->toArray()) as $key => $evaluation) {
if ($evaluation->getQuestionnaire()->getName() == "Stratégie") {
return $evaluation;
}
}
return null;
}
public function getLastEvaluationIT4Green()
{
foreach (array_reverse($this->evaluations->toArray()) as $key => $evaluation) {
if ($evaluation->getQuestionnaire()->getName() == "IT4Green") {
return $evaluation;
}
}
return null;
}
public function getLastEvaluationIT4Good()
{
foreach (array_reverse($this->evaluations->toArray()) as $key => $evaluation) {
if ($evaluation->getQuestionnaire()->getName() == "IT4Good") {
return $evaluation;
}
}
return null;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
/**
* @return Collection<int, CompanyQuestionnaire>
*/
public function getCompanyQuestionnaires(): Collection
{
return $this->companyQuestionnaires;
}
public function addCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
{
if (!$this->companyQuestionnaires->contains($companyQuestionnaire)) {
$this->companyQuestionnaires->add($companyQuestionnaire);
$companyQuestionnaire->setCompany($this);
}
return $this;
}
public function removeCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
{
if ($this->companyQuestionnaires->removeElement($companyQuestionnaire)) {
// set the owning side to null (unless already changed)
if ($companyQuestionnaire->getCompany() === $this) {
$companyQuestionnaire->setCompany(null);
}
}
return $this;
}
// public function getLabelNRType(): ?string
// {
// if (!$this->getCompanyLabelNR()) {
// return "";
// } else {
// return $this->getCompanyLabelNR()->getType();
// }
// }
/**
* @return Collection<int, CompanyIndicatorThematic>
*/
public function getCompanyIndicatorThematics(): Collection
{
return $this->companyIndicatorThematics;
}
public function addCompanyIndicatorThematic(CompanyIndicatorThematic $companyIndicatorThematic): self
{
if (!$this->companyIndicatorThematics->contains($companyIndicatorThematic)) {
$this->companyIndicatorThematics->add($companyIndicatorThematic);
$companyIndicatorThematic->setCompany($this);
}
return $this;
}
public function removeCompanyIndicatorThematic(CompanyIndicatorThematic $companyIndicatorThematic): self
{
if ($this->companyIndicatorThematics->removeElement($companyIndicatorThematic)) {
// set the owning side to null (unless already changed)
if ($companyIndicatorThematic->getCompany() === $this) {
$companyIndicatorThematic->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, Membership>
*/
public function getMemberships(): Collection
{
return $this->memberships;
}
public function addMembership(Membership $membership): self
{
if (!$this->memberships->contains($membership)) {
$this->memberships->add($membership);
$membership->setCompany($this);
}
return $this;
}
public function removeMembership(Membership $membership): self
{
if ($this->memberships->removeElement($membership)) {
// set the owning side to null (unless already changed)
if ($membership->getCompany() === $this) {
$membership->setCompany(null);
}
}
return $this;
}
public function hasMemberShip(): ?bool
{
$now = new DateTimeImmutable();
$memberships = array_reverse($this->memberships->toArray());
if (count($memberships) > 0) {
$this->setLastMembership($memberships[0]);
}
foreach (array_reverse($this->memberships->toArray()) as $key => $membership) {
if ($membership->isActive() && $membership->getStartedAt() < $now && $membership->getEndAt() > $now) {
return true;
}
}
return false;
}
public function getLastMembership(): ?Membership
{
return $this->lastMembership;
}
public function setLastMembership(?Membership $lastMembership): self
{
$this->lastMembership = $lastMembership;
return $this;
}
/**
* @return Collection<int, BCCompany>
*/
public function getBCCompanies(): Collection
{
return $this->BCCompanies;
}
public function addBCCompany(BCCompany $bCCompany): self
{
if (!$this->BCCompanies->contains($bCCompany)) {
$this->BCCompanies->add($bCCompany);
$bCCompany->setCompany($this);
}
return $this;
}
public function removeBCCompany(BCCompany $bCCompany): self
{
if ($this->BCCompanies->removeElement($bCCompany)) {
// set the owning side to null (unless already changed)
if ($bCCompany->getCompany() === $this) {
$bCCompany->setCompany(null);
}
}
return $this;
}
public function getCompanyMembersWithRoles(): array
{
$membersCdP = [];
$membersNormal = [];
foreach ($this->companyMembers as $key => $member) {
if (
in_array("ROLE_COMPANY_PILOT", $member->getUser()->getRoles())
) {
$membersCdP[] = $member->getName() . " (CdP)";
} else {
$membersNormal[] = $member->getName();
}
}
$members = array_merge($membersCdP, $membersNormal);
return $members;
}
/**
* @return Collection<int, CompanyLabelNR>
*/
public function getCompanyLabelNR(): Collection
{
return $this->companyLabelNR;
}
public function addCompanyLabelNR(CompanyLabelNR $companyLabelNR): static
{
if (!$this->companyLabelNR->contains($companyLabelNR)) {
$this->companyLabelNR->add($companyLabelNR);
$companyLabelNR->setCompany($this);
}
return $this;
}
public function removeCompanyLabelNR(CompanyLabelNR $companyLabelNR): static
{
if ($this->companyLabelNR->removeElement($companyLabelNR)) {
// set the owning side to null (unless already changed)
if ($companyLabelNR->getCompany() === $this) {
$companyLabelNR->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, CompanyAuditNR>
*/
public function getCompanyAuditNR(): Collection
{
return $this->companyAuditNR;
}
public function addCompanyAuditNR(CompanyAuditNR $companyAuditNR): static
{
if (!$this->companyAuditNR->contains($companyAuditNR)) {
$this->companyAuditNR->add($companyAuditNR);
$companyAuditNR->setCompany($this);
}
return $this;
}
public function removeCompanyAuditNR(CompanyAuditNR $companyAuditNR): static
{
if ($this->companyAuditNR->removeElement($companyAuditNR)) {
// set the owning side to null (unless already changed)
if ($companyAuditNR->getCompany() === $this) {
$companyAuditNR->setCompany(null);
}
}
return $this;
}
public function isLabelNR(): ?bool
{
return $this->labelNR;
}
public function setLabelNR(bool $labelNR): static
{
$this->labelNR = $labelNR;
return $this;
}
public function isBilanCarbone(): ?bool
{
return $this->bilanCarbone;
}
public function setBilanCarbone(bool $bilanCarbone): static
{
$this->bilanCarbone = $bilanCarbone;
return $this;
}
public function isAuditNR(): ?bool
{
return $this->auditNR;
}
public function setAuditNR(bool $auditNR): static
{
$this->auditNR = $auditNR;
return $this;
}
public function getRoadmapFilters(): array
{
$filters = [];
if ($this->isAuditNR()) {
$filters[] = [
"value" => "audit_nr",
"label" => "Audit NR"
];
}
if ($this->isLabelNR()) {
$filters[] = [
"value" => "label_nr",
"label" => "Label NR"
];
}
if ($this->isBilanCarbone()) {
$filters[] = [
"value" => "bilan_carbone",
"label" => "Bilan Carbone"
];
}
$filters = array_merge($filters, [
[
"value" => "other",
"label" => "Autre"
]
]);
return $filters;
}
public function getLabelNRInfos(): ?array
{
$array = [];
foreach ($this->companyLabelNR as $key => $lnr) {
$typeLabel = $lnr->getType() == 0 ? "Classique" : ($lnr->getType() == 1 ? "ESN" : "Collectivité");
$infos = $lnr->getLabelNR()->getName() . " - " . $typeLabel . " - " . $lnr->getCreatedAt()->format('d/m/Y');
$array[] = [
"infos" => $infos,
"id" => $lnr->getId(),
];
}
return $array;
}
public function getAuditNRInfos(): ?array
{
$array = [];
foreach ($this->companyAuditNR as $key => $lnr) {
$typeLabel = $lnr->getType() == 0 ? "Classique" : ($lnr->getType() == 1 ? "ESN" : "Collectivité");
$infos = $lnr->getLabelNR()->getName() . " - " . $typeLabel . " - " . $lnr->getCreatedAt()->format('d/m/Y');
$array[] = [
"infos" => $infos,
"id" => $lnr->getId(),
];
}
return $array;
}
public function getCompanyQuestionnairesInfos(): ?array
{
$array = [];
foreach ($this->companyQuestionnaires as $key => $cq) {
$array[] = [
"questionnaire" => $cq->getQuestionnaire()->getId(),
"thematic" => $cq->getThematic()->getId(),
];
}
return $array;
}
public function getCompanyIndicatorThematicsInfos(): ?array
{
$array = [];
foreach ($this->companyIndicatorThematics as $key => $companyIndicatorThematic) {
if ($companyIndicatorThematic->isActive()) {
$array[] = $companyIndicatorThematic->getThematic()->getId();
}
}
return $array;
}
public function isTraining(): ?bool
{
return $this->training;
}
public function setTraining(bool $training): static
{
$this->training = $training;
return $this;
}
}