From 40d707c96d022d1f291c58285100ec646f4f6b78 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Fri, 27 Mar 2015 12:55:32 +0100 Subject: [PATCH] Issue #18 Add search engine on admin polls list --- admin/polls.php | 24 +++++- app/classes/Framadate/FramaDB.php | 21 ++++-- .../Framadate/Services/SuperAdminService.php | 12 +-- css/style.css | 5 ++ js/app/admin/polls.js | 23 ++++++ js/app/studs.js | 18 +++++ locale/de.json | 5 +- locale/en.json | 5 +- locale/es.json | 5 +- locale/fr.json | 7 +- tpl/admin/polls.tpl | 75 +++++++++++++++---- 11 files changed, 164 insertions(+), 36 deletions(-) create mode 100644 js/app/admin/polls.js diff --git a/admin/polls.php b/admin/polls.php index bec7daa..e9fbeef 100644 --- a/admin/polls.php +++ b/admin/polls.php @@ -22,13 +22,24 @@ use Framadate\Services\LogService; use Framadate\Services\PollService; use Framadate\Services\SecurityService; use Framadate\Services\SuperAdminService; -use Framadate\Utils; include_once __DIR__ . '/../app/inc/init.php'; include_once __DIR__ . '/../bandeaux.php'; const POLLS_PER_PAGE = 30; +/* Functions */ + +function buildSearchQuery($search) { + $query = ''; + foreach ($search as $key => $value) { + $query .= $key . '=' . urlencode($value) . '&'; + } + return substr($query, 0, -1); +} + +/* --------- */ + /* Variables */ /* --------- */ @@ -49,6 +60,11 @@ $securityService = new SecurityService(); $page = (int)filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT); $page = ($page >= 1) ? $page : 1; +// Search +$search['poll'] = filter_input(INPUT_GET, 'poll', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]); +$search['title'] = filter_input(INPUT_GET, 'title', FILTER_SANITIZE_STRING); +$search['name'] = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING); + /* PAGE */ /* ---- */ @@ -63,17 +79,21 @@ if (!empty($_POST['delete_confirm']) && $securityService->checkCsrf('admin', $_P $adminPollService->deleteEntirePoll($poll_id); } -$found = $superAdminService->findAllPolls($page-1, POLLS_PER_PAGE); +$found = $superAdminService->findAllPolls($search, $page - 1, POLLS_PER_PAGE); $polls = $found['polls']; $count = $found['count']; +$total = $found['total']; // Assign data to template $smarty->assign('polls', $polls); $smarty->assign('count', $count); +$smarty->assign('total', $total); $smarty->assign('page', $page); $smarty->assign('pages', ceil($count / POLLS_PER_PAGE)); $smarty->assign('poll_to_delete', $poll_to_delete); $smarty->assign('crsf', $securityService->getToken('admin')); +$smarty->assign('search', $search); +$smarty->assign('search_query', buildSearchQuery($search)); $smarty->assign('title', __('Admin\\Polls')); diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index d4a198f..c2a5a4b 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -277,20 +277,29 @@ class FramaDB { } /** + * @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 */ - public function findAllPolls($start, $limit) { + public function findAllPolls($search, $start, $limit) { // Polls $prepared = $this->prepare(' SELECT p.*, (SELECT count(1) FROM `' . Utils::table('vote') . '` v WHERE p.id=v.poll_id) votes - FROM ' . Utils::table('poll') . ' p + 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 - LIMIT :start, :limit'); - $prepared->bindParam(':start', $start, PDO::PARAM_INT); - $prepared->bindParam(':limit', $limit, PDO::PARAM_INT); + '); + + $poll = $search['poll'] . '%'; + $title = '%' . $search['title'] . '%'; + $name = '%' . $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(); $polls = $prepared->fetchAll(); @@ -299,7 +308,7 @@ SELECT p.*, $count = $stmt->fetch(); $stmt->closeCursor(); - return ['polls' => $polls, 'count' => $count->nb]; + return ['polls' => array_slice($polls,$start, $limit), 'count' => $prepared->rowCount(), 'total' => $count->nb]; } public function countVotesByPollId($poll_id) { diff --git a/app/classes/Framadate/Services/SuperAdminService.php b/app/classes/Framadate/Services/SuperAdminService.php index af8a305..d434474 100644 --- a/app/classes/Framadate/Services/SuperAdminService.php +++ b/app/classes/Framadate/Services/SuperAdminService.php @@ -19,13 +19,13 @@ class SuperAdminService { /** * Return the list of all 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] + * @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>...] + * @param int $page The page index (O = first page) + * @param int $limit The limit size + * @return array ['polls' => The {$limit} polls, 'count' => Entries found by the query, 'total' => Total count] */ - public function findAllPolls($page, $limit) { - return $this->connect->findAllPolls($page * $limit, $limit); + public function findAllPolls($search, $page, $limit) { + return $this->connect->findAllPolls($search, $page * $limit, $limit); } } diff --git a/css/style.css b/css/style.css index 00b3790..02b5fa7 100644 --- a/css/style.css +++ b/css/style.css @@ -358,3 +358,8 @@ table.results .btn-link.btn-sm { #md-a-imgModalLabel { font-size: 24px; } + +/* Admin */ +#poll_search { + cursor: pointer; +} diff --git a/js/app/admin/polls.js b/js/app/admin/polls.js new file mode 100644 index 0000000..9dc96b6 --- /dev/null +++ b/js/app/admin/polls.js @@ -0,0 +1,23 @@ +/** + * This software is governed by the CeCILL-B license. If a copy of this license + * is not distributed with this file, you can obtain one at + * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt + * + * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ + * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft) + * + * ============================= + * + * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence + * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur + * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt + * + * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ + * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) + */ + +$(document).ready(function () { + $('#poll_search .panel-heading').on('click', function (e) { + $('#poll_search .panel-body').slideToggle('fast'); + }); +}); \ No newline at end of file diff --git a/js/app/studs.js b/js/app/studs.js index a41f156..395a34a 100644 --- a/js/app/studs.js +++ b/js/app/studs.js @@ -1,3 +1,21 @@ +/** + * This software is governed by the CeCILL-B license. If a copy of this license + * is not distributed with this file, you can obtain one at + * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt + * + * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ + * Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft) + * + * ============================= + * + * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence + * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur + * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt + * + * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ + * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) + */ + $(document).ready(function() { $("#poll_form").submit(function( event ) { diff --git a/locale/de.json b/locale/de.json index 099137d..b78d228 100644 --- a/locale/de.json +++ b/locale/de.json @@ -34,7 +34,8 @@ "Page generated in": "Seite generiert in", "seconds": "Sekunden", "Choice": "Wahl", - "Link": "Link" + "Link": "Link", + "Search": "Suche" }, "Date": { "dd/mm/yyyy": "jj/mm/aaaa", @@ -243,7 +244,7 @@ "Author": "Autor", "Email": "E-Mail-Adresse", "Expiration date": "Verfallsdatum", - "Users": "Nutzer", + "Votes": "Stimmen", "Actions": "Aktionen", "See the poll": "Umfrage sehen", "Change the poll": "Umfrage ändern", diff --git a/locale/en.json b/locale/en.json index 0f9b059..1f79e89 100644 --- a/locale/en.json +++ b/locale/en.json @@ -34,7 +34,8 @@ "Page generated in": "Page generated in", "seconds": "seconds", "Choice": "Choice", - "Link": "Link" + "Link": "Link", + "Search": "Search" }, "Date" : { "dd/mm/yyyy": "jj/mm/aaaa", @@ -244,7 +245,7 @@ "Author": "Author", "Email": "Courriel", "Expiration date": "Date d'expiration", - "Users": "Users", + "Votes": "Votes", "Actions": "Actions", "See the poll": "See the poll", "Change the poll": "Change the poll", diff --git a/locale/es.json b/locale/es.json index 3edb006..abbe21d 100644 --- a/locale/es.json +++ b/locale/es.json @@ -34,7 +34,8 @@ "Page generated in": "ES_Page générée en", "seconds": "ES_secondes", "Choice": "Opciòn", - "Link": "ES_Lien" + "Link": "ES_Lien", + "Search": "Búsqueda" }, "Date": { "dd/mm/yyyy": "ES_jj/mm/aaaa", @@ -243,7 +244,7 @@ "Author": "ES_Auteur", "Email": "ES_Courriel", "Expiration date": "ES_Date d'expiration", - "Users": "ES_Utilisateurs", + "Votes": "Votos", "Actions": "Acciones", "See the poll": "Ver la encuesta", "Change the poll": "Cambiar la encuesta", diff --git a/locale/fr.json b/locale/fr.json index c83e1f6..1128f4a 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -34,7 +34,8 @@ "Page generated in": "Page générée en", "seconds": "secondes", "Choice": "Choix", - "Link": "Lien" + "Link": "Lien", + "Search": "Chercher" }, "Date": { "dd/mm/yyyy": "jj/mm/aaaa", @@ -242,8 +243,8 @@ "Title": "Titre", "Author": "Auteur", "Email": "Courriel", - "Expiration date": "Date d'expiration", - "Users": "Utilisateurs", + "Expiration date": "Expiration", + "Votes": "Votes", "Actions": "Actions", "See the poll": "Voir le sondage", "Change the poll": "Modifier le sondage", diff --git a/tpl/admin/polls.tpl b/tpl/admin/polls.tpl index 258233b..5e7e2d4 100644 --- a/tpl/admin/polls.tpl +++ b/tpl/admin/polls.tpl @@ -1,8 +1,41 @@ {extends 'admin/admin_page.tpl'} +{block name="header"} + +{/block} + {block 'admin_main'} + +
- {if $poll_to_delete}

{__('adminstuds\\Confirm removal of the poll')} "{$poll_to_delete->id|html}"

@@ -15,13 +48,13 @@

{/if} +
- {$polls|count} / {$count} {__('Admin\\polls in the database at this time')} + {$count} / {$total} {__('Admin\\polls in the database at this time')}
- @@ -29,7 +62,7 @@ - + @@ -37,9 +70,13 @@ @@ -47,15 +84,26 @@ {if strtotime($poll->end_date) > time()} - + {else} - + {/if} - - - + + + {/foreach}
{__('Admin\\Author')} {__('Admin\\Email')} {__('Admin\\Expiration date')}{__('Admin\\Users')}{__('Admin\\Votes')} {__('Admin\\Poll ID')} {__('Admin\\Actions')}
{if $poll->format === 'D'} - {__('Generic\\Date')} + + {__('Generic\\Date')} {else} - {__('Generic\\Classic')} + + {__('Generic\\Classic')} {/if} {$poll->title|html}{$poll->admin_mail|html}{date('d/m/y', strtotime($poll->end_date))}{date('d/m/y', strtotime($poll->end_date))}{strtotime($poll->end_date)|date_format:'d/m/Y'}{strtotime($poll->end_date)|date_format:'d/m/Y'}{$poll->votes|html} {$poll->id|html}{__('Admin\\See the poll')}{__('Admin\\Change the poll')}{__('Admin\\See the poll')}{__('Admin\\Change the poll')} +
@@ -64,9 +112,10 @@ {__('Admin\\Pages:')} {for $p=1 to $pages} {if $p===$page} - {$p} + {$p} {else} - {$p} + {$p} {/if} {/for}