Skip to content

Instantly share code, notes, and snippets.

@einpraegsam
Created July 3, 2017 10:28
Show Gist options
  • Save einpraegsam/39dfe67a397033765cec74419f7845fa to your computer and use it in GitHub Desktop.
Save einpraegsam/39dfe67a397033765cec74419f7845fa to your computer and use it in GitHub Desktop.
Example radial search SQL statement for TYPO3 Extbase repositories
<?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