diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md b/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md index 116c368..c6774d4 100644 --- a/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/README.md @@ -15,6 +15,8 @@ class Load << (F,LightGreen) >> #Green { + items(array $select, array $tables, ...) : ?array + row(array $select, array $tables, ...) : ?array + item(array $select, array $tables, ...) : ?object + + max(string $field, array $tables, ...) : ?int + + count(array $tables, array $filter) : ?int + value(array $select, array $tables, ...) : mixed # many(array $select, array $tables, ...) : bool # one(array $select, array $tables, ...) : bool @@ -75,6 +77,25 @@ note left of Load::item ?array $order = null end note +note right of Load::max + Get the max value based on a filtered result from a given table + + since: 3.2.0 + return: ?int + + arguments: + string $field + array $tables + array $filter +end note + +note left of Load::count + Count the number of items based on filter result from a given table + + since: 3.2.0 + return: ?int +end note + note right of Load::value Load one value from a row diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php index 5141ca2..5d88778 100644 --- a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php @@ -144,6 +144,71 @@ final class Load extends Database implements LoadInterface return null; } + /** + * Get the max value based on a filtered result from a given table + * + * @param string $field The field key + * @param string $tables The tables + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function max($field, array $tables, array $filter): ?int + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query(["all" => "MAX(`$field`)"], $tables, $filter); + + // Load the max number + $this->db->setQuery($query); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return (int) $this->db->loadResult(); + } + } + + // data does not exist + return null; + } + + /** + * Count the number of items based on filter result from a given table + * + * @param string $tables The table + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function count(array $tables, array $filter): ?int + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query(["all" => 'COUNT(*)'], $tables, $filter); + + // Load the max number + $this->db->setQuery($query); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return (int) $this->db->loadResult(); + } + } + + // data does not exist + return null; + } + /** * Load one value from a row * diff --git a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power index 8a3110b..2444d8f 100644 --- a/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power +++ b/src/06f8eada-d59b-441c-b287-0aea1793da5a/code.power @@ -118,6 +118,71 @@ return null; } + /** + * Get the max value based on a filtered result from a given table + * + * @param string $field The field key + * @param string $tables The tables + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function max($field, array $tables, array $filter): ?int + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query(["all" => "MAX(`$field`)"], $tables, $filter); + + // Load the max number + $this->db->setQuery($query); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return (int) $this->db->loadResult(); + } + } + + // data does not exist + return null; + } + + /** + * Count the number of items based on filter result from a given table + * + * @param string $tables The table + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function count(array $tables, array $filter): ?int + { + // only do check if we have the table set + if (isset($tables['a'])) + { + // get the query + $query = $this->query(["all" => 'COUNT(*)'], $tables, $filter); + + // Load the max number + $this->db->setQuery($query); + $this->db->execute(); + + // check if we have values + if ($this->db->getNumRows()) + { + return (int) $this->db->loadResult(); + } + } + + // data does not exist + return null; + } + /** * Load one value from a row * diff --git a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/README.md b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/README.md index 33acf9c..3d933eb 100644 --- a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/README.md +++ b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/README.md @@ -15,6 +15,8 @@ interface LoadInterface #Lavender { + items(array $select, array $tables, ...) : ?array + row(array $select, array $tables, ...) : ?array + item(array $select, array $tables, ...) : ?object + + max(string $field, array $tables, ...) : ?int + + count(array $tables, array $filter) : ?int + value(array $select, array $tables, ...) : mixed } @@ -72,6 +74,25 @@ note right of LoadInterface::item ?array $order = null end note +note right of LoadInterface::max + Get the max value based on a filtered result from a given table + + since: 3.2.0 + return: ?int + + arguments: + string $field + array $tables + array $filter +end note + +note right of LoadInterface::count + Count the number of items based on filter result from a given table + + since: 3.2.0 + return: ?int +end note + note right of LoadInterface::value Load one value from a row diff --git a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php index efaa5ba..31017c5 100644 --- a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php +++ b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php @@ -75,6 +75,29 @@ interface LoadInterface **/ public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object; + /** + * Get the max value based on a filtered result from a given table + * + * @param string $field The field key + * @param string $tables The table + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function max($field, array $tables, array $filter): ?int; + + /** + * Count the number of items based on filter result from a given table + * + * @param string $tables The table + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function count(array $tables, array $filter): ?int; + /** * Load one value from a row * @@ -86,7 +109,6 @@ interface LoadInterface * @return mixed * @since 3.2.0 **/ - public function value(array $select, array $tables, ?array $where = null, ?array $order = null); - + public function value(array $select, array $tables, ?array $where = null, ?array $order = null); } diff --git a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power index bee23d7..46ae072 100644 --- a/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power +++ b/src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.power @@ -54,6 +54,29 @@ **/ public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object; + /** + * Get the max value based on a filtered result from a given table + * + * @param string $field The field key + * @param string $tables The table + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function max($field, array $tables, array $filter): ?int; + + /** + * Count the number of items based on filter result from a given table + * + * @param string $tables The table + * @param array $filter The filter keys + * + * @return int|null + * @since 3.2.0 + **/ + public function count(array $tables, array $filter): ?int; + /** * Load one value from a row * @@ -65,4 +88,4 @@ * @return mixed * @since 3.2.0 **/ - public function value(array $select, array $tables, ?array $where = null, ?array $order = null); + public function value(array $select, array $tables, ?array $where = null, ?array $order = null); \ No newline at end of file