Skip to content

Commit

Permalink
Merge pull request #526 from systemli/Improve-Performance-for-Alias-a…
Browse files Browse the repository at this point in the history
…nd-Voucher-Admin

Improve Performance for Alias and Voucher Admin
  • Loading branch information
0x46616c6b authored Dec 29, 2023
2 parents d6cf1e7 + 84e7041 commit 87aba82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Improve fixture loading while increasing the number of fixtures
* Fix Filters in User Admin
* Fix Filters in Alias Admin
* Improve Performance for Alias and Voucher Admin

# 3.3.1 (2023.11.12)

Expand Down
4 changes: 1 addition & 3 deletions src/Admin/AliasAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;

class AliasAdmin extends Admin
Expand Down Expand Up @@ -47,7 +45,7 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add('source')
->add('user')
->add('user.email', null, ['label' => 'User'])
->add('domain')
->add('deleted');
}
Expand Down
50 changes: 19 additions & 31 deletions src/Admin/VoucherAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Sonata\DoctrineORMAdminBundle\Filter\DateTimeRangeFilter;
use Sonata\Form\Type\DateRangePickerType;

class VoucherAdmin extends Admin
{
Expand All @@ -18,7 +17,8 @@ class VoucherAdmin extends Admin
'_sort_by' => 'creationTime',
];

protected function generateBaseRoutePattern(bool $isChildAdmin = false): string {
protected function generateBaseRoutePattern(bool $isChildAdmin = false): string
{
return 'voucher';
}

Expand Down Expand Up @@ -69,35 +69,23 @@ protected function configureListFields(ListMapper $list): void
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add('user')
->add('user.email', null, ['label' => 'User'])
->add('code')
->add('created_since', CallbackFilter::class, [
'callback' => function (ProxyQuery $proxyQuery, $alias, $field, $value) {
if (isset($value['value']) && null !== $value = $value['value']) {
$qb = $proxyQuery->getQueryBuilder();
$field = sprintf('%s.creationTime', $alias);
$qb->andWhere(sprintf('%s >= :datetime', $field))
->setParameter('datetime', new \DateTime($value))
->orderBy($field, 'DESC');
}

return true;
},
'field_type' => TextType::class,
->add('creationTime', DateTimeRangeFilter::class, [
'field_type' => DateRangePickerType::class,
'field_options' => [
'field_options' => [
'format' => 'dd.MM.yyyy'
]
]
])
->add('redeemed_since', CallbackFilter::class, [
'callback' => function (ProxyQuery $proxyQuery, $alias, $field, $value) {
if (isset($value['value']) && null !== $value = $value['value']) {
$qb = $proxyQuery->getQueryBuilder();
$field = sprintf('%s.redeemedTime', $alias);
$qb->andWhere(sprintf('%s >= :datetime', $field))
->setParameter('datetime', new \DateTime($value))
->orderBy($field, 'DESC');
}

return true;
},
'field_type' => TextType::class,
->add('redeemedTime', DateTimeRangeFilter::class, [
'field_type' => DateRangePickerType::class,
'field_options' => [
'field_options' => [
'format' => 'dd.MM.yyyy'
]
]
]);
}

Expand Down

0 comments on commit 87aba82

Please sign in to comment.