|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Filter; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
|
15
|
|
|
|
|
16
|
|
|
class CallbackFilter extends Filter |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function association(ProxyQueryInterface $queryBuilder, $data) |
|
22
|
|
|
{ |
|
23
|
|
|
return array($this->getOption('alias', $queryBuilder->getRootAlias()), false); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) |
|
30
|
|
|
{ |
|
31
|
|
|
if (!is_callable($this->getOption('callback'))) { |
|
32
|
|
|
throw new \RuntimeException(sprintf('Please provide a valid callback option "filter" for field "%s"', $this->getName())); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$this->active = call_user_func($this->getOption('callback'), $queryBuilder, $alias, $field, $data); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getDefaultOptions() |
|
42
|
|
|
{ |
|
43
|
|
|
return array( |
|
44
|
|
|
'callback' => null, |
|
45
|
|
|
'field_type' => 'text', |
|
46
|
|
|
'operator_type' => 'hidden', |
|
47
|
|
|
'operator_options' => array() |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getRenderSettings() |
|
55
|
|
|
{ |
|
56
|
|
|
return array('sonata_type_filter_default', array( |
|
57
|
|
|
'field_type' => $this->getFieldType(), |
|
58
|
|
|
'field_options' => $this->getFieldOptions(), |
|
59
|
|
|
'operator_type' => $this->getOption('operator_type'), |
|
60
|
|
|
'operator_options' => $this->getOption('operator_options'), |
|
61
|
|
|
'label' => $this->getLabel() |
|
62
|
|
|
)); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|