diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index a812f2f267..e309da1b3e 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -12,7 +12,6 @@ namespace Alchemy\Phrasea; use Alchemy\Geonames\GeonamesServiceProvider; -use Alchemy\Phrasea\ControllerProvider\Prod\Printer; use Alchemy\Phrasea\ControllerProvider\Prod\Property; use Alchemy\Phrasea\ControllerProvider\Prod\Push; use Alchemy\Phrasea\ControllerProvider\Prod\Query; @@ -315,6 +314,7 @@ class Application extends SilexApplication 'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret' => [], 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection' => [], 'Alchemy\Phrasea\ControllerProvider\Prod\Order' => [], + 'Alchemy\Phrasea\ControllerProvider\Prod\Printer' => [], 'Alchemy\Phrasea\ControllerProvider\Datafiles' => [], 'Alchemy\Phrasea\ControllerProvider\Lightbox' => [], 'Alchemy\Phrasea\ControllerProvider\MediaAccessor' => [], @@ -632,7 +632,6 @@ class Application extends SilexApplication $this->mount('/prod/records/', new Records()); $this->mount('/prod/records/property', new Property()); $this->mount('/prod/push/', new Push()); - $this->mount('/prod/printer/', new Printer()); $this->mount('/prod/share/', new Share()); $this->mount('/prod/TOU/', new TOU()); $this->mount('/prod/tooltip', new Tooltip()); @@ -680,6 +679,7 @@ class Application extends SilexApplication '/prod/language' => 'Alchemy\Phrasea\ControllerProvider\Prod\Language', '/prod/lazaret/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret', '/prod/order/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Order', + '/prod/printer/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Printer', '/prod/records/edit' => 'Alchemy\Phrasea\ControllerProvider\Prod\Edit', '/prod/records/movecollection' => 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection', '/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup', diff --git a/lib/Alchemy/Phrasea/Controller/Prod/PrinterController.php b/lib/Alchemy/Phrasea/Controller/Prod/PrinterController.php new file mode 100644 index 0000000000..1d23606c37 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Prod/PrinterController.php @@ -0,0 +1,44 @@ +render('prod/actions/printer_default.html.twig', ['printer' => $printer, 'message' => '']); + } + + public function printAction(Application $app) + { + $printer = new RecordHelper\Printer($app, $app['request']); + + $layout = $app['request']->request->get('lay'); + + foreach ($printer->get_elements() as $record) { + $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_PRINT, $layout, ''); + } + $PDF = new PDFExport($app, $printer->get_elements(), $layout); + + $response = new Response($PDF->render(), 200, array('Content-Type' => 'application/pdf')); + $response->headers->set('Pragma', 'public', true); + $response->setMaxAge(0); + + return $response; + } +} diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Printer.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Printer.php index 2dfdea170a..32e2548c4b 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Printer.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Printer.php @@ -11,43 +11,36 @@ namespace Alchemy\Phrasea\ControllerProvider\Prod; +use Alchemy\Phrasea\Application as PhraseaApplication; +use Alchemy\Phrasea\Controller\Prod\PrinterController; +use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait; use Silex\Application; use Silex\ControllerProviderInterface; -use Alchemy\Phrasea\Helper\Record as RecordHelper; -use Alchemy\Phrasea\Out\Module\PDF as PDFExport; -use Symfony\Component\HttpFoundation\Response; +use Silex\ServiceProviderInterface; -class Printer implements ControllerProviderInterface +class Printer implements ControllerProviderInterface, ServiceProviderInterface { + use ControllerProviderTrait; + + public function register(Application $app) + { + $app['controller.prod.printer'] = $app->share(function (PhraseaApplication $app) { + return (new PrinterController($app)); + }); + } + + public function boot(Application $app) + { + // no-op + } + public function connect(Application $app) { - $app['controller.prod.printer'] = $this; + $controllers = $this->createCollection($app); + $controllers->post('/', 'controller.prod.printer:postPrinterAction'); - $controllers = $app['controllers_factory']; - - $controllers->post('/', function (Application $app) { - $printer = new RecordHelper\Printer($app, $app['request']); - - return $app['twig']->render('prod/actions/printer_default.html.twig', ['printer' => $printer, 'message' => '']); - } - ); - - $controllers->post('/print.pdf', function (Application $app) { - $printer = new RecordHelper\Printer($app, $app['request']); - - $layout = $app['request']->request->get('lay'); - - foreach ($printer->get_elements() as $record) { - $app['phraseanet.logger']($record->get_databox())->log($record, \Session_Logger::EVENT_PRINT, $layout, ''); - } - $PDF = new PDFExport($app, $printer->get_elements(), $layout); - - $response = new Response($PDF->render(), 200, array('Content-Type' => 'application/pdf')); - $response->headers->set('Pragma', 'public', true); - $response->setMaxAge(0); - - return $response; - })->bind('prod_printer_print'); + $controllers->post('/print.pdf', 'controller.prod.printer:printAction') + ->bind('prod_printer_print'); return $controllers; }