public function downloadAction(Application $app, Request $request, $fileId)
 {
     $repo = $app->getFileRepository();
     $file = $repo->getById($fileId);
     $response = new BinaryFileResponse($file->getPath());
     $response->prepare(Request::createFromGlobals());
     $response->send();
 }
Exemplo n.º 2
0
 public function crearReciboCajaMenorAction(Request $peticion)
 {
     $formulario = $this->createForm(new ReciboCajaMenorType());
     $formulario->handleRequest($peticion);
     if ($formulario->isValid()) {
         $kernel = $this->get('kernel');
         //Se carga la plantilla
         $path = $kernel->locateResource('@FacturaBundle/Template/caja_menor_template.docx');
         $plantilla = new TemplateProcessor($path);
         $datos = $formulario->getData();
         //Se carga el archivo el valor del consecutivo
         $path = $kernel->locateResource('@FacturaBundle/Resources/config/consecutivos.yml');
         $consecutivo = null;
         $value = null;
         try {
             $value = Yaml::parse(file_get_contents($path));
             $consecutivo = $value['consecutivo_caja_menor'];
         } catch (ParseException $e) {
             printf("Problemas con el string: %s", $e->getMessage());
         }
         //Se aumenta el valor del consecutivo almacenado
         $value['consecutivo_caja_menor'] += 1;
         $yaml = Yaml::dump($value);
         file_put_contents($path, $yaml);
         // Se setea el consecutivo
         $plantilla->setValue('consecutivo', $consecutivo);
         //Se setean los datos que estaban en el formulario
         foreach ($datos as $clave => $dato) {
             if ($clave != 'fecha') {
                 $plantilla->setValue($clave, $dato);
             } else {
                 $plantilla->setValue($clave, $dato->format('d/m/Y'));
             }
         }
         //Se almacena la suma en letras
         $conversor = $this->get('numeroLetras');
         $numeroEnLetras = $conversor->numtoletras($datos['valor']);
         $plantilla->setValue('valor_letras', $numeroEnLetras);
         $plantilla->saveAs('descargas/temp.docx');
         //Se manda a guardar al cliente
         $file = 'descargas/temp.docx';
         $response = new BinaryFileResponse($file);
         $response->prepare($peticion);
         $response->send();
     }
     return $this->render('FacturaBundle:Default:creacionReciboCajaMenor.html.twig', array('formulario' => $formulario->createView()));
 }
Exemplo n.º 3
0
 public function download($send = true)
 {
     $this->isAllowedResponse();
     $response = new BinaryFileResponse($this->combined_filename, Response::HTTP_OK, ['content-type' => 'audio/mpeg'], true, 'attachment');
     return $send === true ? $response->send() : $response;
 }