GoogleMapShortCodeHandler::resetCounter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
class GoogleMapShortCodeHandler
4
{
5
    /* Counter used to ensure unique div ids to allow for multiple maps on on page */
6
    private static $gsv_ctr = 1;
7
8 6
    public static function parse_googlemap($arguments, $caption = null, $parser = null)
0 ignored issues
show
Unused Code introduced by
The parameter $caption is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "GoogleMapShortCodeHandler::parse_googlemap" is not in camel caps format
Loading history...
9
    {
10
        // each of latitude and longitude are required at a bare minimum
11 6
        if (!isset($arguments['latitude'])) {
12 1
            return '';
13
        }
14
15 5
        if (!isset($arguments['longitude'])) {
16 1
            return '';
17
        }
18
19
        // defaults - can be overriden by using zoom and FIXME in the shortcode
20
        $defaults = array(
21 4
            'Zoom' => 5,
22 4
            'MapType' => 'road',
23 4
        );
24
25
        // ensure JavaScript for the map service is only downloaded once
26 4
        $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
27 4
        MapUtil::set_map_already_rendered(true);
28
29
        // convert parameters to CamelCase as per standard template conventions
30 4
        $arguments['Latitude'] = $arguments['latitude'];
31 4
        $arguments['Longitude'] = $arguments['longitude'];
32
33
        // optional parameter caption
34 4
        if (isset($arguments['caption'])) {
35 4
            $arguments['Caption'] = $arguments['caption'];
36 4
        }
37
38 4
        if (isset($arguments['maptype'])) {
39 4
            $arguments['MapType'] = $arguments['maptype'];
40 4
        }
41
42
        // optional parameter zoom
43 4
        if (isset($arguments['zoom'])) {
44 4
            $arguments['Zoom'] = $arguments['zoom'];
45 4
        }
46
47
        // the id of the dom element to be used to render the street view
48 4
        $arguments['DomID'] = 'google_sc_map_'.self::$gsv_ctr;
49
50
        // fullscreen
51 4
        $arguments['AllowFullScreen'] = Config::inst()->get('Mappable', 'allow_full_screen');
52
53
        // incrememt the counter to ensure a unique id for each map canvas
54 4
        ++self::$gsv_ctr;
55
56
        // merge defaults and arguments
57 4
        $customised = array_merge($defaults, $arguments);
58
59
        // include JavaScript to be appended at the end of the page, namely params for map rendering
60
        //Requirements::javascriptTemplate("mappable/javascript/google/map.google.template.js", $customised);
61
62
        //get map view template and render the HTML
63 4
        $template = new SSViewer('GoogleMapShortCode');
64
65
        //return the template customised with the parmameters
66 4
        return $template->process(new ArrayData($customised));
67
    }
68
69
    /**
70
     * This is only used for testing, otherwise the sequence of tests change the number returned.
71
     */
72 4
    public static function resetCounter()
73
    {
74 4
        self::$gsv_ctr = 1;
75 4
    }
76
}
77