Skip to content

Instantly share code, notes, and snippets.

@pavel-one
Created August 18, 2019 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavel-one/4823baac0d4f0f65c48c7f58b66e0792 to your computer and use it in GitHub Desktop.
Save pavel-one/4823baac0d4f0f65c48c7f58b66e0792 to your computer and use it in GitHub Desktop.
core/components/msrussianpost/processors/web/country/getlist.class.php
<?php
class rpCountryGetListProcessor extends modProcessor
{
public function process()
{
$countryList = $this->getCountryList();
$countries = array();
foreach ($countryList as $iso => $country) {
$countries[] = array(
'id' => strtoupper($iso),
'text' => $country
);
}
return $this->outputArray($countries);
}
public function getCountryList()
{
$_country_lang = array();
include $this->modx->getOption('core_path') . 'lexicon/country/en.inc.php';
if ($this->modx->getOption('manager_language') != 'en' && file_exists($this->modx->getOption('core_path') . 'lexicon/country/' . $this->modx->getOption('manager_language') . '.inc.php')) {
include $this->modx->getOption('core_path') . 'lexicon/country/' . $this->modx->getOption('manager_language') . '.inc.php';
}
asort($_country_lang);
$search = mb_strtolower($this->getProperty('query', ''));
if (!empty($search)) {
// $this->modx->log(1, "Ищем = $search");
foreach ($_country_lang as $key => $value) {
$value = mb_strtolower($value);
// $this->modx->log(1, "Значение = ".strtolower($value));
if (strripos($value, $search) === false) {
unset($_country_lang[$key]);
}
// if (!stristr(strtolower($value), $search)) {
// $this->modx->log(1, "Удаляем = ".$_country_lang[$key]);
// unset($_country_lang[$key]);
// }
}
return $_country_lang;
}
$iso = $this->getProperty('iso', '');
if (!empty($iso)) {
foreach ($_country_lang as $key => $value) {
if ($key != strtolower($iso)) {
unset($_country_lang[$key]);
}
}
return $_country_lang;
}
return $_country_lang;
}
}
return 'rpCountryGetListProcessor';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment