'931572', 1 => 'C2981A', 2 => '003882', 3 => '27AAE1', 4 => '2BB673']; public function __construct( private OrganizationRepository $organizationRepository ) {} public function support($exportRequest): bool { return $exportRequest instanceof LicenceCmfOrganizationER; } protected 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->setLogoUri( $this->storage->getDownloadIri($logo) ); } $presidents = $this->accessRepository->findByOrganizationAndMission($organization, FunctionEnum::PRESIDENT()->getValue()); if (count($presidents) > 0) { $president = $presidents[0]->getPerson(); $licenceCmf->setPersonId($president->getId()); $licenceCmf->setPersonGender($president->getGender() ?? ''); $licenceCmf->setPersonFirstName($president->getGivenName()); $licenceCmf->setPersonLastName($president->getName()); } $cmf = $this->organizationRepository->find(self::CMF_ID); /** @noinspection NullPointerExceptionInspection */ $qrCode = $cmf->getParameters()?->getQrCode(); if ($qrCode) { $licenceCmf->setQrCodeUri( $this->storage->getDownloadIri($qrCode) ); } $model = new LicenceCmfCollection(); $model->setLicences([$licenceCmf]); return $model; } /** * @param ExportRequest $exportRequest * @return string */ 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 * * @return FileTypeEnum */ protected function getFileType(): FileTypeEnum { return FileTypeEnum::LICENCE_CMF(); } /** * Retourne la couleur de licence pour l'année donnée * * @param int $year * @return string */ 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)]; } }