From 2be0ceac6befc1d20a7fb545d298d54af5b842f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 27 Jul 2019 14:33:17 +0000 Subject: [PATCH] Added "selectToArray" functions in DBA and Item --- src/Database/DBA.php | 17 +++++++++++++++++ src/Model/Item.php | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 6e9bc89be1..937693a792 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -408,6 +408,23 @@ class DBA return self::$database->selectFirst($table, $fields, $condition, $params); } + /** + * @brief Select rows from a table and fills an array with the data + * + * @param string $table Table name + * @param array $fields Array of selected fields, empty for all + * @param array $condition Array of fields for condition + * @param array $params Array of several parameters + * + * @return array Data array + * @throws \Exception + * @see self::select + */ + public static function selectToArray($table, array $fields = [], array $condition = [], array $params = []) + { + return self::$database->toArray(self::$database->select($table, $fields, $condition, $params)); + } + /** * @brief Select rows from a table * diff --git a/src/Model/Item.php b/src/Model/Item.php index 81c60b30b0..c2bb6c8924 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -368,6 +368,33 @@ class Item extends BaseObject } } + /** + * @brief Select rows from the item table and returns them as an array + * + * @param array $selected Array of selected fields, empty for all + * @param array $condition Array of fields for condition + * @param array $params Array of several parameters + * + * @return array + * @throws \Exception + */ + public static function selectToArray(array $fields = [], array $condition = [], $params = []) + { + $result = self::select($fields, $condition, $params); + + if (is_bool($result)) { + return $result; + } + + $data = []; + while ($row = self::fetch($result)) { + $data[] = $row; + } + DBA::close($result); + + return $data; + } + /** * @brief Select rows from the item table * -- 2.39.5