mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
Merge remote-tracking branch 'origin/upgrade-sf3' into upgrade-sf3
This commit is contained in:
commit
f881b3e52a
@ -413,7 +413,7 @@ class UserController extends Controller
|
|||||||
->setAction($this->generateUrl('admin_user_add_group_center',
|
->setAction($this->generateUrl('admin_user_add_group_center',
|
||||||
array('uid' => $user->getId())))
|
array('uid' => $user->getId())))
|
||||||
->setMethod('POST')
|
->setMethod('POST')
|
||||||
->add(self::FORM_GROUP_CENTER_COMPOSED, new ComposedGroupCenterType())
|
->add(self::FORM_GROUP_CENTER_COMPOSED, ComposedGroupCenterType::class)
|
||||||
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
|
->add('submit', SubmitType::class, array('label' => 'Add a new groupCenter'))
|
||||||
->getForm()
|
->getForm()
|
||||||
;
|
;
|
||||||
|
@ -26,11 +26,12 @@ use Symfony\Component\Translation\TranslatorInterface;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Chill\MainBundle\Export\ExportManager;
|
use Chill\MainBundle\Export\ExportManager;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
// command to get the report with curl : curl --user "center a_social:password" "http://localhost:8000/fr/exports/generate/count_person?export[filters][person_gender_filter][enabled]=&export[filters][person_nationality_filter][enabled]=&export[filters][person_nationality_filter][form][nationalities]=&export[aggregators][person_nationality_aggregator][order]=1&export[aggregators][person_nationality_aggregator][form][group_by_level]=country&export[submit]=&export[_token]=RHpjHl389GrK-bd6iY5NsEqrD5UKOTHH40QKE9J1edU" --globoff
|
// command to get the report with curl : curl --user "center a_social:password" "http://localhost:8000/fr/exports/generate/count_person?export[filters][person_gender_filter][enabled]=&export[filters][person_nationality_filter][enabled]=&export[filters][person_nationality_filter][form][nationalities]=&export[aggregators][person_nationality_aggregator][order]=1&export[aggregators][person_nationality_aggregator][form][group_by_level]=country&export[submit]=&export[_token]=RHpjHl389GrK-bd6iY5NsEqrD5UKOTHH40QKE9J1edU" --globoff
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
* @deprecated this formatter is not used any more.
|
* @deprecated this formatter is not used any more.
|
||||||
@ -42,49 +43,49 @@ class CSVFormatter implements FormatterInterface
|
|||||||
* @var TranslatorInterface
|
* @var TranslatorInterface
|
||||||
*/
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
protected $result;
|
protected $result;
|
||||||
|
|
||||||
protected $formatterData;
|
protected $formatterData;
|
||||||
|
|
||||||
protected $export;
|
protected $export;
|
||||||
|
|
||||||
protected $aggregators;
|
protected $aggregators;
|
||||||
|
|
||||||
protected $exportData;
|
protected $exportData;
|
||||||
|
|
||||||
protected $aggregatorsData;
|
protected $aggregatorsData;
|
||||||
|
|
||||||
protected $filtersData;
|
protected $filtersData;
|
||||||
|
|
||||||
protected $labels;
|
protected $labels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var ExportManager
|
* @var ExportManager
|
||||||
*/
|
*/
|
||||||
protected $exportManager;
|
protected $exportManager;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translator,
|
public function __construct(TranslatorInterface $translator,
|
||||||
ExportManager $manager)
|
ExportManager $manager)
|
||||||
{
|
{
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->exportManager = $manager;
|
$this->exportManager = $manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
return 'tabular';
|
return 'tabular';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'Comma separated values (CSV)';
|
return 'Comma separated values (CSV)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @uses appendAggregatorForm
|
* @uses appendAggregatorForm
|
||||||
* @param FormBuilderInterface $builder
|
* @param FormBuilderInterface $builder
|
||||||
* @param type $exportAlias
|
* @param type $exportAlias
|
||||||
@ -94,7 +95,7 @@ class CSVFormatter implements FormatterInterface
|
|||||||
{
|
{
|
||||||
$aggregators = $this->exportManager->getAggregators($aggregatorAliases);
|
$aggregators = $this->exportManager->getAggregators($aggregatorAliases);
|
||||||
$nb = count($aggregatorAliases);
|
$nb = count($aggregatorAliases);
|
||||||
|
|
||||||
foreach ($aggregators as $alias => $aggregator) {
|
foreach ($aggregators as $alias => $aggregator) {
|
||||||
$builderAggregator = $builder->create($alias, FormType::class, array(
|
$builderAggregator = $builder->create($alias, FormType::class, array(
|
||||||
'label' => $aggregator->getTitle(),
|
'label' => $aggregator->getTitle(),
|
||||||
@ -104,19 +105,19 @@ class CSVFormatter implements FormatterInterface
|
|||||||
$builder->add($builderAggregator);
|
$builder->add($builderAggregator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* append a form line by aggregator on the formatter form.
|
* append a form line by aggregator on the formatter form.
|
||||||
*
|
*
|
||||||
* This form allow to choose the aggregator position (row or column) and
|
* This form allow to choose the aggregator position (row or column) and
|
||||||
* the ordering
|
* the ordering
|
||||||
*
|
*
|
||||||
* @param FormBuilderInterface $builder
|
* @param FormBuilderInterface $builder
|
||||||
* @param string $nbAggregators
|
* @param string $nbAggregators
|
||||||
*/
|
*/
|
||||||
private function appendAggregatorForm(FormBuilderInterface $builder, $nbAggregators)
|
private function appendAggregatorForm(FormBuilderInterface $builder, $nbAggregators)
|
||||||
{
|
{
|
||||||
$builder->add('order', 'choice', array(
|
$builder->add('order', ChoiceType::class, array(
|
||||||
'choices' => array_combine(
|
'choices' => array_combine(
|
||||||
range(1, $nbAggregators),
|
range(1, $nbAggregators),
|
||||||
range(1, $nbAggregators)
|
range(1, $nbAggregators)
|
||||||
@ -124,8 +125,8 @@ class CSVFormatter implements FormatterInterface
|
|||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false
|
'expanded' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
$builder->add('position', 'choice', array(
|
$builder->add('position', ChoiceType::class, array(
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
'row' => 'r',
|
'row' => 'r',
|
||||||
'column' => 'c'
|
'column' => 'c'
|
||||||
@ -135,13 +136,13 @@ class CSVFormatter implements FormatterInterface
|
|||||||
'expanded' => false
|
'expanded' => false
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getResponse(
|
public function getResponse(
|
||||||
$result,
|
$result,
|
||||||
$formatterData,
|
$formatterData,
|
||||||
$exportAlias,
|
$exportAlias,
|
||||||
array $exportData,
|
array $exportData,
|
||||||
array $filtersData,
|
array $filtersData,
|
||||||
array $aggregatorsData
|
array $aggregatorsData
|
||||||
) {
|
) {
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
@ -153,25 +154,25 @@ class CSVFormatter implements FormatterInterface
|
|||||||
$this->aggregatorsData = $aggregatorsData;
|
$this->aggregatorsData = $aggregatorsData;
|
||||||
$this->labels = $this->gatherLabels();
|
$this->labels = $this->gatherLabels();
|
||||||
$this->filtersData = $filtersData;
|
$this->filtersData = $filtersData;
|
||||||
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->setStatusCode(200);
|
$response->setStatusCode(200);
|
||||||
$response->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
$response->headers->set('Content-Type', 'text/csv; charset=utf-8');
|
||||||
//$response->headers->set('Content-Disposition','attachment; filename="export.csv"');
|
//$response->headers->set('Content-Disposition','attachment; filename="export.csv"');
|
||||||
|
|
||||||
$response->setContent($this->generateContent());
|
$response->setContent($this->generateContent());
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ordering aggregators, preserving key association.
|
* ordering aggregators, preserving key association.
|
||||||
*
|
*
|
||||||
* This function do not mind about position.
|
* This function do not mind about position.
|
||||||
*
|
*
|
||||||
* If two aggregators have the same order, the second given will be placed
|
* If two aggregators have the same order, the second given will be placed
|
||||||
* after. This is not significant for the first ordering.
|
* after. This is not significant for the first ordering.
|
||||||
*
|
*
|
||||||
* @param type $formatterData
|
* @param type $formatterData
|
||||||
* @return type
|
* @return type
|
||||||
*/
|
*/
|
||||||
@ -179,11 +180,11 @@ class CSVFormatter implements FormatterInterface
|
|||||||
{
|
{
|
||||||
$this->formatterData = $formatterData;
|
$this->formatterData = $formatterData;
|
||||||
uasort($this->formatterData, function($a, $b) {
|
uasort($this->formatterData, function($a, $b) {
|
||||||
|
|
||||||
return ($a['order'] <= $b['order'] ? -1 : 1);
|
return ($a['order'] <= $b['order'] ? -1 : 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateContent()
|
protected function generateContent()
|
||||||
{
|
{
|
||||||
$rowKeysNb = count($this->getRowHeaders());
|
$rowKeysNb = count($this->getRowHeaders());
|
||||||
@ -195,7 +196,7 @@ class CSVFormatter implements FormatterInterface
|
|||||||
/* @var $data string[] the data of the csv file */
|
/* @var $data string[] the data of the csv file */
|
||||||
$contentData = array();
|
$contentData = array();
|
||||||
$content = array();
|
$content = array();
|
||||||
|
|
||||||
function findColumnPosition(&$columnHeaders, $columnToFind) {
|
function findColumnPosition(&$columnHeaders, $columnToFind) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach($columnHeaders as $set) {
|
foreach($columnHeaders as $set) {
|
||||||
@ -204,13 +205,13 @@ class CSVFormatter implements FormatterInterface
|
|||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//we didn't find it, adding the column
|
//we didn't find it, adding the column
|
||||||
$columnHeaders[] = $columnToFind;
|
$columnHeaders[] = $columnToFind;
|
||||||
|
|
||||||
return $i++;
|
return $i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a file pointer connected to the output stream
|
// create a file pointer connected to the output stream
|
||||||
$output = fopen('php://output', 'w');
|
$output = fopen('php://output', 'w');
|
||||||
|
|
||||||
@ -218,18 +219,18 @@ class CSVFormatter implements FormatterInterface
|
|||||||
fputcsv($output, array($this->translator->trans($this->export->getTitle())));
|
fputcsv($output, array($this->translator->trans($this->export->getTitle())));
|
||||||
//blank line
|
//blank line
|
||||||
fputcsv($output, array(""));
|
fputcsv($output, array(""));
|
||||||
|
|
||||||
// add filtering description
|
// add filtering description
|
||||||
foreach($this->gatherFiltersDescriptions() as $desc) {
|
foreach($this->gatherFiltersDescriptions() as $desc) {
|
||||||
fputcsv($output, array($desc));
|
fputcsv($output, array($desc));
|
||||||
}
|
}
|
||||||
// blank line
|
// blank line
|
||||||
fputcsv($output, array(""));
|
fputcsv($output, array(""));
|
||||||
|
|
||||||
// iterate on result to : 1. populate row headers, 2. populate column headers, 3. add result
|
// iterate on result to : 1. populate row headers, 2. populate column headers, 3. add result
|
||||||
foreach ($results as $row) {
|
foreach ($results as $row) {
|
||||||
$rowHeaders = array_slice($row, 0, $rowKeysNb);
|
$rowHeaders = array_slice($row, 0, $rowKeysNb);
|
||||||
|
|
||||||
//first line : we create line and adding them row headers
|
//first line : we create line and adding them row headers
|
||||||
if (!isset($line)) {
|
if (!isset($line)) {
|
||||||
$line = array_slice($row, 0, $rowKeysNb);
|
$line = array_slice($row, 0, $rowKeysNb);
|
||||||
@ -245,49 +246,49 @@ class CSVFormatter implements FormatterInterface
|
|||||||
/* @var $columns string[] the column for this row */
|
/* @var $columns string[] the column for this row */
|
||||||
$columns = array_slice($row, $rowKeysNb, $columnKeysNb);
|
$columns = array_slice($row, $rowKeysNb, $columnKeysNb);
|
||||||
$columnPosition = findColumnPosition($columnHeaders, $columns);
|
$columnPosition = findColumnPosition($columnHeaders, $columns);
|
||||||
|
|
||||||
//fill with blank at the position given by the columnPosition + nbRowHeaders
|
//fill with blank at the position given by the columnPosition + nbRowHeaders
|
||||||
for ($i=0; $i < $columnPosition; $i++) {
|
for ($i=0; $i < $columnPosition; $i++) {
|
||||||
if (!isset($line[$rowKeysNb + $i])) {
|
if (!isset($line[$rowKeysNb + $i])) {
|
||||||
$line[$rowKeysNb + $i] = "";
|
$line[$rowKeysNb + $i] = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$resultData = array_slice($row, $resultsKeysNb*-1);
|
$resultData = array_slice($row, $resultsKeysNb*-1);
|
||||||
foreach($resultData as $data) {
|
foreach($resultData as $data) {
|
||||||
$line[] = $data;
|
$line[] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we add the last line
|
// we add the last line
|
||||||
$contentData[] = $line;
|
$contentData[] = $line;
|
||||||
|
|
||||||
//column title headers
|
//column title headers
|
||||||
for ($i=0; $i < $columnKeysNb; $i++) {
|
for ($i=0; $i < $columnKeysNb; $i++) {
|
||||||
$line = array_fill(0, $rowKeysNb, '');
|
$line = array_fill(0, $rowKeysNb, '');
|
||||||
|
|
||||||
foreach($columnHeaders as $set) {
|
foreach($columnHeaders as $set) {
|
||||||
$line[] = $set[$i];
|
$line[] = $set[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
$content[] = $line;
|
$content[] = $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//row title headers
|
//row title headers
|
||||||
$headerLine = array();
|
$headerLine = array();
|
||||||
foreach($this->getRowHeaders() as $headerKey) {
|
foreach($this->getRowHeaders() as $headerKey) {
|
||||||
$headerLine[] = array_key_exists('_header', $this->labels[$headerKey]) ?
|
$headerLine[] = array_key_exists('_header', $this->labels[$headerKey]) ?
|
||||||
$this->labels[$headerKey]['_header'] : '';
|
$this->labels[$headerKey]['_header'] : '';
|
||||||
}
|
}
|
||||||
foreach($this->export->getQueryKeys($this->exportData) as $key) {
|
foreach($this->export->getQueryKeys($this->exportData) as $key) {
|
||||||
$headerLine[] = array_key_exists('_header', $this->labels[$key]) ?
|
$headerLine[] = array_key_exists('_header', $this->labels[$key]) ?
|
||||||
$this->labels[$key]['_header'] : '';
|
$this->labels[$key]['_header'] : '';
|
||||||
}
|
}
|
||||||
fputcsv($output, $headerLine);
|
fputcsv($output, $headerLine);
|
||||||
unset($headerLine); //free memory
|
unset($headerLine); //free memory
|
||||||
|
|
||||||
//generate CSV
|
//generate CSV
|
||||||
foreach($content as $line) {
|
foreach($content as $line) {
|
||||||
fputcsv($output, $line);
|
fputcsv($output, $line);
|
||||||
@ -295,14 +296,14 @@ class CSVFormatter implements FormatterInterface
|
|||||||
foreach($contentData as $line) {
|
foreach($contentData as $line) {
|
||||||
fputcsv($output, $line);
|
fputcsv($output, $line);
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = stream_get_contents($output);
|
$text = stream_get_contents($output);
|
||||||
fclose($output);
|
fclose($output);
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function getOrderedResults()
|
private function getOrderedResults()
|
||||||
{
|
{
|
||||||
$r = array();
|
$r = array();
|
||||||
@ -312,24 +313,24 @@ class CSVFormatter implements FormatterInterface
|
|||||||
$columnKeys = $this->getColumnHeaders();
|
$columnKeys = $this->getColumnHeaders();
|
||||||
$resultsKeys = $this->export->getQueryKeys($this->exportData);
|
$resultsKeys = $this->export->getQueryKeys($this->exportData);
|
||||||
$headers = array_merge($rowKeys, $columnKeys);
|
$headers = array_merge($rowKeys, $columnKeys);
|
||||||
|
|
||||||
foreach ($results as $row) {
|
foreach ($results as $row) {
|
||||||
$line = array();
|
$line = array();
|
||||||
foreach ($headers as $key) {
|
foreach ($headers as $key) {
|
||||||
|
|
||||||
$line[] = call_user_func($labels[$key], $row[$key]);
|
$line[] = call_user_func($labels[$key], $row[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//append result
|
//append result
|
||||||
foreach ($resultsKeys as $key) {
|
foreach ($resultsKeys as $key) {
|
||||||
$line[] = call_user_func($labels[$key], $row[$key]);
|
$line[] = call_user_func($labels[$key], $row[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$r[] = $line;
|
$r[] = $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
array_multisort($r);
|
array_multisort($r);
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,14 +339,14 @@ class CSVFormatter implements FormatterInterface
|
|||||||
{
|
{
|
||||||
return $this->getPositionnalHeaders('r');
|
return $this->getPositionnalHeaders('r');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getColumnHeaders()
|
protected function getColumnHeaders()
|
||||||
{
|
{
|
||||||
return $this->getPositionnalHeaders('c');
|
return $this->getPositionnalHeaders('c');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $position may be 'c' (column) or 'r' (row)
|
* @param string $position may be 'c' (column) or 'r' (row)
|
||||||
* @return string[]
|
* @return string[]
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
@ -359,19 +360,19 @@ class CSVFormatter implements FormatterInterface
|
|||||||
. "aggregator with alias $alias, but the export do not "
|
. "aggregator with alias $alias, but the export do not "
|
||||||
. "contains data about it");
|
. "contains data about it");
|
||||||
}
|
}
|
||||||
|
|
||||||
$aggregator = $this->aggregators[$alias];
|
$aggregator = $this->aggregators[$alias];
|
||||||
|
|
||||||
if ($data['position'] === $position) {
|
if ($data['position'] === $position) {
|
||||||
$headers = array_merge($headers, $aggregator->getQueryKeys($this->aggregatorsData[$alias]));
|
$headers = array_merge($headers, $aggregator->getQueryKeys($this->aggregatorsData[$alias]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
* @param \Chill\MainBundle\Export\AggregatorInterface[] $aggregators
|
* @param \Chill\MainBundle\Export\AggregatorInterface[] $aggregators
|
||||||
*/
|
*/
|
||||||
@ -382,14 +383,14 @@ class CSVFormatter implements FormatterInterface
|
|||||||
$this->gatherLabelsFromExport()
|
$this->gatherLabelsFromExport()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function gatherLabelsFromAggregators()
|
protected function gatherLabelsFromAggregators()
|
||||||
{
|
{
|
||||||
$labels = array();
|
$labels = array();
|
||||||
/* @var $aggretator \Chill\MainBundle\Export\AggregatorInterface */
|
/* @var $aggretator \Chill\MainBundle\Export\AggregatorInterface */
|
||||||
foreach ($this->aggregators as $alias => $aggregator) {
|
foreach ($this->aggregators as $alias => $aggregator) {
|
||||||
$keys = $aggregator->getQueryKeys($this->aggregatorsData[$alias]);
|
$keys = $aggregator->getQueryKeys($this->aggregatorsData[$alias]);
|
||||||
|
|
||||||
// gather data in an array
|
// gather data in an array
|
||||||
foreach($keys as $key) {
|
foreach($keys as $key) {
|
||||||
$values = array_map(function($row) use ($key, $alias) {
|
$values = array_map(function($row) use ($key, $alias) {
|
||||||
@ -398,57 +399,57 @@ class CSVFormatter implements FormatterInterface
|
|||||||
. "the aggregator with alias '".$alias."' but is not "
|
. "the aggregator with alias '".$alias."' but is not "
|
||||||
. "present in results");
|
. "present in results");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $row[$key];
|
return $row[$key];
|
||||||
}, $this->result);
|
}, $this->result);
|
||||||
$labels[$key] = $aggregator->getLabels($key, array_unique($values),
|
$labels[$key] = $aggregator->getLabels($key, array_unique($values),
|
||||||
$this->aggregatorsData[$alias]);
|
$this->aggregatorsData[$alias]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function gatherLabelsFromExport()
|
protected function gatherLabelsFromExport()
|
||||||
{
|
{
|
||||||
$labels = array();
|
$labels = array();
|
||||||
$export = $this->export;
|
$export = $this->export;
|
||||||
$keys = $this->export->getQueryKeys($this->exportData);
|
$keys = $this->export->getQueryKeys($this->exportData);
|
||||||
|
|
||||||
foreach($keys as $key) {
|
foreach($keys as $key) {
|
||||||
$values = array_map(function($row) use ($key, $export) {
|
$values = array_map(function($row) use ($key, $export) {
|
||||||
if (!array_key_exists($key, $row)) {
|
if (!array_key_exists($key, $row)) {
|
||||||
throw new \LogicException("the key '".$key."' is declared by "
|
throw new \LogicException("the key '".$key."' is declared by "
|
||||||
. "the export with title '".$export->getTitle()."' but is not "
|
. "the export with title '".$export->getTitle()."' but is not "
|
||||||
. "present in results");
|
. "present in results");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $row[$key];
|
return $row[$key];
|
||||||
}, $this->result);
|
}, $this->result);
|
||||||
$labels[$key] = $this->export->getLabels($key, array_unique($values),
|
$labels[$key] = $this->export->getLabels($key, array_unique($values),
|
||||||
$this->exportData);
|
$this->exportData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function gatherFiltersDescriptions()
|
public function gatherFiltersDescriptions()
|
||||||
{
|
{
|
||||||
$descriptions = array();
|
$descriptions = array();
|
||||||
|
|
||||||
foreach($this->filtersData as $key => $filterData) {
|
foreach($this->filtersData as $key => $filterData) {
|
||||||
|
|
||||||
$statement = $this->exportManager
|
$statement = $this->exportManager
|
||||||
->getFilter($key)
|
->getFilter($key)
|
||||||
->describeAction($filterData);
|
->describeAction($filterData);
|
||||||
|
|
||||||
if ($statement === null) {
|
if ($statement === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($statement)) {
|
if (is_array($statement)) {
|
||||||
$descriptions[] = $this->translator->trans(
|
$descriptions[] = $this->translator->trans(
|
||||||
$statement[0],
|
$statement[0],
|
||||||
$statement[1],
|
$statement[1],
|
||||||
isset($statement[2]) ? $statement[2] : null,
|
isset($statement[2]) ? $statement[2] : null,
|
||||||
isset($statement[3]) ? $statement[3] : null);
|
isset($statement[3]) ? $statement[3] : null);
|
||||||
@ -456,8 +457,8 @@ class CSVFormatter implements FormatterInterface
|
|||||||
$descriptions[] = $statement;
|
$descriptions[] = $statement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $descriptions;
|
return $descriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
@ -38,119 +38,119 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
* @var TranslatorInterface
|
* @var TranslatorInterface
|
||||||
*/
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var ExportManager
|
* @var ExportManager
|
||||||
*/
|
*/
|
||||||
protected $exportManager;
|
protected $exportManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result, as returned by the export
|
* The result, as returned by the export
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var type
|
* @var type
|
||||||
*/
|
*/
|
||||||
protected $result;
|
protected $result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var type
|
* @var type
|
||||||
*/
|
*/
|
||||||
protected $formatterData;
|
protected $formatterData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The export
|
* The export
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var \Chill\MainBundle\Export\ExportInterface
|
* @var \Chill\MainBundle\Export\ExportInterface
|
||||||
*/
|
*/
|
||||||
protected $export;
|
protected $export;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var type
|
* @var type
|
||||||
*/
|
*/
|
||||||
//protected $aggregators;
|
//protected $aggregators;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array containing value of export form
|
* array containing value of export form
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $exportData;
|
protected $exportData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* an array where keys are the aggregators aliases and
|
* an array where keys are the aggregators aliases and
|
||||||
* values are the data
|
* values are the data
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var type
|
* @var type
|
||||||
*/
|
*/
|
||||||
protected $aggregatorsData;
|
protected $aggregatorsData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $filtersData;
|
protected $filtersData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* replaced when `getResponse` is called.
|
* replaced when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
//protected $labels;
|
//protected $labels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* temporary file to store spreadsheet
|
* temporary file to store spreadsheet
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $tempfile;
|
protected $tempfile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache for displayable result.
|
* cache for displayable result.
|
||||||
*
|
*
|
||||||
* This cache is reset when `getResponse` is called.
|
* This cache is reset when `getResponse` is called.
|
||||||
*
|
*
|
||||||
* The array's keys are the keys in the raw result, and
|
* The array's keys are the keys in the raw result, and
|
||||||
* values are the callable which will transform the raw result to
|
* values are the callable which will transform the raw result to
|
||||||
* displayable result.
|
* displayable result.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $cacheDisplayableResult;
|
private $cacheDisplayableResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whethe `cacheDisplayableResult` is initialized or not.
|
* Whethe `cacheDisplayableResult` is initialized or not.
|
||||||
*
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $cacheDisplayableResultIsInitialized = false;
|
private $cacheDisplayableResultIsInitialized = false;
|
||||||
|
|
||||||
public function __construct(TranslatorInterface $translatorInterface, ExportManager $exportManager)
|
public function __construct(TranslatorInterface $translatorInterface, ExportManager $exportManager)
|
||||||
{
|
{
|
||||||
$this->translator = $translatorInterface;
|
$this->translator = $translatorInterface;
|
||||||
$this->exportManager = $exportManager;
|
$this->exportManager = $exportManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function buildForm(
|
public function buildForm(
|
||||||
FormBuilderInterface $builder,
|
FormBuilderInterface $builder,
|
||||||
$exportAlias,
|
$exportAlias,
|
||||||
array $aggregatorAliases
|
array $aggregatorAliases
|
||||||
) {
|
) {
|
||||||
// choosing between formats
|
// choosing between formats
|
||||||
@ -163,11 +163,11 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
'choices_as_values' => true,
|
'choices_as_values' => true,
|
||||||
'placeholder' => 'Choose the format'
|
'placeholder' => 'Choose the format'
|
||||||
));
|
));
|
||||||
|
|
||||||
// ordering aggregators
|
// ordering aggregators
|
||||||
$aggregators = $this->exportManager->getAggregators($aggregatorAliases);
|
$aggregators = $this->exportManager->getAggregators($aggregatorAliases);
|
||||||
$nb = count($aggregatorAliases);
|
$nb = count($aggregatorAliases);
|
||||||
|
|
||||||
foreach ($aggregators as $alias => $aggregator) {
|
foreach ($aggregators as $alias => $aggregator) {
|
||||||
$builderAggregator = $builder->create($alias, FormType::class, array(
|
$builderAggregator = $builder->create($alias, FormType::class, array(
|
||||||
'label' => $aggregator->getTitle(),
|
'label' => $aggregator->getTitle(),
|
||||||
@ -177,19 +177,19 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$builder->add($builderAggregator);
|
$builder->add($builderAggregator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* append a form line by aggregator on the formatter form.
|
* append a form line by aggregator on the formatter form.
|
||||||
*
|
*
|
||||||
* This form allow to choose the aggregator position (row or column) and
|
* This form allow to choose the aggregator position (row or column) and
|
||||||
* the ordering
|
* the ordering
|
||||||
*
|
*
|
||||||
* @param FormBuilderInterface $builder
|
* @param FormBuilderInterface $builder
|
||||||
* @param string $nbAggregators
|
* @param string $nbAggregators
|
||||||
*/
|
*/
|
||||||
private function appendAggregatorForm(FormBuilderInterface $builder, $nbAggregators)
|
private function appendAggregatorForm(FormBuilderInterface $builder, $nbAggregators)
|
||||||
{
|
{
|
||||||
$builder->add('order', 'choice', array(
|
$builder->add('order', ChoiceType::class, array(
|
||||||
'choices' => array_combine(
|
'choices' => array_combine(
|
||||||
range(1, $nbAggregators),
|
range(1, $nbAggregators),
|
||||||
range(1, $nbAggregators)
|
range(1, $nbAggregators)
|
||||||
@ -197,7 +197,7 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'expanded' => false
|
'expanded' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
@ -206,11 +206,11 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getResponse(
|
public function getResponse(
|
||||||
$result,
|
$result,
|
||||||
$formatterData,
|
$formatterData,
|
||||||
$exportAlias,
|
$exportAlias,
|
||||||
array $exportData,
|
array $exportData,
|
||||||
array $filtersData,
|
array $filtersData,
|
||||||
array $aggregatorsData
|
array $aggregatorsData
|
||||||
) {
|
) {
|
||||||
// store all data when the process is initiated
|
// store all data when the process is initiated
|
||||||
@ -220,46 +220,46 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$this->exportData = $exportData;
|
$this->exportData = $exportData;
|
||||||
$this->filtersData = $filtersData;
|
$this->filtersData = $filtersData;
|
||||||
$this->aggregatorsData = $aggregatorsData;
|
$this->aggregatorsData = $aggregatorsData;
|
||||||
|
|
||||||
// reset cache
|
// reset cache
|
||||||
$this->cacheDisplayableResult = array();
|
$this->cacheDisplayableResult = array();
|
||||||
$this->cacheDisplayableResultIsInitialized = false;
|
$this->cacheDisplayableResultIsInitialized = false;
|
||||||
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$response->headers->set('Content-Type',
|
$response->headers->set('Content-Type',
|
||||||
$this->getContentType($this->formatterData['format']));
|
$this->getContentType($this->formatterData['format']));
|
||||||
|
|
||||||
$this->tempfile = \tempnam(\sys_get_temp_dir(), '');
|
$this->tempfile = \tempnam(\sys_get_temp_dir(), '');
|
||||||
$this->generatecontent();
|
$this->generatecontent();
|
||||||
|
|
||||||
$f = \fopen($this->tempfile, 'r');
|
$f = \fopen($this->tempfile, 'r');
|
||||||
$response->setContent(\stream_get_contents($f));
|
$response->setContent(\stream_get_contents($f));
|
||||||
fclose($f);
|
fclose($f);
|
||||||
|
|
||||||
// remove the temp file from disk
|
// remove the temp file from disk
|
||||||
\unlink($this->tempfile);
|
\unlink($this->tempfile);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the content and write it to php://temp
|
* Generate the content and write it to php://temp
|
||||||
*/
|
*/
|
||||||
protected function generateContent()
|
protected function generateContent()
|
||||||
{
|
{
|
||||||
list($spreadsheet, $worksheet) = $this->createSpreadsheet();
|
list($spreadsheet, $worksheet) = $this->createSpreadsheet();
|
||||||
|
|
||||||
$this->addTitleToWorkSheet($worksheet);
|
$this->addTitleToWorkSheet($worksheet);
|
||||||
$line = $this->addFiltersDescription($worksheet);
|
$line = $this->addFiltersDescription($worksheet);
|
||||||
|
|
||||||
// at this point, we are going to sort retsults for an easier manipulation
|
// at this point, we are going to sort retsults for an easier manipulation
|
||||||
list($sortedResult, $exportKeys, $aggregatorKeys, $globalKeys) =
|
list($sortedResult, $exportKeys, $aggregatorKeys, $globalKeys) =
|
||||||
$this->sortResult();
|
$this->sortResult();
|
||||||
|
|
||||||
$line = $this->addHeaders($worksheet, $globalKeys, $line);
|
$line = $this->addHeaders($worksheet, $globalKeys, $line);
|
||||||
|
|
||||||
$line = $this->addContentTable($worksheet, $sortedResult, $line);
|
$line = $this->addContentTable($worksheet, $sortedResult, $line);
|
||||||
|
|
||||||
switch ($this->formatterData['format'])
|
switch ($this->formatterData['format'])
|
||||||
{
|
{
|
||||||
case 'ods':
|
case 'ods':
|
||||||
@ -279,32 +279,32 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
// throw an exception to ensure that the error is catched
|
// throw an exception to ensure that the error is catched
|
||||||
throw new \LogicException();
|
throw new \LogicException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$writer->save($this->tempfile);
|
$writer->save($this->tempfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a spreadsheet and a working worksheet
|
* Create a spreadsheet and a working worksheet
|
||||||
*
|
*
|
||||||
* @return array where 1st member is spreadsheet, 2nd is worksheet
|
* @return array where 1st member is spreadsheet, 2nd is worksheet
|
||||||
*/
|
*/
|
||||||
protected function createSpreadsheet()
|
protected function createSpreadsheet()
|
||||||
{
|
{
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// setting the worksheet title and code name
|
// setting the worksheet title and code name
|
||||||
$worksheet
|
$worksheet
|
||||||
->setTitle($this->getTitle())
|
->setTitle($this->getTitle())
|
||||||
->setCodeName('result');
|
->setCodeName('result');
|
||||||
|
|
||||||
return [$spreadsheet, $worksheet];
|
return [$spreadsheet, $worksheet];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the title to the worksheet and merge the cell containing
|
* Add the title to the worksheet and merge the cell containing
|
||||||
* the title
|
* the title
|
||||||
*
|
*
|
||||||
* @param Worksheet $worksheet
|
* @param Worksheet $worksheet
|
||||||
*/
|
*/
|
||||||
protected function addTitleToWorkSheet(Worksheet &$worksheet)
|
protected function addTitleToWorkSheet(Worksheet &$worksheet)
|
||||||
@ -312,50 +312,50 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$worksheet->setCellValue('A1', $this->getTitle());
|
$worksheet->setCellValue('A1', $this->getTitle());
|
||||||
$worksheet->mergeCells('A1:G1');
|
$worksheet->mergeCells('A1:G1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add filter description since line 3.
|
* Add filter description since line 3.
|
||||||
*
|
*
|
||||||
* return the line number after the last description
|
* return the line number after the last description
|
||||||
*
|
*
|
||||||
* @param Worksheet $worksheet
|
* @param Worksheet $worksheet
|
||||||
* @return int the line number after the last description
|
* @return int the line number after the last description
|
||||||
*/
|
*/
|
||||||
protected function addFiltersDescription(Worksheet &$worksheet)
|
protected function addFiltersDescription(Worksheet &$worksheet)
|
||||||
{
|
{
|
||||||
$line = 3;
|
$line = 3;
|
||||||
|
|
||||||
foreach ($this->filtersData as $alias => $data) {
|
foreach ($this->filtersData as $alias => $data) {
|
||||||
$filter = $this->exportManager->getFilter($alias);
|
$filter = $this->exportManager->getFilter($alias);
|
||||||
$description = $filter->describeAction($data, 'string');
|
$description = $filter->describeAction($data, 'string');
|
||||||
|
|
||||||
if (is_array($description)) {
|
if (is_array($description)) {
|
||||||
$description = $this->translator
|
$description = $this->translator
|
||||||
->trans(
|
->trans(
|
||||||
$description[0],
|
$description[0],
|
||||||
isset($description[1]) ? $description[1] : []
|
isset($description[1]) ? $description[1] : []
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$worksheet->setCellValue('A'.$line, $description);
|
$worksheet->setCellValue('A'.$line, $description);
|
||||||
$line ++;
|
$line ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $line;
|
return $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sort the results, and return an array where :
|
* sort the results, and return an array where :
|
||||||
* - 0 => sorted results
|
* - 0 => sorted results
|
||||||
* - 1 => export keys
|
* - 1 => export keys
|
||||||
* - 2 => aggregator keys
|
* - 2 => aggregator keys
|
||||||
* - 3 => global keys (aggregator keys and export keys)
|
* - 3 => global keys (aggregator keys and export keys)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Example, assuming that the result contains two aggregator keys :
|
* Example, assuming that the result contains two aggregator keys :
|
||||||
*
|
*
|
||||||
* array in result :
|
* array in result :
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* array(
|
* array(
|
||||||
* array( //row 1
|
* array( //row 1
|
||||||
@ -370,54 +370,54 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
* )
|
* )
|
||||||
* )
|
* )
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* the sorted result will be :
|
* the sorted result will be :
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* array(
|
* array(
|
||||||
* array( 2, 3, 1 ),
|
* array( 2, 3, 1 ),
|
||||||
* array( 5, 6, 4 )
|
* array( 5, 6, 4 )
|
||||||
* )
|
* )
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function sortResult()
|
protected function sortResult()
|
||||||
{
|
{
|
||||||
// get the keys for each row
|
// get the keys for each row
|
||||||
$exportKeys = $this->export->getQueryKeys($this->exportData);
|
$exportKeys = $this->export->getQueryKeys($this->exportData);
|
||||||
$aggregatorKeys = $this->getAggregatorKeysSorted();
|
$aggregatorKeys = $this->getAggregatorKeysSorted();
|
||||||
|
|
||||||
$globalKeys = \array_merge($aggregatorKeys, $exportKeys);
|
$globalKeys = \array_merge($aggregatorKeys, $exportKeys);
|
||||||
|
|
||||||
$sortedResult = \array_map(function ($row) use ($globalKeys) {
|
$sortedResult = \array_map(function ($row) use ($globalKeys) {
|
||||||
$newRow = array();
|
$newRow = array();
|
||||||
|
|
||||||
foreach ($globalKeys as $key) {
|
foreach ($globalKeys as $key) {
|
||||||
$newRow[] = $this->getDisplayableResult($key, $row[$key]);
|
$newRow[] = $this->getDisplayableResult($key, $row[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newRow;
|
return $newRow;
|
||||||
}, $this->result);
|
}, $this->result);
|
||||||
|
|
||||||
\array_multisort($sortedResult);
|
\array_multisort($sortedResult);
|
||||||
|
|
||||||
return array($sortedResult, $exportKeys, $aggregatorKeys, $globalKeys);
|
return array($sortedResult, $exportKeys, $aggregatorKeys, $globalKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get an array of aggregator keys. The keys are sorted as asked
|
* get an array of aggregator keys. The keys are sorted as asked
|
||||||
* by user in the form.
|
* by user in the form.
|
||||||
*
|
*
|
||||||
* @return string[] an array containing the keys of aggregators
|
* @return string[] an array containing the keys of aggregators
|
||||||
*/
|
*/
|
||||||
protected function getAggregatorKeysSorted()
|
protected function getAggregatorKeysSorted()
|
||||||
{
|
{
|
||||||
// empty array for aggregators keys
|
// empty array for aggregators keys
|
||||||
$keys = array();
|
$keys = array();
|
||||||
// this association between key and aggregator alias will be used
|
// this association between key and aggregator alias will be used
|
||||||
// during sorting
|
// during sorting
|
||||||
$aggregatorKeyAssociation = array();
|
$aggregatorKeyAssociation = array();
|
||||||
|
|
||||||
foreach ($this->aggregatorsData as $alias => $data) {
|
foreach ($this->aggregatorsData as $alias => $data) {
|
||||||
$aggregator = $this->exportManager->getAggregator($alias);
|
$aggregator = $this->exportManager->getAggregator($alias);
|
||||||
$aggregatorsKeys = $aggregator->getQueryKeys($data);
|
$aggregatorsKeys = $aggregator->getQueryKeys($data);
|
||||||
@ -428,12 +428,12 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$aggregatorKeyAssociation[$key] = $alias;
|
$aggregatorKeyAssociation[$key] = $alias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort the result using the form
|
// sort the result using the form
|
||||||
usort($keys, function ($a, $b) use ($aggregatorKeyAssociation) {
|
usort($keys, function ($a, $b) use ($aggregatorKeyAssociation) {
|
||||||
$A = $this->formatterData[$aggregatorKeyAssociation[$a]]['order'];
|
$A = $this->formatterData[$aggregatorKeyAssociation[$a]]['order'];
|
||||||
$B = $this->formatterData[$aggregatorKeyAssociation[$b]]['order'];
|
$B = $this->formatterData[$aggregatorKeyAssociation[$b]]['order'];
|
||||||
|
|
||||||
if ($A === $B) {
|
if ($A === $B) {
|
||||||
return 0;
|
return 0;
|
||||||
} elseif ($A > $B) {
|
} elseif ($A > $B) {
|
||||||
@ -441,18 +441,18 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $keys;
|
return $keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add headers to worksheet
|
* add headers to worksheet
|
||||||
*
|
*
|
||||||
* return the line number where the next content (i.e. result) should
|
* return the line number where the next content (i.e. result) should
|
||||||
* be appended.
|
* be appended.
|
||||||
*
|
*
|
||||||
* @param Worksheet $worksheet
|
* @param Worksheet $worksheet
|
||||||
* @param array $aggregatorKeys
|
* @param array $aggregatorKeys
|
||||||
* @param array $exportKeys
|
* @param array $exportKeys
|
||||||
@ -460,8 +460,8 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function addHeaders(
|
protected function addHeaders(
|
||||||
Worksheet &$worksheet,
|
Worksheet &$worksheet,
|
||||||
array $globalKeys,
|
array $globalKeys,
|
||||||
$line
|
$line
|
||||||
) {
|
) {
|
||||||
// get the displayable form of headers
|
// get the displayable form of headers
|
||||||
@ -471,36 +471,36 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$this->getDisplayableResult($key, '_header')
|
$this->getDisplayableResult($key, '_header')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add headers on worksheet
|
// add headers on worksheet
|
||||||
$worksheet->fromArray(
|
$worksheet->fromArray(
|
||||||
$displayables,
|
$displayables,
|
||||||
NULL,
|
NULL,
|
||||||
'A'.$line);
|
'A'.$line);
|
||||||
|
|
||||||
return $line + 1;
|
return $line + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addContentTable(Worksheet $worksheet,
|
protected function addContentTable(Worksheet $worksheet,
|
||||||
$sortedResults,
|
$sortedResults,
|
||||||
$line
|
$line
|
||||||
) {
|
) {
|
||||||
$worksheet->fromArray(
|
$worksheet->fromArray(
|
||||||
$sortedResults,
|
$sortedResults,
|
||||||
NULL,
|
NULL,
|
||||||
'A'.$line);
|
'A'.$line);
|
||||||
|
|
||||||
return $line + count($sortedResults) + 1;
|
return $line + count($sortedResults) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTitle()
|
protected function getTitle()
|
||||||
{
|
{
|
||||||
return $this->translator->trans($this->export->getTitle());
|
return $this->translator->trans($this->export->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the displayable result.
|
* Get the displayable result.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return string
|
* @return string
|
||||||
@ -510,40 +510,40 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
if ($this->cacheDisplayableResultIsInitialized === false) {
|
if ($this->cacheDisplayableResultIsInitialized === false) {
|
||||||
$this->initializeCache($key);
|
$this->initializeCache($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return call_user_func($this->cacheDisplayableResult[$key], $value);
|
return call_user_func($this->cacheDisplayableResult[$key], $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initializeCache($key)
|
protected function initializeCache($key)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* this function follows the following steps :
|
* this function follows the following steps :
|
||||||
*
|
*
|
||||||
* 1. associate all keys used in result with their export element
|
* 1. associate all keys used in result with their export element
|
||||||
* (export or aggregator) and data;
|
* (export or aggregator) and data;
|
||||||
* 2. associate all keys used in result with all the possible values :
|
* 2. associate all keys used in result with all the possible values :
|
||||||
* this array will be necessary to call `getLabels`
|
* this array will be necessary to call `getLabels`
|
||||||
* 3. store the `callable` in an associative array, in cache
|
* 3. store the `callable` in an associative array, in cache
|
||||||
*/
|
*/
|
||||||
// 1. create an associative array with key and export / aggregator
|
// 1. create an associative array with key and export / aggregator
|
||||||
$keysExportElementAssociation = array();
|
$keysExportElementAssociation = array();
|
||||||
// keys for export
|
// keys for export
|
||||||
foreach ($this->export->getQueryKeys($this->exportData) as $key) {
|
foreach ($this->export->getQueryKeys($this->exportData) as $key) {
|
||||||
$keysExportElementAssociation[$key] = [$this->export,
|
$keysExportElementAssociation[$key] = [$this->export,
|
||||||
$this->exportData];
|
$this->exportData];
|
||||||
}
|
}
|
||||||
// keys for aggregator
|
// keys for aggregator
|
||||||
foreach ($this->aggregatorsData as $alias => $data) {
|
foreach ($this->aggregatorsData as $alias => $data) {
|
||||||
$aggregator = $this->exportManager->getAggregator($alias);
|
$aggregator = $this->exportManager->getAggregator($alias);
|
||||||
|
|
||||||
foreach ($aggregator->getQueryKeys($data) as $key) {
|
foreach ($aggregator->getQueryKeys($data) as $key) {
|
||||||
$keysExportElementAssociation[$key] = [$aggregator, $data];
|
$keysExportElementAssociation[$key] = [$aggregator, $data];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. collect all the keys before iteration
|
// 2. collect all the keys before iteration
|
||||||
$keys = array_keys($keysExportElementAssociation);
|
$keys = array_keys($keysExportElementAssociation);
|
||||||
|
|
||||||
$allValues = array();
|
$allValues = array();
|
||||||
// store all the values in an array
|
// store all the values in an array
|
||||||
foreach ($this->result as $row) {
|
foreach ($this->result as $row) {
|
||||||
@ -551,18 +551,18 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$allValues[$key][] = $row[$key];
|
$allValues[$key][] = $row[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. iterate on `keysExportElementAssociation` to store the callable
|
// 3. iterate on `keysExportElementAssociation` to store the callable
|
||||||
// in cache
|
// in cache
|
||||||
foreach ($keysExportElementAssociation as $key => list($element, $data)) {
|
foreach ($keysExportElementAssociation as $key => list($element, $data)) {
|
||||||
$this->cacheDisplayableResult[$key] =
|
$this->cacheDisplayableResult[$key] =
|
||||||
$element->getLabels($key, \array_unique($allValues[$key]), $data);
|
$element->getLabels($key, \array_unique($allValues[$key]), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the cache is initialized !
|
// the cache is initialized !
|
||||||
$this->cacheDisplayableResultIsInitialized = true;
|
$this->cacheDisplayableResultIsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getContentType($format)
|
protected function getContentType($format)
|
||||||
{
|
{
|
||||||
switch ($format)
|
switch ($format)
|
||||||
|
@ -31,12 +31,13 @@ use Chill\MainBundle\Entity\User;
|
|||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
|
use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait to add an input with reachable scope for a given center and role.
|
* Trait to add an input with reachable scope for a given center and role.
|
||||||
*
|
*
|
||||||
* Example usage :
|
* Example usage :
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* class AbcType extends Symfony\Component\Form\AbstractType
|
* class AbcType extends Symfony\Component\Form\AbstractType
|
||||||
* {
|
* {
|
||||||
@ -45,9 +46,9 @@ use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
|
|||||||
* protected $translatableStringHelper;
|
* protected $translatableStringHelper;
|
||||||
* protected $user;
|
* protected $user;
|
||||||
* protected $om;
|
* protected $om;
|
||||||
*
|
*
|
||||||
* public function __construct(AuthorizationHelper $helper,
|
* public function __construct(AuthorizationHelper $helper,
|
||||||
* TokenStorageInterface $tokenStorage,
|
* TokenStorageInterface $tokenStorage,
|
||||||
* TranslatableStringHelper $translatableStringHelper,
|
* TranslatableStringHelper $translatableStringHelper,
|
||||||
* ObjectManager $om)
|
* ObjectManager $om)
|
||||||
* {
|
* {
|
||||||
@ -56,39 +57,39 @@ use Chill\MainBundle\Form\Type\DataTransformer\ScopeTransformer;
|
|||||||
* $this->translatableStringHelper = $translatableStringHelper;
|
* $this->translatableStringHelper = $translatableStringHelper;
|
||||||
* $this->om = $om;
|
* $this->om = $om;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* public function buildForm(FormBuilder $builder, array $options)
|
* public function buildForm(FormBuilder $builder, array $options)
|
||||||
* {
|
* {
|
||||||
* // ... add your form there
|
* // ... add your form there
|
||||||
*
|
*
|
||||||
* // append the scope using FormEvents: PRE_SET_DATA
|
* // append the scope using FormEvents: PRE_SET_DATA
|
||||||
* $this->appendScopeChoices($builder, $options['role'],
|
* $this->appendScopeChoices($builder, $options['role'],
|
||||||
* $options['center'], $this->user, $this->authorizationHelper,
|
* $options['center'], $this->user, $this->authorizationHelper,
|
||||||
* $this->translatableStringHelper, $this->om);
|
* $this->translatableStringHelper, $this->om);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* public function configureOptions(OptionsResolver $resolver)
|
* public function configureOptions(OptionsResolver $resolver)
|
||||||
* {
|
* {
|
||||||
* // ... add your options
|
* // ... add your options
|
||||||
*
|
*
|
||||||
* // add an option 'role' and 'center' to your form (optional)
|
* // add an option 'role' and 'center' to your form (optional)
|
||||||
* $this->appendScopeChoicesOptions($resolver);
|
* $this->appendScopeChoicesOptions($resolver);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
* @author Champs Libres <info@champs-libres.coop>
|
* @author Champs Libres <info@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
trait AppendScopeChoiceTypeTrait
|
trait AppendScopeChoiceTypeTrait
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Append a scope choice field, with the scopes reachable by given
|
* Append a scope choice field, with the scopes reachable by given
|
||||||
* user for the given role and center.
|
* user for the given role and center.
|
||||||
*
|
*
|
||||||
* The field is added on event FormEvents::PRE_SET_DATA
|
* The field is added on event FormEvents::PRE_SET_DATA
|
||||||
*
|
*
|
||||||
* @param FormBuilderInterface $builder
|
* @param FormBuilderInterface $builder
|
||||||
* @param Role $role
|
* @param Role $role
|
||||||
* @param Center $center
|
* @param Center $center
|
||||||
@ -97,29 +98,29 @@ trait AppendScopeChoiceTypeTrait
|
|||||||
* @param TranslatableStringHelper $translatableStringHelper
|
* @param TranslatableStringHelper $translatableStringHelper
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
protected function appendScopeChoices(FormBuilderInterface $builder,
|
protected function appendScopeChoices(FormBuilderInterface $builder,
|
||||||
Role $role, Center $center, User $user,
|
Role $role, Center $center, User $user,
|
||||||
AuthorizationHelper $authorizationHelper,
|
AuthorizationHelper $authorizationHelper,
|
||||||
TranslatableStringHelper $translatableStringHelper,
|
TranslatableStringHelper $translatableStringHelper,
|
||||||
ObjectManager $om, $name = 'scope')
|
ObjectManager $om, $name = 'scope')
|
||||||
{
|
{
|
||||||
$reachableScopes = $authorizationHelper
|
$reachableScopes = $authorizationHelper
|
||||||
->getReachableScopes($user, $role, $center);
|
->getReachableScopes($user, $role, $center);
|
||||||
|
|
||||||
$choices = array();
|
$choices = array();
|
||||||
foreach($reachableScopes as $scope) {
|
foreach($reachableScopes as $scope) {
|
||||||
$choices[$scope->getId()] = $translatableStringHelper
|
$choices[$scope->getId()] = $translatableStringHelper
|
||||||
->localize($scope->getName());
|
->localize($scope->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$dataTransformer = new ScopeTransformer($om);
|
$dataTransformer = new ScopeTransformer($om);
|
||||||
|
|
||||||
$builder->addEventListener(FormEvents::PRE_SET_DATA,
|
$builder->addEventListener(FormEvents::PRE_SET_DATA,
|
||||||
function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
|
function (FormEvent $event) use ($choices, $name, $dataTransformer, $builder) {
|
||||||
$form = $event->getForm();
|
$form = $event->getForm();
|
||||||
$form->add(
|
$form->add(
|
||||||
$builder
|
$builder
|
||||||
->create($name, 'choice', array(
|
->create($name, ChoiceType::class, array(
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
'auto_initialize' => false
|
'auto_initialize' => false
|
||||||
)
|
)
|
||||||
@ -129,14 +130,14 @@ trait AppendScopeChoiceTypeTrait
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a `role` and `center` option to the form.
|
* Append a `role` and `center` option to the form.
|
||||||
*
|
*
|
||||||
* The allowed types are :
|
* The allowed types are :
|
||||||
* - Chill\MainBundle\Entity\Center for center
|
* - Chill\MainBundle\Entity\Center for center
|
||||||
* - Symfony\Component\Security\Core\Role\Role for role
|
* - Symfony\Component\Security\Core\Role\Role for role
|
||||||
*
|
*
|
||||||
* @param OptionsResolver $resolver
|
* @param OptionsResolver $resolver
|
||||||
*/
|
*/
|
||||||
public function appendScopeChoicesOptions(OptionsResolver $resolver)
|
public function appendScopeChoicesOptions(OptionsResolver $resolver)
|
||||||
@ -149,5 +150,5 @@ trait AppendScopeChoiceTypeTrait
|
|||||||
))
|
))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ namespace Chill\MainBundle\Form\Type;
|
|||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
|
||||||
@ -35,12 +37,12 @@ class ComposedGroupCenterType extends AbstractType
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder->add('permissionsgroup', 'entity', array(
|
$builder->add('permissionsgroup', EntityType::class, array(
|
||||||
'class' => 'Chill\MainBundle\Entity\PermissionsGroup',
|
'class' => 'Chill\MainBundle\Entity\PermissionsGroup',
|
||||||
'choice_label' => function(PermissionsGroup $group) {
|
'choice_label' => function(PermissionsGroup $group) {
|
||||||
return $group->getName();
|
return $group->getName();
|
||||||
}
|
}
|
||||||
))->add('center', 'entity', array(
|
))->add('center', EntityType::class, array(
|
||||||
'class' => 'Chill\MainBundle\Entity\Center',
|
'class' => 'Chill\MainBundle\Entity\Center',
|
||||||
'choice_label' => function(Center $center) {
|
'choice_label' => function(Center $center) {
|
||||||
return $center->getName();
|
return $center->getName();
|
||||||
|
@ -23,11 +23,15 @@ namespace Chill\MainBundle\Form\Type;
|
|||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
use Symfony\Component\Form\FormEvents;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Security\RoleProvider;
|
use Chill\MainBundle\Security\RoleProvider;
|
||||||
use Symfony\Component\Form\FormEvent;
|
|
||||||
use Symfony\Component\Form\FormEvents;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form to Edit/create a role scope. If the role scope does not
|
* Form to Edit/create a role scope. If the role scope does not
|
||||||
@ -85,7 +89,7 @@ class ComposedRoleScopeType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('role', 'choice', array(
|
->add('role', ChoiceType::class, array(
|
||||||
'choices' => $values,
|
'choices' => $values,
|
||||||
'placeholder' => 'Choose amongst roles',
|
'placeholder' => 'Choose amongst roles',
|
||||||
'choice_attr' => function($role) use ($rolesWithoutScopes) {
|
'choice_attr' => function($role) use ($rolesWithoutScopes) {
|
||||||
@ -99,7 +103,7 @@ class ComposedRoleScopeType extends AbstractType
|
|||||||
return $this->roleProvider->getRoleTitle($role);
|
return $this->roleProvider->getRoleTitle($role);
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
->add('scope', 'entity', array(
|
->add('scope', EntityType::class, array(
|
||||||
'class' => 'ChillMainBundle:Scope',
|
'class' => 'ChillMainBundle:Scope',
|
||||||
'choice_label' => function(Scope $scope) use ($translatableStringHelper) {
|
'choice_label' => function(Scope $scope) use ($translatableStringHelper) {
|
||||||
return $translatableStringHelper->localize($scope->getName());
|
return $translatableStringHelper->localize($scope->getName());
|
||||||
@ -109,7 +113,7 @@ class ComposedRoleScopeType extends AbstractType
|
|||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$resolver->setDefault('data_class', 'Chill\MainBundle\Entity\RoleScope');
|
$resolver->setDefault('data_class', 'Chill\MainBundle\Entity\RoleScope');
|
||||||
|
@ -22,47 +22,49 @@ namespace Chill\MainBundle\Form\Type\Export;
|
|||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\ExportManager;
|
use Chill\MainBundle\Export\ExportManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Choose a formatter amongst the available formatters
|
* Choose a formatter amongst the available formatters
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
class PickFormatterType extends AbstractType
|
class PickFormatterType extends AbstractType
|
||||||
{
|
{
|
||||||
protected $exportManager;
|
protected $exportManager;
|
||||||
|
|
||||||
public function __construct(ExportManager $exportManager)
|
public function __construct(ExportManager $exportManager)
|
||||||
{
|
{
|
||||||
$this->exportManager = $exportManager;
|
$this->exportManager = $exportManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$export = $this->exportManager->getExport($options['export_alias']);
|
$export = $this->exportManager->getExport($options['export_alias']);
|
||||||
$allowedFormatters = $this->exportManager
|
$allowedFormatters = $this->exportManager
|
||||||
->getFormattersByTypes($export->getAllowedFormattersTypes());
|
->getFormattersByTypes($export->getAllowedFormattersTypes());
|
||||||
|
|
||||||
//build choices
|
//build choices
|
||||||
$choices = array();
|
$choices = array();
|
||||||
foreach($allowedFormatters as $alias => $formatter) {
|
foreach($allowedFormatters as $alias => $formatter) {
|
||||||
$choices[$formatter->getName()] = $alias;
|
$choices[$formatter->getName()] = $alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->add('alias', 'choice', array(
|
$builder->add('alias', ChoiceType::class, array(
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
'choices_as_values' => true,
|
'choices_as_values' => true,
|
||||||
'multiple' => false
|
'multiple' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
//$builder->get('type')->addModelTransformer($transformer);
|
//$builder->get('type')->addModelTransformer($transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$resolver->setRequired(array('export_alias'));
|
$resolver->setRequired(array('export_alias'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer;
|
use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends choice to allow adding select2 library on widget
|
* Extends choice to allow adding select2 library on widget
|
||||||
@ -64,7 +65,7 @@ class Select2CountryType extends AbstractType
|
|||||||
|
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
return 'select2_choice';
|
return Select2ChoiceType::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
@ -26,6 +26,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Chill\MainBundle\Form\Type\DataTransformer\MultipleObjectsToIdTransformer;
|
use Chill\MainBundle\Form\Type\DataTransformer\MultipleObjectsToIdTransformer;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends choice to allow adding select2 library on widget for languages (multiple)
|
* Extends choice to allow adding select2 library on widget for languages (multiple)
|
||||||
@ -61,7 +62,7 @@ class Select2LanguageType extends AbstractType
|
|||||||
|
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
return 'select2_choice';
|
return Select2ChoiceType::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
@ -8,6 +8,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||||||
use Symfony\Component\Validator\Constraints\Length;
|
use Symfony\Component\Validator\Constraints\Length;
|
||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
use Symfony\Component\Validator\Constraints\Regex;
|
use Symfony\Component\Validator\Constraints\Regex;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||||
|
|
||||||
class UserPasswordType extends AbstractType
|
class UserPasswordType extends AbstractType
|
||||||
{
|
{
|
||||||
@ -18,8 +20,8 @@ class UserPasswordType extends AbstractType
|
|||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('password', 'repeated', array(
|
->add('password', RepeatedType::class, array(
|
||||||
'type' => 'password',
|
'type' => PasswordType::class,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(),
|
'options' => array(),
|
||||||
'first_options' => array(
|
'first_options' => array(
|
||||||
|
@ -5,6 +5,8 @@ namespace Chill\MainBundle\Form;
|
|||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
use Chill\MainBundle\Form\UserPasswordType;
|
use Chill\MainBundle\Form\UserPasswordType;
|
||||||
|
|
||||||
class UserType extends AbstractType
|
class UserType extends AbstractType
|
||||||
@ -25,13 +27,14 @@ class UserType extends AbstractType
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
$builder->add($builder
|
$builder->add($builder
|
||||||
->create('enabled', 'choice', array(
|
->create('enabled', ChoiceType::class, array(
|
||||||
'choices' => array(
|
'choices' => array(
|
||||||
0 => 'Disabled, the user is not allowed to login',
|
'Disabled, the user is not allowed to login' => 0,
|
||||||
1 => 'Enabled, the user is active'
|
'Enabled, the user is active' => 1
|
||||||
),
|
),
|
||||||
'expanded' => false,
|
'expanded' => false,
|
||||||
'multiple' => false
|
'multiple' => false,
|
||||||
|
'choices_as_values' => true // Can be removed when upgraded to Sf3.
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -48,7 +51,7 @@ class UserType extends AbstractType
|
|||||||
|
|
||||||
$resolver
|
$resolver
|
||||||
->setDefaults(array('is_creation' => false))
|
->setDefaults(array('is_creation' => false))
|
||||||
->addAllowedValues(array('is_creation' => array(true, false)))
|
->addAllowedValues('is_creation', array(true, false))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user