diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index c2a5a4bc4ffc7266fe3ef6b58e720a077c6c3a58..d9743be481f68a6c52faf3d08f79c86dd840d91d 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -277,12 +277,12 @@ class FramaDB { } /** + * Search polls in databse. + * * @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>...] - * @param $start int The index of the first poll to return - * @param $limit int The limit size - * @return array + * @return array The found polls */ - public function findAllPolls($search, $start, $limit) { + public function findAllPolls($search) { // Polls $prepared = $this->prepare(' SELECT p.*, @@ -301,14 +301,22 @@ SELECT p.*, $prepared->bindParam(':title', $title, PDO::PARAM_STR); $prepared->bindParam(':name', $name, PDO::PARAM_STR); $prepared->execute(); - $polls = $prepared->fetchAll(); + return $prepared->fetchAll(); + } + + /** + * Get the total number of polls in databse. + * + * @return int The number of polls + */ + public function countPolls() { // Total count $stmt = $this->query('SELECT count(1) nb FROM `' . Utils::table('poll') . '`'); $count = $stmt->fetch(); $stmt->closeCursor(); - return ['polls' => array_slice($polls,$start, $limit), 'count' => $prepared->rowCount(), 'total' => $count->nb]; + return $count->nb; } public function countVotesByPollId($poll_id) { diff --git a/app/classes/Framadate/Services/SuperAdminService.php b/app/classes/Framadate/Services/SuperAdminService.php index d434474eb2711e41c96e1afaad22eaaca27491d5..066af95582ec62c508a6d54cac7e562473afa2b6 100644 --- a/app/classes/Framadate/Services/SuperAdminService.php +++ b/app/classes/Framadate/Services/SuperAdminService.php @@ -25,7 +25,12 @@ class SuperAdminService { * @return array ['polls' => The {$limit} polls, 'count' => Entries found by the query, 'total' => Total count] */ public function findAllPolls($search, $page, $limit) { - return $this->connect->findAllPolls($search, $page * $limit, $limit); + $start = $page * $limit; + $polls = $this->connect->findAllPolls($search); + $total = $this->connect->countPolls(); + + + return ['polls' => array_slice($polls, $start, $limit), 'count' => count($polls), 'total' => $total]; } }