mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
parent
5048008be6
commit
1594a88daf
|
|
@ -441,7 +441,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function getCreatedAt() : \DateTime
|
public function getCreatedAt() : \DateTime
|
||||||
{
|
{
|
||||||
return $this->createdAt ?? new \DateTime('NOW');
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -489,7 +489,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function updateLastActive() : void
|
public function updateLastActive() : void
|
||||||
{
|
{
|
||||||
$this->lastActive = new \DateTime('NOW');
|
$this->lastActive = new \DateTime('now');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2071,13 +2071,19 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
{
|
{
|
||||||
$mapper = static::$ownsOne[$member]['mapper'];
|
$mapper = static::$ownsOne[$member]['mapper'];
|
||||||
|
|
||||||
if (!isset(static::$ownsOne[$member]['by'])) {
|
if (isset(static::$ownsOne[$member]['column'])) {
|
||||||
$value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
|
if (!isset(static::$ownsOne[$member]['by'])) {
|
||||||
} else {
|
return $mapper::getColumn($id, static::$ownsOne[$member]['column']);
|
||||||
$value = $mapper::getBy($id, static::$ownsOne[$member]['by'], RelationType::ALL, null, $depth);
|
}
|
||||||
|
|
||||||
|
return $mapper::getByColumn($id, static::$ownsOne[$member]['by'], static::$ownsOne[$member]['column']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
if (!isset(static::$ownsOne[$member]['by'])) {
|
||||||
|
return self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mapper::getBy($id, static::$ownsOne[$member]['by'], RelationType::ALL, null, $depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2145,6 +2151,10 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
{
|
{
|
||||||
$mapper = static::$belongsTo[$member]['mapper'];
|
$mapper = static::$belongsTo[$member]['mapper'];
|
||||||
|
|
||||||
|
if (isset(static::$belongsTo[$member]['column'])) {
|
||||||
|
return $mapper::getColumn($id, static::$belongsTo[$member]['column']);
|
||||||
|
}
|
||||||
|
|
||||||
return self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
|
return self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2493,6 +2503,45 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get object.
|
||||||
|
*
|
||||||
|
* @param mixed $primaryKey Key
|
||||||
|
* @param string $member Member to load
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getColumn($primaryKey, string $member)
|
||||||
|
{
|
||||||
|
if (!isset(self::$parentMapper)) {
|
||||||
|
self::$parentMapper = static::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::extend(__CLASS__);
|
||||||
|
|
||||||
|
$primaryKey = (array) $primaryKey;
|
||||||
|
$columnValue = [];
|
||||||
|
|
||||||
|
foreach ($primaryKey as $key => $value) {
|
||||||
|
$dbData = self::getRaw($value);
|
||||||
|
$columnValue[] = $dbData[self::getColumnByMember($member)];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::clear();
|
||||||
|
|
||||||
|
$countResulsts = \count($columnValue);
|
||||||
|
|
||||||
|
if ($countResulsts === 0) {
|
||||||
|
return self::createNullModel();
|
||||||
|
} elseif ($countResulsts === 1) {
|
||||||
|
return \reset($columnValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $columnValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object.
|
* Get object.
|
||||||
*
|
*
|
||||||
|
|
@ -2620,7 +2669,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
if (isset(static::$hasMany[$by]) && static::$hasMany[$by]['self'] !== null) {
|
if (isset(static::$hasMany[$by]) && static::$hasMany[$by]['self'] !== null) {
|
||||||
// todo: maybe wrong?!
|
// todo: maybe wrong?!
|
||||||
$toLoad = self::getHasManyPrimaryKeys($value, $by);
|
$toLoad = self::getHasManyPrimaryKeys($value, $by);
|
||||||
} elseif (isset(static::$ownsOne[$by])) {
|
} else {
|
||||||
$toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($by));
|
$toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($by));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2638,6 +2687,53 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get column.
|
||||||
|
*
|
||||||
|
* @param mixed $byKey Key
|
||||||
|
* @param string $by The field that defines the for
|
||||||
|
* @param string $member Member to load
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getByColumn($byKey, string $by, string $member)
|
||||||
|
{
|
||||||
|
if (!isset(self::$parentMapper)) {
|
||||||
|
self::$parentMapper = static::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::extend(__CLASS__);
|
||||||
|
|
||||||
|
$byKey = (array) $byKey;
|
||||||
|
$columnValue = [];
|
||||||
|
|
||||||
|
foreach ($byKey as $key => $value) {
|
||||||
|
$toLoad = [];
|
||||||
|
|
||||||
|
if (isset(static::$hasMany[$by]) && static::$hasMany[$by]['self'] !== null) {
|
||||||
|
// todo: maybe wrong?!
|
||||||
|
$toLoad = self::getHasManyPrimaryKeys($value, $by);
|
||||||
|
} else {
|
||||||
|
$toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($by));
|
||||||
|
}
|
||||||
|
|
||||||
|
$columnValue[$value] = self::getColumn($toLoad, $member);
|
||||||
|
}
|
||||||
|
|
||||||
|
$countResulsts = \count($columnValue);
|
||||||
|
|
||||||
|
if ($countResulsts === 0) {
|
||||||
|
return self::createNullModel();
|
||||||
|
} elseif ($countResulsts === 1) {
|
||||||
|
return \reset($columnValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $columnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object.
|
* Get object.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ class LanguageMapper extends DataMapperAbstract
|
||||||
*/
|
*/
|
||||||
protected static array $columns = [
|
protected static array $columns = [
|
||||||
'language_id' => ['name' => 'language_id', 'type' => 'int', 'internal' => 'id'],
|
'language_id' => ['name' => 'language_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'language_native' => ['name' => 'language_native', 'type' => 'string', 'internal' => 'name'],
|
'language_name' => ['name' => 'language_name', 'type' => 'string', 'internal' => 'name'],
|
||||||
'language_639_1' => ['name' => 'language_639_1', 'type' => 'string', 'internal' => 'native'],
|
'language_native' => ['name' => 'language_native', 'type' => 'string', 'internal' => 'native'],
|
||||||
'language_639_2T' => ['name' => 'language_639_2T', 'type' => 'string', 'internal' => 'code2'],
|
'language_639_1' => ['name' => 'language_639_1', 'type' => 'string', 'internal' => 'code2'],
|
||||||
'language_639_2B' => ['name' => 'language_639_2B', 'type' => 'string', 'internal' => 'code3Native'],
|
'language_639_2B' => ['name' => 'language_639_2B', 'type' => 'string', 'internal' => 'code3'],
|
||||||
'language_639_3' => ['name' => 'language_639_3', 'type' => 'string', 'internal' => 'code3'],
|
'language_639_2T' => ['name' => 'language_639_2T', 'type' => 'string', 'internal' => 'code3Native'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user