Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

AdminList/FormPageAdminListConfigurator.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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([$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)
53 1
            ->addField('lang', 'kuma_form.list.header.language', true)
54 1
            ->addField('url', 'kuma_form.list.header.path', true);
55 1
    }
56
57
    /**
58
     * Add a view action.
59
     */
60 1
    public function buildItemActions()
61
    {
62
        $create_route = function (EntityInterface $item) {
63
            return [
64 1
                'path' => 'KunstmaanFormBundle_formsubmissions_list',
65 1
                'params' => ['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
82
     */
83 1
    public function getEditUrlFor($item)
84
    {
85
        return [
86 1
            'path' => 'KunstmaanFormBundle_formsubmissions_list',
87 1
            'params' => ['nodeTranslationId' => $item->getId()],
88
        ];
89
    }
90
91
    /**
92
     * Return the url to list all the items
93
     *
94
     * @return array
95
     */
96 1
    public function getIndexUrl()
97
    {
98 1
        return ['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
     * @return array
0 ignored issues
show
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...
120
     */
121 1
    public function getAddUrlFor(array $params = [])
122
    {
123 1
        return '';
124
    }
125
126
    /**
127
     * Configure if it's possible to delete the given $item
128
     *
129
     * @param mixed $item
130
     *
131
     * @return bool
132
     */
133 1
    public function canDelete($item)
134
    {
135 1
        return false;
136
    }
137
138
    /**
139
     * Get the delete url for the given $item
140
     *
141
     * @param mixed $item
142
     *
143
     * @return array
144
     */
145 1
    public function getDeleteUrlFor($item)
146
    {
147 1
        return [];
148
    }
149
150
    /**
151
     * @return string
152
     */
153 1
    public function getBundleName()
154
    {
155 1
        return 'KunstmaanNodeBundle';
156
    }
157
158
    /**
159
     * @return string
160
     */
161 1
    public function getEntityName()
162
    {
163 1
        return 'NodeTranslation';
164
    }
165
166
    /**
167
     * Override controller path (because actions for different entities are defined in a single Settings controller).
168
     *
169
     * @return string
170
     */
171 1
    public function getControllerPath()
172
    {
173 1
        return 'KunstmaanFormBundle:FormSubmissions';
174
    }
175
176
    /**
177
     * @param QueryBuilder $queryBuilder The query builder
178
     */
179 1
    public function adaptQueryBuilder(QueryBuilder $queryBuilder)
180
    {
181 1
        parent::adaptQueryBuilder($queryBuilder);
182 1
        $queryBuilder->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
183 1
            ->andWhere(
184 1
                'n.id IN (SELECT m.id FROM Kunstmaan\FormBundle\Entity\FormSubmission s join s.node m)'
185
            )
186 1
            ->addOrderBy('n.id', 'DESC');
187 1
    }
188
}
189