hasPrivilege($this->consultation, Privileges::PRIVILEGE_VOTINGS, null)) { throw new \Exception('Missing privileges'); } $block = $this->consultation->getVotingBlock(intval($votingBlockId)); if (!$block) { throw new \Exception('Voting block not found'); } return $block; } public function actionDownloadVotingResults(string $votingBlockId, string $format): ResponseInterface { $this->handleRestHeaders(['GET'], true); try { $votingBlock = $this->getVotingBlockAndCheckAdminPermission($votingBlockId); } catch (\Exception $e) { return $this->returnRestResponseFromException($e); } $agendaVoting = AgendaVoting::getFromVotingBlock($votingBlock); $formatResponse = match ($format) { 'ods' => BinaryFileResponse::TYPE_ODS, 'xlsx' => BinaryFileResponse::TYPE_XLSX, default => BinaryFileResponse::TYPE_HTML, }; return new BinaryFileResponse( $formatResponse, $this->renderPartial('admin-download-results', ['agendaVoting' => $agendaVoting, 'format' => $format]), true, 'voting-results-' . Tools::sanitizeFilename($votingBlock->title, true) ); } }