58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\AdminBundle\Controller;
|
|
|
|
use KupShop\AdminBundle\AdminRequiredControllerInterface;
|
|
use KupShop\KupShopBundle\Routing\AdminRoute;
|
|
use KupShop\KupShopBundle\Util\System\PathFinder;
|
|
use KupShop\OrderingBundle\Attachment\BaseAttachment;
|
|
use KupShop\OrderingBundle\Exception\InvoiceException;
|
|
use KupShop\OrderingBundle\Exception\UnknownAttachmentTypeException;
|
|
use KupShop\OrderingBundle\Util\Attachment\AttachmentLocator;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class EmailAttachmentController extends AbstractController implements AdminRequiredControllerInterface
|
|
{
|
|
/**
|
|
* @AdminRoute("/email_attachment/{id_order}/{type}/")
|
|
*/
|
|
public function adminAttachmentAction(AttachmentLocator $attachmentLocator, PathFinder $pathFinder, $id_order, $type)
|
|
{
|
|
$order = new \Order();
|
|
$order->createFromDB($id_order);
|
|
if ($order->order_no === null) {
|
|
return new Response('Neexistujici objednavka');
|
|
}
|
|
|
|
try {
|
|
increaseMaxExecutionTime(60);
|
|
$attachment = $attachmentLocator->getServiceByType($type, $order);
|
|
|
|
$response = new Response();
|
|
$response->headers->set('Content-Type', $attachment->getMimeType());
|
|
$response->headers->set('Content-Disposition', 'inline; filename="'.$attachment->getFilename().'"');
|
|
$content = $attachment->getContent();
|
|
if (!$content) {
|
|
throw new \UnexpectedValueException('PDF error: server returned false');
|
|
}
|
|
|
|
if ($attachment->getAttachmentType() == BaseAttachment::TYPE_PATH) {
|
|
$content = file_get_contents($content);
|
|
}
|
|
|
|
$response->setContent($content);
|
|
|
|
return $response;
|
|
} catch (UnknownAttachmentTypeException $e) {
|
|
return new Response('Neexistujici typ prilohy');
|
|
} catch (\UnexpectedValueException $e) {
|
|
getRaven()->captureException($e);
|
|
|
|
return new Response('Přílohu se nepodařilo vygenerovat, zkuste to znovu.');
|
|
} catch (InvoiceException $e) {
|
|
return new Response($e->getMessage());
|
|
}
|
|
}
|
|
}
|