Created
July 3, 2017 10:28
-
-
Save einpraegsam/39dfe67a397033765cec74419f7845fa to your computer and use it in GitHub Desktop.
Example radial search SQL statement for TYPO3 Extbase repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param FilterDto $filterDto | |
* @return string | |
*/ | |
protected function getSqlForRadialSearch(FilterDto $filterDto): string | |
{ | |
$latitude = $filterDto->getLatitudeFromZip(); | |
$longitude = $filterDto->getLongitudeFromZip(); | |
$distance = $filterDto->getDistance(); | |
$sql = 'SELECT | |
uid, | |
latitude, | |
longitude, | |
( | |
6371 * acos( | |
cos( | |
radians(' . $latitude . ') | |
) * cos( | |
radians( latitude ) | |
) * cos( | |
radians( longitude ) - radians(' . $longitude . ') | |
) + sin( | |
radians(' . $latitude . ') | |
) * sin( | |
radians( latitude ) | |
) | |
) | |
) AS distance | |
FROM | |
' . Table::TABLE_NAME . ' | |
HAVING | |
distance <= ' . $distance . ' | |
ORDER BY | |
distance ASC;'; | |
return $sql; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment