Commit | Line | Data |
---|---|---|
0acb7f15 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
0acb7f15 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
0acb7f15 TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
0acb7f15 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class contains functions for managing Action Logs | |
20 | */ | |
21 | class CRM_Core_BAO_Country extends CRM_Core_DAO_Country { | |
22 | ||
23 | /** | |
24 | * Get the list of countries for which we offer provinces. | |
25 | * | |
26 | * @return mixed | |
27 | */ | |
28 | public static function provinceLimit() { | |
29 | if (!isset(Civi::$statics[__CLASS__]['provinceLimit'])) { | |
30 | $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode(); | |
31 | $provinceLimit = Civi::settings()->get('provinceLimit'); | |
be2fb01f | 32 | $country = []; |
0acb7f15 TO |
33 | if (is_array($provinceLimit)) { |
34 | foreach ($provinceLimit as $val) { | |
35 | // CRM-12007 | |
36 | // some countries have disappeared and hence they might be in country limit | |
37 | // but not in the country table | |
38 | if (isset($countryIsoCodes[$val])) { | |
39 | $country[] = $countryIsoCodes[$val]; | |
40 | } | |
41 | } | |
42 | } | |
43 | else { | |
44 | $country[] = $countryIsoCodes[$provinceLimit]; | |
45 | } | |
46 | Civi::$statics[__CLASS__]['provinceLimit'] = $country; | |
47 | } | |
48 | return Civi::$statics[__CLASS__]['provinceLimit']; | |
49 | } | |
50 | ||
51 | /** | |
52 | * Get the list of countries (with names) which are available to user. | |
53 | * | |
54 | * @return mixed | |
55 | */ | |
56 | public static function countryLimit() { | |
57 | if (!isset(Civi::$statics[__CLASS__]['countryLimit'])) { | |
58 | $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode(); | |
be2fb01f | 59 | $country = []; |
0acb7f15 TO |
60 | $countryLimit = Civi::settings()->get('countryLimit'); |
61 | if (is_array($countryLimit)) { | |
62 | foreach ($countryLimit as $val) { | |
63 | // CRM-12007 | |
64 | // some countries have disappeared and hence they might be in country limit | |
65 | // but not in the country table | |
66 | if (isset($countryIsoCodes[$val])) { | |
67 | $country[] = $countryIsoCodes[$val]; | |
68 | } | |
69 | } | |
70 | } | |
71 | else { | |
72 | $country[] = $countryIsoCodes[$countryLimit]; | |
73 | } | |
74 | Civi::$statics[__CLASS__]['countryLimit'] = $country; | |
75 | } | |
76 | return Civi::$statics[__CLASS__]['countryLimit']; | |
77 | } | |
78 | ||
79 | /** | |
80 | * Provide cached default contact country. | |
81 | * | |
82 | * @return string | |
83 | */ | |
84 | public static function defaultContactCountry() { | |
85 | static $cachedContactCountry = NULL; | |
86 | $defaultContactCountry = Civi::settings()->get('defaultContactCountry'); | |
87 | ||
88 | if (!empty($defaultContactCountry) && !$cachedContactCountry) { | |
89 | $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode(); | |
90 | $cachedContactCountry = CRM_Utils_Array::value($defaultContactCountry, | |
91 | $countryIsoCodes | |
92 | ); | |
93 | } | |
94 | return $cachedContactCountry; | |
95 | } | |
96 | ||
97 | /** | |
98 | * Provide cached default country name. | |
99 | * | |
100 | * @return string | |
101 | */ | |
102 | public static function defaultContactCountryName() { | |
103 | static $cachedContactCountryName = NULL; | |
104 | $defaultContactCountry = Civi::settings()->get('defaultContactCountry'); | |
105 | if (!$cachedContactCountryName && $defaultContactCountry) { | |
106 | $countryCodes = CRM_Core_PseudoConstant::country(); | |
107 | $cachedContactCountryName = $countryCodes[$defaultContactCountry]; | |
108 | } | |
109 | return $cachedContactCountryName; | |
110 | } | |
111 | ||
112 | /** | |
113 | * Provide cached default currency symbol. | |
114 | * | |
ad37ac8e | 115 | * @param string $defaultCurrency |
116 | * | |
0acb7f15 TO |
117 | * @return string |
118 | */ | |
119 | public static function defaultCurrencySymbol($defaultCurrency = NULL) { | |
120 | static $cachedSymbol = NULL; | |
121 | if (!$cachedSymbol || $defaultCurrency) { | |
122 | $currency = $defaultCurrency ? $defaultCurrency : Civi::settings()->get('defaultCurrency'); | |
123 | if ($currency) { | |
be2fb01f | 124 | $currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', [ |
0acb7f15 TO |
125 | 'labelColumn' => 'symbol', |
126 | 'orderColumn' => TRUE, | |
be2fb01f | 127 | ]); |
0acb7f15 TO |
128 | $cachedSymbol = CRM_Utils_Array::value($currency, $currencySymbols, ''); |
129 | } | |
130 | else { | |
131 | $cachedSymbol = '$'; | |
132 | } | |
133 | } | |
134 | return $cachedSymbol; | |
135 | } | |
136 | ||
f2ac86d1 | 137 | /** |
138 | * Get the default currency symbol. | |
139 | * | |
140 | * @param string $k Unused variable | |
141 | * | |
142 | * @return string | |
143 | */ | |
d7c217ae | 144 | public static function getDefaultCurrencySymbol($k = NULL) { |
a5dfa653 | 145 | return CRM_Core_BAO_Country::defaultCurrencySymbol(\Civi::settings()->get('defaultCurrency')); |
d7c217ae TO |
146 | } |
147 | ||
0acb7f15 | 148 | } |