diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..4c307ed39 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ + +Branch master +============= + +- [list export] fix error "all custom fields are shown" + diff --git a/Export/Export/ReportList.php b/Export/Export/ReportList.php index 3da656aa0..583db8f4b 100644 --- a/Export/Export/ReportList.php +++ b/Export/Export/ReportList.php @@ -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; }