diff --git a/src/Entity/Field/Date.php b/src/Entity/Field/Date.php index fe0df70..c2c5e7e 100644 --- a/src/Entity/Field/Date.php +++ b/src/Entity/Field/Date.php @@ -4,11 +4,8 @@ namespace Ulmus\Entity\Field; class Date extends Datetime { - public function __toString() - { - return $this->format("Y-m-d"); - } - + public string $format = "Y-m-d"; + public function formatLocale(string $format) : string { return strftime($format, $this->getTimestamp()); diff --git a/src/Entity/Field/Time.php b/src/Entity/Field/Time.php index ecbdd11..df4db07 100644 --- a/src/Entity/Field/Time.php +++ b/src/Entity/Field/Time.php @@ -4,9 +4,6 @@ namespace Ulmus\Entity\Field; class Time extends Datetime { - public function __toString() - { - return $this->format("H:i:s"); - } + public string $format = "H:i:s"; } diff --git a/src/Query/GroupBy.php b/src/Query/GroupBy.php index 7a05b4b..fd969cf 100644 --- a/src/Query/GroupBy.php +++ b/src/Query/GroupBy.php @@ -3,22 +3,23 @@ namespace Ulmus\Query; class GroupBy extends Fragment { - - const SQL_TOKEN = "GROUP BY"; - - public int $order = 70; + public int $order = 75; public array $groupBy = []; + + const SQL_TOKEN = "GROUP BY"; public function set(array $order) : self { - $this->groupBy = $order; + $this->groupBy = [ $orderĀ ]; + return $this; } - public function add(string $field, ? string $direction = null) : self + public function add(string $field) : self { $this->groupBy[] = $field; + return $this; } diff --git a/src/Query/Having.php b/src/Query/Having.php index 5d349cd..d168d0b 100644 --- a/src/Query/Having.php +++ b/src/Query/Having.php @@ -4,5 +4,6 @@ namespace Ulmus\Query; class Having extends Where { const SQL_TOKEN = "HAVING"; - public int $order = 75; + + public int $order = 80; } diff --git a/src/Query/OrderBy.php b/src/Query/OrderBy.php index 5e62ad2..318690a 100644 --- a/src/Query/OrderBy.php +++ b/src/Query/OrderBy.php @@ -3,7 +3,7 @@ namespace Ulmus\Query; class OrderBy extends Fragment { - public int $order = 80; + public int $order = 85; public array $orderBy = []; diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index c597c79..80301a2 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -216,11 +216,6 @@ class QueryBuilder return $this->where($field, $value, $operator, true); } - public function groupBy() : self - { - return $this; - } - public function limit(int $value) : self { if ( null === $limit = $this->getFragment(Query\Limit::class) ) { @@ -257,6 +252,18 @@ class QueryBuilder return $this; } + public function groupBy(string $field, ? string $direction = null) : self + { + if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) { + $groupBy = new Query\GroupBy(); + $this->push($groupBy); + } + + $groupBy->add($field, $direction); + + return $this; + } + public function join(string $type, /*string | QueryBuilder*/ $table, $field, $value, bool $outer = false, ? string $alias = null) : self { $join = new Query\Join($this);