Issue #18 Install pagination on polls admin page
This commit is contained in:
parent
9098fe0aaa
commit
f6a7a1c7bb
@ -27,6 +27,8 @@ use Framadate\Utils;
|
|||||||
include_once __DIR__ . '/../app/inc/init.php';
|
include_once __DIR__ . '/../app/inc/init.php';
|
||||||
include_once __DIR__ . '/../bandeaux.php';
|
include_once __DIR__ . '/../bandeaux.php';
|
||||||
|
|
||||||
|
const POLLS_PER_PAGE = 10;
|
||||||
|
|
||||||
/* Variables */
|
/* Variables */
|
||||||
/* --------- */
|
/* --------- */
|
||||||
|
|
||||||
@ -42,6 +44,11 @@ $adminPollService = new AdminPollService($connect, $pollService, $logService);
|
|||||||
$superAdminService = new SuperAdminService($connect);
|
$superAdminService = new SuperAdminService($connect);
|
||||||
$securityService = new SecurityService();
|
$securityService = new SecurityService();
|
||||||
|
|
||||||
|
/* GET */
|
||||||
|
/*-----*/
|
||||||
|
$page = (int)filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
|
||||||
|
$page = ($page >= 1) ? $page : 1;
|
||||||
|
|
||||||
/* PAGE */
|
/* PAGE */
|
||||||
/* ---- */
|
/* ---- */
|
||||||
|
|
||||||
@ -56,10 +63,15 @@ if (!empty($_POST['delete_confirm']) && $securityService->checkCsrf('admin', $_P
|
|||||||
$adminPollService->deleteEntirePoll($poll_id);
|
$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
|
// Assign data to template
|
||||||
$smarty->assign('polls', $polls);
|
$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('poll_to_delete', $poll_to_delete);
|
||||||
$smarty->assign('log_file', is_readable('../' . LOG_FILE) ? LOG_FILE : null);
|
$smarty->assign('log_file', is_readable('../' . LOG_FILE) ? LOG_FILE : null);
|
||||||
$smarty->assign('crsf', $securityService->getToken('admin'));
|
$smarty->assign('crsf', $securityService->getToken('admin'));
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
namespace Framadate;
|
namespace Framadate;
|
||||||
|
|
||||||
|
use PDO;
|
||||||
|
|
||||||
class FramaDB {
|
class FramaDB {
|
||||||
/**
|
/**
|
||||||
* PDO Object, connection to database.
|
* PDO Object, connection to database.
|
||||||
@ -274,11 +276,26 @@ class FramaDB {
|
|||||||
return $prepared->fetchAll();
|
return $prepared->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findAllPolls() {
|
/**
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' ORDER BY end_date ASC');
|
* @param $start int The index of the first poll to return
|
||||||
$prepared->execute([]);
|
* @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) {
|
public function countVotesByPollId($poll_id) {
|
||||||
|
@ -19,10 +19,13 @@ class SuperAdminService {
|
|||||||
/**
|
/**
|
||||||
* Return the list of all polls.
|
* 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() {
|
public function findAllPolls($page, $limit) {
|
||||||
return $this->connect->findAllPolls();
|
return $this->connect->findAllPolls($page * $limit, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ $smarty->caching = false;
|
|||||||
|
|
||||||
$smarty->assign('APPLICATION_NAME', NOMAPPLICATION);
|
$smarty->assign('APPLICATION_NAME', NOMAPPLICATION);
|
||||||
$smarty->assign('SERVER_URL', Utils::get_server_name());
|
$smarty->assign('SERVER_URL', Utils::get_server_name());
|
||||||
|
$smarty->assign('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
|
||||||
$smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
|
$smarty->assign('TITLE_IMAGE', IMAGE_TITRE);
|
||||||
$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
|
$smarty->assign('use_nav_js', file_exists($_SERVER['DOCUMENT_ROOT'] . '/nav/nav.js'));
|
||||||
$smarty->assign('lang', $lang);
|
$smarty->assign('lang', $lang);
|
||||||
|
@ -610,6 +610,30 @@ msgstr "Umfrage ändern"
|
|||||||
msgid "Logs"
|
msgid "Logs"
|
||||||
msgstr "Verlauf"
|
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 ###########
|
||||||
# Mails studs.php
|
# Mails studs.php
|
||||||
msgid "Poll's participation"
|
msgid "Poll's participation"
|
||||||
|
@ -664,6 +664,9 @@ msgstr "Failed:"
|
|||||||
msgid "Skipped:"
|
msgid "Skipped:"
|
||||||
msgstr "Skipped:"
|
msgstr "Skipped:"
|
||||||
|
|
||||||
|
msgid "Pages:"
|
||||||
|
msgstr "Pages:"
|
||||||
|
|
||||||
########### Mails ###########
|
########### Mails ###########
|
||||||
# Mails studs.php
|
# Mails studs.php
|
||||||
msgid "Poll's participation"
|
msgid "Poll's participation"
|
||||||
|
@ -664,6 +664,9 @@ msgstr "Échoué:"
|
|||||||
msgid "Skipped:"
|
msgid "Skipped:"
|
||||||
msgstr "Passé:"
|
msgstr "Passé:"
|
||||||
|
|
||||||
|
msgid "Pages:"
|
||||||
|
msgstr "Pages :"
|
||||||
|
|
||||||
########### Mails ###########
|
########### Mails ###########
|
||||||
# Mails studs.php
|
# Mails studs.php
|
||||||
msgid "Poll's participation"
|
msgid "Poll's participation"
|
||||||
|
@ -60,5 +60,16 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</table>
|
</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>
|
</form>
|
||||||
{/block}
|
{/block}
|
Loading…
Reference in New Issue
Block a user