Completed
Push — master ( 3fdf06...e648ff )
by Julito
33:51
created

CourseMenuBuilder::skillsMenu()   B

Complexity

Conditions 6
Paths 13

Size

Total Lines 58
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 31
nc 13
nop 2
dl 0
loc 58
rs 8.7274
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Menu;
5
6
use Knp\Menu\FactoryInterface;
7
use Symfony\Component\DependencyInjection\ContainerAware;
8
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
10
11
/**
12
 * Class CourseMenuBuilder
13
 * @package Chamilo\CoreBundle\Menu
14
 */
15
class CourseMenuBuilder implements ContainerAwareInterface
16
{
17
    use ContainerAwareTrait;
18
19
    /**
20
     * Course menu
21
     *
22
     * @param FactoryInterface $factory
23
     * @param array $options
24
     * @return \Knp\Menu\ItemInterface
25
     */
26
    public function courseMenu(FactoryInterface $factory, array $options)
27
    {
28
        $checker = $this->container->get('security.authorization_checker');
29
        $menu = $factory->createItem('root');
30
        $translator = $this->container->get('translator');
31
        $settingsManager = $this->container->get('chamilo.settings.manager');
32
33
        if ($checker->isGranted('IS_AUTHENTICATED_FULLY')) {
34
            $menu->setChildrenAttribute('class', 'nav nav-pills nav-stacked');
35
            $menu->addChild(
36
                $translator->trans('MyCourses'),
37
                [
38
                    'route' => 'userportal',
39
                    'routeParameters' => ['type' => 'courses'],
40
                ]
41
            );
42
43
            $menu->addChild(
44
                $translator->trans('MySessions'),
45
                [
46
                    'route' => 'userportal',
47
                    'routeParameters' => ['type' => 'sessions'],
48
                ]
49
            );
50
51
            if (api_is_allowed_to_create_course()) {
52
                $lang = $translator->trans('CreateCourse');
53
                if ($settingsManager->getSetting(
54
                        'course.course_validation'
55
                    ) == 'true'
56
                ) {
57
                    $lang = $translator->trans('CreateCourseRequest');
58
                }
59
                $menu->addChild(
60
                    $lang,
61
                    ['route' => 'add_course']
62
                );
63
            }
64
65
            if ($checker->isGranted('ROLE_TEACHER') &&
66
                $settingsManager->getSetting(
67
                    'session.allow_teachers_to_create_sessions'
68
                )
69
            ) {
70
71
                $menu->addChild(
72
                    $translator->trans('AddSession'),
73
                    [
74
                        'route' => 'main',
75
                        'routeParameters' => ['name' => 'session/session_add.php'],
76
                    ]
77
                );
78
            }
79
80
            $link = $this->container->get('router')->generate('web.main');
81
82
            $menu->addChild(
83
                $translator->trans('ManageCourses'),
84
                [
85
                    'uri' => $link.'auth/courses.php?action=sortmycourses',
86
                ]
87
            );
88
89
            $browse = $settingsManager->getSetting(
90
                'display.allow_students_to_browse_courses'
91
            );
92
93
            if ($browse == 'true') {
94
                if ($checker->isGranted('ROLE_STUDENT') && !api_is_drh(
95
                    ) && !api_is_session_admin()
96
                ) {
97
                    $menu->addChild(
98
                        $translator->trans('CourseCatalog'),
99
                        [
100
                            'uri' => $link.'auth/courses.php',
101
                        ]
102
                    );
103
                } else {
104
                    $menu->addChild(
105
                        $translator->trans('Dashboard'),
106
                        [
107
                            'uri' => $link.'dashboard/index.php',
108
                        ]
109
                    );
110
                }
111
            }
112
113
            /** @var \Knp\Menu\MenuItem $menu */
114
            $menu->addChild(
115
                $translator->trans('History'),
116
                [
117
                    'route' => 'userportal',
118
                    'routeParameters' => [
119
                        'type' => 'sessions',
120
                        'filter' => 'history',
121
                    ],
122
                ]
123
            );
124
125
        }
126
127
        return $menu;
128
    }
129
130
    /**
131
     * Skills menu
132
     * @param FactoryInterface $factory
133
     * @param array $options
134
     * @return \Knp\Menu\ItemInterface
135
     */
136
    public function skillsMenu(FactoryInterface $factory, array $options)
137
    {
138
        $checker = $this->container->get('security.authorization_checker');
139
        $translator = $this->container->get('translator');
140
        $settingsManager = $this->container->get('chamilo.settings.manager');
141
        //$allow = $settingsManager->getSetting('hide_my_certificate_link');
142
        $allow = api_get_configuration_value('hide_my_certificate_link');
143
144
        $menu = $factory->createItem('root');
145
        if ($checker->isGranted('IS_AUTHENTICATED_FULLY')) {
146
            $menu->setChildrenAttribute('class', 'nav nav-pills nav-stacked');
147
148
            if ($allow == false) {
149
                $menu->addChild(
150
                    $translator->trans('MyCertificates'),
151
                    [
152
                        'route' => 'main',
153
                        'routeParameters' => ['name' => 'gradebook/my_certificates.php'],
154
                    ]
155
                );
156
            }
157
158
            if ($settingsManager->getSetting(
159
                    'allow_public_certificates'
160
                ) === 'true'
161
            ) {
162
                $menu->addChild(
163
                    $translator->trans('Search'),
164
                    [
165
                        'route' => 'main',
166
                        'routeParameters' => ['name' => 'gradebook/search.php'],
167
                    ]
168
                );
169
            }
170
171
            if ($settingsManager->getSetting('allow_skills_tool') === 'true') {
172
                $menu->addChild(
173
                    $translator->trans('MySkills'),
174
                    [
175
                        'route' => 'main',
176
                        'routeParameters' => ['name' => 'social/my_skills_report.php'],
177
                    ]
178
                );
179
180
                if ($checker->isGranted('ROLE_TEACHER')) {
181
                    $menu->addChild(
182
                        $translator->trans('ManageSkills'),
183
                        [
184
                            'route' => 'main',
185
                            'routeParameters' => ['name' => 'admin/skills_wheel.php'],
186
                        ]
187
                    );
188
                }
189
            }
190
        }
191
192
        return $menu;
193
    }
194
}
195