Move some code from FramaDB to Service
This commit is contained in:
parent
a2ca03893a
commit
591c4dd1af
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user