Permalink
Browse files

Added timeline count methods to PeepTable

  • Loading branch information...
1 parent 1f62827 commit 4ddfeddd61f40792853c73e59ffb0dd27d399f09 @weierophinney committed Jun 1, 2012
Showing with 31 additions and 0 deletions.
  1. +31 −0 src/PhlyPeep/Model/PeepTable.php
@@ -30,6 +30,12 @@ public function fetchTimeline($offset = 0, $limit = 20)
return $this->getPeepsFromSelect($select);
}
+ public function fetchTimelineCount()
+ {
+ $select = $this->getCountSelect();
+ return $this->getCountFromSelect($select);
+ }
+
public function fetchUserTimeline($user, $offset = 0, $limit = 20)
{
$select = $this->getSql()->select();
@@ -43,6 +49,14 @@ public function fetchUserTimeline($user, $offset = 0, $limit = 20)
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)
{
$rowset = $this->select(array('identifier' => $identifier));
@@ -83,4 +97,21 @@ protected function getPeepFromRow($row)
$peep->exchangeArray($row);
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.