Skip to content

Commit

Permalink
Added PeepService
Browse files Browse the repository at this point in the history
- Returns paginators for the fetch(User)?Timeline() methods, otherwise delegates
  to the composed PeepTable object
  • Loading branch information
weierophinney committed Jun 1, 2012
1 parent b5b821e commit 5c712ee
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/PhlyPeep/Model/PeepService.php
@@ -0,0 +1,72 @@
<?php

namespace PhlyPeep\Model;

class PeepService
{
protected $pageSize = 20;
protected $table;

public function __construct(PeepTable $table)
{
$this->table = $table;
}

/**
* Set value for page size
*
* @param int $pageSize
* @return PeepService
*/
public function setPageSize($pageSize)
{
$this->pageSize = (int) $pageSize;
return $this;
}

/**
* Get value for page size
*
* @return int
*/
public function getPageSize()
{
return $this->pageSize;
}

public function fetchTimeline($page = 1)
{
$paginator = $this->getTimelinePaginator($page);
return $paginator;
}

public function fetchUserTimeline($user, $page = 1)
{
$paginator = $this->getUserTimelinePaginator($user, $page);
return $paginator;
}

public function fetchPeep($identifier)
{
return $this->table->fetchPeep($identifier);
}

public function insertPeep(PeepEntity $peep)
{
$this->table->insertPeep($peep);
}

protected function getTimelinePaginator($page)
{
$paginator = new Paginator(new PeepPaginator($this->table, PeepPaginator::TYPE_ALL));
$paginator->setCurrentPageNumber($page);
return $paginator;
}

protected function getUserTimelinePaginator($user, $page)
{
$paginator = new Paginator(new PeepPaginator($this->table, PeepPaginator::TYPE_USER, $user));
$paginator->setCurrentPageNumber($page);
return $paginator;
}
}

0 comments on commit 5c712ee

Please sign in to comment.