Issue #18 Install pagination on polls admin page

This commit is contained in:
Olivier PEREZ 2015-01-18 16:14:45 +01:00
parent 9098fe0aaa
commit f6a7a1c7bb
8 changed files with 82 additions and 8 deletions

View File

@ -27,6 +27,8 @@ use Framadate\Utils;
include_once __DIR__ . '/../app/inc/init.php';
include_once __DIR__ . '/../bandeaux.php';
const POLLS_PER_PAGE = 10;
/* Variables */
/* --------- */
@ -42,6 +44,11 @@ $adminPollService = new AdminPollService($connect, $pollService, $logService);
$superAdminService = new SuperAdminService($connect);
$securityService = new SecurityService();
/* GET */
/*-----*/
$page = (int)filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
$page = ($page >= 1) ? $page : 1;
/* PAGE */
/* ---- */
@ -56,10 +63,15 @@ if (!empty($_POST['delete_confirm']) && $securityService->checkCsrf('admin', $_P
$adminPollService->deleteEntirePoll($poll_id);
}
$polls = $superAdminService->findAllPolls();
$found = $superAdminService->findAllPolls($page-1, POLLS_PER_PAGE);
$polls = $found['polls'];
$count = $found['count'];
// Assign data to template
$smarty->assign('polls', $polls);
$smarty->assign('count', $count);
$smarty->assign('page', $page);
$smarty->assign('pages', ceil($count / POLLS_PER_PAGE));
$smarty->assign('poll_to_delete', $poll_to_delete);
$smarty->assign('log_file', is_readable('../' . LOG_FILE) ? LOG_FILE : null);
$smarty->assign('crsf', $securityService->getToken('admin'));

View File

@ -18,6 +18,8 @@
*/
namespace Framadate;
use PDO;
class FramaDB {
/**
* PDO Object, connection to database.
@ -274,11 +276,26 @@ class FramaDB {
return $prepared->fetchAll();
}
public function findAllPolls() {
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' ORDER BY end_date ASC');
$prepared->execute([]);
/**
* @param $start int The index of the first poll to return
* @param $limit int The limit size
* @return array
*/
public function findAllPolls($start, $limit) {
// Polls
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' ORDER BY title ASC LIMIT :start, :limit');
$prepared->bindParam(':start', $start, PDO::PARAM_INT);
$prepared->bindParam(':limit', $limit, PDO::PARAM_INT);
$prepared->execute();
$polls = $prepared->fetchAll();
return $prepared->fetchAll();
// Total count
$prepared = $this->prepare('SELECT count(1) nb FROM ' . Utils::table('poll'));
$prepared->execute();
$count = $prepared->fetch();
$prepared->closeCursor();
return ['polls' => $polls, 'count' => $count->nb];
}
public function countVotesByPollId($poll_id) {

View File

@ -19,10 +19,13 @@ class SuperAdminService {
/**
* Return the list of all polls.
*
* @return array All the polls
* @param $page int The page index (O = first page)
* @param $limit int The limit size
* @return array ['polls' => The {$limit} polls, 'count' => Total count]
* polls, 'count' => Total count]
*/
public function findAllPolls() {
return $this->connect->findAllPolls();
public function findAllPolls($page, $limit) {
return $this->connect->findAllPolls($page * $limit, $limit);
}
}

View File

@ -27,6 +27,7 @@ $smarty->caching = false;
$smarty->assign('APPLICATION_NAME', NOMAPPLICATION);
$smarty->assign('SERVER_URL', Utils::get_server_name());
$smarty->assign('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
$smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
$smarty->assign('lang', $lang);

View File

@ -610,6 +610,30 @@ msgstr "Umfrage ändern"
msgid "Logs"
msgstr "Verlauf"
msgid "Summary"
msgstr "Zusammenfassung"
msgid "Success"
msgstr "Erfolg"
msgid "Fail"
msgstr "scheitern"
msgid "Nothing"
msgstr "Nichts"
msgid "Succeeded:"
msgstr "Erfolgreich:"
msgid "Failed:"
msgstr "fehlgeschlagen:"
msgid "Skipped:"
msgstr "übersprungene:"
msgid "Pages:"
msgstr "Seiten:"
########### Mails ###########
# Mails studs.php
msgid "Poll's participation"

View File

@ -664,6 +664,9 @@ msgstr "Failed:"
msgid "Skipped:"
msgstr "Skipped:"
msgid "Pages:"
msgstr "Pages:"
########### Mails ###########
# Mails studs.php
msgid "Poll's participation"

View File

@ -664,6 +664,9 @@ msgstr "Échoué:"
msgid "Skipped:"
msgstr "Passé:"
msgid "Pages:"
msgstr "Pages :"
########### Mails ###########
# Mails studs.php
msgid "Poll's participation"

View File

@ -60,5 +60,16 @@
</tr>
{/foreach}
</table>
<div>
{_('Pages:')}
{for $p=1 to $pages}
{if $p===$page}
<a href="{$SERVER_URL}{$SCRIPT_NAME}?page={$p}" class="btn btn-danger" disabled="disabled">{$p}</a>
{else}
<a href="{$SERVER_URL}{$SCRIPT_NAME}?page={$p}" class="btn btn-info">{$p}</a>
{/if}
{/for}
</div>
</form>
{/block}