1 | <?php |
||
12 | class ApiGeocode extends ApiBase { |
||
13 | |||
14 | 2 | public function execute() { |
|
15 | 2 | if ( !$this->getUser()->isAllowed( 'geocode' ) || $this->getUser()->isBlocked() ) { |
|
16 | 1 | $this->dieWithError( 'badaccess-groups' ); |
|
17 | } |
||
18 | |||
19 | 1 | $geocoder = MapsFactory::newDefault()->getGeocoder(); |
|
20 | |||
21 | 1 | $params = $this->extractRequestParams(); |
|
22 | |||
23 | 1 | $results = []; |
|
24 | |||
25 | 1 | foreach ( array_unique( $params['locations'] ) as $location ) { |
|
26 | $result = $geocoder->geocode( $location ); |
||
27 | |||
28 | $results[$location] = [ |
||
29 | 'count' => $result === null ? 0 : 1, |
||
30 | 'locations' => [] |
||
31 | ]; |
||
32 | |||
33 | if ( $result !== null ) { |
||
34 | $results[$location]['locations'][] = [ |
||
35 | 'latitude' => $result->getLatitude(), |
||
36 | 'longitude' => $result->getLongitude() |
||
37 | ]; |
||
38 | } |
||
39 | |||
40 | $this->getResult()->setIndexedTagName( $results[$location]['locations'], 'location' ); |
||
41 | } |
||
42 | |||
43 | 1 | $this->getResult()->addValue( |
|
44 | 1 | null, |
|
45 | 1 | 'results', |
|
46 | 1 | $results |
|
47 | ); |
||
48 | 1 | } |
|
49 | |||
50 | 2 | public function getAllowedParams() { |
|
59 | |||
60 | public function getParamDescription() { |
||
65 | |||
66 | public function getDescription() { |
||
71 | |||
72 | protected function getExamples() { |
||
78 | |||
79 | } |
||
80 |