Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b244f4902e
Fetching contributors…

Cannot retrieve contributors at this time

file 51 lines (44 sloc) 1.555 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
<?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;
    }
}
Something went wrong with that request. Please try again.