Split Printer provider into controller/provider

This commit is contained in:
Benoît Burnichon
2015-05-25 12:17:20 +02:00
parent 82da488ba2
commit 3864a31cc8
3 changed files with 69 additions and 32 deletions

View File

@@ -12,7 +12,6 @@
namespace Alchemy\Phrasea; namespace Alchemy\Phrasea;
use Alchemy\Geonames\GeonamesServiceProvider; use Alchemy\Geonames\GeonamesServiceProvider;
use Alchemy\Phrasea\ControllerProvider\Prod\Printer;
use Alchemy\Phrasea\ControllerProvider\Prod\Property; use Alchemy\Phrasea\ControllerProvider\Prod\Property;
use Alchemy\Phrasea\ControllerProvider\Prod\Push; use Alchemy\Phrasea\ControllerProvider\Prod\Push;
use Alchemy\Phrasea\ControllerProvider\Prod\Query; use Alchemy\Phrasea\ControllerProvider\Prod\Query;
@@ -315,6 +314,7 @@ class Application extends SilexApplication
'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret' => [], 'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret' => [],
'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection' => [], 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection' => [],
'Alchemy\Phrasea\ControllerProvider\Prod\Order' => [], 'Alchemy\Phrasea\ControllerProvider\Prod\Order' => [],
'Alchemy\Phrasea\ControllerProvider\Prod\Printer' => [],
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [], 'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [], 'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
'Alchemy\Phrasea\ControllerProvider\MediaAccessor' => [], 'Alchemy\Phrasea\ControllerProvider\MediaAccessor' => [],
@@ -632,7 +632,6 @@ class Application extends SilexApplication
$this->mount('/prod/records/', new Records()); $this->mount('/prod/records/', new Records());
$this->mount('/prod/records/property', new Property()); $this->mount('/prod/records/property', new Property());
$this->mount('/prod/push/', new Push()); $this->mount('/prod/push/', new Push());
$this->mount('/prod/printer/', new Printer());
$this->mount('/prod/share/', new Share()); $this->mount('/prod/share/', new Share());
$this->mount('/prod/TOU/', new TOU()); $this->mount('/prod/TOU/', new TOU());
$this->mount('/prod/tooltip', new Tooltip()); $this->mount('/prod/tooltip', new Tooltip());
@@ -680,6 +679,7 @@ class Application extends SilexApplication
'/prod/language' => 'Alchemy\Phrasea\ControllerProvider\Prod\Language', '/prod/language' => 'Alchemy\Phrasea\ControllerProvider\Prod\Language',
'/prod/lazaret/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret', '/prod/lazaret/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret',
'/prod/order/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Order', '/prod/order/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Order',
'/prod/printer/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Printer',
'/prod/records/edit' => 'Alchemy\Phrasea\ControllerProvider\Prod\Edit', '/prod/records/edit' => 'Alchemy\Phrasea\ControllerProvider\Prod\Edit',
'/prod/records/movecollection' => 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection', '/prod/records/movecollection' => 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection',
'/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup', '/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup',

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Helper\Record as RecordHelper;
use Alchemy\Phrasea\Out\Module\PDF as PDFExport;
use Symfony\Component\HttpFoundation\Response;
class PrinterController extends Controller
{
public function postPrinterAction(Application $app)
{
$printer = new RecordHelper\Printer($app, $app['request']);
return $app['twig']->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;
}
}

View File

@@ -11,43 +11,36 @@
namespace Alchemy\Phrasea\ControllerProvider\Prod; 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\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Alchemy\Phrasea\Helper\Record as RecordHelper; use Silex\ServiceProviderInterface;
use Alchemy\Phrasea\Out\Module\PDF as PDFExport;
use Symfony\Component\HttpFoundation\Response;
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) 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('/print.pdf', 'controller.prod.printer:printAction')
->bind('prod_printer_print');
$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');
return $controllers; return $controllers;
} }