Ver código fonte

extraInfoCity filter by cityAddresse or cityUser

packProduct
Charly 3 anos atrás
pai
commit
83fbec134f
4 arquivos alterados com 59 adições e 1 exclusões
  1. +38
    -0
      Field/Filter/User/UserExtraInfoCityFilter.php
  2. +1
    -1
      Field/Filter/User/UserExtraInfoZipFilter.php
  3. +9
    -0
      Repository/User/UserRepositoryQuery.php
  4. +11
    -0
      Resources/views/admin/user/field/extra_infos_city.html.twig

+ 38
- 0
Field/Filter/User/UserExtraInfoCityFilter.php Ver arquivo

@@ -0,0 +1,38 @@
<?php

namespace Lc\CaracoleBundle\Field\Filter\User;

use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use Lc\SovBundle\Field\Filter\AssociationFilter;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

/**
* @author La clic ! <contact@laclic.fr>
*/
class UserExtraInfoCityFilter extends AssociationFilter
{
public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
{
$builder->add(
$this->getFieldPropertySnake($fieldDto->getProperty()),
TextType::class,
array(
'required' => false,
'attr' => array(
'class' => ' input-sm',
'form' => 'filters-form',
),
)
);
}

public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, $filteredValue = null)
{
if ($filteredValue !== null) {
$repositoryQuery->filterByExtraInfoCity('%' . $filteredValue . '%');
}
}

}

+ 1
- 1
Field/Filter/User/UserExtraInfoZipFilter.php Ver arquivo

@@ -31,7 +31,7 @@ class UserExtraInfoZipFilter extends AssociationFilter
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, $filteredValue = null)
{
if ($filteredValue !== null) {
$repositoryQuery->filterByExtraInfoZip($filteredValue);
$repositoryQuery->filterByExtraInfoZip('%' . $filteredValue . '%');
}
}


+ 9
- 0
Repository/User/UserRepositoryQuery.php Ver arquivo

@@ -59,4 +59,13 @@ class UserRepositoryQuery extends SovUserRepositoryQuery
->andWhere('.extraInfoZip LIKE :extraInfoZip OR addresses.zip LIKE :extraInfoZip')
->setParameter('extraInfoZip', $zip);
}

public function filterByExtraInfoCity(string $city)
{
$this->joinAddresses();

return $this
->andWhere('.extraInfoCity LIKE :extraInfoCity OR addresses.city LIKE :extraInfoCity')
->setParameter('extraInfoCity', $city);
}
}

+ 11
- 0
Resources/views/admin/user/field/extra_infos_city.html.twig Ver arquivo

@@ -0,0 +1,11 @@
{% set user = entity.instance %}
{% set city = user.extraInfoCity %}
{% if city is not empty %}
<span class="badge badge-secondary">{{ city }}</span>
{% elseif user.addresses is not empty %}
{% for addresse in user.addresses %}
<span class="badge badge-secondary">{{ addresse.city }}</span>
{% endfor %}
{% else %}
<span class="badge badge-secondary">Aucun(e)</span>
{% endif %}

Carregando…
Cancelar
Salvar