CRM-16373 - CRM_Core_Config_Variables should be strictly about data
[civicrm-core.git] / CRM / Core / BAO / Country.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This class contains functions for managing Action Logs
38 */
39 class CRM_Core_BAO_Country extends CRM_Core_DAO_Country {
40
41 /**
42 * Get the list of countries for which we offer provinces.
43 *
44 * @return mixed
45 */
46 public static function provinceLimit() {
47 if (!isset(Civi::$statics[__CLASS__]['provinceLimit'])) {
48 $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode();
49 $provinceLimit = Civi::settings()->get('provinceLimit');
50 $country = array();
51 if (is_array($provinceLimit)) {
52 foreach ($provinceLimit as $val) {
53 // CRM-12007
54 // some countries have disappeared and hence they might be in country limit
55 // but not in the country table
56 if (isset($countryIsoCodes[$val])) {
57 $country[] = $countryIsoCodes[$val];
58 }
59 }
60 }
61 else {
62 $country[] = $countryIsoCodes[$provinceLimit];
63 }
64 Civi::$statics[__CLASS__]['provinceLimit'] = $country;
65 }
66 return Civi::$statics[__CLASS__]['provinceLimit'];
67 }
68
69 /**
70 * Get the list of countries (with names) which are available to user.
71 *
72 * @return mixed
73 */
74 public static function countryLimit() {
75 if (!isset(Civi::$statics[__CLASS__]['countryLimit'])) {
76 $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode();
77 $country = array();
78 $countryLimit = Civi::settings()->get('countryLimit');
79 if (is_array($countryLimit)) {
80 foreach ($countryLimit as $val) {
81 // CRM-12007
82 // some countries have disappeared and hence they might be in country limit
83 // but not in the country table
84 if (isset($countryIsoCodes[$val])) {
85 $country[] = $countryIsoCodes[$val];
86 }
87 }
88 }
89 else {
90 $country[] = $countryIsoCodes[$countryLimit];
91 }
92 Civi::$statics[__CLASS__]['countryLimit'] = $country;
93 }
94 return Civi::$statics[__CLASS__]['countryLimit'];
95 }
96
97 /**
98 * Provide cached default contact country.
99 *
100 * @return string
101 */
102 public static function defaultContactCountry() {
103 static $cachedContactCountry = NULL;
104 $defaultContactCountry = Civi::settings()->get('defaultContactCountry');
105
106 if (!empty($defaultContactCountry) && !$cachedContactCountry) {
107 $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode();
108 $cachedContactCountry = CRM_Utils_Array::value($defaultContactCountry,
109 $countryIsoCodes
110 );
111 }
112 return $cachedContactCountry;
113 }
114
115 /**
116 * Provide cached default country name.
117 *
118 * @return string
119 */
120 public static function defaultContactCountryName() {
121 static $cachedContactCountryName = NULL;
122 $defaultContactCountry = Civi::settings()->get('defaultContactCountry');
123 if (!$cachedContactCountryName && $defaultContactCountry) {
124 $countryCodes = CRM_Core_PseudoConstant::country();
125 $cachedContactCountryName = $countryCodes[$defaultContactCountry];
126 }
127 return $cachedContactCountryName;
128 }
129
130 /**
131 * Provide cached default currency symbol.
132 *
133 * @return string
134 */
135 public static function defaultCurrencySymbol($defaultCurrency = NULL) {
136 static $cachedSymbol = NULL;
137 if (!$cachedSymbol || $defaultCurrency) {
138 $currency = $defaultCurrency ? $defaultCurrency : Civi::settings()->get('defaultCurrency');
139 if ($currency) {
140 $currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
141 'labelColumn' => 'symbol',
142 'orderColumn' => TRUE,
143 ));
144 $cachedSymbol = CRM_Utils_Array::value($currency, $currencySymbols, '');
145 }
146 else {
147 $cachedSymbol = '$';
148 }
149 }
150 return $cachedSymbol;
151 }
152
153 }