Skip to content

Commit

Permalink
[Ohme] Fix import command (#11173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg authored Dec 10, 2024
1 parent 8e668c2 commit 9763327
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 41 deletions.
58 changes: 19 additions & 39 deletions src/Admin/Ohme/ContactAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\Adherent;
use App\Entity\Ohme\Contact;
use App\Ohme\ContactHandler;
use App\Query\Utils\MultiColumnsSearchHelper;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
Expand All @@ -26,10 +27,7 @@ class ContactAdmin extends AbstractAdmin

protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection
->remove('show')
->remove('delete')
;
$collection->clearExcept(['list', 'edit']);
}

protected function configureFormFields(FormMapper $form): void
Expand Down Expand Up @@ -70,41 +68,23 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
return false;
}

$search = $value->getValue();

$conditions = $qb->expr()->orX();

preg_match('/(?<first>.*) (?<last>.*)/', $search, $tokens);

if (\array_key_exists('first', $tokens) && \array_key_exists('last', $tokens)) {
$conditions
->add("$alias.firstname LIKE :search_first_token AND $alias.lastname LIKE :search_last_token")
->add("$alias.firstname LIKE :search_last_token AND $alias.lastname LIKE :search_first_token")
->add("$alias.email LIKE :search_first_token AND $alias.email LIKE :search_last_token")
;

$qb
->setParameter('search_first_token', '%'.$tokens['first'].'%')
->setParameter('search_last_token', '%'.$tokens['last'].'%')
;
} else {
$conditions
->add("$alias.firstname LIKE :search")
->add("$alias.lastname LIKE :search")
->add("$alias.email LIKE :search")
;
}

$conditions
->add("REPLACE(REPLACE($alias.phone, ' ', ''), '+', '') LIKE REPLACE(REPLACE(:search, ' ', ''), '+', '')")
->add("$alias.ohmeIdentifier = REPLACE(:strict_search, ' ', '')")
;

$qb
->andWhere($conditions)
->setParameter('search', "%$search%")
->setParameter('strict_search', $search)
;
MultiColumnsSearchHelper::updateQueryBuilderForMultiColumnsSearch(
$qb->getQueryBuilder(),
$value->getValue(),
[
["$alias.firstname", "$alias.lastname"],
["$alias.lastname", "$alias.firstname"],
["$alias.email", "$alias.email"],
],
[
"$alias.phone",
],
[
"$alias.id",
"$alias.uuid",
"$alias.ohmeIdentifier",
]
);

return true;
},
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Ohme/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Contact

#[ORM\Column(unique: true)]
public string $ohmeIdentifier;

#[ORM\Column(nullable: true)]
public ?string $email = null;

Expand Down
4 changes: 2 additions & 2 deletions tests/Ohme/DummyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function getPayments(int $limit = 100, int $offset = 0, array $options =

private function createContact(
string $id,
string $email,
string $firstname,
string $lastname,
string $email,
): array {
return [
'id' => $id,
'email' => $email,
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $email,
];
}

Expand Down

0 comments on commit 9763327

Please sign in to comment.