Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

AdminList/RulesAdminListConfigurator.php (7 issues)

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\LeadGenerationBundle\AdminList;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\QueryBuilder;
7
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
8
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
9
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM;
10
use Kunstmaan\LeadGenerationBundle\Entity\Popup\AbstractPopup;
11
12
class RulesAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
13
{
14
    /**
15
     * @var int
16
     */
17
    protected $popupId;
18
19
    /**
20
     * @param EntityManager $em        The entity manager
21
     * @param AclHelper     $aclHelper The acl helper
22
     * @param int           $id        The if of the popup
23
     */
24 View Code Duplication
    public function __construct(EntityManager $em, AclHelper $aclHelper = null, $id)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        parent::__construct($em, $aclHelper);
27
28
        $this->setPopupId($id);
29
        $this->setListTemplate('@KunstmaanLeadGeneration/AdminList/rules-list.html.twig');
30
        $this->setEditTemplate('@KunstmaanLeadGeneration/AdminList/rules-edit.html.twig');
31
        $this->setAddTemplate('@KunstmaanLeadGeneration/AdminList/rules-edit.html.twig');
32
    }
33
34
    /**
35
     * @param QueryBuilder $queryBuilder
36
     * @param array        $params
37
     */
38
    public function adaptQueryBuilder(QueryBuilder $queryBuilder, array $params = array())
39
    {
40
        $queryBuilder->where('b.popup = :id');
41
        $queryBuilder->setParameter('id', $this->getPopupId());
42
        $queryBuilder->orderBy('b.id', 'ASC');
43
    }
44
45
    /**
46
     * Return the url to list all the items
47
     *
48
     * @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...
49
     */
50
    public function getIndexUrl()
51
    {
52
        return array(
53
            'path' => 'kunstmaanleadgenerationbundle_admin_rule_abstractrule_detail',
54
            'params' => array('popup' => $this->getPopupId()),
55
        );
56
    }
57
58
    /**
59
     * Get the edit url for the given $item
60
     *
61
     * @param object $item
62
     *
63
     * @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...
64
     */
65 View Code Duplication
    public function getEditUrlFor($item)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $params = array('id' => $item->getId(), 'popup' => $this->getPopupId());
68
        $params = array_merge($params, $this->getExtraParameters());
69
70
        return array(
71
            'path' => 'kunstmaanleadgenerationbundle_admin_rule_abstractrule_edit',
72
            'params' => $params,
73
        );
74
    }
75
76
    /**
77
     * Get the delete url for the given $item
78
     *
79
     * @param object $item
80
     *
81
     * @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...
82
     */
83 View Code Duplication
    public function getDeleteUrlFor($item)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $params = array('id' => $item->getId(), 'popup' => $this->getPopupId());
86
        $params = array_merge($params, $this->getExtraParameters());
87
88
        return array(
89
            'path' => 'kunstmaanleadgenerationbundle_admin_rule_abstractrule_delete',
90
            'params' => $params,
91
        );
92
    }
93
94
    /**
95
     * Configure the visible columns
96
     */
97
    public function buildFields()
98
    {
99
        $this->addField('id', 'kuma_lead_generation.rules.list.header.id', true);
100
        $this->addField('classname', 'kuma_lead_generation.rules.list.header.type', false);
101
        $this->addField('jsProperties', 'kuma_lead_generation.rules.list.header.properties', false);
102
    }
103
104
    /**
105
     * Build filters for admin list
106
     */
107
    public function buildFilters()
108
    {
109
        $this->addFilter('id', new ORM\StringFilterType('id'), 'kuma_lead_generation.rules.list.filter.id');
110
    }
111
112
    public function getValue($item, $columnName)
113
    {
114
        if ($columnName == 'jsProperties') {
115
            return json_encode($item->getJsProperties());
116
        }
117
118
        return parent::getValue($item, $columnName);
119
    }
120
121
    /**
122
     * Get bundle name
123
     *
124
     * @return string
125
     */
126
    public function getBundleName()
127
    {
128
        return 'KunstmaanLeadGenerationBundle';
129
    }
130
131
    /**
132
     * Get entity name
133
     *
134
     * @return string
135
     */
136
    public function getEntityName()
137
    {
138
        return 'Rule\AbstractRule';
139
    }
140
141
    /**
142
     * @param object $entity
143
     *
144
     * @return object
145
     */
146
    public function decorateNewEntity($entity)
147
    {
148
        $entity->setPopup($this->getPopup());
149
150
        return $entity;
151
    }
152
153
    /**
154
     * @param object|array $item
155
     *
156
     * @return bool
157
     */
158
    public function canEdit($item)
159
    {
160
        return true;
161
    }
162
163
    /**
164
     * Configure if it's possible to delete the given $item
165
     *
166
     * @param object|array $item
167
     *
168
     * @return bool
169
     */
170
    public function canDelete($item)
171
    {
172
        return true;
173
    }
174
175
    /**
176
     * Configure if it's possible to add new items
177
     *
178
     * @return bool
179
     */
180
    public function canAdd()
181
    {
182
        return true;
183
    }
184
185
    /**
186
     * @return int
187
     */
188
    public function getPopupId()
189
    {
190
        return $this->popupId;
191
    }
192
193
    /**
194
     * @param int $popupId
195
     */
196
    public function setPopupId($popupId)
197
    {
198
        $this->popupId = $popupId;
199
    }
200
201
    /**
202
     * @return AbstractPopup
0 ignored issues
show
Should the return type not be AbstractPopup|null?

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...
203
     */
204
    public function getPopup()
205
    {
206
        return $this->em->getRepository(AbstractPopup::class)->find($this->getPopupId());
207
    }
208
}
209