Completed
Push — master ( 83571a...9e9b74 )
by Nic
30s
created

DistanceDataExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 5
dl 0
loc 20
rs 10

1 Method

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