@@ 10-81 (lines=72) @@ | ||
7 | /** |
|
8 | * StringFilterType |
|
9 | */ |
|
10 | class StringFilterType extends AbstractDBALFilterType |
|
11 | { |
|
12 | /** |
|
13 | * @param Request $request |
|
14 | * @param array &$data |
|
15 | * @param string $uniqueId |
|
16 | */ |
|
17 | public function bindRequest(Request $request, array &$data, $uniqueId) |
|
18 | { |
|
19 | $data['comparator'] = $request->query->get('filter_comparator_'.$uniqueId); |
|
20 | $data['value'] = $request->query->get('filter_value_'.$uniqueId); |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * @param array $data |
|
25 | * @param string $uniqueId |
|
26 | */ |
|
27 | public function apply(array $data, $uniqueId) |
|
28 | { |
|
29 | if (isset($data['value']) && isset($data['comparator'])) { |
|
30 | switch ($data['comparator']) { |
|
31 | case 'equals': |
|
32 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->eq($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
33 | $this->queryBuilder->setParameter('var_'.$uniqueId, $data['value']); |
|
34 | ||
35 | break; |
|
36 | case 'notequals': |
|
37 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->neq($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
38 | $this->queryBuilder->setParameter('var_'.$uniqueId, $data['value']); |
|
39 | ||
40 | break; |
|
41 | case 'contains': |
|
42 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->like($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
43 | $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$data['value'].'%'); |
|
44 | ||
45 | break; |
|
46 | case 'doesnotcontain': |
|
47 | $this->queryBuilder->andWhere($this->getAlias().$this->columnName.' NOT LIKE :var_'.$uniqueId); |
|
48 | $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$data['value'].'%'); |
|
49 | ||
50 | break; |
|
51 | case 'startswith': |
|
52 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->like($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
53 | $this->queryBuilder->setParameter('var_'.$uniqueId, $data['value'].'%'); |
|
54 | ||
55 | break; |
|
56 | case 'endswith': |
|
57 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->like($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
58 | $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$data['value']); |
|
59 | ||
60 | break; |
|
61 | case 'empty': |
|
62 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->orX( |
|
63 | $this->queryBuilder->expr()->isNull($this->getAlias().$this->columnName), |
|
64 | $this->queryBuilder->expr()->eq($this->getAlias().$this->columnName, '\'-\''), |
|
65 | $this->queryBuilder->expr()->eq($this->getAlias().$this->columnName, ':var_empty_'.$uniqueId) |
|
66 | )); |
|
67 | $this->queryBuilder->setParameter('var_empty_'.$uniqueId, ''); |
|
68 | ||
69 | break; |
|
70 | } |
|
71 | } |
|
72 | } |
|
73 | ||
74 | /** |
|
75 | * @return string |
|
76 | */ |
|
77 | public function getTemplate() |
|
78 | { |
|
79 | return 'KunstmaanAdminListBundle:FilterType:stringFilter.html.twig'; |
|
80 | } |
|
81 | } |
|
82 |
@@ 10-81 (lines=72) @@ | ||
7 | /** |
|
8 | * StringFilterType |
|
9 | */ |
|
10 | class StringFilterType extends AbstractORMFilterType |
|
11 | { |
|
12 | /** |
|
13 | * @param Request $request |
|
14 | * @param array &$data |
|
15 | * @param string $uniqueId |
|
16 | */ |
|
17 | public function bindRequest(Request $request, array &$data, $uniqueId) |
|
18 | { |
|
19 | $data['comparator'] = $request->query->get('filter_comparator_'.$uniqueId); |
|
20 | $data['value'] = $request->query->get('filter_value_'.$uniqueId); |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * @param array $data |
|
25 | * @param string $uniqueId |
|
26 | */ |
|
27 | public function apply(array $data, $uniqueId) |
|
28 | { |
|
29 | if (isset($data['value']) && isset($data['comparator'])) { |
|
30 | switch ($data['comparator']) { |
|
31 | case 'equals': |
|
32 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->eq($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
33 | $this->queryBuilder->setParameter('var_'.$uniqueId, $data['value']); |
|
34 | ||
35 | break; |
|
36 | case 'notequals': |
|
37 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->neq($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
38 | $this->queryBuilder->setParameter('var_'.$uniqueId, $data['value']); |
|
39 | ||
40 | break; |
|
41 | case 'contains': |
|
42 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->like($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
43 | $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$data['value'].'%'); |
|
44 | ||
45 | break; |
|
46 | case 'doesnotcontain': |
|
47 | $this->queryBuilder->andWhere($this->getAlias().$this->columnName.' NOT LIKE :var_'.$uniqueId); |
|
48 | $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$data['value'].'%'); |
|
49 | ||
50 | break; |
|
51 | case 'startswith': |
|
52 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->like($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
53 | $this->queryBuilder->setParameter('var_'.$uniqueId, $data['value'].'%'); |
|
54 | ||
55 | break; |
|
56 | case 'endswith': |
|
57 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->like($this->getAlias().$this->columnName, ':var_'.$uniqueId)); |
|
58 | $this->queryBuilder->setParameter('var_'.$uniqueId, '%'.$data['value']); |
|
59 | ||
60 | break; |
|
61 | case 'empty': |
|
62 | $this->queryBuilder->andWhere($this->queryBuilder->expr()->orX( |
|
63 | $this->queryBuilder->expr()->isNull($this->getAlias().$this->columnName), |
|
64 | $this->queryBuilder->expr()->eq($this->getAlias().$this->columnName, '\'-\''), |
|
65 | $this->queryBuilder->expr()->eq($this->getAlias().$this->columnName, ':var_empty_'.$uniqueId) |
|
66 | )); |
|
67 | $this->queryBuilder->setParameter('var_empty_'.$uniqueId, ''); |
|
68 | ||
69 | break; |
|
70 | } |
|
71 | } |
|
72 | } |
|
73 | ||
74 | /** |
|
75 | * @return string |
|
76 | */ |
|
77 | public function getTemplate() |
|
78 | { |
|
79 | return 'KunstmaanAdminListBundle:FilterType:stringFilter.html.twig'; |
|
80 | } |
|
81 | } |
|
82 |