Skip to content

koren-software/ehak-locations-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions Status Coverage Status Latest Stable Version Total Downloads License

EHAK Locations

PHP Library to convert location into EHAK classification code and vice-versa

Install

composer require koren-software/ehak-locations

Usage

use \Koren\EHAK\EHAK;

$ehak = new EHAK(); // init EHAK instance on latest data

// Get EHAK code from location
$countyCode = $ehak->getCode(EHAK::COUNTIES, 'EST', 'Harju maakond'); // 0037

$cityCode = $ehak->getCode(EHAK::CITIES, $countyCode, 'Tallinn'); // 0784
$ehak->getCode(EHAK::CITY_DISTRICTS, $cityCode, 'Haabersti linnaosa'); // 0176

$parishCode = $ehak->getCode(EHAK::PARISHES, $countyCode, 'Anija vald'); // 0141
$ehak->getCode(EHAK::VILLAGES, $parishCode, 'Aegviidu alev'); // 1088

// Get EHAK location from code
$ehak->getLocation(EHAK::COUNTIES, 'EST', '0037'); // Harju maakond

$ehak->getLocation(EHAK::CITIES, '0037', '0784'); // Tallinn
$ehak->getLocation(EHAK::CITY_DISTRICTS, '0784', '0176'); // Haabersti linnaosa

$ehak->getLocation(EHAK::PARISHES, '0037', '0141'); // Anija vald
$ehak->getLocation(EHAK::VILLAGES, '0141', '1088'); // Aegviidu alev

// Get full location from EHAK code
$ehak->getFullLocation('0176');

//Gives:
[
    'counties' => 'Harju maakond',
    'cities' => 'Tallinn',
    'city_districts' => 'Haabersti linnaosa',
    'parishes' => '',
    'villages' => '',
]

// Get code from full location
$ehak->getCodeFromFullLocation([
    EHAK::COUNTIES => 'Harju maakond',
    EHAK::CITIES => 'Tallinn',
    EHAK::CITY_DISTRICTS => 'Haabersti linnaosa',
    EHAK::PARISHES => '',
    EHAK::VILLAGES => '',
]); // 0176

Development

Update data

src/data directory holds different versions of EHAK data. To save new version or update old, run:

bin/update.php --path "EHAK XLSX PATH HERE"

Options

  • --output="FILENAME" / -o FILENAME - set different output destination
  • --debug / -d - enable debug