new Domain - jcobban/Genealogy GitHub Wiki

new Domain($parms)

Up: class Domain

The constructor for an instance of Domain takes one parameter:

parameter description
$parms identifies the database record to be associated with this instance. This is an associative array.

In this array the alternate field names may be used

$parms may be:

  • An associative array containing all of the fields in a record as obtained by a database SELECT.
  • The domain may be identified either by a ISO 3166-2 code, for example : array('code' => 'CA-NB') or array('code' => 'CANB'), or by separate country code and state/province identifiers, for example: array('cc' => 'US', 'state' => 'AK'), where the 'state' code or the state portion of the 'code' may be the state portion of the key of a Synonym record, or by a country code and a state name, for example: array('cc' => 'US', 'state' => 'Michigan').
  • The country code value may either be a ISO 3166-1 code or an instance of class Country.
  • The 'language' parameter may either be a ISO 639-1 two character language code or an instance of class Language. If 'language' is omitted the default is 'en' for English.
  • If 'domain' or 'countrycode' and either 'state' or 'name' is omitted the default is 'CA-ON' for Ontario, Canada.
  • If the constructor is called with no parameters this creates the English entry for Ontario, Canada.

If there is no matching record in the database $domain->isExisting() returns false and $domain['name'] and $domain->getName() return "Domain: $domaincode".

The constructor adds error messages to $record->msg if it is unable to complete due to bad parameters.

For example:

    $domain                = new Domain();
    print $domain->getName();
    $domain                = new Domain(array('domain' => 'CANB'));
    print $domain->getName();
    $domain                = new Domain(array('domain' => 'CANB', 'lang' => 'fr');
    print $domain->getName();
    $domain                = new Domain(array('cc' => 'US', 'name' => 'Michigan');
    print $domain->getName();
    $domain                = new Domain(array('cc' => 'US', 'state' => 'AK');
    print $domain->getName();
    $domain                = new Domain(array('domain' => 'XXXX'));
    print $domain->getName() . ', ' . $domain->getErrors();
    $domain                = new Domain(array('domain' => '1234'));
    print $domain->getName() . ', ' . $domain->getErrors();

will display:

Ontario
New Brunswick
Nouveau Brunswick
Michigan
Alaska
Domain: XXXX,
Domain: 1234, Invalid domain=1234

In the last example '1234' is not a syntactically valid domain identifier because it contains characters other than letters of the Roman alphabet.

The following are some of the error messages returned if this method is not able to construct a valid Domain.

Message interpretation
Invalid CountryCode the country code is not two letters from the Latin Alphabet
Invalid domain the domain code is not 4 or 5 letters with an optional hyphen
Invalid language the language code is not a 2 letter code followed by an optional hyphen and a 2 letter code
Invalid state the state code is not between 2 and 4 letters
Incomplete parameters not enough fields are provided to identify a domain.
Domain::__construct: " 'SELECT FROM Domains ...' Internal logic error indicating a mal-formed database request

Next: $domain->getName()