'931572', 1 => 'C2981A', 2 => '003882', 3 => '27AAE1', 4 => '2BB673']; public function __construct( private OrganizationRepository $organizationRepository, private AccessRepository $accessRepository, private Environment $twig, private EncoderHandler $encoderHandler ) {} public function support($exportRequest): bool { return $exportRequest instanceof LicenceCmfOrganizationER; } /** * */ public function export($exportRequest) { $organization = $exportRequest->getRequester()->getOrganization(); $currentYear = (int)date('Y'); $model = new LicenceCmf(); $model->setId($organization->getId()); $model->setYear($currentYear); $model->setOrganizationName($organization->getName()); $model->setOrganizationIdentifier($organization->getIdentifier()); $parentFederation = $organization->getNetworkOrganizations()[0]->getParent(); $model->setFederationName($parentFederation->getName()); $model->setColor( $this->getLicenceColor($currentYear) ); $logoId = $organization->getLogo()?->getId(); if ($logoId) { $model->setLogoUri( rtrim($_SERVER['INTERNAL_FILES_DOWNLOAD_URI'], '/') . '/' . $logoId ); } $presidents = $this->accessRepository->findByOrganizationAndMission($organization, FunctionEnum::PRESIDENT()->getValue()); if (count($presidents) > 0) { $president = $presidents[0]->getPerson(); $model->setPersonId($president->getId()); $model->setPersonGender($president->getGender()); $model->setPersonFirstName($president->getGivenName()); $model->setPersonLastName($president->getName()); } $cmf = $this->organizationRepository->find(self::CMF_ID); $qrCodeId = $cmf->getParameters()?->getQrCode()?->getId(); if ($qrCodeId) { $model->setQrCodeUri( rtrim($_SERVER['INTERNAL_FILES_DOWNLOAD_URI'], '/') . '/' . $qrCodeId ); } $html = $this->twig->render( '@templates/export/licence_cmf.html.twig', [ 'models' => [$model], 'isOrganizationLicence' => true ] ); $filename = 'licence_cmf_' . $currentYear . '.pdf'; $tempDir = TemporaryFileStorage::makeStorageDirFor($organization->getId()); $tempPath = Path::join($tempDir, $filename); if (file_exists($tempPath)) { unlink($tempPath); } $encoder = $this->encoderHandler->getEncoderFor($exportRequest); $encoder->encodeToFile($html, $tempPath); } /** * Retourne la couleur de licence pour l'année donnée * @param int $year * @return string */ protected function getLicenceColor(int $year): string { if (!self::LICENCE_CMF_COLOR_START_YEAR > $year) { return self::LICENCE_CMF_COLOR[0]; } return self::LICENCE_CMF_COLOR[($year - self::LICENCE_CMF_COLOR_START_YEAR) % count(self::LICENCE_CMF_COLOR)]; } }