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

DistanceDataExtension::augmentSQL()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
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