PointOfInterest::getCMSFields()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 5
Metric Value
dl 0
loc 26
ccs 20
cts 20
cp 1
rs 8.439
cc 5
eloc 17
nc 6
nop 0
crap 5
1
<?php
2
3
class PointOfInterest extends DataObject
4
{
5
    private static $description = 'Represents a point of interest on a map, e.g. railway station';
6
7
    private static $belongs_many_many = array('PointsOfInterestLayers' => 'PointsOfInterestLayer');
8
9
    private static $db = array(
10
        'Name' => 'Varchar',
11
    );
12
13
    private static $summary_fields = array('Name', 'Lat', 'Lon');
14
15
    private static $default_sort = 'Name';
16
17 2
    public function getCMSFields()
18
    {
19 2
        $fields = parent::getCMSFields();
20 2
        $fields->addFieldToTab('Root.Main', new TextField('Name', 'Name of the item on the map'));
21
22 2
        $layers = $this->PointsOfInterestLayers();
23 2
        $ids = array();
24 2
        foreach ($layers->getIterator() as $layer) {
25 1
            array_push($ids, $layer->ID);
26 1
            if ($layer->ShowGuideMarkers) {
27 1
                $this->ShowGuideMarkers = true;
28 1
            }
29 2
        }
30 2
        $csv = implode(',', $ids);
31
32 2
        if ($this->ShowGuideMarkers && strlen($csv) > 0) {
33 1
            $sql = 'ID IN (SELECT DISTINCT  PointOfInterestID from ';
34 1
            $sql .= 'PointsOfInterestLayer_PointsOfInterest WHERE PointsOfInterestLayerID ';
35 1
            $sql .= "IN ($csv))";
36
37 1
            $pois = self::get()->where($sql);
38 1
            $this->owner->getMapField()->setGuidePoints($pois);
39 1
        }
40
41 2
        return $fields;
42
    }
43
}
44