Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add group and having ability to Paginator\Adapter\DbTableGateway #4427

Closed
wants to merge 3 commits into from

3 participants

@samsonasik

No description provided.

@weierophinney

Scheduling for 2.3, as this is a new feature, and we're in freeze for 2.2.

@ralphschindler ralphschindler referenced this pull request from a commit
@ralphschindler ralphschindler PR #4427
* added better testing for DbTableGateway paginator
4a18283
@ralphschindler
Collaborator

Merged to develop branch

@gianarb gianarb referenced this pull request from a commit in zendframework/zend-paginator
@ralphschindler ralphschindler PR zendframework/zf2#4427
* added better testing for DbTableGateway paginator
177d204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
17 library/Zend/Paginator/Adapter/DbTableGateway.php
@@ -10,6 +10,7 @@
namespace Zend\Paginator\Adapter;
use Zend\Db\Sql\Where;
+use Zend\Db\Sql\Having;
use Zend\Db\TableGateway\TableGateway;
use Zend\Paginator\Adapter\DbSelect;
@@ -18,11 +19,13 @@ class DbTableGateway extends DbSelect
/**
* Constructs instance.
*
- * @param TableGateway $tableGateway
- * @param Where|\Closure|string|array $where
- * @param null $order
+ * @param TableGateway $tableGateway
+ * @param null|Where|\Closure|string|array $where
+ * @param null|string|array $order
+ * @param null|string|array $group
+ * @param null|Having|\Closure|string|array $having
*/
- public function __construct(TableGateway $tableGateway, $where = null, $order = null)
+ public function __construct(TableGateway $tableGateway, $where = null, $order = null, $group = null, $having = null)
{
$select = $tableGateway->getSql()->select();
if ($where) {
@@ -31,6 +34,12 @@ public function __construct(TableGateway $tableGateway, $where = null, $order =
if ($order) {
$select->order($order);
}
+ if ($group) {
+ $select->group($group);
+ }
+ if ($having) {
+ $select->having($having);
+ }
$dbAdapter = $tableGateway->getAdapter();
$resultSetPrototype = $tableGateway->getResultSetPrototype();
View
35 tests/ZendTest/Paginator/Adapter/DbTableGatewayTest.php
@@ -100,4 +100,39 @@ public function testGetItemsWithWhereAndOrder()
$items = $this->dbTableGateway->getItems(2, 10);
$this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
}
+
+ public function testGetItemsWithWhereAndOrderAndGroup()
+ {
+ $where = "foo = bar";
+ $order = "foo";
+ $group = "foo";
+ $this->dbTableGateway = new DbTableGateway($this->mockTableGateway, $where, $order, $group);
+
+ $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
+ $this->mockStatement
+ ->expects($this->any())
+ ->method('execute')
+ ->will($this->returnValue($mockResult));
+
+ $items = $this->dbTableGateway->getItems(2, 10);
+ $this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
+ }
+
+ public function testGetItemsWithWhereAndOrderAndGroupAndHaving()
+ {
+ $where = "foo = bar";
+ $order = "foo";
+ $group = "foo";
+ $having = "count(foo)>0";
+ $this->dbTableGateway = new DbTableGateway($this->mockTableGateway, $where, $order, $group, $having);
+
+ $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
+ $this->mockStatement
+ ->expects($this->any())
+ ->method('execute')
+ ->will($this->returnValue($mockResult));
+
+ $items = $this->dbTableGateway->getItems(2, 10);
+ $this->assertInstanceOf('Zend\Db\ResultSet\ResultSet', $items);
+ }
}
Something went wrong with that request. Please try again.