@@ -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 UserExtraInfoZipFilter 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->filterByExtraInfoZip($filteredValue); | |||
} | |||
} | |||
} |
@@ -11,6 +11,7 @@ class UserRepositoryQuery extends SovUserRepositoryQuery | |||
use MerchantRepositoryQueryTrait; | |||
protected $isJoinUserMerchants = false; | |||
protected $isJoinAddresses = false; | |||
public function joinUserMerchants(): self | |||
@@ -24,6 +25,17 @@ class UserRepositoryQuery extends SovUserRepositoryQuery | |||
return $this; | |||
} | |||
public function joinAddresses(): self | |||
{ | |||
if (!$this->isJoinAddresses) { | |||
$this->isJoinAddresses = true; | |||
return $this | |||
->innerJoin('.addresses', 'addresses'); | |||
} | |||
return $this; | |||
} | |||
public function filterMerchantIsActive(): self | |||
{ | |||
$this->joinUserMerchants(); | |||
@@ -38,4 +50,13 @@ class UserRepositoryQuery extends SovUserRepositoryQuery | |||
->andWhere('userMerchants.merchant = :merchant') | |||
->setParameter('merchant', $merchant); | |||
} | |||
public function filterByExtraInfoZip(string $zip) | |||
{ | |||
$this->joinAddresses(); | |||
return $this | |||
->andWhere('.extraInfoZip LIKE :extraInfoZip OR addresses.zip LIKE :extraInfoZip') | |||
->setParameter('extraInfoZip', $zip); | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
{% set user = entity.instance %} | |||
{% set zip = user.extraInfoZip %} | |||
{% if zip is not empty %} | |||
<span class="badge badge-secondary">{{ zip }}</span> | |||
{% elseif user.addresses is not empty %} | |||
{% for addresse in user.addresses %} | |||
<span class="badge badge-secondary">{{ addresse.zip }}</span> | |||
{% endfor %} | |||
{% else %} | |||
<span class="badge badge-secondary">Aucun(e)</span> | |||
{% endif %} |