update 2023-06-20 03:05:20
This commit is contained in:
parent
6cff5ffe50
commit
5fa40eb556
@ -16,8 +16,9 @@ class Load << (F,LightGreen) >> #Green {
|
|||||||
# Database $load
|
# Database $load
|
||||||
+ __construct(Table $table, Model $model, ...)
|
+ __construct(Table $table, Model $model, ...)
|
||||||
+ value(array $keys, string $field, ...) : mixed
|
+ value(array $keys, string $field, ...) : mixed
|
||||||
+ item(array $keys, ?string $table) : ?object
|
+ item(array $keys, string $table) : ?object
|
||||||
+ items(array $ids, string $table) : ?array
|
+ items(array $keys, string $table) : ?array
|
||||||
|
- prefix(array $keys) : array
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of Load::__construct
|
note right of Load::__construct
|
||||||
@ -87,6 +88,13 @@ Example: $this->items($ids, 'table_name');
|
|||||||
since: 2.0.1
|
since: 2.0.1
|
||||||
return: ?array
|
return: ?array
|
||||||
end note
|
end note
|
||||||
|
|
||||||
|
note right of Load::prefix
|
||||||
|
Add prefix to the keys
|
||||||
|
|
||||||
|
since: 2.0.1
|
||||||
|
return: array
|
||||||
|
end note
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
```
|
```
|
||||||
|
@ -75,9 +75,9 @@ final class Load
|
|||||||
* ], 'value_key', 'table_name'
|
* ], 'value_key', 'table_name'
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @param array $keys The item keys
|
* @param array $keys The item keys
|
||||||
* @param string $field The field key
|
* @param string $field The field key
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
@ -112,13 +112,13 @@ final class Load
|
|||||||
* ], 'table_name'
|
* ], 'table_name'
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @param array $keys The item keys
|
* @param array $keys The item keys
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return object|null
|
* @return object|null
|
||||||
* @since 2.0.1
|
* @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
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
@ -154,26 +154,45 @@ final class Load
|
|||||||
* );
|
* );
|
||||||
* Example: $this->items($ids, 'table_name');
|
* Example: $this->items($ids, 'table_name');
|
||||||
*
|
*
|
||||||
* @param array $ids The item ids
|
* @param array $keys The item keys
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
* @since 2.0.1
|
* @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
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
{
|
{
|
||||||
return $this->model->items(
|
return $this->model->items(
|
||||||
$this->load->items(
|
$this->load->items(
|
||||||
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
|
['all' => 'a.*'], ['a' => $table], $keys
|
||||||
),
|
),
|
||||||
$table
|
$table
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +49,9 @@
|
|||||||
* ], 'value_key', 'table_name'
|
* ], 'value_key', 'table_name'
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @param array $keys The item keys
|
* @param array $keys The item keys
|
||||||
* @param string $field The field key
|
* @param string $field The field key
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
@ -86,13 +86,13 @@
|
|||||||
* ], 'table_name'
|
* ], 'table_name'
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @param array $keys The item keys
|
* @param array $keys The item keys
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return object|null
|
* @return object|null
|
||||||
* @since 2.0.1
|
* @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
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
@ -128,24 +128,43 @@
|
|||||||
* );
|
* );
|
||||||
* Example: $this->items($ids, 'table_name');
|
* Example: $this->items($ids, 'table_name');
|
||||||
*
|
*
|
||||||
* @param array $ids The item ids
|
* @param array $keys The item keys
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
* @since 2.0.1
|
* @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
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
{
|
{
|
||||||
return $this->model->items(
|
return $this->model->items(
|
||||||
$this->load->items(
|
$this->load->items(
|
||||||
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
|
['all' => 'a.*'], ['a' => $table], $keys
|
||||||
),
|
),
|
||||||
$table
|
$table
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
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;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user