use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | ||||
use Lc\CaracoleBundle\Context\MerchantContextTrait; | use Lc\CaracoleBundle\Context\MerchantContextTrait; | ||||
use Lc\CaracoleBundle\Field\AssociationField; | use Lc\CaracoleBundle\Field\AssociationField; | ||||
use Lc\CaracoleBundle\Field\Filter\User\UserMerchantEmailFilter; | |||||
use Lc\CaracoleBundle\Field\Filter\User\UserMerchantFirstnameFilter; | |||||
use Lc\CaracoleBundle\Field\Filter\User\UserMerchantLastnameFilter; | |||||
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition; | use Lc\SovBundle\Definition\Field\AbstractFieldDefinition; | ||||
return [ | return [ | ||||
'id'=> IntegerField::new('id')->onlyOnIndex()->setSortable(true), | 'id'=> IntegerField::new('id')->onlyOnIndex()->setSortable(true), | ||||
'lastname'=> TextField::new('user.lastname')->setSortable(true), | |||||
'firstname'=> TextField::new('user.firstname')->setSortable(true), | |||||
'email'=> TextField::new('user.email')->setSortable(true), | |||||
'lastname'=> TextField::new('user.lastname')->setSortable(true) | |||||
->setCustomOption('filter_fqcn', UserMerchantLastnameFilter::class), | |||||
'firstname'=> TextField::new('user.firstname')->setSortable(true) | |||||
->setCustomOption('filter_fqcn', UserMerchantFirstnameFilter::class), | |||||
'email'=> TextField::new('user.email')->setSortable(true) | |||||
->setCustomOption('filter_fqcn', UserMerchantEmailFilter::class), | |||||
'credit'=> NumberField::new('credit')->setSortable(true) | 'credit'=> NumberField::new('credit')->setSortable(true) | ||||
->setTemplatePath('@LcSov/adminlte/crud/field/amount.html.twig') | ->setTemplatePath('@LcSov/adminlte/crud/field/amount.html.twig') | ||||
->setCustomOption('appendHtml', '€'), | ->setCustomOption('appendHtml', '€'), |
<?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 UserMerchantEmailFilter 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->filterByEmail('%'.$filteredValue.'%'); | |||||
} | |||||
} | |||||
} |
<?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 UserMerchantFirstnameFilter 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->filterByFirstname('%'.$filteredValue.'%'); | |||||
} | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Field\Filter\User; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; | |||||
use Lc\SovBundle\Field\Filter\AssociationFilter; | |||||
use Lc\SovBundle\Field\Filter\FilterTrait; | |||||
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 UserMerchantLastnameFilter | |||||
{ | |||||
use FilterTrait; | |||||
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->filterByLastname('%'.$filteredValue.'%'); | |||||
} | |||||
} | |||||
} |
{ | { | ||||
use MerchantRepositoryQueryTrait; | use MerchantRepositoryQueryTrait; | ||||
protected $isJoinUser = false; | |||||
public function __construct(UserMerchantRepository $repository, PaginatorInterface $paginator) | public function __construct(UserMerchantRepository $repository, PaginatorInterface $paginator) | ||||
{ | { | ||||
parent::__construct($repository, 'userMerchant', $paginator); | parent::__construct($repository, 'userMerchant', $paginator); | ||||
public function filterByUser(UserInterface $user) | public function filterByUser(UserInterface $user) | ||||
{ | { | ||||
return $this | return $this | ||||
->andWhere('.user = :user') | |||||
->setParameter('user', $user); | |||||
->andWhere('.user = :user') | |||||
->setParameter('user', $user); | |||||
} | |||||
public function joinUser(): self | |||||
{ | |||||
if (!$this->isJoinUser) { | |||||
$this->isJoinUser = true; | |||||
return $this | |||||
->leftJoin('.user', 'user'); | |||||
} | |||||
return $this; | |||||
} | |||||
public function filterByFirstname(string $firstname) | |||||
{ | |||||
$this->joinUser(); | |||||
return $this | |||||
->andWhere('user.firstname LIKE :firstname') | |||||
->setParameter('firstname', $firstname); | |||||
} | |||||
public function filterByLastname(string $lastname) | |||||
{ | |||||
$this->joinUser(); | |||||
return $this | |||||
->andWhere('user.lastname LIKE :lastname') | |||||
->setParameter('lastname', $lastname); | |||||
} | |||||
public function filterByEmail(string $email) | |||||
{ | |||||
$this->joinUser(); | |||||
return $this | |||||
->andWhere('user.email LIKE :email') | |||||
->setParameter('email', $email); | |||||
} | } | ||||
public function filterIsCreditActive() | public function filterIsCreditActive() |