diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index e3075ee02..702c050ed 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -157,10 +157,6 @@ - - Thelia\Controller\Front\Mail::test - - Thelia\Controller\Front\ContactController::sendAction diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php index 54dcc3059..54ff428ea 100644 --- a/core/lib/Thelia/Controller/Admin/OrderController.php +++ b/core/lib/Thelia/Controller/Admin/OrderController.php @@ -202,48 +202,28 @@ class OrderController extends BaseAdminController public function generateInvoicePdf($order_id) { - return $this->generatePdf($order_id, ConfigQuery::read('pdf_invoice_file', 'invoice')); + if (null !== $response = $this->checkAuth(AdminResources::ORDER, AccessManager::UPDATE)) return $response; + + return $this->generateBackOfficeOrderPdf($order_id, ConfigQuery::read('pdf_invoice_file', 'invoice')); } public function generateDeliveryPdf($order_id) - { - return $this->generatePdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery')); - } - - protected function generatePdf($order_id, $fileName) { if (null !== $response = $this->checkAuth(AdminResources::ORDER, AccessManager::UPDATE)) return $response; - $html = $this->renderRaw( - $fileName, - array( + return $this->generateBackOfficeOrderPdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery')); + } + + private function generateBackOfficeOrderPdf($order_id, $fileName) + { + if(null === $response = $this->generateOrderPdf($order_id, $fileName)){ + $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", array( 'order_id' => $order_id - ), - TemplateHelper::getInstance()->getActivePdfTemplate()->getPath() - ); - - $order = OrderQuery::create()->findPk($order_id); - - try { - $pdfEvent = new PdfEvent($html); - - $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent); - - if ($pdfEvent->hasPdf()) { - return Response::create($pdfEvent->getPdf(), 200, - array( - 'Content-type' => "application/pdf", - 'Content-Disposition' => sprintf('Attachment;filename=%s.pdf', $order->getRef()), - )); - } - - } catch (\Exception $e) { - \Thelia\Log\Tlog::getInstance()->error(sprintf('error during generating invoice pdf for order id : %d with message "%s"', $order_id, $e->getMessage())); - + )))); } - $this->redirect(URL::getInstance()->absoluteUrl($this->getRoute("admin.order.update.view", array( - 'order_id' => $order_id - )))); + return $response; } + + } diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 450f98e74..a8f7b3a63 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -22,6 +22,8 @@ /*************************************************************************************/ namespace Thelia\Controller; +use Thelia\Core\Event\PdfEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Core\HttpFoundation\Response; use Symfony\Component\DependencyInjection\ContainerAware; @@ -31,7 +33,9 @@ use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Router; use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Template\TemplateHelper; use Thelia\Core\Translation\Translator; +use Thelia\Model\OrderQuery; use Thelia\Tools\URL; use Thelia\Tools\Redirect; use Thelia\Core\Template\ParserContext; @@ -52,7 +56,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @author Manuel Raynaud */ -class BaseController extends ContainerAware +abstract class BaseController extends ContainerAware { /** @@ -73,6 +77,21 @@ class BaseController extends ContainerAware return new Response($json_data, $status, array('content-type' => 'application/json')); } + /** + * @param $pdf + * @param $fileName + * @param $status + * @return \Symfony\Component\HttpFoundation\Response + */ + protected function pdfResponse($pdf, $fileName, $status = 200) + { + return Response::create($pdf, $status, + array( + 'Content-type' => "application/pdf", + 'Content-Disposition' => sprintf('Attachment;filename=%s.pdf', $fileName), + )); + } + /** * Dispatch a Thelia event * @@ -207,6 +226,35 @@ class BaseController extends ContainerAware } } + protected function generateOrderPdf($order_id, $fileName) + { + $html = $this->renderRaw( + $fileName, + array( + 'order_id' => $order_id + ), + TemplateHelper::getInstance()->getActivePdfTemplate()->getPath() + ); + + $order = OrderQuery::create()->findPk($order_id); + + try { + $pdfEvent = new PdfEvent($html); + + $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent); + + if ($pdfEvent->hasPdf()) { + return $this->pdfResponse($pdfEvent->getPdf(), $order->getRef()); + } + + } catch (\Exception $e) { + \Thelia\Log\Tlog::getInstance()->error(sprintf('error during generating invoice pdf for order id : %d with message "%s"', $order_id, $e->getMessage())); + + } + + + } + /** * * redirect request to the specified url @@ -311,20 +359,28 @@ class BaseController extends ContainerAware } /** - * - * return an instance of SmartyParser - * - * Caution : maybe there is still not default template defined. - * - * @return ParserInterface instance parser + * @return a ParserInterface instance parser */ - protected function getParser() - { - return $this->container->get("thelia.parser"); - } + abstract protected function getParser($template = null); - protected function render($inline) - { - return $this->getParser()->fetch(sprintf("string:%s", $inline)); - } + /** + * Render the given template, and returns the result as an Http Response. + * + * @param $templateName the complete template name, with extension + * @param array $args the template arguments + * @param int $status http code status + * @return \Thelia\Core\HttpFoundation\Response + */ + abstract protected function render($templateName, $args = array(), $status = 200); + + /** + * Render the given template, and returns the result as a string. + * + * @param $templateName the complete template name, with extension + * @param array $args the template arguments + * @param null $templateDir + * + * @return string + */ + abstract protected function renderRaw($templateName, $args = array(), $templateDir = null); } diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index 003db36c4..124a91296 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -24,10 +24,13 @@ namespace Thelia\Controller\Front; use Symfony\Component\Routing\Router; use Thelia\Controller\BaseController; +use Thelia\Core\HttpFoundation\Response; +use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Core\Template\TemplateHelper; use Thelia\Model\AddressQuery; use Thelia\Model\ConfigQuery; use Thelia\Model\ModuleQuery; +use Thelia\Tools\Redirect; use Thelia\Tools\URL; class BaseFrontController extends BaseController @@ -119,7 +122,7 @@ class BaseFrontController extends BaseController * @param array $args the template arguments * @param null $templateDir * - * @return \Thelia\Core\HttpFoundation\Response + * @return string */ protected function renderRaw($templateName, $args = array(), $templateDir = null) { @@ -138,16 +141,10 @@ class BaseFrontController extends BaseController )); // Render the template. - try { - $data = $this->getParser($templateDir)->render($templateName, $args); - return $data; - } catch (AuthenticationException $ex) { - // User is not authenticated, and templates requires authentication -> redirect to login page - Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate())); - } catch (AuthorizationException $ex) { - // User is not allowed to perform the required action. Return the error page instead of the requested page. - return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action."), 403); - } + $data = $this->getParser($templateDir)->render($templateName, $args); + + return $data; + } } diff --git a/core/lib/Thelia/Controller/Front/Mail.php b/core/lib/Thelia/Controller/Front/Mail.php deleted file mode 100644 index f25024f99..000000000 --- a/core/lib/Thelia/Controller/Front/Mail.php +++ /dev/null @@ -1,48 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Thelia\Controller\Front; - -/** - * Class Mail - * @package Thelia\Controller\Front - * @author Manuel Raynaud - */ -class Mail extends BaseFrontController -{ - /** - * This is a demo how to send a mail using swiftmailer + smarty - */ - public function test() - { - $message = \Swift_Message::newInstance('Wonderful Subject') - ->setFrom(array('john@doe.com' => 'John Doe')) - ->setTo(array('mraynaud@openstudio.fr' => 'name')) - ->setBody($this->render('Here is the message itself')) - ; - - $this->getMailer()->send($message); - - exit; - } -} diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php index 38d95a1bd..997d1e2f6 100755 --- a/core/lib/Thelia/Controller/Front/OrderController.php +++ b/core/lib/Thelia/Controller/Front/OrderController.php @@ -249,45 +249,17 @@ class OrderController extends BaseFrontController public function generateInvoicePdf($order_id) { - return $this->generatePdf($order_id, ConfigQuery::read('pdf_invoice_file', 'invoice')); + /* check customer */ + $this->checkAuth(); + return $this->generateOrderPdf($order_id, ConfigQuery::read('pdf_invoice_file', 'invoice')); } public function generateDeliveryPdf($order_id) - { - return $this->generatePdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery')); - } - - protected function generatePdf($order_id, $fileName) { /* check customer */ $this->checkAuth(); - - $html = $this->renderRaw( - $fileName, - array( - 'order_id' => $order_id - ), - TemplateHelper::getInstance()->getActivePdfTemplate()->getPath() - ); - - $order = OrderQuery::create()->findPk($order_id); - - try { - $pdfEvent = new PdfEvent($html); - - $this->dispatch(TheliaEvents::GENERATE_PDF, $pdfEvent); - - if ($pdfEvent->hasPdf()) { - return Response::create($pdfEvent->getPdf(), 200, - array( - 'Content-type' => "application/pdf", - 'Content-Disposition' => sprintf('Attachment;filename=%s.pdf', $order->getRef()), - )); - } - - } catch (\Exception $e) { - \Thelia\Log\Tlog::getInstance()->error(sprintf('error during generating invoice pdf for order id : %d with message "%s"', $order_id, $e->getMessage())); - - } + return $this->generateOrderPdf($order_id, ConfigQuery::read('pdf_delivery_file', 'delivery')); } + + } diff --git a/web/test_to_remove/admin-stats.json b/web/test_to_remove/admin-stats.json deleted file mode 100644 index 220b140c4..000000000 --- a/web/test_to_remove/admin-stats.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "title" : "Stats on September 2013", - "series" : [ - { - "datas" : [[0,10.00],[1,200.00],[2,5.00],[3,2.75],[4,20.30],[5,14.09],[6,5],[7,23],[8,5],[9,42],[10,0],[11,4],[12,78],[13,75],[14,70],[15,65],[16,102],[17,50],[18,27],[19,35],[20,37],[21,29],[22,56],[23,52],[24,12],[25,6],[26,82],[27,32],[28,15],[29,50],[30,42]], - "color" : "#adadad" - }, - { - "datas" : [[0,2],[1,5],[2,5],[3,7],[4,8],[5,9],[6,5],[7,2],[8,5],[9,4],[10,0],[11,4],[12,7],[13,7],[14,7],[15,6],[16,1],[17,5],[18,2],[19,3],[20,3],[21,2],[22,5],[23,5],[24,1],[25,6],[26,8],[27,3],[28,1],[29,5],[30,4]], - "color" : "#f39922" - }, - { - "datas" : [[0,15],[1,20],[2,1],[3,1],[4,2],[5,3]], - "color" : "#5cb85c" - }, - { - "datas" : [[0,45],[1,40],[2,41],[3,41],[4,42],[5,43]], - "color" : "#5bc0de" - }, - { - "datas" : [[0,25],[1,20],[2,21],[3,21],[4,22],[5,23]], - "color" : "#d9534f" - } - ] -}