update 2023-07-24 18:13:46

This commit is contained in:
Robot 2023-07-24 18:13:52 +02:00
parent b95f25e885
commit c8b6170397
Signed by untrusted user: Robot
GPG Key ID: 14DECD44E7E1BB95
6 changed files with 220 additions and 3 deletions

View File

@ -15,6 +15,8 @@ class Load << (F,LightGreen) >> #Green {
+ items(array $select, array $tables, ...) : ?array + items(array $select, array $tables, ...) : ?array
+ row(array $select, array $tables, ...) : ?array + row(array $select, array $tables, ...) : ?array
+ item(array $select, array $tables, ...) : ?object + item(array $select, array $tables, ...) : ?object
+ max(string $field, array $tables, ...) : ?int
+ count(array $tables, array $filter) : ?int
+ value(array $select, array $tables, ...) : mixed + value(array $select, array $tables, ...) : mixed
# many(array $select, array $tables, ...) : bool # many(array $select, array $tables, ...) : bool
# one(array $select, array $tables, ...) : bool # one(array $select, array $tables, ...) : bool
@ -75,6 +77,25 @@ note left of Load::item
?array $order = null ?array $order = null
end note 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 note right of Load::value
Load one value from a row Load one value from a row

View File

@ -144,6 +144,71 @@ final class Load extends Database implements LoadInterface
return null; 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 * Load one value from a row
* *

View File

@ -118,6 +118,71 @@
return null; 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 * Load one value from a row
* *

View File

@ -15,6 +15,8 @@ interface LoadInterface #Lavender {
+ items(array $select, array $tables, ...) : ?array + items(array $select, array $tables, ...) : ?array
+ row(array $select, array $tables, ...) : ?array + row(array $select, array $tables, ...) : ?array
+ item(array $select, array $tables, ...) : ?object + item(array $select, array $tables, ...) : ?object
+ max(string $field, array $tables, ...) : ?int
+ count(array $tables, array $filter) : ?int
+ value(array $select, array $tables, ...) : mixed + value(array $select, array $tables, ...) : mixed
} }
@ -72,6 +74,25 @@ note right of LoadInterface::item
?array $order = null ?array $order = null
end note 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 note right of LoadInterface::value
Load one value from a row Load one value from a row

View File

@ -75,6 +75,29 @@ interface LoadInterface
**/ **/
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object; 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 * Load one value from a row
* *
@ -87,6 +110,5 @@ interface LoadInterface
* @since 3.2.0 * @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);
} }

View File

@ -54,6 +54,29 @@
**/ **/
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object; 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 * Load one value from a row
* *