This page is still a beta!

3.3. Frontend API

Class tx_staticinfotables_pi1 may be used in any Frontend Typo3 extension.

Some default values may be configured using the TS template constant editor. See the Configuration section.

Class inclusion

Use the following statement to include it in your script:

require_once(t3lib_extMgm::extPath('static_info_tables').'pi1/class.tx_staticinfotables_pi1.php');

Class initialization

The following example statements will instantiate and initialize the class:

$staticInfoObj = &t3lib_div::getUserObj('&tx_staticinfotables_pi1');
if ($staticInfoObj->needsInit()){
$staticInfoObj->init();
}

Init() will initialize:

  1. the language of display: using the TypoScript template config.language property;

  2. the default currency used to format amounts: using the configured currencyCode;

  3. defaults for selected values in drop-down lists: using  the configured countryCode, countryZoneCode, currencyCode and languageCode.

Getting a localized name

Each of the following example statements will return the name of some entity given its code. The name will be in the language specified by the TypoScript config.language property.

$this->staticInfo->getStaticInfoName('COUNTRIES', $countryCode);
$this->staticInfo->getStaticInfoName('SUBDIVISIONS', $zoneCode, $countryCode);
$this->staticInfo->getStaticInfoName('CURRENCIES', $currencyCode);
$this->staticInfo->getStaticInfoName('LANGUAGES', $languageCode, '', '', $self);

In the case of LANGUAGES, if $self is set to 1, the name of the language will be returned in the language itself.

See the source code for a description of the parameters.

Creating a localized drop-down selector

Each of the following example statements will return a string of <select> and <option> HTML tags to display a drop-down selector of countries, country subdivisions, currencies or languages. The drop-down selector will be produced in the language specified by the TS config.language property.

$this->staticInfo->buildStaticInfoSelector('COUNTRIES', $fieldName, $CSSClassName, $selectedCountryCode, '', $submitFlag, $id, $title, §where, $lang, $local);
$this->staticInfo->buildStaticInfoSelector('SUBDIVISIONS',  $fieldName, $CSSClassName, $selectedZoneCode, $countryCode, $submitFlag, $id, $title);
$this->staticInfo->buildStaticInfoSelector('CURRENCIES', $fieldName, $CSSClassName, $selectedCurrencyCode, '', $submitFlag, $id, $title);
$this->staticInfo->buildStaticInfoSelector('LANGUAGES', $fieldName, $CSSClassName, $selectedLanguageCode, '', $submitFlag, $id, $title);

See the source code for a description of these and other parameters.

Note that the entries of the drop-down selector are sorted using the current locale. If the front end page is using utf-8 encoding (config.metaCharset = utf-8), then the locale should be fully qualified; for example: config.locale_all = fr_CA.UTF-8.

Formating an amount

The following statement will return the amount $amount formated for display in the default currency or in the currency specified in the previously called loadCurrencyInfo method.

$formatedAmount = $this->staticInfo->formatAmount($amount);

Loading an alternate currency

The currency to be used to format amounts may be overridden using method loadCurrencyInfo

$this->staticInfo->loadCurrencyInfo($currencyCode);

where $currencyCode is the ISO alpha-3 code (cu_iso_3) of some currency.

The loaded currency will be effective until the same method is called again with a different currency code.

Init() loads the default currency.

Formating an address

The following statement will return an address formated for display according to the address format specified for the country in the static_countries table (cn_address_format).

$formatedAddress = $this->staticInfo->formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode, $countryCode);

where $delim will often be chr(10), $subdivisionCode is country subdivision code, and $countryCode is a ISO alpha-3 country code.

Getting country info

You can get now the info for different countries by applying the parameters you have obtained from a FE edit field.

$countryArray = tx_staticinfotables_div::fetchCountries($input['country'], $input['countryISO2'], $input['countryISO3'], $input['countryISONr']);

where the first parameter may be the text of the country in English or the local language and only parts of it. The fitting languages will be guessed by the input text.