Skip to content

Commit

Permalink
Use Doctrine query builder type
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg committed Jul 15, 2024
1 parent 3f9ee12 commit 2fd7f7c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 52 deletions.
32 changes: 7 additions & 25 deletions src/Admin/Procuration/ProxySlotAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Admin\Procuration;

use App\Entity\ProcurationV2\Request;
use App\Query\Utils\MultiColumnsSearchHelper;
use Doctrine\ORM\QueryBuilder;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
Expand All @@ -13,10 +11,10 @@
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\DoctrineORMAdminBundle\Filter\BooleanFilter;
use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class ProxySlotAdmin extends AbstractAdmin
{
Expand All @@ -41,14 +39,14 @@ protected function configureFormFields(FormMapper $form): void
array $properties,
string $value
): void {
/** @var QueryBuilder $qb */
/** @var ProxyQueryInterface $qb */
$qb = $admin->getDatagrid()->getQuery();
$alias = $qb->getRootAliases()[0];

$qb->join("$alias.request", 'request');

MultiColumnsSearchHelper::updateQueryBuilderForMultiColumnsSearch(
$qb,
$qb->getQueryBuilder(),
$value,
[
['request.firstNames', 'request.lastName'],
Expand Down Expand Up @@ -102,6 +100,10 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
return true;
},
])
->add('round', null, [
'label' => 'Tour',
'show_filter' => true,
])
->add('manual', BooleanFilter::class, [
'label' => 'Traitement manuel',
'show_filter' => true,
Expand Down Expand Up @@ -132,24 +134,4 @@ protected function configureListFields(ListMapper $list): void
])
;
}

/**
* @param Request $object
*/
protected function alterObject(object $object): void
{
}

/**
* @param Request $object
*/
protected function postUpdate(object $object): void
{
}

/** @required */
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}
}
32 changes: 7 additions & 25 deletions src/Admin/Procuration/RequestSlotAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Admin\Procuration;

use App\Entity\ProcurationV2\Request;
use App\Query\Utils\MultiColumnsSearchHelper;
use Doctrine\ORM\QueryBuilder;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
Expand All @@ -13,10 +11,10 @@
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\DoctrineORMAdminBundle\Filter\BooleanFilter;
use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class RequestSlotAdmin extends AbstractAdmin
{
Expand All @@ -41,14 +39,14 @@ protected function configureFormFields(FormMapper $form): void
array $properties,
string $value
): void {
/** @var QueryBuilder $qb */
/** @var ProxyQueryInterface $qb */
$qb = $admin->getDatagrid()->getQuery();
$alias = $qb->getRootAliases()[0];

$qb->join("$alias.proxy", 'proxy');

MultiColumnsSearchHelper::updateQueryBuilderForMultiColumnsSearch(
$qb,
$qb->getQueryBuilder(),
$value,
[
['proxy.firstNames', 'proxy.lastName'],
Expand Down Expand Up @@ -102,6 +100,10 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
return true;
},
])
->add('round', null, [
'label' => 'Tour',
'show_filter' => true,
])
->add('manual', BooleanFilter::class, [
'label' => 'Traitement manuel',
'show_filter' => true,
Expand Down Expand Up @@ -132,24 +134,4 @@ protected function configureListFields(ListMapper $list): void
])
;
}

/**
* @param Request $object
*/
protected function alterObject(object $object): void
{
}

/**
* @param Request $object
*/
protected function postUpdate(object $object): void
{
}

/** @required */
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}
}
3 changes: 1 addition & 2 deletions src/Query/Utils/MultiColumnsSearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
namespace App\Query\Utils;

use Doctrine\ORM\QueryBuilder;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;

class MultiColumnsSearchHelper
{
public static function updateQueryBuilderForMultiColumnsSearch(
QueryBuilder|ProxyQueryInterface $queryBuilder,
QueryBuilder $queryBuilder,
string $searchTerm,
array $mainColumns,
array $additionalColumns = [],
Expand Down

0 comments on commit 2fd7f7c

Please sign in to comment.