Country helper methods

version 3.0.0
since 3.0.0
package contrexx
subpackage core
copyright CONTREXX CMS - COMVATION AG
author Reto Kohli

 Methods

Activate the countries whose IDs are listed in the comma separated list of Country IDs

activate(string $strCountryIds) : boolean
Static

Any Country not included in the list is deactivated.

Parameters

$strCountryIds

string

The comma separated list of to-be-active Country IDs

Returns

booleanTrue on success, false otherwise

Deletes the Country with the given ID from the database

deleteById(integer $country_id) : boolean
Static

Parameters

$country_id

integer

The Country ID

Returns

booleanTrue on success, false otherwise

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

errorHandler() : boolean
Static

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

Returns

booleanFalse. Always.

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

getAlpha2ById(integer $country_id) : string
Static

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

static

Parameters

$country_id

integer

The country ID

Returns

stringThe ISO 2 code, or the empty string

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

getAlpha3ById(integer $country_id) : string
Static

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

static

Parameters

$country_id

integer

The country ID

Returns

stringThe ISO 3 code, or the empty string

Returns an array of Country arrays

getArray(integer $count, integer $lang_id, integer $limit, integer $offset, string $order) : array
Static

The array created is of the form array( country ID => array( 'id' => country ID, 'name' => country name, 'alpha2' => alpha-2 (two letter) code, 'alpha3' => alpha-3 (three letter) code, 'active' => boolean, 'ord' => ordinal value, ), ... more ... ) Notes: - The Countries are returned in the current frontend language as set in FRONTEND_LANG_ID, except if the optional $lang_id argument is not empty. - Empty arguments are set to their default values, which are: - $lang_id: The current value of the FRONTEND_LANG_ID constant - $limit: -1, meaning no limit - $offset: 0, meaning no offset - $order: name ASC, meaning ordered by country name, ascending

global ADONewConnection $objDatabase

Parameters

$count

integer

The record count, by reference

$lang_id

integer

The optional language ID

$limit

integer

The optional record limit

$offset

integer

The optional record offset

$order

string

The optional order direction

Returns

arrayThe Country array on success, false otherwise

Returns an array of two arrays; one with countries in the given zone, the other with the remaining countries.

getArraysByZoneId(integer $zone_id) : array
Static

If $zone_id is empty, includes Countries for all Zones present. The array looks like this: array( 'in' => array( // Countries in the zone country ID => array( 'id' => country ID, 'name' => country name, ), ... more ... ), 'out' => array( // Countries not in the zone country ID => array( 'id' => country ID, 'name' => country name, ), ... more ... ), );

todo Shop use only (should be moved back there)!

Parameters

$zone_id

integer

The optional Zone ID

Returns

arrayCountries array, as described above

Returns an array of Country data for the given ID

getById(integer $country_id, integer $lang_id) : array
Static

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, 'active' => boolean, 'ord' => ordinal value, ), The Country is returned in the current frontend language as set in FRONTEND_LANG_ID, except if the optional $lang_id argument is not empty.

global ADONewConnection $objDatabase

Parameters

$country_id

integer

The Country ID

$lang_id

integer

The optional language ID

Returns

arrayThe Country array on success, false otherwise

Returns the ID of the Country specified by its alpha2 code

getIdByAlpha2(string $alpha2) : integer
Static

Parameters

$alpha2

string

The alpha2 code

Returns

integerThe Country ID on success, null otherwise

Returns the HTML dropdown menu or hidden input field plus name string

getMenu(string $menuName, string $selected, boolean $active, string $onchange) : string
Static

If there is just one active country, returns a hidden tag with the countries' name appended. If there are more, returns a dropdown menu with the optional ID preselected and optional onchange method added.

static

Parameters

$menuName

string

Optional name of the menu, defaults to "countryId"

$selected

string

Optional selected country ID

$active

boolean

Include inactive countries if false. Defaults to true

$onchange

string

Optional onchange callback function

Returns

stringThe HTML dropdown menu code

Returns the HTML code for the countries dropdown menu options

getMenuoptions(string $selected, boolean $active) : string
Static
static

Parameters

$selected

string

The optional selected Country ID

$active

boolean

If true, only active countries are added to the options, all otherwise.

Returns

stringThe HTML dropdown menu options code

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

getNameArray($active, integer $lang_id) : array
Static

If the optional $lang_id parameter is empty, the FRONTEND_LANG_ID constant's value is used instead.

Parameters

$active

$lang_id

integer

The optional language ID. Defaults to the FRONTEND_LANG_ID if empty

Returns

arrayThe country names array on success, false otherwise

Returns the name of the country selected by its ID

getNameById(integer $country_id) : string
Static

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

static

Parameters

$country_id

integer

The country ID

Returns

stringThe country name, or the empty string

Returns the country settings page, always.

getPage() : 
Static

Returns

Returns the current number of Country records present in the database

getRecordcount() : integer
Static

Returns

integerThe number of records on success, false otherwise.

Returns SQL query snippets for the Country name for including in any full query

getSqlSnippets(integer $lang_id) : array
Static

Simply calls {@see Text::getSqlSnippets()} using 'name' as the alias for the Country name field.

todo Maybe add an optional $alias parameter?

Parameters

$lang_id

integer

The optional Language ID. Defaults to the FRONTEND_LANG_ID constant value

Returns

arrayThe SQL snippet array

Initialises the class array of Countries

init(integer $lang_id) : void
Static

Calls {@see getArray()} to accomplish this.

Parameters

$lang_id

integer

The optional language ID. Defaults to the FRONTEND_LANG_ID if empty

Inserts the Country into the database

insert(string $alpha2, string $alpha3, integer $ord, boolean $active, integer $country_id) : boolean
Static

Note that the Country name is inserted or updated in {@see store()} only.

Parameters

$alpha2

string

The ISO 2-character code

$alpha3

string

The ISO 3-character code

$ord

integer

The ordinal value, or null

$active

boolean

The active status, or null

$country_id

integer

The Country ID, or null

Returns

booleanTrue on success, false otherwise

Returns true if the country selected by its ID is active

isActiveById(integer $country_id) : boolean
Static

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

static

Parameters

$country_id

integer

The country ID

Returns

booleanTrue if active, false otherwise

Returns true if the record for the given ID exists in the database

recordExists(integer $country_id) : boolean
Static

Returns true if the $country_id argument is empty. Returns false both if the ID cannot be found and on failure.

Parameters

$country_id

integer

The Country ID

Returns

booleanTrue if the Country ID is present, false otherwise.

Resets the state of the class

reset() : void
Static
static

Sets up the Country settings page

settings() : string
Static

Returns

stringThe page content

Stores a Country in the database.

store(string $alpha2, string $alpha3, $lang_id, integer $country_name, integer $ord, boolean $active, integer $country_id) : boolean
Static

Decides whether to call {@see insert()} or {@see update()} by means of calling {@see getById()} if $country_id is valid. Optional values equal to null are ignored and not updated, or inserted with default values. Note, however, that $country_name, $alpha2 and $alpha3 are mandatory and must be non-empty when a new record is to be {@see insert()}ed!

Parameters

$alpha2

string

The ISO 2-character code, or null

$alpha3

string

The ISO 3-character code, or null

$lang_id

$country_name

integer

The name of the Country, or null

$ord

integer

The ordinal value, or null

$active

boolean

The active status, or null

$country_id

integer

The Country ID, or null

Returns

booleanTrue on success, false otherwise

Store the Countries posted from the (settings) page

storeFromPost() : void
Static

Appends any errors encountered to the class array variable $errors.

storeSettings()

storeSettings() 
Static

Updates the Country in the database

update(integer $country_id, integer $ord, boolean $active, string $alpha2, string $alpha3) : boolean
Static

Note that it should never be necessary to update the Text ID, so that parameter is not present here. Call {@see store()} to update the Country name as well.

Parameters

$country_id

integer

The Country ID

$ord

integer

The ordinal value, or null

$active

boolean

The active status, or null

$alpha2

string

The ISO 2-character code, or null

$alpha3

string

The ISO 3-character code, or null

Returns

booleanTrue on success, false otherwise

 Properties

 

$arrCountries : array
access private
see \init()
 

$errors : string
 

$messages : string

 Constants

 

Text key

TEXT_NAME 
© Copyright 2014 by Comvation AG
Generated on 2014-07-11T08:39:25+02:00.