4
0

update 2023-06-20 03:05:20

This commit is contained in:
Robot 2023-06-20 03:05:20 +02:00
parent 6cff5ffe50
commit 5fa40eb556
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
3 changed files with 64 additions and 18 deletions

View File

@ -16,8 +16,9 @@ class Load << (F,LightGreen) >> #Green {
# Database $load
+ __construct(Table $table, Model $model, ...)
+ value(array $keys, string $field, ...) : mixed
+ item(array $keys, ?string $table) : ?object
+ items(array $ids, string $table) : ?array
+ item(array $keys, string $table) : ?object
+ items(array $keys, string $table) : ?array
- prefix(array $keys) : array
}
note right of Load::__construct
@ -87,6 +88,13 @@ Example: $this->items($ids, 'table_name');
since: 2.0.1
return: ?array
end note
note right of Load::prefix
Add prefix to the keys
since: 2.0.1
return: array
end note
@enduml
```

View File

@ -75,9 +75,9 @@ final class Load
* ], 'value_key', 'table_name'
* );
*
* @param array $keys The item keys
* @param string $field The field key
* @param string $table The table
* @param array $keys The item keys
* @param string $field The field key
* @param string $table The table
*
* @return mixed
* @since 2.0.1
@ -112,13 +112,13 @@ final class Load
* ], 'table_name'
* );
*
* @param array $keys The item keys
* @param array $keys The item keys
* @param string $table The table
*
* @return object|null
* @since 2.0.1
*/
public function item(array $keys, ?string $table): ?object
public function item(array $keys, string $table): ?object
{
// check if this is a valid table
if ($this->prefix($keys) && $this->table->exist($table))
@ -154,26 +154,45 @@ final class Load
* );
* Example: $this->items($ids, 'table_name');
*
* @param array $ids The item ids
* @param array $keys The item keys
* @param string $table The table
*
* @return array|null
* @since 2.0.1
*/
public function items(array $ids, string $table): ?array
public function items(array $keys, string $table): ?array
{
// check if this is a valid table
if ($this->prefix($keys) && $this->table->exist($table))
{
return $this->model->items(
$this->load->items(
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
['all' => 'a.*'], ['a' => $table], $keys
),
$table
);
}
return null;
}
/**
* Add prefix to the keys
*
* @param array $keys The query keys
*
* @return array
* @since 2.0.1
*/
private function prefix(array $keys): array
{
// update the key values
$bucket = [];
foreach ($keys as $k => $v)
{
$bucket['a.' . $k] = $v;
}
return $bucket;
}
}

View File

@ -49,9 +49,9 @@
* ], 'value_key', 'table_name'
* );
*
* @param array $keys The item keys
* @param string $field The field key
* @param string $table The table
* @param array $keys The item keys
* @param string $field The field key
* @param string $table The table
*
* @return mixed
* @since 2.0.1
@ -86,13 +86,13 @@
* ], 'table_name'
* );
*
* @param array $keys The item keys
* @param array $keys The item keys
* @param string $table The table
*
* @return object|null
* @since 2.0.1
*/
public function item(array $keys, ?string $table): ?object
public function item(array $keys, string $table): ?object
{
// check if this is a valid table
if ($this->prefix($keys) && $this->table->exist($table))
@ -128,24 +128,43 @@
* );
* Example: $this->items($ids, 'table_name');
*
* @param array $ids The item ids
* @param array $keys The item keys
* @param string $table The table
*
* @return array|null
* @since 2.0.1
*/
public function items(array $ids, string $table): ?array
public function items(array $keys, string $table): ?array
{
// check if this is a valid table
if ($this->prefix($keys) && $this->table->exist($table))
{
return $this->model->items(
$this->load->items(
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
['all' => 'a.*'], ['a' => $table], $keys
),
$table
);
}
return null;
}
/**
* Add prefix to the keys
*
* @param array $keys The query keys
*
* @return array
* @since 2.0.1
*/
private function prefix(array $keys): array
{
// update the key values
$bucket = [];
foreach ($keys as $k => $v)
{
$bucket['a.' . $k] = $v;
}
return $bucket;
}