コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * Add data to the cache.
  *
  * @param string    $address The address which where use for the search.
  *
  * @param string    $country The country.
  *
  * @param Container $result  The container with all information.
  *
  * @return void
  */
 protected function addToCache($address, $country, $result)
 {
     $this->getDataBase()->prepare('INSERT INTO tl_metamodel_perimetersearch %s')->set(array('search' => $address, 'country' => $country, 'geo_lat' => $result->getLatitude(), 'geo_long' => $result->getLongitude()))->execute();
 }