/**
     * Find locations by contraint
     *
     * @param \Evoweb\StoreFinder\Domain\Model\Constraint $constraint
     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
     */
    public function findByConstraint($constraint)
    {
        /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Query $query */
        $query = $this->createQuery();
        if (!$constraint->isGeocoded()) {
            return array();
        }
        $queryParts = array('SELECT' => '
				distinct l.*,
				(acos(
					sin(' . $constraint->getLatitude() * M_PI . ' / 180) *
					sin(latitude * ' . M_PI . ' / 180) +
					cos(' . $constraint->getLatitude() * M_PI . ' / 180) *
					cos(latitude * ' . M_PI . ' / 180) *
					cos((' . $constraint->getLongitude() . ' - longitude) * ' . M_PI . ' / 180)
				) * 6370) as distance', 'FROM' => 'tx_storefinder_domain_model_location l', 'WHERE' => 'l.pid IN (' . implode(',', $query->getQuerySettings()->getStoragePageIds()) . ')' . $this->getWhereClauseForEnabledFields('tx_storefinder_domain_model_location', 'l'), 'GROUPBY' => '', 'ORDERBY' => 'distance', 'LIMIT' => '');
        $queryParts = $this->addCountryQueryPart($constraint, $queryParts);
        $queryParts = $this->addCategoryQueryPart($constraint, $queryParts);
        $queryParts = $this->addRadiusQueryPart($constraint, $queryParts);
        $queryParts = $this->addLimitQueryParts($constraint, $queryParts);
        /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
        $database = $GLOBALS['TYPO3_DB'];
        $sql = $database->SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
        $query->statement($sql);
        return $query->execute();
    }
Esempio n. 2
0
 /**
  * Add calculated coordinate for hash
  *
  * @param Model\Constraint|Model\Location $address
  * @param array $fields
  *
  * @throws \TYPO3\CMS\Core\Exception
  * @return void
  */
 public function addCoordinateForAddress($address, $fields)
 {
     $coordinate = array('latitude' => $address->getLatitude(), 'longitude' => $address->getLongitude());
     $hash = $this->getHashForAddressWithFields($address, $fields);
     if (count($fields) <= 3) {
         $this->setValueInCacheTable($hash, $coordinate);
     } else {
         $this->setValueInSession($hash, $coordinate);
     }
 }
Esempio n. 3
0
 /**
  * Geocode requested address and use as center or fetch location that was
  * flagged as center. If
  *
  * @param Model\Constraint $constraint
  *
  * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
  * @return Model\Location
  */
 public function getCenter(Model\Constraint $constraint = null)
 {
     $center = null;
     if ($constraint !== null) {
         if ($constraint->getLatitude() && $constraint->getLongitude()) {
             /** @var Model\Location $center */
             $center = $this->objectManager->get('Evoweb\\StoreFinder\\Domain\\Model\\Location');
             $center->setLatitude($constraint->getLatitude());
             $center->setLongitude($constraint->getLongitude());
         } else {
             $center = $this->geocodeService->geocodeAddress($constraint);
         }
     }
     if ($center === null) {
         $center = $this->locationRepository->findOneByCenter();
     }
     if ($center === null) {
         $center = $this->locationRepository->findCenterByLatitudeAndLongitude();
     }
     return $center;
 }