Skip to content

Commit

Permalink
Added timeline count methods to PeepTable
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jun 1, 2012
1 parent 1f62827 commit 4ddfedd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/PhlyPeep/Model/PeepTable.php
Expand Up @@ -30,6 +30,12 @@ public function fetchTimeline($offset = 0, $limit = 20)
return $this->getPeepsFromSelect($select); return $this->getPeepsFromSelect($select);
} }


public function fetchTimelineCount()
{
$select = $this->getCountSelect();
return $this->getCountFromSelect($select);
}

public function fetchUserTimeline($user, $offset = 0, $limit = 20) public function fetchUserTimeline($user, $offset = 0, $limit = 20)
{ {
$select = $this->getSql()->select(); $select = $this->getSql()->select();
Expand All @@ -43,6 +49,14 @@ public function fetchUserTimeline($user, $offset = 0, $limit = 20)
return $this->getPeepsFromSelect($select); return $this->getPeepsFromSelect($select);
} }


public function fetchUserTimelineCount()
{
$select = $this->getCountSelect();
$where = $select->where();
$where->equalTo('username', $user);
return $this->getCountFromSelect($select);
}

public function fetchPeep($identifier) public function fetchPeep($identifier)
{ {
$rowset = $this->select(array('identifier' => $identifier)); $rowset = $this->select(array('identifier' => $identifier));
Expand Down Expand Up @@ -83,4 +97,21 @@ protected function getPeepFromRow($row)
$peep->exchangeArray($row); $peep->exchangeArray($row);
return $peep; return $peep;
} }

protected function getCountSelect()
{
$select = $this->getSql()->select();
$select->columns(array('peeps' => new Expression('COUNT(identifier)')));
return $select;
}

protected function getCountFromSelect($select)
{
$resultset = $this->selectWith($select);
if (!count($resultset)) {
throw new \DomainException('Unable to determine timeline count!');
}
$row = $resultset->current();
return $row['peeps'];
}
} }

0 comments on commit 4ddfedd

Please sign in to comment.