1 | <?php |
||
8 | class MenuController extends FiCoreController |
||
9 | { |
||
10 | |||
11 | 10 | protected function initGestionePermessi() |
|
17 | |||
18 | 10 | public function generamenuAction() |
|
19 | { |
||
20 | 10 | $router = $this->get('router')->match('/')['_route']; |
|
21 | //$homeurl = $this->generateUrl($router, array(), true); |
||
|
|||
22 | 10 | $rispostahome = array(); |
|
23 | 10 | $rispostahome[] = array('percorso' => $this->getUrlObject($this->container->getParameter('appname'), $router, ''), |
|
24 | 10 | 'nome' => $this->container->getParameter('appname'), |
|
25 | 10 | 'target' => '', |
|
26 | ); |
||
27 | |||
28 | 10 | $em = $this->get('doctrine')->getManager(); |
|
29 | /* @var $qb \Doctrine\ORM\QueryBuilder */ |
||
30 | 10 | $qb = $em->createQueryBuilder(); |
|
31 | 10 | $qb->select(array('a')); |
|
32 | 10 | $qb->from('FiCoreBundle:MenuApplicazione', 'a'); |
|
33 | 10 | $qb->where('a.attivo = :attivo and (a.padre is null or a.padre = 0)'); |
|
34 | 10 | $qb->setParameter('attivo', true); |
|
35 | 10 | $qb->orderBy('a.padre', 'ASC'); |
|
36 | 10 | $qb->orderBy('a.ordine', 'ASC'); |
|
37 | 10 | $menu = $qb->getQuery()->getResult(); |
|
38 | |||
39 | 10 | $risposta = array_merge($rispostahome, $this->getMenu($menu)); |
|
40 | 10 | $webdir = $this->get('kernel')->getRootDir() . '/../web'; |
|
41 | 10 | $pathmanuale = '/uploads/manuale.pdf'; |
|
42 | 10 | $username = ""; |
|
43 | 10 | $urlLogout = ""; |
|
44 | |||
45 | 10 | if (file_exists($webdir . $pathmanuale)) { |
|
46 | $risposta[] = array('percorso' => $this->getUrlObject('Manuale', $pathmanuale, '_blank'), 'nome' => 'Manuale', 'target' => '_blank'); |
||
47 | } |
||
48 | |||
49 | 10 | if ($this->get('security.token_storage')->getToken()->getProviderKey() === 'secured_area') { |
|
50 | $username = $this->getUser()->getUsername(); |
||
51 | $urlLogout = $this->generateUrl('fi_autenticazione_signout'); |
||
52 | } |
||
53 | |||
54 | 10 | if ($this->get('security.token_storage')->getToken()->getProviderKey() === 'main') { |
|
55 | 10 | $username = $this->get('security.token_storage')->getToken()->getUser()->getUsername(); |
|
56 | 10 | $urlLogout = $this->generateUrl('fos_user_security_logout'); |
|
57 | 10 | } |
|
58 | |||
59 | 10 | $risposta[] = array('percorso' => $this->getUrlObject($username, '', ''), 'nome' => $username, 'target' => '', |
|
60 | 'sottolivello' => array( |
||
61 | 10 | array('percorso' => $urlLogout, 'nome' => 'Logout', 'target' => ''), |
|
62 | 10 | ), |
|
63 | ); |
||
64 | |||
65 | 10 | return $this->render('FiCoreBundle:Menu:menu.html.twig', array('risposta' => $risposta)); |
|
66 | } |
||
67 | |||
68 | 10 | protected function getMenu($menu) |
|
69 | { |
||
70 | 10 | $gestionepermessi = $this->initGestionePermessi(); |
|
71 | |||
72 | 10 | $risposta = array(); |
|
73 | 10 | $em = $this->get('doctrine')->getManager(); |
|
74 | |||
75 | 10 | foreach ($menu as $item) { |
|
76 | 10 | $visualizzare = true; |
|
77 | |||
78 | 10 | if ($item->isAutorizzazionerichiesta()) { |
|
79 | $visualizzare = $gestionepermessi->sulmenu(array('modulo' => $item->getTag())); |
||
80 | } |
||
81 | |||
82 | 10 | if ($visualizzare) { |
|
83 | 10 | $qb = $em->createQueryBuilder(); |
|
84 | 10 | $qb->select(array('a')); |
|
85 | 10 | $qb->from('FiCoreBundle:MenuApplicazione', 'a'); |
|
86 | 10 | $qb->where('a.padre = :padre_id'); |
|
87 | 10 | $qb->andWhere('a.attivo = :attivo'); |
|
88 | 10 | $qb->orderBy('a.padre', 'ASC'); |
|
89 | 10 | $qb->orderBy('a.ordine', 'ASC'); |
|
90 | 10 | $qb->setParameter('padre_id', $item->getId()); |
|
91 | 10 | $qb->setParameter('attivo', true); |
|
92 | 10 | $submenu = $qb->getQuery()->getResult(); |
|
93 | |||
94 | 10 | $sottomenutabelle = $this->getSubMenu($submenu); |
|
95 | |||
96 | 10 | $risposta[] = array( |
|
97 | 10 | 'percorso' => $this->getUrlObject($item->getNome(), $item->getPercorso(), $item->getTarget()), |
|
98 | 10 | 'nome' => $item->getNome(), |
|
99 | 10 | 'sottolivello' => $sottomenutabelle, |
|
100 | 10 | 'target' => $item->getTarget(), |
|
101 | 10 | 'notifiche' => $item->hasNotifiche(), |
|
102 | 10 | 'tag' => $item->getTag(), |
|
103 | 10 | 'percorsonotifiche' => $this->getUrlObject($item->getNome(), $item->getPercorsonotifiche(), ''), |
|
104 | ); |
||
105 | 10 | unset($submenu); |
|
106 | 10 | unset($sottomenutabelle); |
|
107 | 10 | } |
|
108 | 10 | } |
|
109 | |||
110 | 10 | return $risposta; |
|
111 | } |
||
112 | |||
113 | 10 | protected function getSubMenu($submenu) |
|
114 | { |
||
115 | 10 | $gestionepermessi = $this->initGestionePermessi(); |
|
116 | |||
117 | 10 | $sottomenutabelle = array(); |
|
118 | 10 | foreach ($submenu as $subitem) { |
|
119 | 10 | $visualizzare = true; |
|
120 | 10 | if ($subitem->isAutorizzazionerichiesta()) { |
|
121 | $visualizzare = $gestionepermessi->sulmenu(array('modulo' => $subitem->getTag())); |
||
122 | } |
||
123 | |||
124 | 10 | if ($visualizzare) { |
|
125 | 10 | $vettoresottomenu = $this->getMenu(array($subitem)); |
|
126 | 10 | $sottomenu = $vettoresottomenu[0]; |
|
127 | |||
128 | 10 | if (isset($sottomenu['sottolivello']) && count($sottomenu['sottolivello']) > 0) { |
|
129 | 10 | $sottolivellomenu = array('sottolivello' => $sottomenu['sottolivello']); |
|
130 | 10 | $menuobj = $this->getUrlObject($subitem->getNome(), $subitem->getPercorso(), $subitem->getTarget()); |
|
131 | 10 | $sottomenutabelle[] = array_merge($menuobj, $sottolivellomenu); |
|
132 | 10 | } else { |
|
133 | 10 | $sottomenutabelle[] = $this->getUrlObject($subitem->getNome(), $subitem->getPercorso(), $subitem->getTarget()); |
|
134 | } |
||
135 | 10 | } |
|
136 | 10 | } |
|
137 | |||
138 | 10 | return $sottomenutabelle; |
|
139 | } |
||
140 | |||
141 | 10 | protected function getUrlObject($nome, $percorso, $target) |
|
149 | |||
150 | 10 | protected function routeExists($name) |
|
160 | |||
161 | protected function urlExists($name) |
||
173 | |||
174 | protected function checkUrl($name, $proxy) |
||
175 | { |
||
176 | $ch = curl_init($name); |
||
198 | } |
||
199 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.