mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: [export] Add a list of accompanying periods
This commit is contained in:
@@ -14,9 +14,11 @@ namespace Chill\MainBundle\Export\Helper;
|
||||
use Chill\MainBundle\Repository\AddressRepository;
|
||||
use Chill\MainBundle\Templating\Entity\AddressRender;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use function in_array;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,10 @@ use function strlen;
|
||||
*/
|
||||
class ExportAddressHelper
|
||||
{
|
||||
public const F_ALL =
|
||||
self::F_ATTRIBUTES | self::F_BUILDING | self::F_COUNTRY |
|
||||
self::F_GEOM | self::F_POSTAL_CODE | self::F_STREET;
|
||||
|
||||
public const F_AS_STRING = 0b00010000;
|
||||
|
||||
public const F_ATTRIBUTES = 0b01000000;
|
||||
@@ -77,6 +83,87 @@ class ExportAddressHelper
|
||||
$this->addressRender = $addressRender;
|
||||
}
|
||||
|
||||
public function addSelectClauses(int $params, QueryBuilder $queryBuilder, $entityName = 'address', $prefix = 'add')
|
||||
{
|
||||
foreach (self::ALL as $key => $bitmask) {
|
||||
if (($params & $bitmask) === $bitmask) {
|
||||
foreach (self::COLUMN_MAPPING[$key] as $field) {
|
||||
switch ($field) {
|
||||
case 'id':
|
||||
case '_as_string':
|
||||
$queryBuilder->addSelect(sprintf('%s.id AS %s%s', $entityName, $prefix, $field));
|
||||
|
||||
break;
|
||||
|
||||
case 'street':
|
||||
case 'streetNumber':
|
||||
case 'building':
|
||||
case 'floor':
|
||||
case 'corridor':
|
||||
case 'steps':
|
||||
case 'buildingName':
|
||||
case 'flat':
|
||||
case 'distribution':
|
||||
case 'extra':
|
||||
$queryBuilder->addSelect(sprintf('%s.%s AS %s%s', $entityName, $field, $prefix, $field));
|
||||
|
||||
break;
|
||||
|
||||
case 'country':
|
||||
case 'postcode_name':
|
||||
case 'postcode_code':
|
||||
$postCodeAlias = sprintf('%spostcode_t', $prefix);
|
||||
|
||||
if (!in_array($postCodeAlias, $queryBuilder->getAllAliases(), true)) {
|
||||
$queryBuilder->leftJoin($entityName . '.postcode', $postCodeAlias);
|
||||
}
|
||||
|
||||
if ('postcode_name' === $field) {
|
||||
$queryBuilder->addSelect(sprintf('%s.%s AS %s%s', $postCodeAlias, 'name', $prefix, $field));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ('postcode_code' === $field) {
|
||||
$queryBuilder->addSelect(sprintf('%s.%s AS %s%s', $postCodeAlias, 'code', $prefix, $field));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$countryAlias = sprintf('%scountry_t', $prefix);
|
||||
|
||||
if (!in_array($countryAlias, $queryBuilder->getAllAliases(), true)) {
|
||||
$queryBuilder->leftJoin(sprintf('%s.country', $postCodeAlias), $countryAlias);
|
||||
}
|
||||
|
||||
$queryBuilder->addSelect(sprintf('%s.%s AS %s%s', $countryAlias, 'name', $prefix, $field));
|
||||
|
||||
break;
|
||||
|
||||
case 'isNoAddress':
|
||||
case 'confidential':
|
||||
$queryBuilder->addSelect(sprintf('CASE WHEN %s.%s = \'TRUE\' THEN 1 ELSE 0 END AS %s%s', $entityName, $field, $prefix, $field));
|
||||
|
||||
break;
|
||||
|
||||
case '_lat':
|
||||
$queryBuilder->addSelect(sprintf('ST_Y(%s.point) AS %s%s', $entityName, $prefix, $field));
|
||||
|
||||
break;
|
||||
|
||||
case '_lon':
|
||||
$queryBuilder->addSelect(sprintf('ST_X(%s.point) AS %s%s', $entityName, $prefix, $field));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new LogicException('This key is not supported: ' . $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param self::F_* $params
|
||||
*
|
||||
@@ -115,23 +202,11 @@ class ExportAddressHelper
|
||||
case 'extra':
|
||||
case 'flat':
|
||||
case 'floor':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
return $this->propertyAccess->getValue($address, $sanitizedKey);
|
||||
};
|
||||
|
||||
case '_lat':
|
||||
case '_lon':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
case 'postcode_code':
|
||||
case 'postcode_name':
|
||||
return static function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
@@ -140,28 +215,25 @@ class ExportAddressHelper
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
$geom = $address->getPoint();
|
||||
return $value;
|
||||
};
|
||||
|
||||
if (null === $geom) {
|
||||
case 'country':
|
||||
return function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return 'export.list.acp' . $key;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
switch ($sanitizedKey) {
|
||||
case '_lat':
|
||||
return $geom->getLat();
|
||||
|
||||
case '_lon':
|
||||
return $geom->getLon();
|
||||
|
||||
default:
|
||||
throw new LogicException('only _lat or _lon accepted, given: ' . $sanitizedKey);
|
||||
}
|
||||
return $this->translatableStringHelper->localize(json_decode($value, true));
|
||||
};
|
||||
|
||||
case 'isNoAddress':
|
||||
case 'confidential':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
return static function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
@@ -170,9 +242,7 @@ class ExportAddressHelper
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
switch ($val = $this->propertyAccess->getValue($address, $sanitizedKey)) {
|
||||
switch ($value) {
|
||||
case null:
|
||||
return '';
|
||||
|
||||
@@ -187,21 +257,6 @@ class ExportAddressHelper
|
||||
}
|
||||
};
|
||||
|
||||
case 'country':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
return $this->translatableStringHelper->localize($address->getPostcode()->getCountry()->getName());
|
||||
};
|
||||
|
||||
case '_as_string':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
@@ -217,31 +272,6 @@ class ExportAddressHelper
|
||||
return $this->addressRender->renderString($address, []);
|
||||
};
|
||||
|
||||
case 'postcode_code':
|
||||
case 'postcode_name':
|
||||
return function ($value) use ($sanitizedKey, $translationPrefix) {
|
||||
if ('_header' === $value) {
|
||||
return $translationPrefix . $sanitizedKey;
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = $this->addressRepository->find($value);
|
||||
|
||||
switch ($sanitizedKey) {
|
||||
case 'postcode_code':
|
||||
return $address->getPostcode()->getCode();
|
||||
|
||||
case 'postcode_name':
|
||||
return $address->getPostcode()->getName();
|
||||
|
||||
default:
|
||||
throw new LogicException('this key is not supported: ' . $sanitizedKey);
|
||||
}
|
||||
};
|
||||
|
||||
default:
|
||||
throw new LogicException('this key is not supported: ' . $sanitizedKey);
|
||||
}
|
||||
|
Reference in New Issue
Block a user