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\Controller; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\Entity\EntityInterface; |
||
6 | use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractAdminListConfigurator; |
||
7 | use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface; |
||
8 | use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction; |
||
9 | use Kunstmaan\AdminListBundle\Controller\AdminListController; |
||
10 | use Kunstmaan\MenuBundle\Entity\BaseMenu; |
||
11 | use Symfony\Component\Routing\Annotation\Route; |
||
12 | use Symfony\Component\HttpFoundation\RedirectResponse; |
||
13 | use Symfony\Component\HttpFoundation\Request; |
||
14 | use Symfony\Component\HttpFoundation\Response; |
||
15 | |||
16 | class MenuItemAdminListController extends AdminListController |
||
17 | { |
||
18 | /** |
||
19 | * @var AdminListConfiguratorInterface |
||
20 | */ |
||
21 | private $configurator; |
||
22 | |||
23 | /** |
||
24 | * @param Request $request |
||
25 | * @param int $menuid |
||
26 | * @param int $entityId |
||
27 | * |
||
28 | * @return AbstractAdminListConfigurator |
||
29 | */ |
||
30 | public function getAdminListConfigurator(Request $request, $menuid, $entityId = null) |
||
31 | { |
||
32 | if (!isset($this->configurator)) { |
||
33 | $menu = $this->getDoctrine()->getManager()->getRepository( |
||
34 | $this->container->getParameter('kunstmaan_menu.entity.menu.class') |
||
35 | )->find($menuid); |
||
36 | $rootNode = $this->container->get('kunstmaan_admin.domain_configuration')->getRootNode(); |
||
37 | |||
38 | $configuratorClass = $this->container->getParameter('kunstmaan_menu.adminlist.menuitem_configurator.class'); |
||
39 | $this->configurator = new $configuratorClass($this->getEntityManager(), null, $menu); |
||
40 | |||
41 | $adminType = $this->container->getParameter('kunstmaan_menu.form.menuitem_admintype.class'); |
||
42 | $menuItemClass = $this->container->getParameter('kunstmaan_menu.entity.menuitem.class'); |
||
43 | $this->configurator->setAdminType($adminType); |
||
44 | $this->configurator->setAdminTypeOptions(array('menu' => $menu, 'rootNode' => $rootNode, 'menuItemClass' => $menuItemClass, 'entityId' => $entityId, 'locale' => $request->getLocale())); |
||
45 | } |
||
46 | |||
47 | return $this->configurator; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * The index action |
||
52 | * |
||
53 | * @param Request $request |
||
54 | * @param int $menuid |
||
55 | * |
||
56 | * @return Response |
||
57 | * |
||
58 | * @Route("/{menuid}/items", name="kunstmaanmenubundle_admin_menuitem") |
||
59 | */ |
||
60 | public function indexAction(Request $request, $menuid) |
||
61 | { |
||
62 | $menuRepo = $this->getDoctrine()->getManager()->getRepository( |
||
63 | $this->container->getParameter('kunstmaan_menu.entity.menu.class') |
||
64 | ); |
||
65 | |||
66 | /** @var BaseMenu $menu */ |
||
67 | $menu = $menuRepo->find($menuid); |
||
68 | if ($menu->getLocale() != $request->getLocale()) { |
||
69 | /** @var BaseMenu $translatedMenu */ |
||
70 | $translatedMenu = $menuRepo->findOneBy(['locale' => $request->getLocale(), 'name' => $menu->getName()]); |
||
71 | $menuid = $translatedMenu->getId(); |
||
72 | } |
||
73 | |||
74 | $configurator = $this->getAdminListConfigurator($request, $menuid); |
||
75 | $itemRoute = function (EntityInterface $item) use ($menuid) { |
||
76 | return array( |
||
77 | 'path' => 'kunstmaanmenubundle_admin_menuitem_move_up', |
||
78 | 'params' => array( |
||
79 | 'menuid' => $menuid, |
||
80 | 'item' => $item->getId(), |
||
81 | ), |
||
82 | ); |
||
83 | }; |
||
84 | $configurator->addItemAction(new SimpleItemAction($itemRoute, 'arrow-up', 'kuma_admin_list.action.move_up')); |
||
85 | |||
86 | $itemRoute = function (EntityInterface $item) use ($menuid) { |
||
87 | return array( |
||
88 | 'path' => 'kunstmaanmenubundle_admin_menuitem_move_down', |
||
89 | 'params' => array( |
||
90 | 'menuid' => $menuid, |
||
91 | 'item' => $item->getId(), |
||
92 | ), |
||
93 | ); |
||
94 | }; |
||
95 | $configurator->addItemAction(new SimpleItemAction($itemRoute, 'arrow-down', 'kuma_admin_list.action.move_down')); |
||
96 | |||
97 | return parent::doIndexAction($configurator, $request); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * The add action |
||
102 | * |
||
103 | * @Route("/{menuid}/items/add", name="kunstmaanmenubundle_admin_menuitem_add", methods={"GET", "POST"}) |
||
104 | * |
||
105 | * @return array |
||
0 ignored issues
–
show
|
|||
106 | */ |
||
107 | public function addAction(Request $request, $menuid) |
||
108 | { |
||
109 | return parent::doAddAction($this->getAdminListConfigurator($request, $menuid), null, $request); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * The edit action |
||
114 | * |
||
115 | * @param int $id |
||
116 | * |
||
117 | * @Route("{menuid}/items/{id}/edit", requirements={"id" = "\d+"}, name="kunstmaanmenubundle_admin_menuitem_edit", methods={"GET", "POST"}) |
||
118 | * |
||
119 | * @return array |
||
0 ignored issues
–
show
|
|||
120 | */ |
||
121 | public function editAction(Request $request, $menuid, $id) |
||
122 | { |
||
123 | return parent::doEditAction($this->getAdminListConfigurator($request, $menuid, $id), $id, $request); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * The delete action |
||
128 | * |
||
129 | * @param int $id |
||
130 | * |
||
131 | * @Route("{menuid}/items/{id}/delete", requirements={"id" = "\d+"}, name="kunstmaanmenubundle_admin_menuitem_delete", methods={"GET", "POST"}) |
||
132 | * |
||
133 | * @return array |
||
0 ignored issues
–
show
|
|||
134 | */ |
||
135 | public function deleteAction(Request $request, $menuid, $id) |
||
136 | { |
||
137 | return parent::doDeleteAction($this->getAdminListConfigurator($request, $menuid), $id, $request); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Move an item up in the list. |
||
142 | * |
||
143 | * @Route("{menuid}/items/{item}/move-up", name="kunstmaanmenubundle_admin_menuitem_move_up", methods={"GET"}) |
||
144 | * |
||
145 | * @return RedirectResponse |
||
146 | */ |
||
147 | View Code Duplication | public function moveUpAction(Request $request, $menuid, $item) |
|
148 | { |
||
149 | $em = $this->getEntityManager(); |
||
150 | $repo = $em->getRepository($this->container->getParameter('kunstmaan_menu.entity.menuitem.class')); |
||
151 | $item = $repo->find($item); |
||
152 | |||
153 | if ($item) { |
||
154 | $repo->moveUp($item); |
||
155 | } |
||
156 | |||
157 | return new RedirectResponse( |
||
158 | $this->generateUrl('kunstmaanmenubundle_admin_menuitem', array('menuid' => $menuid)) |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Move an item down in the list. |
||
164 | * |
||
165 | * @Route("{menuid}/items/{item}/move-down", name="kunstmaanmenubundle_admin_menuitem_move_down", methods={"GET"}) |
||
166 | * |
||
167 | * @return RedirectResponse |
||
168 | */ |
||
169 | View Code Duplication | public function moveDownAction(Request $request, $menuid, $item) |
|
170 | { |
||
171 | $em = $this->getEntityManager(); |
||
172 | $repo = $em->getRepository($this->container->getParameter('kunstmaan_menu.entity.menuitem.class')); |
||
173 | $item = $repo->find($item); |
||
174 | |||
175 | if ($item) { |
||
176 | $repo->moveDown($item); |
||
177 | } |
||
178 | |||
179 | return new RedirectResponse( |
||
180 | $this->generateUrl('kunstmaanmenubundle_admin_menuitem', array('menuid' => $menuid)) |
||
181 | ); |
||
182 | } |
||
183 | } |
||
184 |
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.