GoogleMapBasic_Controller   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 5
dl 0
loc 106
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A HasGoogleMap() 0 4 2
B GoogleMapBasic() 0 41 4
A GoogleMapBasicStaticMapSource() 0 12 1
A GoogleMapBasicExternalLink() 0 7 2
A GoogleMapBasicExternalLinkHTML() 0 6 2
A googleMapBasicCenterForLink() 0 12 4
A cleanJS() 0 8 1
1
<?php
2
3
class GoogleMapBasic_Controller extends Extension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private static $js_location = '';
0 ignored issues
show
Unused Code introduced by
The property $js_location is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
6
7
    private static $id_of_map_div = 'GoogleMapBasic';
0 ignored issues
show
Unused Code introduced by
The property $id_of_map_div is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
8
9
    private static $api_key = '';
0 ignored issues
show
Unused Code introduced by
The property $api_key is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
    public function HasGoogleMap()
12
    {
13
        return $this->owner->ShowMap && $this->owner->Address;
0 ignored issues
show
Bug introduced by
The property ShowMap does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property Address does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
14
    }
15
16
    public function GoogleMapBasic()
17
    {
18
        if ($this->owner->HasGoogleMap()) {
19
            if ($this->owner->StaticMap) {
0 ignored issues
show
Bug introduced by
The property StaticMap does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
20
                return true;
21
            } else {
22
                $fileLocation = Config::inst()->get("GoogleMapBasic_Controller", "js_location");
23
                $idOfMapDiv = Config::inst()->get("GoogleMapBasic_Controller", "id_of_map_div");
24
                $apiKey = Config::inst()->get("GoogleMapBasic_Controller", "api_key");
25
                if (! $fileLocation) {
26
                    $fileLocation = 'googlemapbasic/javascript/GoogleMapBasic.js';
27
                }
28
                Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
29
                Requirements::javascript(Director::protocol() . 'maps.googleapis.com/maps/api/js?key='.$apiKey .'');
30
                Requirements::javascript($fileLocation);
31
                $infoWindow = '<div class="infoWindowContent typography">'.$this->owner->InfoWindowContent.$this->GoogleMapBasicExternalLinkHTML().'</div>';
0 ignored issues
show
Bug introduced by
The property InfoWindowContent does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
32
                Requirements::customScript(
33
                    "
34
                    if(typeof GoogleMapBasicOptions === 'undefined') {
35
                        var GoogleMapBasicOptions = new Array();
36
                    }
37
                    GoogleMapBasicOptions.push(
38
                        {
39
                            idOfMapDiv: \"".$this->cleanJS($idOfMapDiv)."\",
40
                            infoWindowContent: \"".$this->cleanJS($infoWindow)."\",
41
                            title: \"".$this->cleanJS($this->owner->Title)."\",
0 ignored issues
show
Bug introduced by
The property Title does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
                            address: \"".$this->cleanJS($this->owner->Address)."\",
0 ignored issues
show
Bug introduced by
The property Address does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
43
                            lat: ".floatval($this->owner->Lat).",
0 ignored issues
show
Bug introduced by
The property Lat does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
44
                            lng: ".floatval($this->owner->Lng).",
0 ignored issues
show
Bug introduced by
The property Lng does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
45
                            zoomLevel: ".intval($this->owner->ZoomLevel)."
0 ignored issues
show
Bug introduced by
The property ZoomLevel does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
46
                        }
47
                    );
48
                    ",
49
                    'GoogleMapBasicData'
50
                );
51
                Requirements::themedCSS('GoogleMapBasic', "googlemapbasic");
52
                return _t("GoolgeMapBasic.MAPLOADING", "map loading...");
53
            }
54
        }
55
        return false;
56
    }
57
58
    public function GoogleMapBasicStaticMapSource($width = 512, $height = 512)
59
    {
60
        $center = $this->googleMapBasicCenterForLink();
61
        $src = Director::protocol() . 'maps.googleapis.com/maps/api/staticmap?';
62
        $src .= 'center='.$center;
63
        $src .= '&zoom='.$this->owner->ZoomLevel;
0 ignored issues
show
Bug introduced by
The property ZoomLevel does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64
        $src .= '&size='.$width.'x'.$height.'';
65
        $src .= '&maptype=roadmap';
66
        $src .= '&markers=color:red%7C'.$center;
67
68
        return $src;
69
    }
70
71
72
    public function GoogleMapBasicExternalLink()
73
    {
74
        if ($this->owner->HasGoogleMap()) {
75
            $center = $this->googleMapBasicCenterForLink();
76
            return Director::protocol() . 'maps.google.com/maps?q='.$center.'&z='.$this->owner->ZoomLevel;
0 ignored issues
show
Bug introduced by
The property ZoomLevel does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
77
        }
78
    }
79
80
    public function GoogleMapBasicExternalLinkHTML()
81
    {
82
        if ($this->owner->HasGoogleMap()) {
83
            return '<p id="GoogleMapBasicExternalLink"><a href="'.$this->GoogleMapBasicExternalLink().'" target="_map">'._t("GoogleMapBasic.OPENINGOOGLEMAPS", "open in Google Maps").'</a></p>';
84
        }
85
    }
86
87
    protected function googleMapBasicCenterForLink()
88
    {
89
        if ($this->owner->Lat && $this->owner->Lng) {
90
            $center = $this->owner->Lat.','.$this->owner->Lng;
0 ignored issues
show
Bug introduced by
The property Lat does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property Lng does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
91
        } elseif ($this->owner->Address) {
0 ignored issues
show
Bug introduced by
The property Address does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
92
            $center = urlencode($this->owner->Address);
93
        } else {
94
            $center = '';
95
        }
96
97
        return $center;
98
    }
99
100
    protected function cleanJS($s)
101
    {
102
        $s = Convert::raw2js($s);
103
        $s = str_replace("\r\n", " ", $s);
104
        $s = str_replace("\n", " ", $s);
105
        $s = str_replace('/', '\/', $s);
106
        return $s;
107
    }
108
}
109