Example #1
0
 /**
  * Returns a list of country names that can be used by
  * a select input localized in the lang of which the code is provided.
  * 
  * @since 0.1
  * 
  * @param string $langCode
  * 
  * @return array
  */
 public static function getCountryOptions($langCode)
 {
     $countries = CountryNames::getNames($langCode);
     return array_merge(array('' => ''), array_combine(array_map(function ($value, $key) {
         return $key . ' - ' . $value;
     }, array_values($countries), array_keys($countries)), array_keys($countries)));
 }
 /**
  * Returns true if the country value is valid or an error message if it's not.
  *
  * @since 0.1
  *
  * @param string $value
  * @param array $alldata
  *
  * @return string|true
  */
 public function countryIsValid($value, array $alldata = null)
 {
     $countries = array_keys(CountryNames::getNames($this->getLanguage()->getCode()));
     if ($this->isNew()) {
         array_unshift($countries, '');
     }
     return in_array($value, $countries) ? true : wfMsg('educationprogram-org-invalid-country');
 }
Example #3
0
 /**
  * Gets the summary data.
  *
  * @since 0.1
  *
  * @param EPOrg $org
  *
  * @return array
  */
 protected function getSummaryData(EPDBObject $org)
 {
     $stats = array();
     $stats['name'] = $org->getField('name');
     $stats['city'] = $org->getField('city');
     $countries = CountryNames::getNames($this->getLanguage()->getCode());
     $stats['country'] = $countries[$org->getField('country')];
     $stats['status'] = wfMsgHtml($org->getField('active') ? 'ep-institution-active' : 'ep-institution-inactive');
     $stats['courses'] = $this->getLanguage()->formatNum($org->getField('courses'));
     $stats['students'] = $this->getLanguage()->formatNum($org->getField('students'));
     foreach ($stats as &$stat) {
         $stat = htmlspecialchars($stat);
     }
     if ($org->getField('courses') > 0) {
         $stats['courses'] = Linker::linkKnown(SpecialPage::getTitleFor('Courses'), $stats['courses'], array(), array('org_id' => $org->getId()));
     }
     return $stats;
 }
 /**
  * Return all of the available countries for geotargeting
  * TODO: Move this out of CentralNoticeDB (or rename the class)
  * @param string $code The language code to return the country list in
  * @return array
  */
 static function getCountriesList($code)
 {
     $countries = array();
     if (is_callable(array('CountryNames', 'getNames'))) {
         // Retrieve the list of countries in user's language (via CLDR)
         $countries = CountryNames::getNames($code);
     }
     if (!$countries) {
         // Use this as fallback if CLDR extension is not enabled
         $countries = array('AF' => 'Afghanistan', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AS' => 'American Samoa', 'AD' => 'Andorra', 'AO' => 'Angola', 'AI' => 'Anguilla', 'AQ' => 'Antarctica', 'AG' => 'Antigua and Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AW' => 'Aruba', 'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BM' => 'Bermuda', 'BT' => 'Bhutan', 'BO' => 'Bolivia', 'BA' => 'Bosnia and Herzegovina', 'BW' => 'Botswana', 'BV' => 'Bouvet Island', 'BR' => 'Brazil', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'KH' => 'Cambodia', 'CM' => 'Cameroon', 'CA' => 'Canada', 'CV' => 'Cape Verde', 'KY' => 'Cayman Islands', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', 'CO' => 'Colombia', 'KM' => 'Comoros', 'CD' => 'Congo, Democratic Republic of the', 'CG' => 'Congo', 'CK' => 'Cook Islands', 'CR' => 'Costa Rica', 'CI' => 'Côte d\'Ivoire', 'HR' => 'Croatia', 'CU' => 'Cuba', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'EC' => 'Ecuador', 'EG' => 'Egypt', 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'EE' => 'Estonia', 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', 'FO' => 'Faroe Islands', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 'GF' => 'French Guiana', 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', 'DE' => 'Germany', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GU' => 'Guam', 'GT' => 'Guatemala', 'GW' => 'Guinea-Bissau', 'GN' => 'Guinea', 'GY' => 'Guyana', 'HT' => 'Haiti', 'HM' => 'Heard Island and McDonald Islands', 'VA' => 'Holy See (Vatican City State)', 'HN' => 'Honduras', 'HK' => 'Hong Kong', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran', 'IQ' => 'Iraq', 'IE' => 'Ireland', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 'JP' => 'Japan', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 'KI' => 'Kiribati', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Lao People\'s Democratic Republic', 'LV' => 'Latvia', 'LB' => 'Lebanon', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libyan Arab Jamahiriya', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MO' => 'Macao', 'MK' => 'Macedonia, Republic of', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 'MH' => 'Marshall Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MX' => 'Mexico', 'FM' => 'Micronesia', 'MD' => 'Moldova, Republic of', 'MC' => 'Moldova', 'MN' => 'Mongolia', 'ME' => 'Montenegro', 'MS' => 'Montserrat', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'MM' => 'Myanmar', 'NA' => 'Namibia', 'NR' => 'Nauru', 'NP' => 'Nepal', 'AN' => 'Netherlands Antilles', 'NL' => 'Netherlands', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'KP' => 'North Korea', 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PS' => 'Palestinian Territory', 'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 'PH' => 'Philippines', 'PN' => 'Pitcairn', 'PL' => 'Poland', 'PT' => 'Portugal', 'PR' => 'Puerto Rico', 'QA' => 'Qatar', 'RE' => 'Reunion', 'RO' => 'Romania', 'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'SH' => 'Saint Helena', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 'PM' => 'Saint Pierre and Miquelon', 'VC' => 'Saint Vincent and the Grenadines', 'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome and Principe', 'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'CS' => 'Serbia and Montenegro', 'RS' => 'Serbia', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'KR' => 'South Korea', 'SS' => 'South Sudan', 'ES' => 'Spain', 'LK' => 'Sri Lanka', 'SD' => 'Sudan', 'SR' => 'Suriname', 'SJ' => 'Svalbard and Jan Mayen', 'SZ' => 'Swaziland', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan', 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania', 'TH' => 'Thailand', 'TL' => 'Timor-Leste', 'TG' => 'Togo', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TT' => 'Trinidad and Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'TC' => 'Turks and Caicos Islands', 'TV' => 'Tuvalu', 'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 'GB' => 'United Kingdom', 'UM' => 'United States Minor Outlying Islands', 'US' => 'United States', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VE' => 'Venezuela', 'VN' => 'Vietnam', 'VG' => 'Virgin Islands, British', 'VI' => 'Virgin Islands, U.S.', 'WF' => 'Wallis and Futuna', 'EH' => 'Western Sahara', 'YE' => 'Yemen', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe');
     }
     return $countries;
 }
Example #5
0
 /**
  * Returns a list of country names that can be used by
  * a select input localized in the lang of which the code is provided.
  * 
  * @since 0.1
  * 
  * @param string $langCode
  * 
  * @return array
  */
 public static function getCountryOptions($langCode)
 {
     return self::getKeyPrefixedValues(CountryNames::getNames($langCode));
 }
Example #6
0
 /**
  * Get an array of country codes and return the country names array indexed by corresponding codes
  * @param array $countryCodes
  * @return array Country names indexed by code
  */
 public static function getCountryNames(array $countryCodes)
 {
     if (empty($countryCodes)) {
         return [];
     }
     // This is hacky and I'm not proud of this :(
     // Load only files required for country names to avoid loading the whole CLDR
     // The files are included on the fly as needed instead of loading it every single time
     global $IP;
     require_once "{$IP}/extensions/cldr/CldrNames.php";
     require_once "{$IP}/extensions/cldr/CountryNames.body.php";
     $userLanguageCode = F::app()->wg->Lang->getCode();
     // Retrieve the list of countries in user's language (via CLDR)
     $countries = CountryNames::getNames($userLanguageCode);
     if (empty($countries)) {
         return [];
     }
     foreach ($countryCodes as $countryCode) {
         if (isset($countries[$countryCode])) {
             $countryNames[$countryCode] = $countries[$countryCode];
         }
     }
     return $countryNames;
 }