Completed
Push — master ( e6c0c9...d841f8 )
by Jeroen
35:52 queued 19:21
created

AdminList/RulesAdminListConfigurator.php (3 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)
25
    {
26
        parent::__construct($em, $aclHelper);
27
28
        $this->setPopupId($id);
29
        $this->setListTemplate('KunstmaanLeadGenerationBundle:AdminList:rules-list.html.twig');
30
        $this->setEditTemplate('KunstmaanLeadGenerationBundle:AdminList:rules-edit.html.twig');
31
        $this->setAddTemplate('KunstmaanLeadGenerationBundle: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
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
64
     */
65 View Code Duplication
    public function getEditUrlFor($item)
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
82
     */
83 View Code Duplication
    public function getDeleteUrlFor($item)
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);
0 ignored issues
show
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...
100
        $this->addField('classname', 'kuma_lead_generation.rules.list.header.type', false);
0 ignored issues
show
false 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...
101
        $this->addField('jsProperties', 'kuma_lead_generation.rules.list.header.properties', false);
0 ignored issues
show
false 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...
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
203
     */
204
    public function getPopup()
205
    {
206
        return $this->em->getRepository('KunstmaanLeadGenerationBundle:Popup\AbstractPopup')->find($this->getPopupId());
207
    }
208
}
209