From afd6079420e55a10cc49042e100e5e16544eb9ff Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Wed, 7 Jan 2015 23:29:46 +0100 Subject: [PATCH] Issue #22 Enable vote name modification --- adminstuds.php | 3 ++- app/classes/Framadate/FramaDB.php | 6 +++--- app/classes/Framadate/Services/PollService.php | 4 ++-- studs.php | 6 +++--- tpl/part/vote_table_classic.tpl | 12 ++++++++++-- tpl/part/vote_table_date.tpl | 12 ++++++++++-- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/adminstuds.php b/adminstuds.php index 1cdff56..b168345 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -126,6 +126,7 @@ if (!empty($_POST['edit_vote'])) { // ------------------------------- if (!empty($_POST['save'])) { // Save edition of an old vote + $name = filter_input(INPUT_POST, 'name', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => NAME_REGEX]]); $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT); $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]); @@ -138,7 +139,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote if ($message == null) { // Update vote - $result = $pollService->updateVote($poll_id, $editedVote, $choices); + $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices); if ($result) { $message = new Message('success', _('Update vote successfully.')); } else { diff --git a/app/classes/Framadate/FramaDB.php b/app/classes/Framadate/FramaDB.php index 15ae3ce..c41a439 100644 --- a/app/classes/Framadate/FramaDB.php +++ b/app/classes/Framadate/FramaDB.php @@ -238,10 +238,10 @@ class FramaDB { return $prepared->execute([$poll_id]); } - function updateVote($poll_id, $vote_id, $choices) { - $prepared = $this->prepare('UPDATE ' . Utils::table('vote') . ' SET choices = ? WHERE poll_id = ? AND id = ?'); + function updateVote($poll_id, $vote_id, $name, $choices) { + $prepared = $this->prepare('UPDATE ' . Utils::table('vote') . ' SET choices = ?, name = ? WHERE poll_id = ? AND id = ?'); - return $prepared->execute([$choices, $poll_id, $vote_id]); + return $prepared->execute([$choices, $name, $poll_id, $vote_id]); } function insertComment($poll_id, $name, $comment) { diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 949afcb..5193081 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -58,10 +58,10 @@ class PollService { return $this->connect->allSlotsByPollId($poll_id); } - public function updateVote($poll_id, $vote_id, $choices) { + public function updateVote($poll_id, $vote_id, $name, $choices) { $choices = implode($choices); - return $this->connect->updateVote($poll_id, $vote_id, $choices); + return $this->connect->updateVote($poll_id, $vote_id, $name, $choices); } function addVote($poll_id, $name, $choices) { diff --git a/studs.php b/studs.php index 96b2360..09bddab 100644 --- a/studs.php +++ b/studs.php @@ -47,7 +47,7 @@ $mailService = new MailService($config['use_smtp']); /** * Send a notification to the poll admin to notify him about an update. * - * @param $poll Object The poll + * @param $poll stdClass The poll * @param $mailService MailService The mail service */ function sendUpdateNotification($poll, $mailService) { @@ -87,12 +87,12 @@ if (!empty($_POST['edit_vote'])) { $editingVoteId = filter_input(INPUT_POST, 'edit_vote', FILTER_VALIDATE_INT); } - // ------------------------------- // Something to save (edit or add) // ------------------------------- if (!empty($_POST['save'])) { // Save edition of an old vote + $name = filter_input(INPUT_POST, 'name', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => NAME_REGEX]]); $editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT); $choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]); @@ -105,7 +105,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote if ($message == null) { // Update vote - $result = $pollService->updateVote($poll_id, $editedVote, $choices); + $result = $pollService->updateVote($poll_id, $editedVote, $name, $choices); if ($result) { $message = new Message('success', _('Update vote successfully.')); sendUpdateNotification($poll, $mailService); diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index 13be21f..5fb4014 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -35,9 +35,15 @@ {* Edited line *} - {$vote->name} - {if $editingVoteId == $vote->id} + + +
+ + +
+ + {foreach $vote->choices as $id=>$choice} @@ -68,6 +74,8 @@ {* Voted line *} + {$vote->name} + {foreach $vote->choices as $choice} {if $choice==2} diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index 5983e8e..e3945a8 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -61,9 +61,15 @@ {* Edited line *} - {$vote->name} - {if $editingVoteId == $vote->id} + + +
+ + +
+ + {foreach $vote->choices as $k=>$choice} @@ -94,6 +100,8 @@ {* Voted line *} + {$vote->name} + {foreach $vote->choices as $k=>$choice} {if $choice==2}