Completed
Push — 1.x ( e997bd )
by Sullivan
19:38
created

CallbackFilter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 8 2
A getDefaultOptions() 0 9 1
A getRenderSettings() 0 10 1
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