Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
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
     * @return object
144
     */
145
    public function decorateNewEntity($entity)
146
    {
147
        $entity->setPopup($this->getPopup());
148
149
        return $entity;
150
    }
151
152
    /**
153
     * @param object|array $item
154
     *
155
     * @return bool
156
     */
157
    public function canEdit($item)
158
    {
159
        return true;
160
    }
161
162
    /**
163
     * Configure if it's possible to delete the given $item
164
     *
165
     * @param object|array $item
166
     *
167
     * @return bool
168
     */
169
    public function canDelete($item)
170
    {
171
        return true;
172
    }
173
174
    /**
175
     * Configure if it's possible to add new items
176
     *
177
     * @return bool
178
     */
179
    public function canAdd()
180
    {
181
        return true;
182
    }
183
184
    /**
185
     * @return int
186
     */
187
    public function getPopupId()
188
    {
189
        return $this->popupId;
190
    }
191
192
    /**
193
     * @param int $popupId
194
     */
195
    public function setPopupId($popupId)
196
    {
197
        $this->popupId = $popupId;
198
    }
199
200
    /**
201
     * @return AbstractPopup
202
     */
203
    public function getPopup()
204
    {
205
        return $this->em->getRepository('KunstmaanLeadGenerationBundle:Popup\AbstractPopup')->find($this->getPopupId());
206
    }
207
}
208