/** * Build array with countries * * @param string $key * @param string $value * @param string $sortbyField * @param string $sorting * @return array */ public function getCountries($key = 'isoCodeA3', $value = 'officialNameLocal', $sortbyField = 'isoCodeA3', $sorting = 'asc') { $countries = $this->countryRepository->findAllOrderedBy($sortbyField, $sorting); $countriesArray = []; foreach ($countries as $country) { /** @var $country \SJBR\StaticInfoTables\Domain\Model\Country */ $countriesArray[ObjectAccess::getProperty($country, $key)] = ObjectAccess::getProperty($country, $value); } return $countriesArray; }
/** * Build an country array * * @param \string $key * @param \string $value * @param \string $sortbyField * @param \string $sorting * @return \array */ public function render($key = 'isoCodeA3', $value = 'officialNameLocal', $sortbyField = 'isoCodeA3', $sorting = 'asc') { $countries = $this->countryRepository->findAllOrderedBy($sortbyField, $sorting); $countriesArray = array(); foreach ($countries as $country) { if (method_exists($country, 'get' . ucfirst($key)) && method_exists($country, 'get' . ucfirst($value))) { $countriesArray[$country->{'get' . ucfirst($key)}()] = $country->{'get' . ucfirst($value)}(); } else { $countriesArray[$country->getIsoCodeA3()] = $country->getOfficialNameLocal(); } } return $countriesArray; }
/** * Store search * * @return void */ public function storeSearchAction() { $this->view->assign('displayMode', 'storeSearch'); $this->settings['filter']['default']['radius'] = $this->getDefaultRadiusAsArray(); $this->view->assign('settings', $this->settings); if ($this->settings['filter']['showAllCountries']) { $countries = $this->countryRepository->findAllOrderedBy('officialNameEn'); } else { $countries = $this->getOnlyCountriesWhereStoresAvailable(); } $this->view->assign('countries', $countries); $this->view->assign('preSelectedCountry', $this->countryRepository->findOneByIsoCodeA2($this->region)); }
/** * @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; }
/** * Creation/update a language pack for the Static Info Tables * * @return string An HTML display of data overview */ public function sqlDumpNonLocalizedDataAction() { // Create a SQL dump of non-localized data $dumpContent = array(); $dumpContent[] = $this->countryRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->countryZoneRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->currencyRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->languageRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->territoryRepository->sqlDumpNonLocalizedData(); // Write the SQL dump file $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName); $extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey); $filename = 'export-ext_tables_static+adt.sql'; \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($extensionPath . $filename, implode(LF, $dumpContent)); $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sqlDumpCreated', $this->extensionName) . ' ' . $extensionPath . $filename; $this->addFlashMessage($message, '', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK); $this->forward('information'); }
public function getCountryFromIp() { $ip = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'); $tmpDir = PATH_site . 'typo3temp/ip2country/'; if (!is_dir($tmpDir)) { mkdir($tmpDir); } $tmpName = $tmpDir . sha1($ip) . '.txt'; if (!file_exists($tmpName)) { $countryCode = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl('http://ipinfo.io/' . $ip . '/country'); foreach ($this->countryRepository->findAll() as $country) { if (strtolower($country->getIsoCodeA2()) == trim(strtolower($countryCode))) { $country = $country->getShortNameEn(); break; } } file_put_contents($tmpName, $country); } else { $country = file_get_contents($tmpName); } return $country; }
/** * Constructs a new Repository * * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager */ public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) { parent::__construct($objectManager); $nsSeparator = strpos($this->getRepositoryClassName(), '\\') !== false ? '\\\\' : '_'; $this->objectType = preg_replace(array('/' . $nsSeparator . 'Repository' . $nsSeparator . '(?!.*' . $nsSeparator . 'Repository' . $nsSeparator . ')/', '/Repository$/'), array($nsSeparator . 'Model' . $nsSeparator, ''), get_parent_class($this)); }
/** * Gets the update queries for this language pack * * @return string update queries in sql format */ public function getUpdateQueries() { $updateQueries = array(); $locale = $this->getLocale(); $updateQueries = array_merge($updateQueries, $this->countryRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->countryZoneRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->currencyRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->languageRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->territoryRepository->getUpdateQueries($locale)); return implode(LF, $updateQueries); }
/** * Get EU countries * * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface */ public function getCountries() { $countries = $this->countryRepository->findByEuMember(1); return $countries; }
/** * Get items with custom sub select. * Signal: getItemsWithSubselect * * @param string $repository * @return array */ protected function emitGetItemsWithSubselect($repository) { /** @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array $items */ $items = array(); $subselects = $this->arguments['staticInfoTableSubselect']; foreach ($subselects as $fieldname => $fieldvalue) { // default implemented Subselect if (strtolower($fieldname) === 'country' && MathUtility::canBeInterpretedAsInteger($fieldvalue)) { $findby = 'findBy' . ucfirst($fieldname); $fieldvalue = $this->countryRepository->findByUid((int) $fieldvalue); $items = call_user_func_array(array($this->{$repository}, $findby), array($fieldvalue)); } /** @var array $list */ $list = $this->signalSlotDispatcher->dispatch(__CLASS__, 'getItemsWithSubselect', array('arguments' => $this->arguments, 'items' => $items, 'fieldname' => $fieldname, 'fieldvalue' => $fieldvalue)); $this->arguments = $list['arguments']; if ($list['items']) { $items = $list['items']->toArray(); } } return $items; }
/** * @return void */ public function setStaticCountry() { $this->staticCountry = $this->countryRepository->findOneByIsoCodeA2($this->getIsoCode()); }