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\DoctrinePHPCRAdminBundle\Filter; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
15
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Filter\Filter as BaseFilter; |
16
|
|
|
|
17
|
|
|
class CallbackFilter extends BaseFilter |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
* |
22
|
|
|
* @throws \InvalidArgumentException if the filter is not configured with a |
23
|
|
|
* callable in the 'callback' option field. |
24
|
|
|
*/ |
25
|
|
|
public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data) |
26
|
|
|
{ |
27
|
|
|
if (!is_callable($this->getOption('callback'))) { |
28
|
|
|
throw new \RuntimeException(sprintf('Please provide a valid callback for option "callback" and field "%s"', $this->getName())); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->active = call_user_func($this->getOption('callback'), $proxyQuery, $alias, $field, $data) === true; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
public function getDefaultOptions() |
38
|
|
|
{ |
39
|
|
|
return array( |
40
|
|
|
'callback' => null, |
41
|
|
|
'field_type' => 'text', |
42
|
|
|
'operator_type' => 'hidden', |
43
|
|
|
'operator_options' => array() |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
public function getRenderSettings() |
51
|
|
|
{ |
52
|
|
|
return array('sonata_type_filter_default', array( |
53
|
|
|
'field_type' => $this->getFieldType(), |
54
|
|
|
'field_options' => $this->getFieldOptions(), |
55
|
|
|
'operator_type' => $this->getOption('operator_type'), |
56
|
|
|
'operator_options' => $this->getOption('operator_options'), |
57
|
|
|
'label' => $this->getLabel() |
58
|
|
|
)); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|