diff --git a/src/c03b9c61-17d3-4774-a335-783903719f83/README.md b/src/c03b9c61-17d3-4774-a335-783903719f83/README.md index 289cd25..96a262f 100644 --- a/src/c03b9c61-17d3-4774-a335-783903719f83/README.md +++ b/src/c03b9c61-17d3-4774-a335-783903719f83/README.md @@ -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 ``` diff --git a/src/c03b9c61-17d3-4774-a335-783903719f83/code.php b/src/c03b9c61-17d3-4774-a335-783903719f83/code.php index ea97a0e..9f87815 100644 --- a/src/c03b9c61-17d3-4774-a335-783903719f83/code.php +++ b/src/c03b9c61-17d3-4774-a335-783903719f83/code.php @@ -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; } } diff --git a/src/c03b9c61-17d3-4774-a335-783903719f83/code.power b/src/c03b9c61-17d3-4774-a335-783903719f83/code.power index 3c8363d..c323fda 100644 --- a/src/c03b9c61-17d3-4774-a335-783903719f83/code.power +++ b/src/c03b9c61-17d3-4774-a335-783903719f83/code.power @@ -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; } \ No newline at end of file