From bc962fe29eee8cd169c90346edea65e2cd7bf380 Mon Sep 17 00:00:00 2001 From: pmvcoelho <49378150+pmvcoelho@users.noreply.github.com> Date: Mon, 8 Apr 2019 00:16:07 +0100 Subject: [PATCH] Add files via upload --- src/GroupModel.php | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/GroupModel.php b/src/GroupModel.php index 4532000..2195a2a 100644 --- a/src/GroupModel.php +++ b/src/GroupModel.php @@ -25,6 +25,10 @@ * The base model must not be UnionModel or another GroupModel, however it's possible to use GroupModel as nestedModel inside UnionModel. * UnionModel implements identical grouping rule on its own. */ + + + + class GroupModel extends \atk4\data\Model { /** @@ -86,6 +90,8 @@ public function groupBy($group, $aggregate = []) foreach ($aggregate as $field=>$expr) { + + //$this->addField($field); // field originally defined in the parent model $field_object = $this->master_model->hasElement($field); // use hasElement here! @@ -159,6 +165,9 @@ public function addGrouping($query) $query->group($this->expr($field)); } } + + + } /** @@ -186,12 +195,7 @@ public function setLimit($count, $offset = null) * * @todo Incorrect implementation */ - public function setOrder($field, $desc = null) - { - $this->master_model->setOrder($field, $desc); - return $this; - } /** * Set action. @@ -247,6 +251,8 @@ public function action($mode, $args = []) $this->hook('afterGroupSelect', [$query]); + $query = $this->orderByQuery($query); + return $query; case 'count': @@ -301,6 +307,32 @@ public function action($mode, $args = []) return $query; } + /** + * Applies Order By to the query + * + */ + function orderByQuery($query) + { + + if ($this->order) { + + foreach ($this->order as $o) { + + if(is_string($o[1])){ + $query->order($o[0]." ".$o[1]); + } else { + $query->order($o[0],$o[1]); + } + } + } + + return $query; + + } + + + + /** * Our own way applying conditions, where we use "having" for * fields