@@ -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 . '%'); | |||
} | |||
} | |||
} |
@@ -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 . '%'); | |||
} | |||
} | |||
@@ -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); | |||
} | |||
} |
@@ -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 %} |