improve exports, filters, aggregators

This commit is contained in:
2017-01-17 00:33:44 +01:00
parent d75783632f
commit 045119d61f
7 changed files with 249 additions and 10 deletions

View File

@@ -130,7 +130,7 @@ class CountPerson implements ExportInterface
public function supportsModifiers()
{
return array(Declarations::PERSON_TYPE);
return array(Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN);
}
}

View File

@@ -15,6 +15,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
/**
* Render a list of peoples
@@ -35,18 +36,27 @@ class ListPerson implements ListInterface
*/
protected $translator;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
protected $fields = array(
'id', 'firstName', 'lastName', 'birthdate',
'placeOfBirth', 'gender', 'memo', 'email', 'phonenumber'
'placeOfBirth', 'gender', 'memo', 'email', 'phonenumber',
'countryOfBirth', 'nationality'
);
public function __construct(
EntityManagerInterface $em,
TranslatorInterface $translator
TranslatorInterface $translator,
TranslatableStringHelper $translatableStringHelper
)
{
$this->entityManager = $em;
$this->translator = $translator;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
@@ -133,7 +143,26 @@ class ListPerson implements ListInterface
return $this->translator->trans($value);
};
case 'countryOfBirth':
case 'nationality':
$countryRepository = $this->entityManager
->getRepository('ChillMainBundle:Country');
// load all countries in a single query
$countryRepository->findBy(array('countryCode' => $values));
return function($value) use ($key, $countryRepository) {
if ($value === '_header') { return \strtolower($key); }
if ($value === NULL) {
return $this->translator->trans('no data');
}
$country = $countryRepository->find($value);
return $this->translatableStringHelper->localize(
$country->getName());
};
default:
return function($value) use ($key) {
if ($value === '_header') { return \strtolower($key); }
@@ -202,7 +231,14 @@ class ListPerson implements ListInterface
foreach ($this->fields as $f) {
if (in_array($f, $data['fields'])) {
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
switch ($f) {
case 'countryOfBirth':
case 'nationality':
$qb->addSelect(sprintf('IDENTITY(person.%s) as %s', $f, $f));
break;
default:
$qb->addSelect(sprintf('person.%s as %s', $f, $f));
}
}
}
@@ -232,6 +268,6 @@ class ListPerson implements ListInterface
*/
public function supportsModifiers()
{
return array(Declarations::PERSON_TYPE);
return array(Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN);
}
}