This commit is contained in:
Dennis Eichhorn 2020-02-08 22:31:48 +01:00
parent babbca7fcc
commit f28515fcf1
13 changed files with 249 additions and 59 deletions

View File

@ -144,7 +144,7 @@ class Account implements ArrayableInterface, \JsonSerializable
* @var Localization
* @since 1.0.0
*/
protected Localization $localization;
protected $localization;
use PermissionHandlingTrait;
@ -186,7 +186,7 @@ class Account implements ArrayableInterface, \JsonSerializable
*
* @since 1.0.0
*/
public function getL11n() : Localization
public function getL11n()
{
return $this->localization;
}

View File

@ -39,6 +39,7 @@ use phpOMS\Router\RouterInterface;
* @property int $orgId
* @property \phpOMS\DataStorage\Database\DatabasePool $dbPool
* @property \phpOMS\Localization\L11nManager $l11nManager
* @property \phpOMS\Localization\Localization $l11nServer
* @property \phpOMS\Router\RouterInterface $router
* @property \phpOMS\DataStorage\Session\SessionInterface $sessionManager
* @property \phpOMS\DataStorage\Cookie\CookieJar $cookieJar

View File

@ -549,8 +549,9 @@ class DataMapperAbstract implements DataMapperInterface
$query->insert($column['name'])->value($value);
} elseif ($column['name'] !== static::$primaryField || !empty($property->getValue($obj))) {
$tValue = $property->getValue($obj);
if (\stripos($column['internal'], '/') === 0) {
$tValue = ArrayUtils::getArray($column['internal'], $tValue, '/');
if (\stripos($column['internal'], '/') !== false) {
$path = \substr($column['internal'], \stripos($column['internal'], '/') + 1);
$tValue = ArrayUtils::getArray($path, $tValue, '/');
}
$value = self::parseValue($column['type'], $tValue);
@ -1280,7 +1281,7 @@ class DataMapperAbstract implements DataMapperInterface
* The reference is stored in the main model
*
* @param string $propertyName Property name to initialize
* @param object $obj Object to update
* @param mixed $obj Object to update
* @param int $relations Create all relations as well
* @param int $depth Depth of relations to update (default = 1 = none)
*
@ -1288,8 +1289,12 @@ class DataMapperAbstract implements DataMapperInterface
*
* @since 1.0.0
*/
private static function updateOwnsOne(string $propertyName, object $obj, int $relations = RelationType::ALL, int $depth = 1)
private static function updateOwnsOne(string $propertyName, $obj, int $relations = RelationType::ALL, int $depth = 1)
{
if (!\is_object($obj)) {
return $obj;
}
/** @var string $mapper */
$mapper = static::$ownsOne[$propertyName]['mapper'];
@ -1336,14 +1341,14 @@ class DataMapperAbstract implements DataMapperInterface
*/
private static function updateBelongsTo(string $propertyName, $obj, int $relations = RelationType::ALL, int $depth = 1)
{
if (\is_object($obj)) {
/** @var string $mapper */
$mapper = static::$belongsTo[$propertyName]['mapper'];
return $mapper::update($obj, $relations, $depth);
if (!\is_object($obj)) {
return $obj;
}
return $obj;
/** @var string $mapper */
$mapper = static::$belongsTo[$propertyName]['mapper'];
return $mapper::update($obj, $relations, $depth);
}
/**
@ -1431,8 +1436,9 @@ class DataMapperAbstract implements DataMapperInterface
$query->set([static::$table . '.' . $column['name'] => $value]);
} elseif ($column['name'] !== static::$primaryField) {
$tValue = $property->getValue($obj);
if (\stripos($column['internal'], '/') === 0) {
$tValue = ArrayUtils::getArray($column['internal'], $tValue, '/');
if (\stripos($column['internal'], '/') !== false) {
$path = \substr($column['internal'], \stripos($column['internal'], '/') + 1);
$tValue = ArrayUtils::getArray($path, $tValue, '/');
}
$value = self::parseValue($column['type'], $tValue);
@ -1481,8 +1487,9 @@ class DataMapperAbstract implements DataMapperInterface
if ($column['name'] !== $conditional['external']) {
$tValue = $property->getValue($obj);
if (\stripos($column['internal'], '/') === 0) {
$tValue = ArrayUtils::getArray($column['internal'], $tValue, '/');
if (\stripos($column['internal'], '/') !== false) {
$path = \substr($column['internal'], \stripos($column['internal'], '/') + 1);
$tValue = ArrayUtils::getArray($path, $tValue, '/');
}
$value = self::parseValue($column['type'], $tValue);
@ -1524,8 +1531,9 @@ class DataMapperAbstract implements DataMapperInterface
}
$path = $column['internal'];
if (\stripos($column['internal'], '/') === 0) {
$path = \ltrim($column['internal'], '/');
if (\stripos($column['internal'], '/') !== false) {
$path = \substr($column['internal'], \stripos($column['internal'], '/') + 1);
//$path = \ltrim($column['internal'], '/');
}
$property = ArrayUtils::getArray($column['internal'], $obj, '/');

View File

@ -3,7 +3,8 @@
"country": "DE",
"currency": {
"code": "EUR",
"position": 0
"position": 0,
"format": "%s1 %s2"
},
"thousand": ".",
"decimal": ",",
@ -17,7 +18,7 @@
"very_heavy": "t"
},
"speed": {
"very_slow": "ns",
"very_slow": "mps",
"slow": "ms",
"medium": "kph",
"fast": "kph",
@ -25,7 +26,7 @@
"sea": "knot"
},
"length": {
"very_short": "nm",
"very_short": "micron",
"short": "mm",
"medium": "cm",
"long": "m",
@ -33,29 +34,29 @@
"sea": "mile"
},
"area": {
"very_small": "nm",
"very_small": "micron",
"small": "mm",
"medium": "cm",
"large": "m",
"very_large": "km"
},
"volume": {
"very_small": "ml",
"very_small": "mul",
"small": "ml",
"medium": "l",
"large": "m",
"very_large": "km",
"teaspoon": "metric teaspoon",
"tablespoon": "metric tablespoon",
"glass": "metric glass"
"large": "cm",
"very_large": "m",
"teaspoon": "Metric tsp",
"tablespoon": "Metric tblsp",
"glass": "Metric cup"
},
"datetime": {
"delim_date": ".",
"delim_time": ":",
"very_short": "d.m",
"short": "m.y",
"medium": "d.m.Y",
"long": "d.m.Y h:i",
"very_long": "d.m.Y h:i:s"
"medium": "Y.m.d",
"long": "Y.m.d h:i",
"very_long": "Y.m.d h:i:s"
}
}

View File

@ -3,7 +3,8 @@
"country": "US",
"currency": {
"code": "USD",
"position": 0
"position": 0,
"format": "%s1 %s2"
},
"thousand": ",",
"decimal": ".",
@ -17,7 +18,7 @@
"very_heavy": "t"
},
"speed": {
"very_slow": "ns",
"very_slow": "mps",
"slow": "ms",
"medium": "kph",
"fast": "kph",
@ -25,7 +26,7 @@
"sea": "knot"
},
"length": {
"very_short": "nm",
"very_short": "micron",
"short": "mm",
"medium": "cm",
"long": "m",
@ -33,21 +34,21 @@
"sea": "mile"
},
"area": {
"very_small": "nm",
"very_small": "micron",
"small": "mm",
"medium": "cm",
"large": "m",
"very_large": "km"
},
"volume": {
"very_small": "ml",
"very_small": "mul",
"small": "ml",
"medium": "l",
"large": "m",
"very_large": "km",
"teaspoon": "metric teaspoon",
"tablespoon": "metric tablespoon",
"glass": "metric glass"
"large": "cm",
"very_large": "m",
"teaspoon": "Metric tsp",
"tablespoon": "Metric tblsp",
"glass": "Metric cup"
},
"datetime": {
"delim_date": ".",

View File

@ -3,7 +3,8 @@
"country": "US",
"currency": {
"code": "USD",
"position": 0
"position": 0,
"format": "%s1 %s2"
},
"thousand": ",",
"decimal": ".",
@ -17,7 +18,7 @@
"very_heavy": "t"
},
"speed": {
"very_slow": "ns",
"very_slow": "mps",
"slow": "ms",
"medium": "kph",
"fast": "kph",
@ -25,7 +26,7 @@
"sea": "knot"
},
"length": {
"very_short": "nm",
"very_short": "micron",
"short": "mm",
"medium": "cm",
"long": "m",
@ -33,21 +34,21 @@
"sea": "mile"
},
"area": {
"very_small": "nm",
"very_small": "micron",
"small": "mm",
"medium": "cm",
"large": "m",
"very_large": "km"
},
"volume": {
"very_small": "ml",
"very_small": "mul",
"small": "ml",
"medium": "l",
"large": "m",
"very_large": "km",
"teaspoon": "metric teaspoon",
"tablespoon": "metric tablespoon",
"glass": "metric glass"
"large": "cm",
"very_large": "m",
"teaspoon": "Metric tsp",
"tablespoon": "Metric tblsp",
"glass": "Metric cup"
},
"datetime": {
"delim_date": ".",

View File

@ -26,7 +26,7 @@ use phpOMS\Utils\Converter\TemperatureType;
* @link https://orange-management.org
* @since 1.0.0
*/
class Localization
class Localization implements \JsonSerializable
{
/**
* Country ID.
@ -60,6 +60,14 @@ class Localization
*/
protected string $currency = ISO4217CharEnum::_USD;
/**
* Currency format.
*
* @var string
* @since 1.0.0
*/
protected string $currencyFormat = '%s1 %s2';
/**
* Number format.
*
@ -100,6 +108,22 @@ class Localization
*/
protected array $datetime = [];
/**
* Datetime delim.
*
* @var string
* @since 1.0.0
*/
protected string $dateDelim = '.';
/**
* Datetime delim.
*
* @var string
* @since 1.0.0
*/
protected string $timeDelim = ':';
/**
* Weight.
*
@ -178,6 +202,39 @@ class Localization
return $l11n;
}
/**
* Create localization from json
*
* @param array $json Json serialization
*
* @return Localization
*
* @since 1.0.0
*/
public static function fromJson(array $json) : self
{
$l11n = new self();
$l11n->setCountry($json['country']);
$l11n->setTimezone($json['timezone']);
$l11n->setLanguage($json['language']);
$l11n->setCurrency($json['currency']);
$l11n->setCurrencyFormat($json['currencyformat']);
$l11n->setDecimal($json['decimal']);
$l11n->setThousands($json['thousands']);
$l11n->setAngle($json['angle']);
$l11n->setTemperature($json['temperature']);
$l11n->setDatetime($json['datetime']);
$l11n->setDateDelim($json['datedelim']);
$l11n->setTimeDelim($json['timedelim']);
$l11n->setWeight($json['weight']);
$l11n->setSpeed($json['speed']);
$l11n->setLength($json['length']);
$l11n->setArea($json['area']);
$l11n->setVolume($json['volume']);
return $l11n;
}
/**
* Load localization from language code
*
@ -388,6 +445,32 @@ class Localization
$this->currency = $currency;
}
/**
* Get currency format
*
* @return string
*
* @since 1.0.0
*/
public function getCurrencyFormat() : string
{
return $this->currencyFormat;
}
/**
* Set currency format
*
* @param string $format Currency format
*
* @return void
*
* @since 1.0.0
*/
public function setCurrencyFormat(string $format) : void
{
$this->currencyFormat = $format;
}
/**
* get datetime format
*
@ -414,6 +497,58 @@ class Localization
$this->datetime = $datetime;
}
/**
* Set dateDelim char
*
* @return string
*
* @since 1.0.0
*/
public function getDateDelim() : string
{
return $this->dateDelim;
}
/**
* Get dateDelim char
*
* @param string $dateDelim Date delim char
*
* @return void
*
* @since 1.0.0
*/
public function setDateDelim(string $dateDelim) : void
{
$this->dateDelim = $dateDelim;
}
/**
* Get timeDelim char
*
* @return string
*
* @since 1.0.0
*/
public function getTimeDelim() : string
{
return $this->timeDelim;
}
/**
* Set timeDelim char
*
* @param string $timeDelim Time delim char
*
* @return void
*
* @since 1.0.0
*/
public function setTimeDelim(string $timeDelim) : void
{
$this->timeDelim = $timeDelim;
}
/**
* Set decimal char
*
@ -657,4 +792,39 @@ class Localization
{
$this->volume = $volume;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'country' => $this->country,
'timezone' => $this->timezone,
'language' => $this->language,
'currency' => $this->currency,
'currencyformat' => $this->currencyFormat,
'decimal' => $this->decimal,
'thousands' => $this->thousands,
'angle' => $this->angle,
'temperature' => $this->temperature,
'datetime' => $this->datetime,
'datedelim' => $this->dateDelim,
'timedelim' => $this->timeDelim,
'weight' => $this->weight,
'speed' => $this->speed,
'length' => $this->length,
'area' => $this->area,
'volume' => $this->volume,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
return $this->toArray();
}
}

View File

@ -28,6 +28,7 @@ abstract class LengthType extends Enum
{
public const MILES = 'mi';
public const METERS = 'm';
public const NANOMETER = 'nm';
public const MICROMETER = 'micron';
public const CENTIMETERS = 'cm';
public const MILLIMETERS = 'mm';

View File

@ -296,6 +296,9 @@ final class Measurement
case LengthType::MICROINCH:
$value *= 39370000;
break;
case LengthType::NANOMETER:
$value *= 1000000000;
break;
case LengthType::INCHES:
$value *= 39.370;
break;
@ -357,6 +360,9 @@ final class Measurement
case LengthType::MICROMETER:
$value /= 1000000;
break;
case LengthType::NANOMETER:
$value /= 1000000000;
break;
case LengthType::CENTIMETERS:
$value /= 100;
break;

View File

@ -37,9 +37,9 @@ abstract class VolumeType extends Enum
public const UK_QUARTS = 'UK qt dry';
public const US_GILL = 'US gi';
public const UK_GILL = 'UK gi';
public const LITER = 'L';
public const LITER = 'l';
public const MICROLITER = 'mul';
public const MILLILITER = 'mL';
public const MILLILITER = 'ml';
public const CENTILITER = 'cl';
public const KILOLITER = 'kl';
public const UK_BARREL = 'UK bbl';

View File

@ -75,8 +75,8 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
self::assertEquals(
$sql,
$query->createTable('user_roles')
->field('user_id', 'INT', null, false, true, true, 'users', 'ext1_id')
->field('role_id', 'VARCHAR(10)', '1', true, false, false, 'roles', 'ext2_id')
->field('user_id', 'INT', null, false, true, false, true, 'users', 'ext1_id')
->field('role_id', 'VARCHAR(10)', '1', true, false, false, false, 'roles', 'ext2_id')
->toSql()
);
}

View File

@ -27,7 +27,7 @@ class LengthTypeTest extends \PHPUnit\Framework\TestCase
*/
public function testEnumCount() : void
{
self::assertCount(21, LengthType::getConstants());
self::assertCount(22, LengthType::getConstants());
}
/**
@ -48,6 +48,7 @@ class LengthTypeTest extends \PHPUnit\Framework\TestCase
self::assertEquals('mi', LengthType::MILES);
self::assertEquals('m', LengthType::METERS);
self::assertEquals('micron', LengthType::MICROMETER);
self::assertEquals('nm', LengthType::NANOMETER);
self::assertEquals('cm', LengthType::CENTIMETERS);
self::assertEquals('mm', LengthType::MILLIMETERS);
self::assertEquals('km', LengthType::KILOMETERS);

View File

@ -56,9 +56,9 @@ class VolumeTypeTest extends \PHPUnit\Framework\TestCase
self::assertEquals('UK qt dry', VolumeType::UK_QUARTS);
self::assertEquals('US gi', VolumeType::US_GILL);
self::assertEquals('UK gi', VolumeType::UK_GILL);
self::assertEquals('L', VolumeType::LITER);
self::assertEquals('l', VolumeType::LITER);
self::assertEquals('mul', VolumeType::MICROLITER);
self::assertEquals('mL', VolumeType::MILLILITER);
self::assertEquals('ml', VolumeType::MILLILITER);
self::assertEquals('cl', VolumeType::CENTILITER);
self::assertEquals('kl', VolumeType::KILOLITER);
self::assertEquals('UK bbl', VolumeType::UK_BARREL);