Example #1
0
 /**
  * @return bool
  */
 public function execute()
 {
     $zeroResults = array();
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->persistenceManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
     $this->storeRepository = $objectManager->get('Aijko\\StoreLocator\\Domain\\Repository\\StoreRepository');
     $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['store_locator']);
     $stores = $this->storeRepository->findAllStoresWithoutLatLong($this->storagePid);
     foreach ($stores as $store) {
         try {
             $data = \Aijko\StoreLocator\Utility\GoogleUtility::getLatLongFromAddress($store->getAddress(), $extensionConfiguration['googleApiKey']);
             if (isset($data['ZERO_RESULTS'])) {
                 $zeroResults[] = $data['ZERO_RESULTS'];
                 $store->setHidden(TRUE);
             } else {
                 $store->setLatitude($data['latitude']);
                 $store->setLongitude($data['longitude']);
             }
             $this->storeRepository->update($store);
             sleep(2);
             // Usage limits exceeded - https://developers.google.com/maps/documentation/business/articles/usage_limits
         } catch (\Aijko\StoreLocator\Task\Store\GoogleException $e) {
             $this->addMessage($e->getMessage(), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
             return FALSE;
         }
     }
     $this->addMessage('Bei folgenden Adressen wurde der Datensatz deaktiviert da keine Lat/Long dazu vorhanden sind:<br> - ' . implode('<br> - ', $zeroResults), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
     $this->persistenceManager->persistAll();
     return TRUE;
 }
 /**
  * @param string $status
  * @param string $table
  * @param int $id
  * @param array $fieldArray
  * @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
  */
 public function processDatamap_postProcessFieldArray($status, $table, $id, array &$fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
 {
     if ('tx_storelocator_domain_model_store' !== $table || !isset($fieldArray['address'])) {
         return;
     }
     $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['store_locator']);
     $data = \Aijko\StoreLocator\Utility\GoogleUtility::getLatLongFromAddress($fieldArray['address'], $extensionConfiguration['googleApiKey']);
     $fieldArray['latitude'] = isset($data['latitude']) ? $data['latitude'] : 0;
     $fieldArray['longitude'] = isset($data['longitude']) ? $data['longitude'] : 0;
 }
Example #3
0
 /**
  * @return bool
  */
 public function execute()
 {
     $csvData = $this->getCsvData($this->csvPath);
     if (count($csvData) > 0) {
         $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
         $propertyMapper = $objectManager->get('TYPO3\\CMS\\Extbase\\Property\\PropertyMapper');
         $this->persistenceManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
         $this->storeRepository = $objectManager->get('Aijko\\StoreLocator\\Domain\\Repository\\StoreRepository');
         $this->countryRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryRepository');
         if ($this->truncate) {
             // Remove all stores
             $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_storelocator_domain_model_store', 'pid = ' . $this->storagePid);
         }
         foreach ($csvData as $row) {
             $setCountry = FALSE;
             if (array_key_exists('country', $row)) {
                 $country = $this->countryRepository->findOneByIsoCodeA2($row['country']);
                 if ($country) {
                     $setCountry = TRUE;
                 }
                 unset($row['country']);
             }
             $store = $propertyMapper->convert($row, 'Aijko\\StoreLocator\\Domain\\Model\\Store');
             $address = \Aijko\StoreLocator\Utility\GoogleUtility::getFullAddressFromUserData($row);
             // Import with task:GeoTask
             #$data = \Aijko\StoreLocator\Utility\GoogleUtility::getLatLongFromAddress($address);
             #$store->setLatitude($data['latitude']);
             #$store->setLongitude($data['longitude']);
             $store->setAddress($address);
             $store->setPid($this->storagePid);
             if (TRUE === $setCountry) {
                 $store->setCountry($country);
             }
             $this->storeRepository->add($store);
         }
         $this->persistenceManager->persistAll();
     }
     return TRUE;
 }