'931572', 1 => 'C2981A', 2 => '003882', 3 => '27AAE1', 4 => '2BB673']; public function __construct( private readonly OrganizationRepository $organizationRepository ) { } public function support(ExportRequest $exportRequest): bool { return $exportRequest instanceof LicenceCmfOrganizationER; } /** * @param LicenceCmfOrganizationER $exportRequest */ public function buildModel(ExportRequest $exportRequest): LicenceCmfCollection { $organization = $this->accessRepository->find($exportRequest->getRequesterId())?->getOrganization(); if ($organization === null) { throw new \RuntimeException('Unable to determine the organization of the curent user; abort.'); } $licenceCmf = new LicenceCmf(); $licenceCmf->setId($organization->getId()); $licenceCmf->setYear($exportRequest->getYear()); $licenceCmf->setIsOrganizationLicence($exportRequest instanceof LicenceCmfOrganizationER); $licenceCmf->setOrganizationName($organization->getName()); $licenceCmf->setOrganizationIdentifier($organization->getIdentifier()); $parentFederation = $organization->getNetworkOrganizations()->get(0)?->getParent(); if ($parentFederation !== null) { $licenceCmf->setFederationName($parentFederation->getName()); } $licenceCmf->setColor( $this->getLicenceColor($exportRequest->getYear()) ); $logo = $organization->getLogo(); if ($logo) { $licenceCmf->setLogo($logo); } $presidents = $this->accessRepository->findByOrganizationAndMission($organization, FunctionEnum::PRESIDENT); if (count($presidents) > 0) { $president = $presidents[0]->getPerson(); if ($president !== null) { $licenceCmf->setPersonId($president->getId()); $licenceCmf->setPersonGender($president->getGender() ?? null); $licenceCmf->setPersonFirstName($president->getGivenName()); $licenceCmf->setPersonLastName($president->getName()); } } $cmf = $this->organizationRepository->find(self::CMF_ID); /** @noinspection NullPointerExceptionInspection */ $qrCode = $cmf->getParameters()->getQrCode(); if ($qrCode) { $licenceCmf->setQrCode($qrCode); } $model = new LicenceCmfCollection(); $model->setLicences([$licenceCmf]); return $model; } /** * @param LicenceCmfOrganizationER $exportRequest */ protected function getFileBasename(ExportRequest $exportRequest): string { return 'licence_cmf_'.$exportRequest->getYear().'.pdf'; } /** * Retourne le type de fichier tel qu'il apparait au niveau du champ File.type. */ protected function getFileType(): FileTypeEnum { return FileTypeEnum::LICENCE_CMF; } /** * Retourne la couleur de licence pour l'année donnée. */ protected function getLicenceColor(int $year): string { if (!($year > self::LICENCE_CMF_COLOR_START_YEAR)) { return self::LICENCE_CMF_COLOR[0]; } return self::LICENCE_CMF_COLOR[($year - self::LICENCE_CMF_COLOR_START_YEAR) % count(self::LICENCE_CMF_COLOR)]; } }