Documentation

Country
in package

Country helper methods

Tags
since
3.0.0
subpackage

core_country

copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

Thomas Wirz thomas.wirz@cloudrexx.com

Table of Contents

Properties

$arrCountries  : array<string|int, mixed>
Array of all countries
$arrLocales  : array<string|int, mixed>
Localized lists of countries

Methods

errorHandler()  : bool
Tries to recreate the database table(s) for the class
getAlpha2ById()  : string
Returns the ISO 2 code of the country selected by its ID
getAlpha3ById()  : string
Returns the ISO 3 code of the country selected by its ID
getById()  : array<string|int, mixed>
Returns an array of Country data for the given ID
getByName()  : array<string|int, mixed>
Returns an array of Country data for the given Name
getData()  : array<string|int, mixed>
Returns an array of Country arrays
getIdByAlpha2()  : int
Returns the ID of the Country specified by its alpha2 code
getMenu()  : string
Returns the HTML dropdown menu
getMenuoptions()  : string
Returns the HTML code for the countries dropdown menu options
getNameArray()  : array<string|int, mixed>
Returns the array of all country names, indexed by their ID
getNameById()  : string
Returns the name of the country selected by its ID
searchByName()  : array<string|int, mixed>
Returns matched array of Countries data for the given Name
init()  : mixed
Initialises the class array of Countries

Properties

$arrCountries

Array of all countries

protected static array<string|int, mixed> $arrCountries = array()
Tags
see
init()

$arrLocales

Localized lists of countries

protected static array<string|int, mixed> $arrLocales = array()

Methods

errorHandler()

Tries to recreate the database table(s) for the class

public static errorHandler() : bool

Should be called whenever there's a problem with the database table.

Return values
bool —

False. Always.

getAlpha2ById()

Returns the ISO 2 code of the country selected by its ID

public static getAlpha2ById(int $country_id) : string

If a country with the given ID does not exist, returns the empty string.

Parameters
$country_id : int

The country ID

Tags
static
Return values
string —

The ISO 2 code, or the empty string

getAlpha3ById()

Returns the ISO 3 code of the country selected by its ID

public static getAlpha3ById(int $country_id) : string

If a country with the given ID does not exist, returns the empty string.

Parameters
$country_id : int

The country ID

Tags
static
Return values
string —

The ISO 3 code, or the empty string

getById()

Returns an array of Country data for the given ID

public static getById(int $country_id[, int $lang_id = 0 ]) : array<string|int, mixed>

The array created is of the form array( 'id' => country ID, 'name' => country name, 'alpha2' => alpha-2 (two letter) code, 'alpha3' => alpha-3 (three letter) code, ), The Country is returned in the current language, except if the optional $lang_id argument is not empty.

Parameters
$country_id : int

The Country ID

$lang_id : int = 0

The optional language ID

Return values
array<string|int, mixed> —

The Country array on success, false otherwise

getByName()

Returns an array of Country data for the given Name

public static getByName(string $country_name[, int $lang_id = 0 ]) : array<string|int, mixed>

The array created is of the form array( 'id' => country ID, 'name' => country name, 'alpha2' => alpha-2 (two letter) code, 'alpha3' => alpha-3 (three letter) code, ), The Country is returned in the current language, except if the optional $lang_id argument is not empty.

Parameters
$country_name : string

The Country name

$lang_id : int = 0

The optional language ID

Tags
global

ADONewConnection $objDatabase

Return values
array<string|int, mixed> —

The Country array on success, false otherwise

getData()

Returns an array of Country arrays

public static getData([int $langId = 0 ]) : array<string|int, mixed>

The array returned has the following structure array( country ID => array( 'id' => country ID, 'name' => country name, 'alpha2' => alpha-2 (two letter) code, 'alpha3' => alpha-3 (three letter) code, ), ... more ... ) Notes:

  • The Countries are returned in the current locale of the interface, except if the optional $langId argument is set.
Parameters
$langId : int = 0

The optional language ID

Return values
array<string|int, mixed> —

The Country array on success, an empty array otherwise

getIdByAlpha2()

Returns the ID of the Country specified by its alpha2 code

public static getIdByAlpha2(string $alpha2) : int
Parameters
$alpha2 : string

The alpha2 code

Return values
int —

The Country ID on success, null otherwise

getMenu()

Returns the HTML dropdown menu

public static getMenu([string $menuName = 'countryId' ][, string $selected = '' ][, string $onchange = '' ]) : string

Returns a dropdown menu with the optional ID preselected and optional onchange method added.

Parameters
$menuName : string = 'countryId'

Optional name of the menu, defaults to "countryId"

$selected : string = ''

Optional selected country ID

$onchange : string = ''

Optional onchange callback function

Tags
static
Return values
string —

The HTML dropdown menu code

getMenuoptions()

Returns the HTML code for the countries dropdown menu options

public static getMenuoptions([string $selected = 0 ]) : string
Parameters
$selected : string = 0

The optional selected Country ID are added to the options, all otherwise.

Tags
static
Return values
string —

The HTML dropdown menu options code

getNameArray()

Returns the array of all country names, indexed by their ID

public static getNameArray([int $lang_id = 0 ]) : array<string|int, mixed>
Parameters
$lang_id : int = 0

Language ID of language the countries should be returned in. If not set, then the language locale of the current request is used.

Return values
array<string|int, mixed> —

The country names array on success, false otherwise

getNameById()

Returns the name of the country selected by its ID

public static getNameById(int $country_id[, int $localeId = 0 ]) : string

If a country with the given ID does not exist, returns the empty string.

Parameters
$country_id : int

The country ID

$localeId : int = 0

Id of locale to return the name of the country in.

Return values
string —

The country name, or the empty string

searchByName()

Returns matched array of Countries data for the given Name

public static searchByName(string $term[, int $lang_id = 0 ]) : array<string|int, mixed>

The array created is of the form array( 'id' => country ID, 'name' => country name, 'alpha2' => alpha-2 (two letter) code, 'alpha3' => alpha-3 (three letter) code, ), The Countries are returned in the current language, except if the optional $lang_id argument is not empty.

Parameters
$term : string

The search term to get countries

$lang_id : int = 0

The optional language ID

Return values
array<string|int, mixed> —

The Country array on success, false otherwise

init()

Initialises the class array of Countries

protected static init() : mixed

The array created is of the form array( country ID => array( 'id' => country ID, 'alpha2' => alpha-2 (two letter) code, 'alpha3' => alpha-3 (three letter) code, ), ... more ... )

On this page

Search results