/** * Run the search for the complex attribute geolocation. * * @param Container $container The container with all information. * * @param array $idList The list with the current ID's. * * @param IAttribute $latAttribute The attribute to filter on. * * @param IAttribute $longAttribute The attribute to filter on. * * @return array A list with all sorted id's. */ protected function doSearchForTwoSimpleAtt($container, $idList, $latAttribute, $longAttribute) { // Get location. $lat = $container->getLatitude(); $lng = $container->getLongitude(); $intDist = $container->getDistance(); $subSQL = sprintf('SELECT id, round ( sqrt ( power ( 2 * pi() / 360 * (%1$s - CAST(%3$s AS DECIMAL(10,6)) ) * 6371,2) + power(2 * pi() / 360 * (%2$s - CAST(%4$s AS DECIMAL(10,6))) * 6371 * COS(2 * pi() / 360 * (%1$s + CAST(%3$s AS DECIMAL(10,6))) * 0.5),2 ) ) ) AS item_dist FROM %6$s WHERE id IN(%5$s) ORDER BY item_dist', $lat, $lng, $latAttribute->getColName(), $longAttribute->getColName(), implode(', ', $idList), $this->getMetaModel()->getTableName()); $objResult = \Database::getInstance()->prepare($subSQL)->execute($intDist); $newIdList = array(); foreach ($objResult->fetchAllAssoc() as $item) { $id = $item['id']; $distance = $item['item_dist']; $newIdList[] = $id; self::$data[$id] = $distance; } $diff = array_diff($idList, $newIdList); return array_merge($newIdList, $diff); }
/** * Run the search for the complex attribute geolocation. * * @param Container $container The container with all information. * * @param IFilter $filter The filter container. * * @param IAttribute $latAttribute The attribute to filter on. * * @param IAttribute $longAttribute The attribute to filter on. * * @return void */ protected function doSearchForTwoSimpleAtt($container, $filter, $latAttribute, $longAttribute) { // Get location. $lat = $container->getLatitude(); $lng = $container->getLongitude(); $intDist = $container->getDistance(); $distance = sprintf('round(sqrt(' . 'power(2 * pi() / 360 * (%1$s - %3$s) * 6371,2)' . '+ power(2 * pi() / 360 * (%2$s - %4$s) * 6371 * COS( 2 * pi() / 360 * (%1$s + %3$s) * 0.5), 2)' . '))', $lat, $lng, $latAttribute->getColName(), $longAttribute->getColName()); $objResult = \Database::getInstance()->prepare(sprintf('SELECT id FROM %1$s WHERE %2$s<=? ORDER BY %2$s', $this->getMetaModel()->getTableName(), $distance))->execute($intDist); if ($objResult->numRows == 0) { $filter->addFilterRule(new StaticIdList(array())); } else { $filter->addFilterRule(new StaticIdList($objResult->fetchEach('id'))); } }