improve test, modify exportInterface, use constants for ExportType keys

- add a test for 'generate' ;
- the ExportType declare keys, and those keys are used in ExportManager;
- the export interface does not require the "has form" function, and
  export form is taken into account
This commit is contained in:
2016-02-05 12:51:26 +01:00
parent fed93f47a1
commit f888b39cdb
5 changed files with 150 additions and 38 deletions

View File

@@ -60,17 +60,9 @@ interface ExportInterface extends ExportElementInterface
* @param QueryBuilder $qb
* @param array $requiredModifiers
* @param array $acl an array where each row as a `center` key containing the Chill\MainBundle\Entity\Center, and `circles` containing the reachable circles
* TODO : we should add ability to receive data from a form
* @param array $data the data from the form, if any
*/
public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, $acl);
/**
* Return wether this export has a form.
*
* @return bool
*/
public function hasForm();
public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, array $acl, array $data = array());
/**
* Inform which ModifiersInterface (i.e. AggregatorInterface, FilterInterface)

View File

@@ -32,6 +32,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Chill\MainBundle\Form\Type\Export\PickCenterType;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Chill\MainBundle\Form\Type\Export\ExportType;
/**
* Collects all agregators, filters and export from
@@ -384,14 +385,18 @@ class ExportManager
$qb = $this->em->createQueryBuilder();
$centers = $this->getPickedCenters($pickedCentersData);
$qb = $export->initiateQuery($qb, $this->retrieveUsedModifiers($data),
$this->buildCenterReachableScopes($centers, $export));
$qb = $export->initiateQuery(
$qb,
$this->retrieveUsedModifiers($data),
$this->buildCenterReachableScopes($centers, $export),
$data[ExportType::EXPORT_KEY]
);
//handle filters
$this->handleFilters($export, $qb, $data['filters'], $centers);
$this->handleFilters($export, $qb, $data[ExportType::FILTER_KEY], $centers);
//handle aggregators
$this->handleAggregators($export, $qb, $data['aggregators'], $centers);
$this->handleAggregators($export, $qb, $data[ExportType::AGGREGATOR_KEY], $centers);
$this->logger->debug('current query is '.$qb->getDQL(), array(
'class' => self::class, 'function' => __FUNCTION__
@@ -403,10 +408,10 @@ class ExportManager
$formatter = $this->getFormatter($this->getFormatterAlias($data));
$filters = array();
$aggregators = $this->retrieveUsedAggregators($data['aggregators']);
$aggregators = $this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]);
$aggregatorsData = array();
foreach($aggregators as $alias => $aggregator) {
$aggregatorsData[$alias] = $data['aggregators'][$alias]['form'];
$aggregatorsData[$alias] = $data[ExportType::AGGREGATOR_KEY][$alias]['form'];
}
return $formatter->getResponse($result, $formatterData, $exportAlias, $data,
@@ -441,7 +446,7 @@ class ExportManager
*/
public function getUsedAggregatorsAliases(array $data)
{
$aggregators = $this->retrieveUsedAggregators($data['aggregators']);
$aggregators = $this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]);
return array_keys(iterator_to_array($aggregators));
}
@@ -454,7 +459,7 @@ class ExportManager
*/
public function getFormatterAlias(array $data)
{
return $data['pick_formatter']['alias'];
return $data[ExportType::PICK_FORMATTER_KEY]['alias'];
}
/**
@@ -478,14 +483,14 @@ class ExportManager
private function retrieveUsedModifiers($data)
{
$usedTypes = array_merge(
$this->retrieveUsedFiltersType($data['filters']),
$this->retrieveUsedAggregatorsType($data['aggregators'])
$this->retrieveUsedFiltersType($data[ExportType::FILTER_KEY]),
$this->retrieveUsedAggregatorsType($data[ExportType::AGGREGATOR_KEY])
);
$this->logger->debug('Required types are '.implode(', ', $usedTypes),
array('class' => self::class, 'function' => __FUNCTION__));
return $usedTypes;
return array_unique($usedTypes);
}
/**