public function invoiceAction(Convention $convention, Request $request) { $registrations = $convention->getRegistrations(); $zip = new ZipArchive(); $title = $convention->getSlug(); $filename = tempnam('/tmp/', 'ritsiGA-' . $title . '-'); unlink($filename); if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) { throw new \Exception("cannot open <{$filename}>\n"); } if (false === $zip->addEmptyDir($title)) { throw new \Exception("cannot add empty dir {$title}\n"); } $route_dir = $this->container->getParameter('kernel.root_dir'); foreach ($registrations as $registration) { $single_file = $route_dir . '/../private/documents/invoices/' . $registration->getId() . '.pdf'; if (false === file_exists($single_file)) { continue; } $name = $registration->getId(); if (false === $zip->addFile($single_file, implode('/', array($title, $name . '.pdf')))) { throw new \Exception("cannot add file\n"); } } if (false === $zip->close()) { throw new \Exception("cannot close <{$filename}>\n"); } $response = new BinaryFileResponse($filename); $response->trustXSendfileTypeHeader(); $response->prepare($request); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $convention->getSlug() . '-facturas.zip', iconv('UTF-8', 'ASCII//TRANSLIT', $convention->getSlug() . '-facturas.zip')); return $response; }
/** * OrganizerRole constructor. * * @param Convention $convention */ public function __construct(Convention $convention) { $this->role = 'ROLE_RITSIGA_ORGANIZER_' . $convention->getSlug(); $this->code = $convention->getSlug(); }