Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: b244f4902e
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (44 sloc) 1.555 kB
<?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)
{
$result = null;
switch ($this->timelineType) {
case self::TYPE_ALL:
$result = $this->table->fetchTimeline($offset, $itemCountPerPage);
break;
case self::TYPE_USER:
$result = $this->table->fetchUserTimeline($this->user, $offset, $itemCountPerPage);
break;
}
return $result;
}
}
Jump to Line
Something went wrong with that request. Please try again.