From 7edece193899e8c35fe7abf90507a7a9ab5ee0e5 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 2 Dec 2015 12:25:04 -0500 Subject: [PATCH] Remove station podcast from podcast table count --- .../rest/controllers/PodcastController.php | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/modules/rest/controllers/PodcastController.php b/airtime_mvc/application/modules/rest/controllers/PodcastController.php index 9035297bf..0ec89f73b 100644 --- a/airtime_mvc/application/modules/rest/controllers/PodcastController.php +++ b/airtime_mvc/application/modules/rest/controllers/PodcastController.php @@ -16,36 +16,29 @@ class Rest_PodcastController extends Zend_Rest_Controller public function indexAction() { - $totalPodcastCount = PodcastQuery::create()->count(); - // Check if offset and limit were sent with request. // Default limit to zero and offset to $totalFileCount $offset = $this->_getParam('offset', 0); - $limit = $this->_getParam('limit', $totalPodcastCount); + $limit = $this->_getParam('limit', 0); //Sorting parameters $sortColumn = $this->_getParam('sort', PodcastPeer::ID); $sortDir = $this->_getParam('sort_dir', Criteria::ASC); $stationPodcastId = Application_Model_Preference::getStationPodcastId(); - $query = PodcastQuery::create() + $result = PodcastQuery::create() // Don't return the Station podcast - we fetch it separately - ->filterByDbId($stationPodcastId, Criteria::NOT_EQUAL) - ->setLimit($limit) - ->setOffset($offset) + ->filterByDbId($stationPodcastId, Criteria::NOT_EQUAL); + if ($limit > 0) { $result->setLimit($limit); } + $result->setOffset($offset) ->orderBy($sortColumn, $sortDir); + $result = $result->find(); - $queryResult = $query->find(); - - $podcastArray = array(); - foreach ($queryResult as $podcast) - { - array_push($podcastArray, $podcast->toArray(BasePeer::TYPE_FIELDNAME)); - } + $podcastArray = $result->toArray(null, false, BasePeer::TYPE_FIELDNAME); $this->getResponse() ->setHttpResponseCode(200) - ->setHeader('X-TOTAL-COUNT', $totalPodcastCount) + ->setHeader('X-TOTAL-COUNT', $result->count()) ->appendBody(json_encode($podcastArray)); }