Refactor move collection

This commit is contained in:
Romain Neutron
2012-07-24 19:51:14 +02:00
parent 58e5053a8c
commit 8bebadffad

View File

@@ -14,8 +14,8 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Silex\ControllerCollection; use Silex\ControllerCollection;
use Alchemy\Phrasea\Helper\Record\MoveCollection as Helper;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Alchemy\Phrasea\Helper\Record as RecordHelper; use Alchemy\Phrasea\Helper\Record as RecordHelper;
/** /**
@@ -25,22 +25,27 @@ use Alchemy\Phrasea\Helper\Record as RecordHelper;
*/ */
class MoveCollection implements ControllerProviderInterface class MoveCollection implements ControllerProviderInterface
{ {
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->post('/', function(Application $app, Request $request) { $controllers->post('/', $this->call('displayForm'));
$request = $app['request']; $controllers->post('/apply/', $this->call('apply'));
$move = new RecordHelper\MoveCollection($app['phraseanet.core'], $app['request']);
return $controllers;
}
public function displayForm(Application $app, Request $request)
{
$move = new Helper($app['phraseanet.core'], $request);
$move->propose(); $move->propose();
return $app['twig']->render('prod/actions/collection_default.html.twig', array('action' => $move, 'message' => '')); return $app['twig']->render('prod/actions/collection_default.html.twig', array('action' => $move, 'message' => ''));
} }
);
$controllers->post('/apply/', function(Application $app, Request $request) { public function apply(Application $app, Request $request)
$move = new RecordHelper\MoveCollection($app['phraseanet.core'], $request); {
$move = new Helper($app['phraseanet.core'], $request);
$success = false; $success = false;
try { try {
@@ -58,9 +63,17 @@ class MoveCollection implements ControllerProviderInterface
'message' => $msg 'message' => $msg
); );
return new JsonResponse($datas); return $app->json($datas);
}); }
return $controllers; /**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
} }
} }