From fa1be795ecd1a4294b141d17986a33bf80e83b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 12 Jan 2016 17:34:15 +0100 Subject: [PATCH] add method helper on manager to simplify controller The controller does not have to handle data of the form ExportType. The ExportManager now handles those data. This is supposed to limit the number of place where the form data are handled. --- Controller/ExportController.php | 13 +++++++------ Export/ExportManager.php | 26 +++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Controller/ExportController.php b/Controller/ExportController.php index 91a8b8021..b2f3aa05c 100644 --- a/Controller/ExportController.php +++ b/Controller/ExportController.php @@ -25,11 +25,8 @@ namespace Chill\MainBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Chill\MainBundle\Form\Type\Export\ExportType; -use Chill\MainBundle\Form\Type\Export\PickFormatterType; use Chill\MainBundle\Form\Type\Export\FormatterType; use Symfony\Component\Form\Extension\Core\Type\FormType; -use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; /** @@ -108,6 +105,9 @@ class ExportController extends Controller */ protected function createCreateFormExport($alias, $step, $data = array()) { + /* @var $exportManager \Chill\MainBundle\Export\ExportManager */ + $exportManager = $this->get('chill.main.export_manager'); + $builder = $this->get('form.factory') ->createNamedBuilder(null, FormType::class, array(), array( 'method' => 'GET', @@ -125,9 +125,11 @@ class ExportController extends Controller if ($step === 'formatter') { $builder->add('formatter', FormatterType::class, array( - 'formatter_alias' => $data['export']['pick_formatter']['alias'], + 'formatter_alias' => $exportManager + ->getFormatterAlias($data['export']), 'export_alias' => $alias, - 'aggregator_aliases' => array() //TODO + 'aggregator_aliases' => $exportManager + ->getUsedAggregatorsAliases($data['export']) )); } @@ -171,7 +173,6 @@ class ExportController extends Controller if ($exportForm->isValid()) { $data = $exportForm->getData(); - $this->get('session')->set('export_step', $data); $this->get('session')->set('export_step_raw', $request->query->all()); $form = $this->createCreateFormExport($alias, diff --git a/Export/ExportManager.php b/Export/ExportManager.php index 7ac05d127..5b5741991 100644 --- a/Export/ExportManager.php +++ b/Export/ExportManager.php @@ -257,7 +257,7 @@ class ExportManager * @param mixed[] $data * @return Response */ - public function generate($exportAlias, array $data) + public function generate($exportAlias, array $data, array $formatterData) { $export = $this->getExport($exportAlias); $qb = $this->em->createQueryBuilder(); @@ -288,6 +288,30 @@ class ExportManager $filters, $aggregators, array(), $data['filters'], $aggregatorsData); } + /** + * get the aggregators typse used in the form export data + * + * @param array $data the data from the export form + * @return string[] + */ + public function getUsedAggregatorsAliases(array $data) + { + $aggregators = $this->retrieveUsedAggregators($data['aggregators']); + + return array_keys(iterator_to_array($aggregators)); + } + + /** + * get the formatter alias from the form export data + * + * @param array $data the data from the export form + * @string the formatter alias + */ + public function getFormatterAlias(array $data) + { + return $data['pick_formatter']['alias']; + } + /** * parse the data to retrieve the used filters and aggregators *