diff --git a/app/classes/Framadate/Repositories/PollRepository.php b/app/classes/Framadate/Repositories/PollRepository.php index 1771b3d425953dac0c5cacb84b007434843ed253..95debe4d0c98693fc02d44bfad439fb18151e0be 100644 --- a/app/classes/Framadate/Repositories/PollRepository.php +++ b/app/classes/Framadate/Repositories/PollRepository.php @@ -65,9 +65,11 @@ class PollRepository extends AbstractRepository { * Search polls in databse. * * @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>...] + * @param int $start The number of first entry to select + * @param int $limit The number of entries to find * @return array The found polls */ - public function findAll($search) { + public function findAll($search, $start, $limit) { // Polls $prepared = $this->prepare(' SELECT p.*, @@ -77,6 +79,7 @@ SELECT p.*, AND (:title = "" OR p.title LIKE :title) AND (:name = "" OR p.admin_name LIKE :name) ORDER BY p.title ASC + LIMIT :start, :limit '); $poll = $search['poll'] . '%'; @@ -85,6 +88,8 @@ SELECT p.*, $prepared->bindParam(':id', $poll, PDO::PARAM_STR); $prepared->bindParam(':title', $title, PDO::PARAM_STR); $prepared->bindParam(':name', $name, PDO::PARAM_STR); + $prepared->bindParam(':start', $start, PDO::PARAM_INT); + $prepared->bindParam(':limit', $limit, PDO::PARAM_INT); $prepared->execute(); return $prepared->fetchAll(); @@ -106,13 +111,33 @@ SELECT p.*, /** * Get the total number of polls in databse. * + * @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>...] * @return int The number of polls */ - public function count() { + public function count($search = null) { // Total count - $stmt = $this->query('SELECT count(1) nb FROM `' . Utils::table('poll') . '`'); - $count = $stmt->fetch(); - $stmt->closeCursor(); + $prepared = $this->prepare(' +SELECT count(1) nb + FROM `' . Utils::table('poll') . '` p + WHERE (:id = "" OR p.id LIKE :id) + AND (:title = "" OR p.title LIKE :title) + AND (:name = "" OR p.admin_name LIKE :name) + ORDER BY p.title ASC'); + + $poll = $search == null ? '' : $search['poll'] . '%'; + $title = $search == null ? '' : '%' . $search['title'] . '%'; + $name = $search == null ? '' : '%' . $search['name'] . '%'; + $prepared->bindParam(':id', $poll, PDO::PARAM_STR); + $prepared->bindParam(':title', $title, PDO::PARAM_STR); + $prepared->bindParam(':name', $name, PDO::PARAM_STR); + + $prepared->execute(); + $count = $prepared->fetch(); + + /*echo '---'; + print_r($count); + echo '---'; + exit;*/ return $count->nb; } diff --git a/app/classes/Framadate/Services/SuperAdminService.php b/app/classes/Framadate/Services/SuperAdminService.php index a4b7850045987e69173b0dd370fa654491653b76..3945f079ea385d66d78312f6445af8e3bcbbe5c8 100644 --- a/app/classes/Framadate/Services/SuperAdminService.php +++ b/app/classes/Framadate/Services/SuperAdminService.php @@ -26,11 +26,12 @@ class SuperAdminService { */ public function findAllPolls($search, $page, $limit) { $start = $page * $limit; - $polls = $this->pollRepository->findAll($search); + $polls = $this->pollRepository->findAll($search, $start, $limit); + $count = $this->pollRepository->count($search); $total = $this->pollRepository->count(); - return ['polls' => array_slice($polls, $start, $limit), 'count' => count($polls), 'total' => $total]; + return ['polls' => $polls, 'count' => $count, 'total' => $total]; } } diff --git a/tpl/admin/polls.tpl b/tpl/admin/polls.tpl index 53bbd1f896c4dd8029e45ca8d1b924552ee5890f..2963ed25610ce132cdc9e94e8be2a6b20de1fbd5 100644 --- a/tpl/admin/polls.tpl +++ b/tpl/admin/polls.tpl @@ -53,7 +53,7 @@ <div class="panel panel-default"> <div class="panel-heading"> - {$count} / {$total} {__('Admin', 'polls in the database at this time')} + {if $count == $total}{$count}{else}{$count} / {$total}{/if} {__('Admin', 'polls in the database at this time')} </div> <table class="table table-bordered table-polls">