Completed
Push — master ( 911a15...50617c )
by Julito
30:21
created

SidebarController::socialPanelAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * SidebarController.php
4
 * avanzu-admin
5
 * Date: 23.02.14
6
 */
7
8
namespace Chamilo\ThemeBundle\Controller;
9
10
use Chamilo\ThemeBundle\Event\ShowUserEvent;
11
use Chamilo\ThemeBundle\Event\SidebarMenuEvent;
12
use Chamilo\ThemeBundle\Event\SidebarMenuKnpEvent;
13
use Chamilo\ThemeBundle\Event\ThemeEvents;
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
18
/**
19
 * Class SidebarController
20
 * @package Chamilo\ThemeBundle\Controller
21
 */
22
class SidebarController extends Controller
23
{
24
    /**
25
     * "Hello user" section
26
     * @return Response
27
     */
28 View Code Duplication
    public function userPanelAction()
29
    {
30
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
31
            return new Response();
32
        }
33
34
        $userEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_SIDEBAR_USER, new ShowUserEvent());
35
36
        return $this->render(
37
            'ChamiloThemeBundle:Sidebar:user-panel.html.twig',
38
            array(
39
                'user' => $userEvent->getUser()
40
            )
41
        );
42
    }
43
44
     /**
45
     * User menu section
46
     * @return Response
47
     */
48 View Code Duplication
    public function userProfileAction()
49
    {
50
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
51
            return new Response();
52
        }
53
54
        $userEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_SIDEBAR_USER, new ShowUserEvent());
55
56
        return $this->render(
57
            'ChamiloThemeBundle:Sidebar:user-profile.html.twig',
58
            array(
59
                'user' => $userEvent->getUser()
60
            )
61
        );
62
    }
63
64
      /**
65
     * User menu section
66
     * @return Response
67
     */
68 View Code Duplication
    public function socialPanelAction()
69
    {
70
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_USER)) {
71
            return new Response();
72
        }
73
74
        $userEvent = $this->getDispatcher()->dispatch(ThemeEvents::THEME_SIDEBAR_USER, new ShowUserEvent());
75
76
        return $this->render(
77
            'ChamiloThemeBundle:Sidebar:social-panel.html.twig',
78
            array(
79
                'user' => $userEvent->getUser()
80
            )
81
        );
82
    }
83
84
    /**
85
     * Search bar
86
     * @return Response
87
     */
88
    public function searchFormAction()
89
    {
90
        return $this->render('ChamiloThemeBundle:Sidebar:search-form.html.twig', array());
91
    }
92
93
    /**
94
     * @return EventDispatcher
95
     */
96
    protected function getDispatcher()
97
    {
98
        return $this->get('event_dispatcher');
99
    }
100
101
    /**
102
     * @param Request $request
103
     * @return Response
104
     */
105
    public function menuAction(Request $request)
106
    {
107
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_SETUP_MENU)) {
108
            return new Response();
109
        }
110
111
        $event = $this->getDispatcher()->dispatch(
112
            ThemeEvents::THEME_SIDEBAR_SETUP_MENU,
113
            new SidebarMenuEvent($request)
114
        );
115
116
        return $this->render(
117
            'ChamiloThemeBundle:Sidebar:menu.html.twig',
118
            array(
119
                'menu' => $event->getItems()
120
            )
121
        );
122
    }
123
124
    /**
125
     * @param Request $request
126
     * @return Response
127
     */
128
    public function menuKnpAction(Request $request)
129
    {
130
        if (!$this->getDispatcher()->hasListeners(ThemeEvents::THEME_SIDEBAR_SETUP_MENU_KNP)) {
131
            return new Response();
132
        }
133
134
        /** @var SidebarMenuKnpEvent $event */
135
        $event = $this->getDispatcher()->dispatch(
136
            ThemeEvents::THEME_SIDEBAR_SETUP_MENU_KNP,
137
            new SidebarMenuKnpEvent($request)
138
        );
139
140
        return $this->render(
141
            'ChamiloThemeBundle:Sidebar:menu_knp.html.twig',
142
            array(
143
                'menu' => $event->getMenu()
144
            )
145
        );
146
    }
147
}
148