public function invoiceAction(Convention $convention, Request $request) { $registrations = $convention->getRegistrations(); $zip = new ZipArchive(); $title = $convention->getDomain(); $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->getDomain() . '-facturas.zip', iconv('UTF-8', 'ASCII//TRANSLIT', $convention->getDomain() . '-facturas.zip')); return $response; }
/** * Returns the base url of a convention * * * @param Convention $convention * @return string */ public function conventionURL(Convention $convention) { $request = $this->requestStack->getCurrentRequest(); $domain = $convention->getDomain(); $url = str_replace('http://', '', $request->getUri()); $url_complete = "http://" . $domain . "." . $url; return $url_complete; }
/** * OrganizerRole constructor. * @param Convention $convention */ public function __construct(Convention $convention) { $this->role = 'ROLE_RITSIGA_ORGANIZER_' . strtoupper($convention->getDomain()); }