Admin: Fix the number of polls + Set to 30 the number of polls displayed per page
This commit is contained in:
parent
a4dd36d1bc
commit
3aa3ee486c
@ -27,7 +27,7 @@ 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;
|
const POLLS_PER_PAGE = 30;
|
||||||
|
|
||||||
/* Variables */
|
/* Variables */
|
||||||
/* --------- */
|
/* --------- */
|
||||||
|
@ -80,7 +80,7 @@ class FramaDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findPollById($poll_id) {
|
function findPollById($poll_id) {
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' WHERE id = ?');
|
$prepared = $this->prepare('SELECT * FROM `' . Utils::table('poll') . '` WHERE id = ?');
|
||||||
|
|
||||||
$prepared->execute([$poll_id]);
|
$prepared->execute([$poll_id]);
|
||||||
$poll = $prepared->fetch();
|
$poll = $prepared->fetch();
|
||||||
@ -90,40 +90,40 @@ class FramaDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updatePoll($poll) {
|
function updatePoll($poll) {
|
||||||
$prepared = $this->prepare('UPDATE ' . Utils::table('poll') . ' SET title=?, admin_name=?, admin_mail=?, description=?, end_date=FROM_UNIXTIME(?), active=?, editable=? WHERE id = ?');
|
$prepared = $this->prepare('UPDATE `' . Utils::table('poll') . '` SET title=?, admin_name=?, admin_mail=?, description=?, end_date=FROM_UNIXTIME(?), active=?, editable=? WHERE id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll->title, $poll->admin_name, $poll->admin_mail, $poll->description, $poll->end_date, $poll->active, $poll->editable, $poll->id]);
|
return $prepared->execute([$poll->title, $poll->admin_name, $poll->admin_mail, $poll->description, $poll->end_date, $poll->active, $poll->editable, $poll->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function allCommentsByPollId($poll_id) {
|
function allCommentsByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('comment') . ' WHERE poll_id = ? ORDER BY id');
|
$prepared = $this->prepare('SELECT * FROM `' . Utils::table('comment') . '` WHERE poll_id = ? ORDER BY id');
|
||||||
$prepared->execute(array($poll_id));
|
$prepared->execute(array($poll_id));
|
||||||
|
|
||||||
return $prepared->fetchAll();
|
return $prepared->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
function allUserVotesByPollId($poll_id) {
|
function allUserVotesByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('vote') . ' WHERE poll_id = ? ORDER BY id');
|
$prepared = $this->prepare('SELECT * FROM `' . Utils::table('vote') . '` WHERE poll_id = ? ORDER BY id');
|
||||||
$prepared->execute(array($poll_id));
|
$prepared->execute(array($poll_id));
|
||||||
|
|
||||||
return $prepared->fetchAll();
|
return $prepared->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
function allSlotsByPollId($poll_id) {
|
function allSlotsByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('slot') . ' WHERE poll_id = ? ORDER BY title');
|
$prepared = $this->prepare('SELECT * FROM `' . Utils::table('slot') . '` WHERE poll_id = ? ORDER BY title');
|
||||||
$prepared->execute(array($poll_id));
|
$prepared->execute(array($poll_id));
|
||||||
|
|
||||||
return $prepared->fetchAll();
|
return $prepared->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertDefaultVote($poll_id, $insert_position) {
|
function insertDefaultVote($poll_id, $insert_position) {
|
||||||
$prepared = $this->prepare('UPDATE ' . Utils::table('vote') . ' SET choices = CONCAT(SUBSTRING(choices, 1, ?), "0", SUBSTRING(choices, ?)) WHERE poll_id = ?');
|
$prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = CONCAT(SUBSTRING(choices, 1, ?), "0", SUBSTRING(choices, ?)) WHERE poll_id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$insert_position, $insert_position + 1, $poll_id]);
|
return $prepared->execute([$insert_position, $insert_position + 1, $poll_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertVote($poll_id, $name, $choices) {
|
function insertVote($poll_id, $name, $choices) {
|
||||||
$prepared = $this->prepare('INSERT INTO ' . Utils::table('vote') . ' (poll_id, name, choices) VALUES (?,?,?)');
|
$prepared = $this->prepare('INSERT INTO `' . Utils::table('vote') . '` (poll_id, name, choices) VALUES (?,?,?)');
|
||||||
$prepared->execute([$poll_id, $name, $choices]);
|
$prepared->execute([$poll_id, $name, $choices]);
|
||||||
|
|
||||||
$newVote = new \stdClass();
|
$newVote = new \stdClass();
|
||||||
@ -136,7 +136,7 @@ class FramaDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteVote($poll_id, $vote_id) {
|
function deleteVote($poll_id, $vote_id) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('vote') . ' WHERE poll_id = ? AND id = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('vote') . '` WHERE poll_id = ? AND id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id, $vote_id]);
|
return $prepared->execute([$poll_id, $vote_id]);
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ class FramaDB {
|
|||||||
* @return bool|null true if action succeeded.
|
* @return bool|null true if action succeeded.
|
||||||
*/
|
*/
|
||||||
function deleteVotesByPollId($poll_id) {
|
function deleteVotesByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('vote') . ' WHERE poll_id = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('vote') . '` WHERE poll_id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id]);
|
return $prepared->execute([$poll_id]);
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ class FramaDB {
|
|||||||
* @return bool|null true if action succeeded.
|
* @return bool|null true if action succeeded.
|
||||||
*/
|
*/
|
||||||
function deleteVotesByIndex($poll_id, $index) {
|
function deleteVotesByIndex($poll_id, $index) {
|
||||||
$prepared = $this->prepare('UPDATE ' . Utils::table('vote') . ' SET choices = CONCAT(SUBSTR(choices, 1, ?), SUBSTR(choices, ?)) WHERE poll_id = ?');
|
$prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = CONCAT(SUBSTR(choices, 1, ?), SUBSTR(choices, ?)) WHERE poll_id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$index, $index + 2, $poll_id]);
|
return $prepared->execute([$index, $index + 2, $poll_id]);
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ class FramaDB {
|
|||||||
* @return mixed Object The slot found, or null
|
* @return mixed Object The slot found, or null
|
||||||
*/
|
*/
|
||||||
function findSlotByPollIdAndDatetime($poll_id, $datetime) {
|
function findSlotByPollIdAndDatetime($poll_id, $datetime) {
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('slot') . ' WHERE poll_id = ? AND SUBSTRING_INDEX(title, \'@\', 1) = ?');
|
$prepared = $this->prepare('SELECT * FROM `' . Utils::table('slot') . '` WHERE poll_id = ? AND SUBSTRING_INDEX(title, \'@\', 1) = ?');
|
||||||
|
|
||||||
$prepared->execute([$poll_id, $datetime]);
|
$prepared->execute([$poll_id, $datetime]);
|
||||||
$slot = $prepared->fetch();
|
$slot = $prepared->fetch();
|
||||||
@ -192,7 +192,7 @@ class FramaDB {
|
|||||||
* @return bool true if action succeeded
|
* @return bool true if action succeeded
|
||||||
*/
|
*/
|
||||||
function insertSlot($poll_id, $title, $moments) {
|
function insertSlot($poll_id, $title, $moments) {
|
||||||
$prepared = $this->prepare('INSERT INTO ' . Utils::table('slot') . ' (poll_id, title, moments) VALUES (?,?,?)');
|
$prepared = $this->prepare('INSERT INTO `' . Utils::table('slot') . '` (poll_id, title, moments) VALUES (?,?,?)');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id, $title, $moments]);
|
return $prepared->execute([$poll_id, $title, $moments]);
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ class FramaDB {
|
|||||||
* @return bool|null true if action succeeded.
|
* @return bool|null true if action succeeded.
|
||||||
*/
|
*/
|
||||||
function updateSlot($poll_id, $datetime, $newMoments) {
|
function updateSlot($poll_id, $datetime, $newMoments) {
|
||||||
$prepared = $this->prepare('UPDATE ' . Utils::table('slot') . ' SET moments = ? WHERE poll_id = ? AND title = ?');
|
$prepared = $this->prepare('UPDATE `' . Utils::table('slot') . '` SET moments = ? WHERE poll_id = ? AND title = ?');
|
||||||
|
|
||||||
return $prepared->execute([$newMoments, $poll_id, $datetime]);
|
return $prepared->execute([$newMoments, $poll_id, $datetime]);
|
||||||
}
|
}
|
||||||
@ -218,12 +218,12 @@ class FramaDB {
|
|||||||
* @param $datetime mixed The datetime of the slot
|
* @param $datetime mixed The datetime of the slot
|
||||||
*/
|
*/
|
||||||
function deleteSlot($poll_id, $datetime) {
|
function deleteSlot($poll_id, $datetime) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('slot') . ' WHERE poll_id = ? AND title = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('slot') . '` WHERE poll_id = ? AND title = ?');
|
||||||
$prepared->execute([$poll_id, $datetime]);
|
$prepared->execute([$poll_id, $datetime]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteSlotsByPollId($poll_id) {
|
function deleteSlotsByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('slot') . ' WHERE poll_id = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('slot') . '` WHERE poll_id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id]);
|
return $prepared->execute([$poll_id]);
|
||||||
}
|
}
|
||||||
@ -235,31 +235,31 @@ class FramaDB {
|
|||||||
* @return bool|null true if action succeeded.
|
* @return bool|null true if action succeeded.
|
||||||
*/
|
*/
|
||||||
function deleteCommentsByPollId($poll_id) {
|
function deleteCommentsByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('comment') . ' WHERE poll_id = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('comment') . '` WHERE poll_id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id]);
|
return $prepared->execute([$poll_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVote($poll_id, $vote_id, $name, $choices) {
|
function updateVote($poll_id, $vote_id, $name, $choices) {
|
||||||
$prepared = $this->prepare('UPDATE ' . Utils::table('vote') . ' SET choices = ?, name = ? WHERE poll_id = ? AND id = ?');
|
$prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = ?, name = ? WHERE poll_id = ? AND id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$choices, $name, $poll_id, $vote_id]);
|
return $prepared->execute([$choices, $name, $poll_id, $vote_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertComment($poll_id, $name, $comment) {
|
function insertComment($poll_id, $name, $comment) {
|
||||||
$prepared = $this->prepare('INSERT INTO ' . Utils::table('comment') . ' (poll_id, name, comment) VALUES (?,?,?)');
|
$prepared = $this->prepare('INSERT INTO `' . Utils::table('comment') . '` (poll_id, name, comment) VALUES (?,?,?)');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id, $name, $comment]);
|
return $prepared->execute([$poll_id, $name, $comment]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteComment($poll_id, $comment_id) {
|
function deleteComment($poll_id, $comment_id) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('comment') . ' WHERE poll_id = ? AND id = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('comment') . '` WHERE poll_id = ? AND id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id, $comment_id]);
|
return $prepared->execute([$poll_id, $comment_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deletePollById($poll_id) {
|
function deletePollById($poll_id) {
|
||||||
$prepared = $this->prepare('DELETE FROM ' . Utils::table('poll') . ' WHERE id = ?');
|
$prepared = $this->prepare('DELETE FROM `' . Utils::table('poll') . '` WHERE id = ?');
|
||||||
|
|
||||||
return $prepared->execute([$poll_id]);
|
return $prepared->execute([$poll_id]);
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ class FramaDB {
|
|||||||
* @return array Array of old polls
|
* @return array Array of old polls
|
||||||
*/
|
*/
|
||||||
public function findOldPolls() {
|
public function findOldPolls() {
|
||||||
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('poll') . ' WHERE end_date < NOW() AND end_date != 0 LIMIT 20');
|
$prepared = $this->prepare('SELECT * FROM `' . Utils::table('poll') . '` WHERE end_date < NOW() AND end_date != 0 LIMIT 20');
|
||||||
$prepared->execute([]);
|
$prepared->execute([]);
|
||||||
|
|
||||||
return $prepared->fetchAll();
|
return $prepared->fetchAll();
|
||||||
@ -285,7 +285,7 @@ class FramaDB {
|
|||||||
// Polls
|
// Polls
|
||||||
$prepared = $this->prepare('
|
$prepared = $this->prepare('
|
||||||
SELECT p.*,
|
SELECT p.*,
|
||||||
(SELECT count(1) FROM ' . Utils::table('vote') . ' v WHERE p.id=v.poll_id) votes
|
(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
|
||||||
ORDER BY p.title ASC
|
ORDER BY p.title ASC
|
||||||
LIMIT :start, :limit');
|
LIMIT :start, :limit');
|
||||||
@ -295,16 +295,15 @@ SELECT p.*,
|
|||||||
$polls = $prepared->fetchAll();
|
$polls = $prepared->fetchAll();
|
||||||
|
|
||||||
// Total count
|
// Total count
|
||||||
$prepared = $this->prepare('SELECT count(1) nb FROM ' . Utils::table('poll'));
|
$stmt = $this->query('SELECT count(1) nb FROM `' . Utils::table('poll') . '`');
|
||||||
$prepared->execute();
|
$count = $stmt->fetch();
|
||||||
$count = $prepared->fetch();
|
$stmt->closeCursor();
|
||||||
$prepared->closeCursor();
|
|
||||||
|
|
||||||
return ['polls' => $polls, 'count' => $count->nb];
|
return ['polls' => $polls, 'count' => $count->nb];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countVotesByPollId($poll_id) {
|
public function countVotesByPollId($poll_id) {
|
||||||
$prepared = $this->prepare('SELECT count(1) nb FROM ' . Utils::table('vote') . ' WHERE poll_id = ?');
|
$prepared = $this->prepare('SELECT count(1) nb FROM `' . Utils::table('vote') . '` WHERE poll_id = ?');
|
||||||
|
|
||||||
$prepared->execute([$poll_id]);
|
$prepared->execute([$poll_id]);
|
||||||
$result = $prepared->fetch();
|
$result = $prepared->fetch();
|
||||||
@ -312,5 +311,4 @@ SELECT p.*,
|
|||||||
|
|
||||||
return $result->nb;
|
return $result->nb;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
{$polls|count} {_('polls in the database at this time')}
|
{$polls|count} / {$count} {_('polls in the database at this time')}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user