1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Lukasz D. Tulikowski <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace App\Form\Filter; |
13
|
|
|
|
14
|
|
|
use Lexik\Bundle\FormFilterBundle\Filter\Form\Type as Filters; |
15
|
|
|
use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; |
16
|
|
|
use Symfony\Component\Form\AbstractType; |
17
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
|
20
|
|
|
class UserFilter extends AbstractType |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
2 |
|
public function buildForm(FormBuilderInterface $builder, array $options) |
26
|
|
|
{ |
27
|
|
|
// Allows filter Users movie title they watched. |
28
|
|
|
$builder |
29
|
2 |
|
->add('email', Filters\TextFilterType::class) |
30
|
2 |
|
->add('movies', Filters\TextFilterType::class, [ |
31
|
2 |
|
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { |
32
|
1 |
|
if (empty($values['value'])) { |
33
|
1 |
|
return null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$query = $filterQuery->getQueryBuilder(); |
37
|
|
|
$query->innerJoin($field, 't'); |
38
|
|
|
|
39
|
|
|
$paramName = sprintf('p_%s', str_replace('.', '_', $field)); |
40
|
|
|
$expression = $filterQuery->getExpr()->eq('t.title', ':'.$paramName); |
41
|
|
|
$parameters = [$paramName => $values['value']]; |
42
|
|
|
|
43
|
|
|
return $filterQuery->createCondition($expression, $parameters); |
44
|
2 |
|
}, |
45
|
|
|
]); |
46
|
2 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
2 |
|
public function configureOptions(OptionsResolver $resolver) |
52
|
|
|
{ |
53
|
2 |
|
$resolver->setDefaults([ |
54
|
2 |
|
'validation_groups' => ['filtering'], |
55
|
|
|
]); |
56
|
2 |
|
} |
57
|
|
|
} |
58
|
|
|
|