Skip to content

Commit

Permalink
[Referral] Add admin filters (#11523)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémi <[email protected]>
  • Loading branch information
Remg and Rémi authored Feb 26, 2025
1 parent 4b44982 commit 7531c2e
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 12 deletions.
16 changes: 8 additions & 8 deletions config/services/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
<argument />
</service>

<service id="app.admin.referral" class="App\Admin\ReferralAdmin">
<tag name="sonata.admin" manager-type="orm" label="Parrainages" group="Adhérents" />

<argument />
<argument>App\Entity\Referral</argument>
<argument />
</service>

<!--
######################################################
# Communication
Expand Down Expand Up @@ -304,14 +312,6 @@
</service>
<service id="App\Admin\ReportAdmin" alias="app.admin.report" />

<service id="app.admin.referral" class="App\Admin\ReferralAdmin">
<tag name="sonata.admin" manager-type="orm" label="Parrainages" group="Territoires" />

<argument />
<argument>App\Entity\Referral</argument>
<argument />
</service>

<!--
######################################################
# Idées
Expand Down
91 changes: 87 additions & 4 deletions src/Admin/ReferralAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

namespace App\Admin;

use App\Adherent\Referral\ModeEnum;
use App\Adherent\Referral\StatusEnum;
use App\Adherent\Referral\TypeEnum;
use App\Entity\Adherent;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter;
use Symfony\Component\Form\Extension\Core\Type\EnumType;

class ReferralAdmin extends AbstractAdmin
{
Expand Down Expand Up @@ -38,15 +47,89 @@ protected function configureListFields(ListMapper $list): void
])
->add('type', null, [
'label' => 'Type',
'format' => 'referral.type.%s',
'template' => 'admin/referral/list_type.html.twig',
])
->add('mode', null, [
->add('mode', 'null', [
'label' => 'Mode',
'format' => 'referral.mode.%s',
'template' => 'admin/referral/list_mode.html.twig',
])
->add('status', null, [
'label' => 'Statut',
'format' => 'referral.status.%s',
'template' => 'admin/referral/list_status.html.twig',
])
;
}

protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add('identifier', null, [
'label' => 'Numéro',
'show_filter' => true,
])
->add('emailAddress', null, [
'label' => 'Email (parrainé)',
])
->add('firstName', null, [
'label' => 'Prénom (parrainé)',
])
->add('lastName', null, [
'label' => 'Nom (parrainé)',
])
->add('referrer', ModelFilter::class, [
'label' => 'Parrain',
'show_filter' => true,
'field_type' => ModelAutocompleteType::class,
'field_options' => [
'model_manager' => $this->getModelManager(),
'property' => [
'search',
],
'to_string_callback' => static function (Adherent $adherent): string {
return \sprintf(
'%s (%s) [%s]',
$adherent->getFullName(),
$adherent->getEmailAddress(),
$adherent->getId()
);
},
],
])
->add('type', ChoiceFilter::class, [
'label' => 'Type',
'show_filter' => true,
'field_type' => EnumType::class,
'field_options' => [
'class' => TypeEnum::class,
'choice_label' => static function (TypeEnum $type): string {
return 'referral.type.'.$type->value;
},
'multiple' => true,
],
])
->add('mode', ChoiceFilter::class, [
'label' => 'Mode',
'show_filter' => true,
'field_type' => EnumType::class,
'field_options' => [
'class' => ModeEnum::class,
'choice_label' => static function (ModeEnum $mode): string {
return 'referral.mode.'.$mode->value;
},
'multiple' => true,
],
])
->add('status', ChoiceFilter::class, [
'label' => 'Statut',
'show_filter' => true,
'field_type' => EnumType::class,
'field_options' => [
'class' => StatusEnum::class,
'choice_label' => static function (StatusEnum $status): string {
return 'referral.status.'.$status->value;
},
'multiple' => true,
],
])
;
}
Expand Down
5 changes: 5 additions & 0 deletions templates/admin/referral/list_mode.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field %}
{{ ('referral.mode.' ~ object.mode.value)|trans }}
{% endblock %}
5 changes: 5 additions & 0 deletions templates/admin/referral/list_status.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field %}
{{ ('referral.status.' ~ object.status.value)|trans }}
{% endblock %}
5 changes: 5 additions & 0 deletions templates/admin/referral/list_type.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field %}
{{ ('referral.type.' ~ object.type.value)|trans }}
{% endblock %}
1 change: 1 addition & 0 deletions translations/messages+intl-icu.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1334,3 +1334,4 @@ referral.status.invitation_sent: Invitation envoyée
referral.status.account_created: Compte créé
referral.status.adhesion_finished: Adhésion effectuée
referral.status.adhesion_via_other_link: Adhésion via une autre invitation
referral.status.reported: Signalé

0 comments on commit 7531c2e

Please sign in to comment.