Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "redound/phalcon-api",
"name": "stevie/phalcon-api",
"description": "Phalcon API Library",
"version": "2.0.0",
"require": {
Expand Down
27 changes: 27 additions & 0 deletions src/PhalconApi/Data/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Query
protected $conditions = [];
protected $sorters = [];
protected $excludes = [];
protected $groups = [];

public function __construct()
{
Expand All @@ -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()) {
Expand All @@ -75,6 +82,10 @@ public function merge(Query $query)
$this->addManyExcludes($query->getExcludes());
}

if ($query->hasGroups()) {
$this->addManyGroups($query->getGroups());
}

return $this;
}

Expand Down Expand Up @@ -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;
}
}
8 changes: 7 additions & 1 deletion src/PhalconApi/Data/Query/QueryParsers/UrlQueryParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -63,6 +65,10 @@ public function createQuery($params)
$query->addManyExcludes($excludes);
}

if ($groups) {
$query->addManyGroups($groups);
}

if ($having) {

foreach ($having as $field => $value) {
Expand Down