mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
improve export to add filtering parameters on result
The csv formatter now add a message about filtering parameters. The filterInterface has been adapted to render a message.
This commit is contained in:
@@ -54,6 +54,8 @@ class CSVFormatter implements FormatterInterface
|
||||
|
||||
protected $aggregatorsData;
|
||||
|
||||
protected $filtersData;
|
||||
|
||||
protected $labels;
|
||||
|
||||
/**
|
||||
@@ -133,14 +135,6 @@ class CSVFormatter implements FormatterInterface
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mixed $result
|
||||
* @param mixed $data
|
||||
* @param \Chill\MainBundle\Export\ExportInterface $export
|
||||
* @param \Chill\MainBundle\Export\FilterInterface[] $filters
|
||||
* @param \Chill\MainBundle\Export\AggregatorInterface[] $aggregators
|
||||
*/
|
||||
public function getResponse(
|
||||
$result,
|
||||
$formatterData,
|
||||
@@ -157,6 +151,7 @@ class CSVFormatter implements FormatterInterface
|
||||
$this->exportData = $exportData;
|
||||
$this->aggregatorsData = $aggregatorsData;
|
||||
$this->labels = $this->gatherLabels();
|
||||
$this->filtersData = $filtersData;
|
||||
|
||||
$response = new Response();
|
||||
$response->setStatusCode(200);
|
||||
@@ -223,6 +218,13 @@ class CSVFormatter implements FormatterInterface
|
||||
//blank line
|
||||
fputcsv($output, array(""));
|
||||
|
||||
// add filtering description
|
||||
foreach($this->gatherFiltersDescriptions() as $desc) {
|
||||
fputcsv($output, array($desc));
|
||||
}
|
||||
// blank line
|
||||
fputcsv($output, array(""));
|
||||
|
||||
// iterate on result to : 1. populate row headers, 2. populate column headers, 3. add result
|
||||
foreach ($results as $row) {
|
||||
$rowHeaders = array_slice($row, 0, $rowKeysNb);
|
||||
@@ -434,4 +436,32 @@ class CSVFormatter implements FormatterInterface
|
||||
return $labels;
|
||||
}
|
||||
|
||||
public function gatherFiltersDescriptions()
|
||||
{
|
||||
$descriptions = array();
|
||||
|
||||
foreach($this->filtersData as $key => $filterData) {
|
||||
|
||||
$statement = $this->exportManager
|
||||
->getFilter($key)
|
||||
->describeAction($filterData);
|
||||
|
||||
if ($statement === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($statement)) {
|
||||
$descriptions[] = $this->translator->trans(
|
||||
$statement[0],
|
||||
$statement[1],
|
||||
isset($statement[2]) ? $statement[2] : null,
|
||||
isset($statement[3]) ? $statement[3] : null);
|
||||
} else {
|
||||
$descriptions[] = $statement;
|
||||
}
|
||||
}
|
||||
|
||||
return $descriptions;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user