Completed
Push — require/versionedDO2 ( a1f545 )
by Jason
05:34
created

DistanceDataExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 24
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A augmentSQL() 0 18 3
1
<?php
2
3
class DistanceDataExtension extends DataExtension
4
{
5
    /**
6
     * @param SQLQuery $query
7
     */
8
    public function augmentSQL(SQLQuery &$query)
9
    {
10
        $address = Controller::curr()->getRequest()->getVar('Address');
11
        if ($this->owner->hasMethod('updateAddressValue')) {
12
            $address = $this->owner->updateAddressValue($address);
13
        }
14
        if ($address) { // on frontend
15
            $coords = GoogleGeocoding::address_to_point($address);
16
17
            $Lat = $coords['lat'];
18
            $Lng = $coords['lng'];
19
20
            $query
21
                ->addSelect(array(
22
                    '( 3959 * acos( cos( radians(' . $Lat . ') ) * cos( radians( `Lat` ) ) * cos( radians( `Lng` ) - radians(' . $Lng . ') ) + sin( radians(' . $Lat . ') ) * sin( radians( `Lat` ) ) ) ) AS distance',
23
                ));
24
        }
25
    }
26
}
27