MapLayerExtension::updateHasGeo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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 View Code Duplication
    public function updateCMSFields(FieldList $fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17 1
        $gridConfig2 = GridFieldConfig_RelationEditor::create();
18 1
        $gridConfig2->getComponentByType(
19 1
            'GridFieldAddExistingAutocompleter'
20 1
        )->
21 1
            setSearchFields(
22 1
                array('Title')
23 1
        );
24 1
        $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100);
25 1
        $gridField2 = new GridField(
26
            'Map Layers',
27 1
            'Map Layers:',
28 1
            $this->owner->MapLayers(),
29 1
            $gridConfig2
30
        );
31
        $fields->addFieldToTab('Root.MapLayers', $gridField2);
32
    }
33
34
    /**
35 10
     * Only set has geo to true if layers exist
36
     * @param  boolean &$hasGeo will be set to true if any layers
37 10
     */
38 1
    public function updateHasGeo(&$hasGeo)
39 1
    {
40 10
        if ($this->owner->MapLayers()->count() > 0) {
41
            $hasGeo = true;
42
        }
43
    }
44
45
    /**
46
     * Add layers if the exist to a map from the MapExtension
47 2
     * @param  MapAPI &$map      object representing the map
48
     * @param  boolean &$autozoom true to auto zoom, false not to
49
     */
50 2
    public function updateBasicMap(&$map, &$autozoom)
51 1
    {
52
        // add any KML map layers
53 1
        foreach ($this->owner->MapLayers() as $layer) {
54 2
            $map->addKML($layer->KmlFile()->getAbsoluteURL());
55 2
            // we have a layer, so turn on autozoom
56
            $autozoom = true;
57 1
        }
58
    }
59
}
60