Completed
Push — 3.1 ( 9bc055...44afa5 )
by Gordon
19:43
created

MapLayerExtension::updateHasGeo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
class MapLayerExtension extends DataExtension
4
{
5
    public static $many_many = array(
6
            'MapLayers' => 'MapLayer',
7
    );
8
9
    public static $belongs_many_many_extraFields = array(
10
        'MapLayers' => array(
11
            'SortOrder' => 'Int',
12
        ),
13
    );
14
15 1
    public function updateCMSFields(FieldList $fields)
16
    {
17 1
        $gridConfig2 = GridFieldConfig_RelationEditor::create();
18 1
        $gridConfig2->getComponentByType(
19 1
            'GridFieldAddExistingAutocompleter')->
20 1
            setSearchFields(array('Title')
21 1
        );
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 12 spaces, but found 8).
Loading history...
22 1
        $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100);
23 1
        $gridField2 = new GridField('Map Layers',
24 1
            'Map Layers:',
25 1
            $this->owner->MapLayers(),
26
            $gridConfig2
27 1
        );
28 1
        $fields->addFieldToTab('Root.MapLayers', $gridField2);
29 1
    }
30
31 1
    /**
32
     * Only set has geo to true if layers exist
33
     * @param  boolean &$hasGeo will be set to true if any layers
34
     */
35
    public function updateHasGeo(&$hasGeo)
36
    {
37
        if ($this->owner->MapLayers()->count() > 0) {
38
            $hasGeo = true;
39
        }
40
    }
41
42
    /**
43
     * Add layers if the exist to a map from the MapExtension
44
     * @param  MapAPI &$map      object representing the map
45
     * @param  boolean &$autozoom true to auto zoom, false not to
46
     */
47
    public function updateBasicMap(&$map, &$autozoom)
48
    {
49
        // add any KML map layers
50
        foreach ($this->owner->MapLayers() as $layer) {
51
            $map->addKML($layer->KmlFile()->getAbsoluteURL());
52
            // we have a layer, so turn on autozoom
53
            $autozoom = true;
54
        }
55
    }
56
}
57