mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
parent
5b879ae13c
commit
a182dcc1a1
@ -57,12 +57,12 @@ interface ExportInterface extends ExportElementInterface
|
|||||||
* what the user is allowed to see. (Do not show personal data the user
|
* what the user is allowed to see. (Do not show personal data the user
|
||||||
* is not allowed to see).
|
* is not allowed to see).
|
||||||
*
|
*
|
||||||
* @param QueryBuilder $qb
|
|
||||||
* @param array $requiredModifiers
|
* @param array $requiredModifiers
|
||||||
* @param array $acl an array where each row has a `center` key containing the Chill\MainBundle\Entity\Center, and `circles` keys containing the reachable circles. Example: `array( array('center' => $centerA, 'circles' => array($circleA, $circleB) ) )`
|
* @param array $acl an array where each row has a `center` key containing the Chill\MainBundle\Entity\Center, and `circles` keys containing the reachable circles. Example: `array( array('center' => $centerA, 'circles' => array($circleA, $circleB) ) )`
|
||||||
* @param array $data the data from the form, if any
|
* @param array $data the data from the form, if any
|
||||||
|
* @return the query to execute.
|
||||||
*/
|
*/
|
||||||
public function initiateQuery(QueryBuilder $qb, array $requiredModifiers, array $acl, array $data = array());
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inform which ModifiersInterface (i.e. AggregatorInterface, FilterInterface)
|
* Inform which ModifiersInterface (i.e. AggregatorInterface, FilterInterface)
|
||||||
@ -102,11 +102,11 @@ interface ExportInterface extends ExportElementInterface
|
|||||||
/**
|
/**
|
||||||
* Return the results of the query builder.
|
* Return the results of the query builder.
|
||||||
*
|
*
|
||||||
* @param QueryBuilder $qb
|
* @param QueryBuilder|\Doctrine\ORM\NativeQuery $query
|
||||||
* @param mixed[] $data the data from the export's fomr (added by self::buildForm)
|
* @param mixed[] $data the data from the export's fomr (added by self::buildForm)
|
||||||
* @return mixed[] an array of results
|
* @return mixed[] an array of results
|
||||||
*/
|
*/
|
||||||
public function getResult(QueryBuilder $qb, $data);
|
public function getResult($query, $data);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -382,36 +382,53 @@ class ExportManager
|
|||||||
public function generate($exportAlias, array $pickedCentersData, array $data, array $formatterData)
|
public function generate($exportAlias, array $pickedCentersData, array $data, array $formatterData)
|
||||||
{
|
{
|
||||||
$export = $this->getExport($exportAlias);
|
$export = $this->getExport($exportAlias);
|
||||||
$qb = $this->em->createQueryBuilder();
|
//$qb = $this->em->createQueryBuilder();
|
||||||
$centers = $this->getPickedCenters($pickedCentersData);
|
$centers = $this->getPickedCenters($pickedCentersData);
|
||||||
|
|
||||||
$qb = $export->initiateQuery(
|
$query = $export->initiateQuery(
|
||||||
$qb,
|
|
||||||
$this->retrieveUsedModifiers($data),
|
$this->retrieveUsedModifiers($data),
|
||||||
$this->buildCenterReachableScopes($centers, $export),
|
$this->buildCenterReachableScopes($centers, $export),
|
||||||
$data[ExportType::EXPORT_KEY]
|
$data[ExportType::EXPORT_KEY]
|
||||||
);
|
);
|
||||||
|
|
||||||
//handle filters
|
if ($query instanceof \Doctrine\ORM\NativeQuery) {
|
||||||
$this->handleFilters($export, $qb, $data[ExportType::FILTER_KEY], $centers);
|
// throw an error if the export require other modifier, which is
|
||||||
|
// not allowed when the export return a `NativeQuery`
|
||||||
|
if (count($export->supportsModifiers()) > 0) {
|
||||||
|
throw new \LogicException("The export with alias `$exportAlias` return "
|
||||||
|
. "a `\Doctrine\ORM\NativeQuery` and supports modifiers, which is not "
|
||||||
|
. "allowed. Either the method `supportsModifiers` should return an empty "
|
||||||
|
. "array, or return a `Doctrine\ORM\QueryBuilder`");
|
||||||
|
}
|
||||||
|
} elseif ($query instanceof QueryBuilder) {
|
||||||
|
//handle filters
|
||||||
|
$this->handleFilters($export, $query, $data[ExportType::FILTER_KEY], $centers);
|
||||||
|
|
||||||
|
//handle aggregators
|
||||||
|
$this->handleAggregators($export, $query, $data[ExportType::AGGREGATOR_KEY], $centers);
|
||||||
|
|
||||||
|
$this->logger->debug('current query is '.$query->getDQL(), array(
|
||||||
|
'class' => self::class, 'function' => __FUNCTION__
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
throw new \UnexpectedValueException("The method `intiateQuery` should return "
|
||||||
|
. "a `\Doctrine\ORM\NativeQuery` or a `Doctrine\ORM\QueryBuilder` "
|
||||||
|
. "object.");
|
||||||
|
}
|
||||||
|
|
||||||
//handle aggregators
|
$result = $export->getResult($query, $data[ExportType::EXPORT_KEY]);
|
||||||
$this->handleAggregators($export, $qb, $data[ExportType::AGGREGATOR_KEY], $centers);
|
|
||||||
|
|
||||||
// $this->logger->debug('current query is '.$qb->getDQL(), array(
|
|
||||||
// 'class' => self::class, 'function' => __FUNCTION__
|
|
||||||
// ));
|
|
||||||
|
|
||||||
$result = $export->getResult($qb, $data[ExportType::EXPORT_KEY]);
|
|
||||||
|
|
||||||
/* @var $formatter Formatter\CSVFormatter */
|
/* @var $formatter Formatter\CSVFormatter */
|
||||||
$formatter = $this->getFormatter($this->getFormatterAlias($data));
|
$formatter = $this->getFormatter($this->getFormatterAlias($data));
|
||||||
$filters = array();
|
$filters = array();
|
||||||
|
|
||||||
$aggregators = $this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]);
|
|
||||||
$aggregatorsData = array();
|
$aggregatorsData = array();
|
||||||
foreach($aggregators as $alias => $aggregator) {
|
|
||||||
$aggregatorsData[$alias] = $data[ExportType::AGGREGATOR_KEY][$alias]['form'];
|
if ($query instanceof QueryBuilder) {
|
||||||
|
$aggregators = $this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]);
|
||||||
|
|
||||||
|
foreach($aggregators as $alias => $aggregator) {
|
||||||
|
$aggregatorsData[$alias] = $data[ExportType::AGGREGATOR_KEY][$alias]['form'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $formatter->getResponse(
|
return $formatter->getResponse(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user