get('provinceLimit'); $country = []; if (is_array($provinceLimit)) { foreach ($provinceLimit as $val) { // CRM-12007 // some countries have disappeared and hence they might be in country limit // but not in the country table if (isset($countryIsoCodes[$val])) { $country[] = $countryIsoCodes[$val]; } } } else { $country[] = $countryIsoCodes[$provinceLimit]; } Civi::$statics[__CLASS__]['provinceLimit'] = $country; } return Civi::$statics[__CLASS__]['provinceLimit']; } /** * Get the list of countries (with names) which are available to user. * * @return mixed */ public static function countryLimit() { if (!isset(Civi::$statics[__CLASS__]['countryLimit'])) { $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode(); $country = []; $countryLimit = Civi::settings()->get('countryLimit') ?? []; if (is_array($countryLimit)) { foreach ($countryLimit as $val) { // CRM-12007 // some countries have disappeared and hence they might be in country limit // but not in the country table if (isset($countryIsoCodes[$val])) { $country[] = $countryIsoCodes[$val]; } } } else { $country[] = $countryIsoCodes[$countryLimit]; } Civi::$statics[__CLASS__]['countryLimit'] = $country; } return Civi::$statics[__CLASS__]['countryLimit']; } /** * Provide cached default contact country. * * @return string */ public static function defaultContactCountry() { static $cachedContactCountry = NULL; $defaultContactCountry = Civi::settings()->get('defaultContactCountry'); if (!empty($defaultContactCountry) && !$cachedContactCountry) { $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode(); $cachedContactCountry = CRM_Utils_Array::value($defaultContactCountry, $countryIsoCodes ); } return $cachedContactCountry; } /** * Provide list of favourite contries. * * @param $availableCountries * @return array */ public static function favouriteContactCountries($availableCountries) { static $cachedFavouriteContactCountries = []; $favouriteContactCountries = Civi::settings()->get('favouriteContactCountries'); if (!empty($favouriteContactCountries) && !$cachedFavouriteContactCountries) { $favouriteCountries = []; foreach($favouriteContactCountries as $favouriteContactCountry) { if (array_key_exists($favouriteContactCountry, $availableCountries)) { $favouriteCountries[$favouriteContactCountry] = $availableCountries[$favouriteContactCountry]; } } $cachedFavouriteContactCountries = $favouriteCountries; } return $cachedFavouriteContactCountries; } /** * Provide sorted list of countries with default country with first position * then favourite countries then rest of countries. * * @param $availableCountries * @return array */ public static function _defaultContactCountries($availableCountries) { // localise the country names if in an non-en_US locale $tsLocale = CRM_Core_I18n::getLocale(); if ($tsLocale != '' and $tsLocale != 'en_US') { $i18n = CRM_Core_I18n::singleton(); $i18n->localizeArray($availableCountries, [ 'context' => 'country', ]); $availableCountries = CRM_Utils_Array::asort($availableCountries); } $favouriteContactCountries = CRM_Core_BAO_Country::favouriteContactCountries($availableCountries); // if default country is set, percolate it to the top if ($defaultContactCountry = CRM_Core_BAO_Country::defaultContactCountry()) { $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode(); $defaultID = array_search($defaultContactCountry, $countryIsoCodes); if ($defaultID !== FALSE) { $default = []; $default[$defaultID] = $availableCountries[$defaultID] ?? NULL; $availableCountries = $default + $favouriteContactCountries + $availableCountries; } } elseif (!empty($favouriteContactCountries)) { $availableCountries = $favouriteContactCountries + $availableCountries; } return $availableCountries; } /** * Provide cached default country name. * * @return string */ public static function defaultContactCountryName() { static $cachedContactCountryName = NULL; $defaultContactCountry = Civi::settings()->get('defaultContactCountry'); if (!$cachedContactCountryName && $defaultContactCountry) { $countryCodes = CRM_Core_PseudoConstant::country(); $cachedContactCountryName = $countryCodes[$defaultContactCountry]; } return $cachedContactCountryName; } /** * Provide cached default currency symbol. * * @param string $defaultCurrency * * @return string */ public static function defaultCurrencySymbol($defaultCurrency = NULL) { static $cachedSymbol = NULL; if (!$cachedSymbol || $defaultCurrency) { $currency = $defaultCurrency ? $defaultCurrency : Civi::settings()->get('defaultCurrency'); if ($currency) { $currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', [ 'labelColumn' => 'symbol', 'orderColumn' => TRUE, ]); $cachedSymbol = CRM_Utils_Array::value($currency, $currencySymbols, ''); } else { $cachedSymbol = '$'; } } return $cachedSymbol; } /** * Get the default currency symbol. * * @param string $k Unused variable * * @return string */ public static function getDefaultCurrencySymbol($k = NULL) { return CRM_Core_BAO_Country::defaultCurrencySymbol(\Civi::settings()->get('defaultCurrency')); } }