public function downloadAttachmentAction(Request $request, $id, $name)
{
$em = $this->get('em');
$attachmentService = $this->get('attachment');
$download = $request->query->get('g_download');
$showInBrowser = $request->query->get('g_show_in_browser');
$attachment = $em->getRepository('Newscoop\\Entity\\Attachment')->getAttachment($id)->getOneOrNullResult();
if (!$attachment) {
throw new ResourceNotFoundException("Attachment not found");
}
if ($download) {
$response = $this->sendFileAsAttachment($attachment, $attachmentService);
} elseif ($showInBrowser) {
$response = $this->openFileInBrowser($attachment, $attachmentService);
} else {
if ($attachment->getContentDisposition() == Attachment::CONTENT_DISPOSITION) {
$response = $this->sendFileAsAttachment($attachment, $attachmentService);
} else {
$response = $this->openFileInBrowser($attachment, $attachmentService);
}
}
return $response;
}