mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-12 23:08:41 +00:00
Implement basic localization db mapper
This commit is contained in:
parent
a9bb4b9224
commit
31209d2b30
|
|
@ -65,6 +65,7 @@ final class SqliteConnection extends ConnectionAbstract
|
||||||
|
|
||||||
$this->status = DatabaseStatus::OK;
|
$this->status = DatabaseStatus::OK;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
$this->status = DatabaseStatus::MISSING_DATABASE;
|
$this->status = DatabaseStatus::MISSING_DATABASE;
|
||||||
$this->con = null;
|
$this->con = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class CountryMapper extends DataMapperAbstract
|
||||||
'country_code2' => ['name' => 'country_code2', 'type' => 'string', 'internal' => 'code2'],
|
'country_code2' => ['name' => 'country_code2', 'type' => 'string', 'internal' => 'code2'],
|
||||||
'country_code3' => ['name' => 'country_code3', 'type' => 'string', 'internal' => 'code3'],
|
'country_code3' => ['name' => 'country_code3', 'type' => 'string', 'internal' => 'code3'],
|
||||||
'country_numeric' => ['name' => 'country_numeric', 'type' => 'int', 'internal' => 'numeric'],
|
'country_numeric' => ['name' => 'country_numeric', 'type' => 'int', 'internal' => 'numeric'],
|
||||||
'country_subdevision' => ['name' => 'country_subdevision', 'type' => 'float', 'internal' => 'subdevision'],
|
'country_subdevision' => ['name' => 'country_subdevision', 'type' => 'string', 'internal' => 'subdevision'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class CurrencyMapper extends DataMapperAbstract
|
||||||
'currency_name' => ['name' => 'currency_name', 'type' => 'string', 'internal' => 'name'],
|
'currency_name' => ['name' => 'currency_name', 'type' => 'string', 'internal' => 'name'],
|
||||||
'currency_code' => ['name' => 'currency_code', 'type' => 'string', 'internal' => 'code'],
|
'currency_code' => ['name' => 'currency_code', 'type' => 'string', 'internal' => 'code'],
|
||||||
'currency_number' => ['name' => 'currency_number', 'type' => 'int', 'internal' => 'number'],
|
'currency_number' => ['name' => 'currency_number', 'type' => 'int', 'internal' => 'number'],
|
||||||
'currency_decimal' => ['name' => 'currency_decimal', 'type' => 'int', 'internal' => 'decimal'],
|
'currency_decimal' => ['name' => 'currency_decimal', 'type' => 'int', 'internal' => 'decimals'],
|
||||||
'currency_countries' => ['name' => 'currency_countries', 'type' => 'string', 'internal' => 'countries'],
|
'currency_countries' => ['name' => 'currency_countries', 'type' => 'string', 'internal' => 'countries'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ final class Iban
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $chars = '';
|
private $chars = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iban bban.
|
* Iban bban.
|
||||||
|
|
@ -79,11 +79,11 @@ final class Iban
|
||||||
/**
|
/**
|
||||||
* Get iban chars
|
* Get iban chars
|
||||||
*
|
*
|
||||||
* @return string
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getChars() : string
|
public function getChars() : int
|
||||||
{
|
{
|
||||||
return $this->chars;
|
return $this->chars;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class IbanMapper extends DataMapperAbstract
|
||||||
protected static $columns = [
|
protected static $columns = [
|
||||||
'iban_id' => ['name' => 'iban_id', 'type' => 'int', 'internal' => 'id'],
|
'iban_id' => ['name' => 'iban_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'iban_country' => ['name' => 'iban_country', 'type' => 'string', 'internal' => 'country'],
|
'iban_country' => ['name' => 'iban_country', 'type' => 'string', 'internal' => 'country'],
|
||||||
'iban_chars' => ['name' => 'iban_chars', 'type' => 'string', 'internal' => 'chars'],
|
'iban_chars' => ['name' => 'iban_chars', 'type' => 'int', 'internal' => 'chars'],
|
||||||
'iban_bban' => ['name' => 'iban_bban', 'type' => 'string', 'internal' => 'bban'],
|
'iban_bban' => ['name' => 'iban_bban', 'type' => 'string', 'internal' => 'bban'],
|
||||||
'iban_fields' => ['name' => 'iban_fields', 'type' => 'string', 'internal' => 'fields'],
|
'iban_fields' => ['name' => 'iban_fields', 'type' => 'string', 'internal' => 'fields'],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,14 @@ final class Language
|
||||||
*/
|
*/
|
||||||
private $code3 = '';
|
private $code3 = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language code.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $code3Native = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get language name
|
* Get language name
|
||||||
*
|
*
|
||||||
|
|
@ -111,4 +119,16 @@ final class Language
|
||||||
{
|
{
|
||||||
return $this->code3;
|
return $this->code3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get language code
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getCode3Native() : string
|
||||||
|
{
|
||||||
|
return $this->code3Native;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,10 @@ class LanguageMapper extends DataMapperAbstract
|
||||||
*/
|
*/
|
||||||
protected static $columns = [
|
protected static $columns = [
|
||||||
'language_id' => ['name' => 'language_id', 'type' => 'int', 'internal' => 'id'],
|
'language_id' => ['name' => 'language_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'language_name' => ['name' => 'language_name', 'type' => 'string', 'internal' => 'name'],
|
'language_native' => ['name' => 'language_native', 'type' => 'string', 'internal' => 'name'],
|
||||||
'language_native' => ['name' => 'language_native', 'type' => 'string', 'internal' => 'native'],
|
'language_639_1' => ['name' => 'language_639_1', 'type' => 'string', 'internal' => 'native'],
|
||||||
'language_639_2T' => ['name' => 'language_639_2T', 'type' => 'string', 'internal' => 'code2'],
|
'language_639_2T' => ['name' => 'language_639_2T', 'type' => 'string', 'internal' => 'code2'],
|
||||||
|
'language_639_2B' => ['name' => 'language_639_2B', 'type' => 'string', 'internal' => 'code3Native'],
|
||||||
'language_639_3' => ['name' => 'language_639_3', 'type' => 'string', 'internal' => 'code3'],
|
'language_639_3' => ['name' => 'language_639_3', 'type' => 'string', 'internal' => 'code3'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
32
Message/NotificationLevel.php
Normal file
32
Message/NotificationLevel.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.2
|
||||||
|
*
|
||||||
|
* @package phpOMS\Message
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\Message;
|
||||||
|
|
||||||
|
use phpOMS\Stdlib\Base\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notification level enum.
|
||||||
|
*
|
||||||
|
* @package phpOMS\Message
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract class NotificationLevel extends Enum
|
||||||
|
{
|
||||||
|
public const OK = 'ok';
|
||||||
|
public const WARNING = 'warning';
|
||||||
|
public const ERROR = 'error';
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,36 @@ require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Localization\Defaults\City;
|
use phpOMS\Localization\Defaults\City;
|
||||||
use phpOMS\Localization\Defaults\CityMapper;
|
use phpOMS\Localization\Defaults\CityMapper;
|
||||||
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
|
||||||
class CityMapperTest extends \PHPUnit\Framework\TestCase
|
class CityMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
$con = new SqliteConnection([
|
||||||
|
'prefix' => '',
|
||||||
|
'db' => 'sqlite',
|
||||||
|
'path' => realpath(__DIR__ . '/../../../Localization/Defaults/localization.sqlite'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DataMapperAbstract::setConnection($con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testR()
|
||||||
|
{
|
||||||
|
$obj = CityMapper::get(101079);
|
||||||
|
self::assertEquals('DE', $obj->getCountryCode());
|
||||||
|
self::assertEquals('Frankfurt', $obj->getName());
|
||||||
|
self::assertEquals(60322, $obj->getPostal());
|
||||||
|
self::assertGreaterThan(50, $obj->getLat());
|
||||||
|
self::assertGreaterThan(8, $obj->getLong());
|
||||||
|
self::assertLessThan(51, $obj->getLat());
|
||||||
|
self::assertLessThan(9, $obj->getLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,34 @@ require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Localization\Defaults\Country;
|
use phpOMS\Localization\Defaults\Country;
|
||||||
use phpOMS\Localization\Defaults\CountryMapper;
|
use phpOMS\Localization\Defaults\CountryMapper;
|
||||||
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
|
||||||
class CountryMapperTest extends \PHPUnit\Framework\TestCase
|
class CountryMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
$con = new SqliteConnection([
|
||||||
|
'prefix' => '',
|
||||||
|
'db' => 'sqlite',
|
||||||
|
'path' => realpath(__DIR__ . '/../../../Localization/Defaults/localization.sqlite'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DataMapperAbstract::setConnection($con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testR()
|
||||||
|
{
|
||||||
|
$obj = CountryMapper::get(83);
|
||||||
|
self::assertEquals('Germany', $obj->getName());
|
||||||
|
self::assertEquals('DE', $obj->getCode2());
|
||||||
|
self::assertEquals('DEU', $obj->getCode3());
|
||||||
|
self::assertEquals(276, $obj->getNumeric());
|
||||||
|
self::assertEquals('ISO 3166-2:DE', $obj->getSubdevision());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,34 @@ require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Localization\Defaults\Currency;
|
use phpOMS\Localization\Defaults\Currency;
|
||||||
use phpOMS\Localization\Defaults\CurrencyMapper;
|
use phpOMS\Localization\Defaults\CurrencyMapper;
|
||||||
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
|
||||||
class CurrencyMapperTest extends \PHPUnit\Framework\TestCase
|
class CurrencyMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
$con = new SqliteConnection([
|
||||||
|
'prefix' => '',
|
||||||
|
'db' => 'sqlite',
|
||||||
|
'path' => realpath(__DIR__ . '/../../../Localization/Defaults/localization.sqlite'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DataMapperAbstract::setConnection($con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testR()
|
||||||
|
{
|
||||||
|
$obj = CurrencyMapper::get(50);
|
||||||
|
self::assertEquals('Euro', $obj->getName());
|
||||||
|
self::assertEquals('EUR', $obj->getCode());
|
||||||
|
self::assertEquals(978, $obj->getNumber());
|
||||||
|
self::assertEquals(2, $obj->getDecimals());
|
||||||
|
self::assertContains('Germany', $obj->getCountries());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,33 @@ require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Localization\Defaults\Iban;
|
use phpOMS\Localization\Defaults\Iban;
|
||||||
use phpOMS\Localization\Defaults\IbanMapper;
|
use phpOMS\Localization\Defaults\IbanMapper;
|
||||||
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
|
||||||
class IbanMapperTest extends \PHPUnit\Framework\TestCase
|
class IbanMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
$con = new SqliteConnection([
|
||||||
|
'prefix' => '',
|
||||||
|
'db' => 'sqlite',
|
||||||
|
'path' => realpath(__DIR__ . '/../../../Localization/Defaults/localization.sqlite'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DataMapperAbstract::setConnection($con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testR()
|
||||||
|
{
|
||||||
|
$obj = IbanMapper::get(22);
|
||||||
|
self::assertEquals('DE', $obj->getCountry());
|
||||||
|
self::assertEquals(22, $obj->getChars());
|
||||||
|
self::assertEquals('18n', $obj->getBban());
|
||||||
|
self::assertEquals('DEkk bbbb bbbb cccc cccc cc', $obj->getFields());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class IbanTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$obj = new Iban();
|
$obj = new Iban();
|
||||||
self::assertEquals('', $obj->getCountry());
|
self::assertEquals('', $obj->getCountry());
|
||||||
self::assertEquals('', $obj->getChars());
|
self::assertEquals(2, $obj->getChars());
|
||||||
self::assertEquals('', $obj->getBban());
|
self::assertEquals('', $obj->getBban());
|
||||||
self::assertEquals('', $obj->getFields());
|
self::assertEquals('', $obj->getFields());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,34 @@ require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Localization\Defaults\Language;
|
use phpOMS\Localization\Defaults\Language;
|
||||||
use phpOMS\Localization\Defaults\LanguageMapper;
|
use phpOMS\Localization\Defaults\LanguageMapper;
|
||||||
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
||||||
|
|
||||||
class LanguageMapperTest extends \PHPUnit\Framework\TestCase
|
class LanguageMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
$con = new SqliteConnection([
|
||||||
|
'prefix' => '',
|
||||||
|
'db' => 'sqlite',
|
||||||
|
'path' => realpath(__DIR__ . '/../../../Localization/Defaults/localization.sqlite'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DataMapperAbstract::setConnection($con);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testR()
|
||||||
|
{
|
||||||
|
$obj = LanguageMapper::get(53);
|
||||||
|
self::assertEquals('German', $obj->getName());
|
||||||
|
self::assertEquals('Deutsch', $obj->getNative());
|
||||||
|
self::assertEquals('de', $obj->getCode2());
|
||||||
|
self::assertEquals('deu', $obj->getCode3Native());
|
||||||
|
self::assertEquals('ger', $obj->getCode3());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,6 @@ class LanguageTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals('', $obj->getNative());
|
self::assertEquals('', $obj->getNative());
|
||||||
self::assertEquals('', $obj->getCode2());
|
self::assertEquals('', $obj->getCode2());
|
||||||
self::assertEquals('', $obj->getCode3());
|
self::assertEquals('', $obj->getCode3());
|
||||||
|
self::assertEquals('', $obj->getCode3Native());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user