SiteController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 7
dl 0
loc 89
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 11 1
B Menu() 0 51 5
A MenuItemType() 0 4 1
A GATrackingCode() 0 4 2
A LinkWithSearch() 0 8 1
1
<?php
2
/**
3
 * The base site controller.
4
 */
5
class SiteController extends Controller
6
{
7
8
    public function init()
9
    {
10
        RSSFeed::linkToFeed("add-ons/rss", "New modules on addons.silverstripe.org");
11
12
        Requirements::javascript("//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js");
13
        Requirements::javascript("themes/".SSViewer::current_theme()."/bootstrap/js/bootstrap.min.js");
0 ignored issues
show
Deprecated Code introduced by
The method SSViewer::current_theme() has been deprecated with message: 4.0 Use the "SSViewer.theme" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
14
        Requirements::javascript("themes/".SSViewer::current_theme()."/javascript/addons.js");
0 ignored issues
show
Deprecated Code introduced by
The method SSViewer::current_theme() has been deprecated with message: 4.0 Use the "SSViewer.theme" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
15
        Requirements::javascript("//www.google.com/jsapi");
16
        Requirements::javascript("themes/".SSViewer::current_theme()."/javascript/chart.js");
0 ignored issues
show
Deprecated Code introduced by
The method SSViewer::current_theme() has been deprecated with message: 4.0 Use the "SSViewer.theme" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
17
        parent::init();
18
    }
19
20
    public function Menu()
21
    {
22
        $menu = new ArrayList();
23
24
        $menuEntries = array(
25
            //array('controller' => 'HomeController'),
26
            array('controller' => 'AddonsController'),
27
            array(
28
                'link' => Controller::join_links(
29
                    singleton('AddonsController')->Link(),
30
                    '?type=theme&view=expanded'
31
                ),
32
                'title' => 'Themes',
33
            ),
34
            array('controller' => 'VendorsController'),
35
            array('controller' => 'AuthorsController'),
36
            array('controller' => 'TagsController'),
37
            array('controller' => 'SubmitAddonController'),
38
        );
39
40
        foreach ($menuEntries as $menuEntry) {
41
            if (isset($menuEntry['controller'])) {
42
                $inst = singleton($menuEntry['controller']);
43
                $active = false;
44
45
                foreach (self::$controller_stack as $candidate) {
46
                    $active = (
47
                        $candidate instanceof $menuEntry['controller']
48
                        && $this->request->getVar('type') != 'theme'
49
                    );
50
                }
51
52
                $menu->push(new ArrayData(array(
53
                    'Title' => $inst->Title(),
54
                    'Link' => $inst->Link(),
55
                    'Active' => $active,
56
                    'MenuItemType' => $inst->MenuItemType()
57
                )));
58
            } else {
59
                $active = ($this->request->getVar('type') == 'theme');
60
                $menu->push(new ArrayData(array(
61
                    'Title' => $menuEntry['title'],
62
                    'Link' => $menuEntry['link'],
63
                    'Active' => $active,
64
                    'MenuItemType' => 'link',
65
                )));
66
            }
67
        }
68
69
        return $menu;
70
    }
71
72
    /**
73
     * @return String 'link' or 'button'
74
     */
75
    public function MenuItemType()
76
    {
77
        return 'link';
78
    }
79
80
    public function GATrackingCode()
81
    {
82
        return defined('GA_TRACKING_CODE') ? GA_TRACKING_CODE : null;
83
    }
84
85
    public function LinkWithSearch($extraParamStr = '')
86
    {
87
        $params = array_diff_key($this->request->getVars(), array('url' => null));
88
        parse_str($extraParamStr, $extraParams);
89
        $params = array_merge($params, (array)$extraParams);
90
91
        return Controller::join_links($this->Link(), '?' . http_build_query($params));
92
    }
93
}
94