Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

AdminList/FormSubmissionAdminListConfigurator.php (2 issues)

Checks whether return doc types can be made more specific.

Documentation Informational

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\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
9
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\DateFilterType;
10
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\StringFilterType;
11
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
12
13
/**
14
 * Adminlist configuration to list all the form submissions for a given NodeTranslation
15
 */
16
class FormSubmissionAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
17
{
18
    /**
19
     * @var NodeTranslation
20
     */
21
    protected $nodeTranslation;
22
23
    /**
24
     * @var bool
25
     */
26
    protected $deletableFormsubmissions;
27
28
    /**
29
     * @param EntityManager   $em                       The entity manager
30
     * @param NodeTranslation $nodeTranslation          The node translation
31
     * @param bool            $deletableFormsubmissions Can formsubmissions be deleted or not
32
     */
33
    public function __construct(EntityManager $em, $nodeTranslation, $deletableFormsubmissions = false)
34
    {
35
        parent::__construct($em);
36
        $this->nodeTranslation = $nodeTranslation;
37
        $this->deletableFormsubmissions = $deletableFormsubmissions;
38
    }
39
40
    /**
41
     * Configure the fields you can filter on
42
     */
43
    public function buildFilters()
44
    {
45
        $builder = $this->getFilterBuilder();
46
        $builder->add('created', new DateFilterType('created'), 'Date')
47
                ->add('lang', new StringFilterType('lang'), 'Language')
48
                ->add('ipAddress', new StringFilterType('ipAddress'), 'IP Address');
49
    }
50
51
    /**
52
     * Configure the visible columns
53
     */
54
    public function buildFields()
55
    {
56
        $this->addField('created', 'kuma_form.submission.list.header.created', true)
57
             ->addField('lang', 'kuma_form.submission.list.header.language', true)
58
             ->addField('ipAddress', 'kuma_form.submission.list.header.ip_address', true);
59
    }
60
61
    /**
62
     * Add a view action.
63
     */
64
    public function buildItemActions()
65
    {
66
        $nodeTranslation = $this->nodeTranslation;
67
        $create_route = function (EntityInterface $item) use ($nodeTranslation) {
68
            $arr = array('path' => 'KunstmaanFormBundle_formsubmissions_list_edit', 'params' => array('nodeTranslationId' => $nodeTranslation->getId(), 'submissionId' => $item->getId()));
69
70
            return $arr;
71
        };
72
        $ia = new \Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction($create_route, 'eye', 'View');
73
        $this->addItemAction($ia);
74
    }
75
76
    public function canEdit($item)
77
    {
78
        return false;
79
    }
80
81
    /**
82
     * Return the url to edit the given $item
83
     *
84
     * @param mixed $item
85
     *
86
     * @return array
0 ignored issues
show
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...
87
     */
88
    public function getEditUrlFor($item)
89
    {
90
        return array(
91
            'path' => 'KunstmaanFormBundle_formsubmissions_list_edit',
92
            'params' => array('nodeTranslationId' => $this->nodeTranslation->getId(), 'submissionId' => $item->getId()),
93
        );
94
    }
95
96
    /**
97
     * Return the url to list all the items
98
     *
99
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,string|array<string,integer>>.

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...
100
     */
101
    public function getIndexUrl()
102
    {
103
        return array(
104
            'path' => 'KunstmaanFormBundle_formsubmissions_list',
105
            'params' => array('nodeTranslationId' => $this->nodeTranslation->getId()),
106
        );
107
    }
108
109
    /**
110
     * Configure if it's possible to add new items
111
     *
112
     * @return bool
113
     */
114
    public function canAdd()
115
    {
116
        return false;
117
    }
118
119
    /**
120
     * Configure the types of items you can add
121
     *
122
     * @param array $params
123
     *
124
     * @return string
125
     */
126
    public function getAddUrlFor(array $params = array())
127
    {
128
        return '';
129
    }
130
131
    /**
132
     * Configure if it's possible to delete the given $item
133
     *
134
     * @param mixed $item
135
     *
136
     * @return bool
137
     */
138
    public function canDelete($item)
139
    {
140
        return $this->deletableFormsubmissions;
141
    }
142
143
    /**
144
     * Configure if it's possible to export the listed items
145
     *
146
     * @return bool
147
     */
148
    public function canExport()
149
    {
150
        return true;
151
    }
152
153
    /**
154
     * Get the delete url for the given $item
155
     *
156
     * @param mixed $item
157
     *
158
     * @return array
159
     */
160
    public function getDeleteUrlFor($item)
161
    {
162
        if (!$this->deletableFormsubmissions) {
163
            return [];
164
        }
165
166
        return [
167
            'path' => 'KunstmaanFormBundle_formsubmissions_delete',
168
            'params' => ['id' => $item->getId()],
169
        ];
170
    }
171
172
    /**
173
     * Get the url to export the listed items
174
     *
175
     * @return array|string
176
     */
177
    public function getExportUrl()
178
    {
179
        return array('path' => 'KunstmaanFormBundle_formsubmissions_export', 'params' => array('nodeTranslationId' => $this->nodeTranslation->getId()));
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getBundleName()
186
    {
187
        return 'KunstmaanFormBundle';
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getEntityName()
194
    {
195
        return 'FormSubmission';
196
    }
197
198
    /**
199
     * Make some modifications to the default created query builder
200
     *
201
     * @param QueryBuilder $queryBuilder The query builder
202
     * @param array        $params       The parameters
203
     */
204
    public function adaptQueryBuilder(QueryBuilder $queryBuilder, array $params = array())
205
    {
206
        parent::adaptQueryBuilder($queryBuilder);
207
        $queryBuilder
208
                ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
209
                ->andWhere('n.id = :node')
210
                ->andWhere('b.lang = :lang')
211
                ->setParameter('node', $this->nodeTranslation->getNode()->getId())
212
                ->setParameter('lang', $this->nodeTranslation->getLang())
213
                ->addOrderBy('b.created', 'DESC');
214
    }
215
}
216