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

AdminList/MenuItemAdminListConfigurator.php (5 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\MenuBundle\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\MenuBundle\Entity\Menu;
10
use Kunstmaan\MenuBundle\Entity\MenuItem;
11
12
class MenuItemAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurator
13
{
14
    /**
15
     * @var Menu
16
     */
17
    private $menu;
18
19
    /**
20
     * @param EntityManager $em        The entity manager
21
     * @param AclHelper     $aclHelper The acl helper
22
     * @param Menu          $menu
23
     */
24 View Code Duplication
    public function __construct(EntityManager $em, AclHelper $aclHelper = null, Menu $menu)
25
    {
26
        parent::__construct($em, $aclHelper);
27
28
        $this->setListTemplate('KunstmaanMenuBundle:AdminList:list-menu-item.html.twig');
29
        $this->setAddTemplate('KunstmaanMenuBundle:AdminList:edit-menu-item.html.twig');
30
        $this->setEditTemplate('KunstmaanMenuBundle:AdminList:edit-menu-item.html.twig');
31
        $this->menu = $menu;
32
    }
33
34
    /**
35
     * Configure the visible columns
36
     */
37
    public function buildFields()
38
    {
39
        $this->addField('title', 'kuma_menu.menu_item.adminlist.field.title', false, 'KunstmaanMenuBundle:AdminList:menu-item-title.html.twig');
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...
40
        $this->addField('online', 'kuma_menu.menu_item.adminlist.field.online', false, 'KunstmaanMenuBundle:AdminList:menu-item-online.html.twig');
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...
41
        $this->addField('type', 'kuma_menu.menu_item.adminlist.field.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...
42
        $this->addField('url', 'kuma_menu.menu_item.adminlist.field.url', false, 'KunstmaanMenuBundle:AdminList:menu-item-url.html.twig');
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...
43
        $this->addField('newWindow', 'kuma_menu.menu_item.adminlist.field.new_window', 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...
44
    }
45
46
    /**
47
     * Get bundle name
48
     *
49
     * @return string
50
     */
51
    public function getBundleName()
52
    {
53
        return 'KunstmaanMenuBundle';
54
    }
55
56
    /**
57
     * Get entity name
58
     *
59
     * @return string
60
     */
61
    public function getEntityName()
62
    {
63
        return 'MenuItem';
64
    }
65
66
    /**
67
     * @param QueryBuilder $qb
68
     */
69
    public function adaptQueryBuilder(QueryBuilder $qb)
70
    {
71
        $qb->andWhere('b.menu = :menu');
72
        $qb->setParameter('menu', $this->menu);
73
        $qb->orderBy('b.lft', 'ASC');
74
    }
75
76
    /**
77
     * @param array|object $item       The item
78
     * @param string       $columnName The column name
79
     *
80
     * @return mixed
81
     */
82
    public function getValue($item, $columnName)
83
    {
84
        if ($columnName == 'title') {
85
            return $item->getDisplayTitle();
86
        } elseif ($columnName == 'online') {
87
            return $item;
88
        } elseif ($columnName == 'type') {
89
            if ($item->getType() == MenuItem::TYPE_PAGE_LINK) {
90
                return 'Page link';
91
            } else {
92
                return 'External link';
93
            }
94
        } elseif ($columnName == 'url') {
95
            return $item;
96
        }
97
98
        return parent::getValue($item, $columnName);
99
    }
100
101
    /**
102
     * Return extra parameters for use in list actions.
103
     *
104
     * @return array
105
     */
106
    public function getExtraParameters()
107
    {
108
        return array('menuid' => $this->menu->getId());
109
    }
110
111
    /**
112
     * You can override this method to do some custom things you need to do when adding an entity
113
     *
114
     * @param object $entity
115
     *
116
     * @return mixed
117
     */
118
    public function decorateNewEntity($entity)
119
    {
120
        $entity->setMenu($this->menu);
121
122
        return $entity;
123
    }
124
125
    public function getMenu()
126
    {
127
        return $this->menu;
128
    }
129
130
    /**
131
     * @return int
132
     */
133
    public function getLimit()
134
    {
135
        return 1000;
136
    }
137
}
138