diff --git a/composer.json b/composer.json index 0e3a91b..adf69c2 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "redound/phalcon-api", + "name": "stevie/phalcon-api", "description": "Phalcon API Library", "version": "2.0.0", "require": { diff --git a/src/PhalconApi/Data/Query.php b/src/PhalconApi/Data/Query.php index 1382a13..f28d272 100644 --- a/src/PhalconApi/Data/Query.php +++ b/src/PhalconApi/Data/Query.php @@ -25,6 +25,7 @@ class Query protected $conditions = []; protected $sorters = []; protected $excludes = []; + protected $groups = []; public function __construct() { @@ -49,6 +50,12 @@ public function addSorter(Sorter $sorter) return $this; } + public function addGroup($group) + { + $this->groups[] = $group; + return $this; + } + public function merge(Query $query) { if ($query->hasFields()) { @@ -75,6 +82,10 @@ public function merge(Query $query) $this->addManyExcludes($query->getExcludes()); } + if ($query->hasGroups()) { + $this->addManyGroups($query->getGroups()); + } + return $this; } @@ -173,4 +184,20 @@ public function getExcludes() { return $this->excludes; } + + public function hasGroups() + { + return !empty($this->groups); + } + + public function addManyGroups($groups) + { + $this->groups = array_merge($this->groups, $groups); + return $this; + } + + public function getGroups() + { + return $this->groups; + } } diff --git a/src/PhalconApi/Data/Query/QueryParsers/UrlQueryParser.php b/src/PhalconApi/Data/Query/QueryParsers/UrlQueryParser.php index be6f0b1..f405bd0 100644 --- a/src/PhalconApi/Data/Query/QueryParsers/UrlQueryParser.php +++ b/src/PhalconApi/Data/Query/QueryParsers/UrlQueryParser.php @@ -12,6 +12,7 @@ class UrlQueryParser const OFFSET = 'offset'; const LIMIT = 'limit'; const HAVING = 'having'; + const GROUPS = 'groups'; const WHERE = 'where'; const SORT = 'sort'; const EXCLUDES = 'excludes'; @@ -30,7 +31,7 @@ class UrlQueryParser const SORT_ASCENDING = 1; const SORT_DESCENDING = -1; - protected $enabledFeatures = [ self::FIELDS, self::OFFSET, self::LIMIT, self::HAVING, self::WHERE, self::SORT, self::EXCLUDES ]; + protected $enabledFeatures = [ self::FIELDS, self::OFFSET, self::LIMIT, self::GROUPS, self::HAVING, self::WHERE, self::SORT, self::EXCLUDES ]; public function createQuery($params) @@ -40,6 +41,7 @@ public function createQuery($params) $fields = $this->isEnabled(self::FIELDS) ? $this->extractCommaSeparatedValues($params, 'fields') : null; $offset = $this->isEnabled(self::OFFSET) ? $this->extractInt($params, 'offset') : null; $limit = $this->isEnabled(self::LIMIT) ? $this->extractInt($params, 'limit') : null; + $groups = $this->isEnabled(self::GROUPS) ? $this->extractCommaSeparatedValues($params, 'groups') : null; $having = $this->isEnabled(self::HAVING) ? $this->extractArray($params, 'having') : null; $where = $this->isEnabled(self::WHERE) ? $this->extractArray($params, 'where') : null; $or = $this->isEnabled(self::WHERE) ? $this->extractArray($params, 'or') : null; @@ -63,6 +65,10 @@ public function createQuery($params) $query->addManyExcludes($excludes); } + if ($groups) { + $query->addManyGroups($groups); + } + if ($having) { foreach ($having as $field => $value) {