CRM-19948: Store the logged in contact ID as the file uploader
[civicrm-core.git] / CRM / Core / BAO / Country.php
CommitLineData
0acb7f15
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
0acb7f15 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
0acb7f15
TO
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
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
0acb7f15
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class contains functions for managing Action Logs
38 */
39class 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 *
ad37ac8e 133 * @param string $defaultCurrency
134 *
0acb7f15
TO
135 * @return string
136 */
137 public static function defaultCurrencySymbol($defaultCurrency = NULL) {
138 static $cachedSymbol = NULL;
139 if (!$cachedSymbol || $defaultCurrency) {
140 $currency = $defaultCurrency ? $defaultCurrency : Civi::settings()->get('defaultCurrency');
141 if ($currency) {
142 $currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array(
143 'labelColumn' => 'symbol',
144 'orderColumn' => TRUE,
145 ));
146 $cachedSymbol = CRM_Utils_Array::value($currency, $currencySymbols, '');
147 }
148 else {
149 $cachedSymbol = '$';
150 }
151 }
152 return $cachedSymbol;
153 }
154
f2ac86d1 155 /**
156 * Get the default currency symbol.
157 *
158 * @param string $k Unused variable
159 *
160 * @return string
161 */
d7c217ae
TO
162 public static function getDefaultCurrencySymbol($k = NULL) {
163 $config = CRM_Core_Config::singleton();
164 return $config->defaultCurrencySymbol(Civi::settings()->get('defaultCurrency'));
165 }
166
0acb7f15 167}