[report list] fix "all fields are always shown"

This commit is contained in:
Julien Fastré 2018-09-12 10:57:55 +02:00
parent 6d8d99c572
commit 67d62e8d03
2 changed files with 16 additions and 1 deletions

6
CHANGELOG.md Normal file
View File

@ -0,0 +1,6 @@
Branch master
=============
- [list export] fix error "all custom fields are shown"

View File

@ -447,11 +447,14 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
$qb = $this->em->createQueryBuilder();
// process fields which are not custom fields
foreach ($this->fields as $f) {
// do not add fields which are not selected
if (!\in_array($f, $data['fields'])) {
continue;
}
// add a column to the query for each field
switch ($f) {
case 'person_countryOfBirth':
case 'person_nationality':
@ -500,10 +503,16 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
}
// process fields which are custom fields
foreach ($this->getCustomFields() as $cf) {
// do not add custom fields which are not selected
if (!\in_array($cf->getSlug(), $data['fields'])) {
continue;
}
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
// if is multiple, split into multiple columns
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
foreach($cfType->getChoices($cf) as $choiceSlug => $label) {
$slug = $this->slugToDQL($cf->getSlug(), 'choice', [ 'choiceSlug' => $choiceSlug ]);
@ -513,6 +522,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
}
} else {
// not multiple, add a single column
$slug = $this->slugToDQL($cf->getSlug());
$qb->addSelect(
sprintf('GET_JSON_FIELD_BY_KEY(report.cFData, :slug%s) AS %s',
@ -531,7 +541,6 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
->setParameter('authorized_centers', $centers);
;
return $qb;
}