Skip to content
Browse files

Added paginator

- Implements paginator AdapterInterface; expects a table, type, and optional
  user (if type is TYPE_USER)
  - count() and getItems() proxy to related methods in PeepTable
- Fixed fetchUserTimelineCount() to accept a $user argument
  • Loading branch information...
1 parent 4ddfedd commit b5b821e003b342b95dca0bd06eb6cc6770614c85 @weierophinney committed Jun 1, 2012
Showing with 48 additions and 1 deletion.
  1. +47 −0 src/PhlyPeep/Model/PeepPaginator.php
  2. +1 −1 src/PhlyPeep/Model/PeepTable.php
View
47 src/PhlyPeep/Model/PeepPaginator.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace PhlyPeep\Model;
+
+use Zend\Paginator\Adapter\AdapterInterface as PaginatorAdapter;
+
+class PeepPaginator implements PaginatorAdapter
+{
+ const TYPE_ALL = 'all';
+ const TYPE_USER = 'user';
+
+ protected $table;
+ protected $type;
+ protected $user;
+
+ public function __construct(PeepTable $table, $timelineType = self::TYPE_ALL, $user = null)
+ {
+ $this->table = $table;
+ $this->timelineType = in_array($timelineType, array(self::TYPE_ALL, self::TYPE_USER))
+ ? $timelineType
+ : self::TYPE_ALL;
+ if ($this->timelineType == self::TYPE_USER && !$user) {
+ throw new \DomainException('TYPE_USER specified for paginator, but no user provided');
+ }
+ $this->user = $user;
+ }
+
+ public function count()
+ {
+ switch ($this->timelineType) {
+ case self::TYPE_ALL:
+ return $this->table->fetchTimelineCount();
+ case self::TYPE_USER:
+ return $this->table->fetchUserTimelineCount($this->user);
+ }
+ }
+
+ public function getItems($offset, $itemCountPerPage)
+ {
+ switch ($this->timelineType) {
+ case self::TYPE_ALL:
+ return $this->table->fetchTimeline($offset, $itemCountPerPage);
+ case self::TYPE_USER:
+ return $this->table->fetchUserTimeline($this->user, $offset, $itemCountPerPage);
+ }
+ }
+}
View
2 src/PhlyPeep/Model/PeepTable.php
@@ -49,7 +49,7 @@ public function fetchUserTimeline($user, $offset = 0, $limit = 20)
return $this->getPeepsFromSelect($select);
}
- public function fetchUserTimelineCount()
+ public function fetchUserTimelineCount($user)
{
$select = $this->getCountSelect();
$where = $select->where();

0 comments on commit b5b821e

Please sign in to comment.
Something went wrong with that request. Please try again.