Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved pagination to PeepTable

- PeepTable now returns paginators directly
- PeepService simply configures returned paginators
  • Loading branch information...
commit 7caf8e399659ccdaf987ee4f9dc6c584d1bb390f 1 parent 01779c3
@weierophinney authored
Showing with 19 additions and 27 deletions.
  1. +6 −17 src/PhlyPeep/Model/PeepService.php
  2. +13 −10 src/PhlyPeep/Model/PeepTable.php
View
23 src/PhlyPeep/Model/PeepService.php
@@ -3,7 +3,6 @@
namespace PhlyPeep\Model;
use Zend\Paginator\Adapter\DbSelect;
-use Zend\Paginator\Paginator;
class PeepService
{
@@ -39,13 +38,17 @@ public function getPageSize()
public function fetchTimeline($page = 1)
{
- $paginator = $this->getTimelinePaginator($page);
+ $paginator = $this->table->fetchTimeline();
+ $paginator->setItemCountPerPage($this->getPageSize());
+ $paginator->setCurrentPageNumber($page);
return $paginator;
}
public function fetchUserTimeline($user, $page = 1)
{
- $paginator = $this->getUserTimelinePaginator($user, $page);
+ $paginator = $this->table->fetchUserTimeline($user);
+ $paginator->setItemCountPerPage($this->getPageSize());
+ $paginator->setCurrentPageNumber($page);
return $paginator;
}
@@ -58,18 +61,4 @@ public function insertPeep(PeepEntity $peep)
{
$this->table->insertPeep($peep);
}
-
- protected function getTimelinePaginator($page)
- {
- $paginator = new Paginator(new DbSelect($this->table->fetchTimeline(), $this->table->getAdapter(), $this->table->getResultSetPrototype()));
- $paginator->setCurrentPageNumber($page);
- return $paginator;
- }
-
- protected function getUserTimelinePaginator($user, $page)
- {
- $paginator = new Paginator(new DbSelect($this->table->fetchUserTimeline($user), $this->table->getAdapter(), $this->table->getResultSetPrototype()));
- $paginator->setCurrentPageNumber($page);
- return $paginator;
- }
}
View
23 src/PhlyPeep/Model/PeepTable.php
@@ -9,13 +9,12 @@
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Where;
use Zend\Db\TableGateway\AbstractTableGateway;
+use Zend\Paginator\Adapter\DbSelect;
+use Zend\Paginator\Paginator;
use Zend\Stdlib\Hydrator\ArraySerializable as ArraySerializableHydrator;
class PeepTable extends AbstractTableGateway
{
- protected $peepHydrator;
- protected $peepPrototype;
- protected $peepsPrototype;
protected $table = 'peep';
protected $tableName = 'peep';
@@ -23,11 +22,11 @@ public function __construct(Adapter $adapter, $tableName = 'peep')
{
$this->adapter = $adapter;
$this->table = $this->tableName = $tableName;
- $this->peepHydrator = new ArraySerializableHydrator();
- $this->peepPrototype = new PeepEntity;
- $this->peepsPrototype = new HydratingResultSet($this->peepHydrator, $this->peepPrototype);
- $this->peepsPrototype->buffer();
- $this->resultSetPrototype = $this->peepsPrototype;
+ $this->resultSetPrototype = new HydratingResultSet(
+ new ArraySerializableHydrator(),
+ new PeepEntity()
+ );
+ $this->resultSetPrototype->buffer();
$this->initialize();
}
@@ -35,7 +34,9 @@ public function fetchTimeline()
{
$select = $this->getSql()->select();
$select->order('timestamp DESC');
- return $select;
+ return new Paginator(
+ new DbSelect($select, $this->adapter, $this->resultSetPrototype)
+ );
}
public function fetchUserTimeline($user)
@@ -46,7 +47,9 @@ public function fetchUserTimeline($user)
$where->equalTo('username', $user);
$select->where($where)
->order('timestamp DESC');
- return $select;
+ return new Paginator(
+ new DbSelect($select, $this->adapter, $this->resultSetPrototype)
+ );
}
public function fetchPeep($identifier)
Please sign in to comment.
Something went wrong with that request. Please try again.