|
6 | 6 | use Knp\Component\Pager\Event\ItemsEvent;
|
7 | 7 | use Knp\Component\Pager\Event\Subscriber\Filtration\Doctrine\ORM\Query\WhereWalker;
|
8 | 8 | use Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query\Helper as QueryHelper;
|
| 9 | +use Knp\Component\Pager\PaginatorInterface; |
9 | 10 | use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
10 | 11 |
|
11 | 12 | class QuerySubscriber implements EventSubscriberInterface
|
12 | 13 | {
|
13 | 14 | public function items(ItemsEvent $event)
|
14 | 15 | {
|
15 | 16 | if ($event->target instanceof Query) {
|
16 |
| - if (!isset($_GET[$event->options['filterValueParameterName']]) || (empty($_GET[$event->options['filterValueParameterName']]) && $_GET[$event->options['filterValueParameterName']] !== "0")) { |
| 17 | + if (!isset($_GET[$event->options[PaginatorInterface::FILTER_VALUE_PARAMETER_NAME]]) || (empty($_GET[$event->options[PaginatorInterface::FILTER_VALUE_PARAMETER_NAME]]) && $_GET[$event->options[PaginatorInterface::FILTER_VALUE_PARAMETER_NAME]] !== "0")) { |
17 | 18 | return;
|
18 | 19 | }
|
19 |
| - if (!empty($_GET[$event->options['filterFieldParameterName']])) { |
20 |
| - $columns = $_GET[$event->options['filterFieldParameterName']]; |
21 |
| - } elseif (!empty($event->options['defaultFilterFields'])) { |
22 |
| - $columns = $event->options['defaultFilterFields']; |
| 20 | + if (!empty($_GET[$event->options[PaginatorInterface::FILTER_FIELD_PARAMETER_NAME]])) { |
| 21 | + $columns = $_GET[$event->options[PaginatorInterface::FILTER_FIELD_PARAMETER_NAME]]; |
| 22 | + } elseif (!empty($event->options[PaginatorInterface::DEFAULT_FILTER_FIELDS])) { |
| 23 | + $columns = $event->options[PaginatorInterface::DEFAULT_FILTER_FIELDS]; |
23 | 24 | } else {
|
24 | 25 | return;
|
25 | 26 | }
|
26 |
| - $value = $_GET[$event->options['filterValueParameterName']]; |
| 27 | + $value = $_GET[$event->options[PaginatorInterface::FILTER_VALUE_PARAMETER_NAME]]; |
27 | 28 | if (false !== strpos($value, '*')) {
|
28 | 29 | $value = str_replace('*', '%', $value);
|
29 | 30 | }
|
30 | 31 | if (is_string($columns) && false !== strpos($columns, ',')) {
|
31 | 32 | $columns = explode(',', $columns);
|
32 | 33 | }
|
33 | 34 | $columns = (array) $columns;
|
34 |
| - if (isset($event->options['filterFieldWhitelist'])) { |
| 35 | + if (isset($event->options[PaginatorInterface::FILTER_FIELD_WHITELIST])) { |
35 | 36 | foreach ($columns as $column) {
|
36 |
| - if (!in_array($column, $event->options['filterFieldWhitelist'])) { |
| 37 | + if (!in_array($column, $event->options[PaginatorInterface::FILTER_FIELD_WHITELIST])) { |
37 | 38 | throw new \UnexpectedValueException("Cannot filter by: [{$column}] this field is not in whitelist");
|
38 | 39 | }
|
39 | 40 | }
|
|
0 commit comments