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