Issue #22 Enable vote name modification

This commit is contained in:
Olivier PEREZ 2015-01-07 23:29:46 +01:00
parent c67a4c7c14
commit afd6079420
6 changed files with 30 additions and 13 deletions

View File

@ -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 {

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

View File

@ -35,9 +35,15 @@
<tr>
{* Edited line *}
<th class="bg-info">{$vote->name}</th>
{if $editingVoteId == $vote->id}
<td class="bg-info" style="padding:5px">
<div class="input-group input-group-sm">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" id="name" name="name" value="{$vote->name}" class="form-control" title="{_('Your name')}" placeholder="{_('Your name')}" />
</div>
</td>
{foreach $vote->choices as $id=>$choice}
<td class="bg-info" headers="C{$id}">
@ -68,6 +74,8 @@
{* Voted line *}
<th class="bg-info">{$vote->name}</th>
{foreach $vote->choices as $choice}
{if $choice==2}

View File

@ -61,9 +61,15 @@
<tr>
{* Edited line *}
<th class="bg-info">{$vote->name}</th>
{if $editingVoteId == $vote->id}
<td class="bg-info" style="padding:5px">
<div class="input-group input-group-sm">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" id="name" name="name" value="{$vote->name}" class="form-control" title="{_('Your name')}" placeholder="{_('Your name')}" />
</div>
</td>
{foreach $vote->choices as $k=>$choice}
<td class="bg-info" headers="M{$headersM[$k]} D{$headersD[$k]} H{$k}">
@ -94,6 +100,8 @@
{* Voted line *}
<th class="bg-info">{$vote->name}</th>
{foreach $vote->choices as $k=>$choice}
{if $choice==2}