Completed
Push — master ( b453a3...b1e9d6 )
by Ruud
40:05 queued 27:14
created

FormPageAdminListConfigurator::adaptQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Kunstmaan\FormBundle\AdminList;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\QueryBuilder;
7
use Kunstmaan\AdminBundle\Entity\EntityInterface;
8
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
9
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionDefinition;
10
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
11
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\BooleanFilterType;
12
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType;
13
14
/**
15
 * Adminlist configuration to list all the form pages
16
 */
17
class FormPageAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $permission;
23
24
    /**
25
     * @param EntityManager $em         The entity manager
26
     * @param AclHelper     $aclHelper  The ACL helper
27
     * @param string        $permission The permission
28
     */
29 5
    public function __construct(EntityManager $em, AclHelper $aclHelper, $permission)
30
    {
31 5
        parent::__construct($em, $aclHelper);
32 5
        $this->setPermissionDefinition(
33 5
            new PermissionDefinition(array($permission), 'Kunstmaan\NodeBundle\Entity\Node', 'n')
34
        );
35 5
    }
36
37
    /**
38
     * Configure filters
39
     */
40 1
    public function buildFilters()
41
    {
42 1
        $builder = $this->getFilterBuilder();
43 1
        $builder->add('title', new StringFilterType('title'), 'kuma_form.list.filter.title')
44 1
            ->add('online', new BooleanFilterType('online'), 'kuma_form.list.filter.online');
45 1
    }
46
47
    /**
48
     * Configure the visible columns
49
     */
50 1
    public function buildFields()
51
    {
52 1
        $this->addField('title', 'kuma_form.list.header.title', true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53 1
            ->addField('lang', 'kuma_form.list.header.language', true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54 1
            ->addField('url', 'kuma_form.list.header.path', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55 1
    }
56
57
    /**
58
     * Add a view action.
59
     */
60 1
    public function buildItemActions()
61
    {
62
        $create_route = function (EntityInterface $item) {
63
            return array(
64 1
                'path' => 'KunstmaanFormBundle_formsubmissions_list',
65 1
                'params' => array('nodeTranslationId' => $item->getId()),
66
            );
67 1
        };
68 1
        $ia = new \Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction(
69 1
            $create_route,
70 1
            'eye',
71 1
            'View'
72
        );
73 1
        $this->addItemAction($ia);
74 1
    }
75
76
    /**
77
     * Return the url to edit the given $item
78
     *
79
     * @param mixed $item
80
     *
81
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string|array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
82
     */
83 1
    public function getEditUrlFor($item)
84
    {
85
        return array(
86 1
            'path' => 'KunstmaanFormBundle_formsubmissions_list',
87 1
            'params' => array('nodeTranslationId' => $item->getId()),
88
        );
89
    }
90
91
    /**
92
     * Return the url to list all the items
93
     *
94
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
95
     */
96 1
    public function getIndexUrl()
97
    {
98 1
        return array('path' => 'KunstmaanFormBundle_formsubmissions');
99
    }
100
101
    /**
102
     * Configure if it's possible to add new items
103
     *
104
     * @return bool
105
     */
106 1
    public function canAdd()
107
    {
108 1
        return false;
109
    }
110
111 1
    public function canEdit($item)
112
    {
113 1
        return false;
114
    }
115
116
    /**
117
     * Configure the types of items you can add
118
     *
119
     * @param array $params
120
     *
121
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
122
     */
123 1
    public function getAddUrlFor(array $params = array())
124
    {
125 1
        return '';
126
    }
127
128
    /**
129
     * Configure if it's possible to delete the given $item
130
     *
131
     * @param mixed $item
132
     *
133
     * @return bool
134
     */
135 1
    public function canDelete($item)
136
    {
137 1
        return false;
138
    }
139
140
    /**
141
     * Get the delete url for the given $item
142
     *
143
     * @param mixed $item
144
     *
145
     * @return array
146
     */
147 1
    public function getDeleteUrlFor($item)
148
    {
149 1
        return array();
150
    }
151
152
    /**
153
     * @return string
154
     */
155 1
    public function getBundleName()
156
    {
157 1
        return 'KunstmaanNodeBundle';
158
    }
159
160
    /**
161
     * @return string
162
     */
163 1
    public function getEntityName()
164
    {
165 1
        return 'NodeTranslation';
166
    }
167
168
    /**
169
     * Override controller path (because actions for different entities are defined in a single Settings controller).
170
     *
171
     * @return string
172
     */
173 1
    public function getControllerPath()
174
    {
175 1
        return 'KunstmaanFormBundle:FormSubmissions';
176
    }
177
178
    /**
179
     * @param QueryBuilder $queryBuilder The query builder
180
     */
181 1
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
182
    {
183 1
        parent::adaptQueryBuilder($queryBuilder);
184 1
        $queryBuilder->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
185 1
            ->andWhere(
186 1
                'n.id IN (SELECT m.id FROM Kunstmaan\FormBundle\Entity\FormSubmission s join s.node m)'
187
            )
188 1
            ->addOrderBy('n.id', 'DESC');
189 1
    }
190
}
191