Skip to content
Snippets Groups Projects
Commit 591c4dd1 authored by Olivier PEREZ's avatar Olivier PEREZ
Browse files

Move some code from FramaDB to Service

parent a2ca0389
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment