Hidden results option is taken into account.

- Also added possibility for the poll's maker to edit this hidden results option.
This commit is contained in:
Antonin 2015-04-06 12:39:58 +02:00
parent 0c2ba20bfa
commit a135f74383
12 changed files with 166 additions and 100 deletions

View File

@ -70,7 +70,7 @@ if (!$poll) {
if (isset($_POST['update_poll_info'])) { if (isset($_POST['update_poll_info'])) {
$updated = false; $updated = false;
$field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'description', 'rules', 'expiration_date', 'name']); $field = $inputService->filterAllowedValues($_POST['update_poll_info'], ['title', 'admin_mail', 'description', 'rules', 'expiration_date', 'name', 'hidden']);
// Update the right poll field // Update the right poll field
if ($field == 'title') { if ($field == 'title') {
@ -128,6 +128,13 @@ if (isset($_POST['update_poll_info'])) {
$poll->admin_name = $admin_name; $poll->admin_name = $admin_name;
$updated = true; $updated = true;
} }
} elseif ($field == 'hidden') {
$hidden = filter_input(INPUT_POST, 'hidden', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => BOOLEAN_REGEX]]);
$hidden = $hidden==null?false:true;
if ($hidden != $poll->hidden) {
$poll->hidden = $hidden;
$updated = true;
}
} }
// Update poll in database // Update poll in database

View File

@ -90,9 +90,9 @@ class FramaDB {
} }
function updatePoll($poll) { function updatePoll($poll) {
$prepared = $this->prepare('UPDATE `' . Utils::table('poll') . '` SET title=?, admin_name=?, admin_mail=?, description=?, end_date=?, active=?, editable=? WHERE id = ?'); $prepared = $this->prepare('UPDATE `' . Utils::table('poll') . '` SET title=?, admin_name=?, admin_mail=?, description=?, end_date=?, active=?, editable=?, hidden=? 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->hidden, $poll->id]);
} }
function allCommentsByPollId($poll_id) { function allCommentsByPollId($poll_id) {

View File

@ -124,6 +124,7 @@ caption {
#email-form .btn-edit, #email-form .btn-edit,
#description-form .btn-edit, #description-form .btn-edit,
#poll-rules-form .btn-edit, #poll-rules-form .btn-edit,
#poll-hidden-form .btn-edit,
#expiration-form .btn-edit, #expiration-form .btn-edit,
#name-form .btn-edit { #name-form .btn-edit {
position:absolute; position:absolute;
@ -138,6 +139,8 @@ caption {
#description-form:hover .btn-edit, #description-form:hover .btn-edit,
#poll-rules-form .btn-edit:focus, #poll-rules-form .btn-edit:focus,
#poll-rules-form:hover .btn-edit, #poll-rules-form:hover .btn-edit,
#poll-hidden-form .btn-edit:focus,
#poll-hidden-form:hover .btn-edit,
#expiration-form .btn-edit:focus, #expiration-form .btn-edit:focus,
#expiration-form:hover .btn-edit, #expiration-form:hover .btn-edit,
#name-form .btn-edit:focus, #name-form .btn-edit:focus,
@ -155,7 +158,7 @@ caption {
margin-bottom:0; margin-bottom:0;
} }
#poll-rules-form p, #poll-rules-form p, #poll-hidden-form p,
.jumbotron p.well { .jumbotron p.well {
font-size:16px; font-size:16px;
} }

View File

@ -98,6 +98,20 @@ $(document).ready(function() {
return false; return false;
}); });
$('#poll-hidden-form .btn-edit').on('click', function() {
$('#poll-hidden-form p').hide();
$('#poll-hidden-form .js-poll-hidden').removeClass("hidden");
$('.js-poll-hidden input[type=checkbox]').focus();
return false;
});
$('#poll-hidden-form .btn-cancel').on('click', function() {
$('#poll-hidden-form p').show();
$('#poll-hidden-form .js-poll-hidden').addClass("hidden");
$('.js-poll-hidden .btn-edit').focus();
return false;
});
$('#expiration-form .btn-edit').on('click', function() { $('#expiration-form .btn-edit').on('click', function() {
$('#expiration-form p').hide(); $('#expiration-form p').hide();
$('.js-expiration').removeClass("hidden"); $('.js-expiration').removeClass("hidden");

View File

@ -114,7 +114,9 @@
"Votes are editable solely by their owner.": "DE_Les votes sont modifiables uniquement par leur créateur", "Votes are editable solely by their owner.": "DE_Les votes sont modifiables uniquement par leur créateur",
"Save the new rules": "Neue Regeln speichern", "Save the new rules": "Neue Regeln speichern",
"Cancel the rules edit": "Neue Regeln nicht speichern", "Cancel the rules edit": "Neue Regeln nicht speichern",
"The name is invalid.": "Der Name ist ungültig." "The name is invalid.": "Der Name ist ungültig.",
"Results are hidden.": "DE_Les résultats sont cachés.",
"Results are visible.": "DE_Les résultats sont visibles."
}, },
"Poll results": { "Poll results": {
"Votes of the poll": "Abstimmungen der Umfrage ", "Votes of the poll": "Abstimmungen der Umfrage ",
@ -302,7 +304,7 @@
"Framadate is not properly installed, please check the \"INSTALL\" to setup the database before continuing.": "Framadate ist nicht richtig installiert, überprüfen Sie bitte die Schaltfläche \"INSTALL\", um das Setup der Datenbank, bevor Sie fortfahren.", "Framadate is not properly installed, please check the \"INSTALL\" to setup the database before continuing.": "Framadate ist nicht richtig installiert, überprüfen Sie bitte die Schaltfläche \"INSTALL\", um das Setup der Datenbank, bevor Sie fortfahren.",
"Failed to save poll": "Fehlgeschlagen Umfrage sparen", "Failed to save poll": "Fehlgeschlagen Umfrage sparen",
"Update vote failed": "Update vote failed", "Update vote failed": "Update vote failed",
"Adding vote failed": "Adding vote failed" "Adding vote failed": "Adding vote failed",
"You can't create a poll with hidden results with the following edition option : ": "DE_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : " "You can't create a poll with hidden results with the following edition option : ": "DE_Vous ne pouvez pas créer de sondage avec résulats cachés avec les options d'éditions suivantes : "
} }
} }

View File

@ -115,7 +115,9 @@
"Votes are editable solely by their owner.": "Votes are editable solely by their owner", "Votes are editable solely by their owner.": "Votes are editable solely by their owner",
"Save the new rules": "Save the new rules", "Save the new rules": "Save the new rules",
"Cancel the rules edit": "Cancel the rules edit", "Cancel the rules edit": "Cancel the rules edit",
"The name is invalid.": "The name is invalid." "The name is invalid.": "The name is invalid.",
"Results are hidden.": "Results are hidden.",
"Results are visible.": "Results are visible."
}, },
"Poll results": { "Poll results": {
"Votes of the poll": "Votes of the poll", "Votes of the poll": "Votes of the poll",

View File

@ -114,7 +114,9 @@
"Votes are editable solely by their owner.": "ES_Les votes sont modifiables uniquement par leur créateur", "Votes are editable solely by their owner.": "ES_Les votes sont modifiables uniquement par leur créateur",
"Save the new rules": "ES_Enregistrer les nouvelles permissions", "Save the new rules": "ES_Enregistrer les nouvelles permissions",
"Cancel the rules edit": "ES_Annuler le changement de permissions", "Cancel the rules edit": "ES_Annuler le changement de permissions",
"The name is invalid.": "ES_Le nom n'est pas valide." "The name is invalid.": "ES_Le nom n'est pas valide.",
"Results are hidden.": "ES_Les résultats sont cachés.",
"Results are visible.": "ES_Les résultats sont visibles."
}, },
"Poll results": { "Poll results": {
"Votes of the poll": "ES_Votes du sondage", "Votes of the poll": "ES_Votes du sondage",

View File

@ -114,7 +114,9 @@
"Votes are editable solely by their owner.": "Les votes sont modifiables uniquement par leur créateur", "Votes are editable solely by their owner.": "Les votes sont modifiables uniquement par leur créateur",
"Save the new rules": "Enregistrer les nouvelles permissions", "Save the new rules": "Enregistrer les nouvelles permissions",
"Cancel the rules edit": "Annuler le changement de permissions", "Cancel the rules edit": "Annuler le changement de permissions",
"The name is invalid.": "Le nom n'est pas valide." "The name is invalid.": "Le nom n'est pas valide.",
"Results are hidden.": "Les résultats sont cachés.",
"Results are visible.": "Les résultats sont visibles."
}, },
"Poll results": { "Poll results": {
"Votes of the poll": "Votes du sondage", "Votes of the poll": "Votes du sondage",

View File

@ -212,6 +212,7 @@ $smarty->assign('comments', $comments);
$smarty->assign('editingVoteId', $editingVoteId); $smarty->assign('editingVoteId', $editingVoteId);
$smarty->assign('message', $message); $smarty->assign('message', $message);
$smarty->assign('admin', false); $smarty->assign('admin', false);
$smarty->assign('hidden', $poll->hidden);
$smarty->assign('parameter_name_regex', NAME_REGEX); $smarty->assign('parameter_name_regex', NAME_REGEX);
$smarty->display('studs.tpl'); $smarty->display('studs.tpl');

View File

@ -118,14 +118,41 @@
</div> </div>
{if $admin} {if $admin}
<div class="row"> <div class="row">
<div class="col-md-4 col-md-offset-8" > <div class="col-md-4 col-md-offset-4" >
<div id="poll-hidden-form">
{if $poll->hidden}
{$hidden_icon = "glyphicon-eye-close"}
{$hidden_text = __('PollInfo', 'Results are hidden.')}
{else}
{$hidden_icon = "glyphicon-eye-open"}
{$hidden_text = __('PollInfo', 'Results are visible.')}
{/if}
<p class=""><span class="glyphicon {$hidden_icon}"> </span> {$hidden_text}<button class="btn btn-link btn-sm btn-edit" title="{__('PollInfo', 'Edit the poll rules')}"><span class="glyphicon glyphicon-pencil"></span><span class="sr-only">{__('Generic', 'Edit')}</span></button></p>
<div class="hidden js-poll-hidden">
<div class="input-group">
<input type="checkbox" id="hidden" name="hidden" {if $poll->hidden}checked="checked"{/if}/>
<label for="hidden">{__('PollInfo', 'Results are hidden.')}</label>
<span class="input-group-btn">
<button type="submit" name="update_poll_info" value="hidden" class="btn btn-success" title="{__('PollInfo', 'Save the new rules')}"><span class="glyphicon glyphicon-ok"></span><span class="sr-only">{__('Generic', 'Save')}</span></button>
<button class="btn btn-link btn-cancel" title="{__('PollInfo', 'Cancel the rules edit')}"><span class="glyphicon glyphicon-remove"></span><span class="sr-only">{__('Generic', 'Cancel')}</span></button>
</span>
</div>
</div>
</div>
</div>
<div class="col-md-4" >
<div id="poll-rules-form"> <div id="poll-rules-form">
{if $poll->active} {if $poll->active}
{if $poll->editable} {if $poll->editable}
{$rule_id = 2} {if $poll->editable == constant("Framadate\Editable::EDITABLE_BY_ALL")}
{$rule_id = 2}
{$rule_txt = __('PollInfo', 'Votes are editable')}
{else}
{$rule_id = 3}
{$rule_txt = __('PollInfo', 'Votes are editable solely by their owner.')}
{/if}
{$rule_icon = '<span class="glyphicon glyphicon-edit"></span>'} {$rule_icon = '<span class="glyphicon glyphicon-edit"></span>'}
{$rule_txt = __('PollInfo', 'Votes are editable')} {else}
{else}
{$rule_id = 1} {$rule_id = 1}
{$rule_icon = '<span class="glyphicon glyphicon-check"></span>'} {$rule_icon = '<span class="glyphicon glyphicon-check"></span>'}
{$rule_txt = __('PollInfo', 'Votes and comments are open')} {$rule_txt = __('PollInfo', 'Votes and comments are open')}

View File

@ -2,7 +2,7 @@
{$best_choices = [0]} {$best_choices = [0]}
{/if} {/if}
<h3>{__('Poll results', 'Votes of the poll')}</h3> <h3>{__('Poll results', 'Votes of the poll')} {if $hidden}<i>({__('PollInfo', 'Results are hidden.')})</i>{/if}</h3>
<div id="tableContainer" class="tableContainer"> <div id="tableContainer" class="tableContainer">
<form action="{poll_url id=$poll_id}" method="POST" id="poll_form"> <form action="{poll_url id=$poll_id}" method="POST" id="poll_form">
@ -69,7 +69,7 @@
</td> </td>
{/foreach} {/foreach}
<td style="padding:5px"><button type="submit" class="btn btn-success btn-xs" name="save" value="{$vote->id|html}" title="{__('Poll results', 'Save the choices')} {$vote->name|html}">{__('Generic', 'Save')}</button></td> <td style="padding:5px"><button type="submit" class="btn btn-success btn-xs" name="save" value="{$vote->id|html}" title="{__('Poll results', 'Save the choices')} {$vote->name|html}">{__('Generic', 'Save')}</button></td>
{else} {elseif !$hidden}
{* Voted line *} {* Voted line *}
<th class="bg-info">{$vote->name|html}</th> <th class="bg-info">{$vote->name|html}</th>
@ -142,55 +142,58 @@
</tr> </tr>
{/if} {/if}
{* Line displaying best moments *} {if !$hidden}
{$count_bests = 0} {* Line displaying best moments *}
{$max = max($best_choices)} {$count_bests = 0}
{if $max > 0} {$max = max($best_choices)}
<tr id="addition"> {if $max > 0}
<td>{__('Poll results', 'Addition')}</td> <tr id="addition">
{foreach $best_choices as $best_choice} <td>{__('Poll results', 'Addition')}</td>
{if $max == $best_choice} {foreach $best_choices as $best_choice}
{$count_bests = $count_bests +1} {if $max == $best_choice}
<td><span class="glyphicon glyphicon-star text-warning"></span>{$best_choice|html}</td> {$count_bests = $count_bests +1}
{elseif $best_choice > 0} <td><span class="glyphicon glyphicon-star text-warning"></span>{$best_choice|html}</td>
<td>{$best_choice|html}</td> {elseif $best_choice > 0}
{else} <td>{$best_choice|html}</td>
<td></td> {else}
{/if} <td></td>
{/foreach} {/if}
</tr> {/foreach}
</tr>
{/if}
{/if} {/if}
</tbody> </tbody>
</table> </table>
</form> </form>
</div> </div>
{* Best votes listing *} {if !$hidden}
{* Best votes listing *}
{$max = max($best_choices)} {$max = max($best_choices)}
{if $max > 0} {if $max > 0}
<div class="row"> <div class="row">
{if $count_bests == 1} {if $count_bests == 1}
<div class="col-sm-12"><h3>{__('Poll results', 'Best choice')}</h3></div> <div class="col-sm-12"><h3>{__('Poll results', 'Best choice')}</h3></div>
<div class="col-sm-6 col-sm-offset-3 alert alert-success">
<p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The best choice at this time is:')}</p>
{elseif $count_bests > 1}
<div class="col-sm-12"><h3>{__('Poll results', 'Best choices')}</h3></div>
<div class="col-sm-6 col-sm-offset-3 alert alert-success"> <div class="col-sm-6 col-sm-offset-3 alert alert-success">
<p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The bests choices at this time are:')}</p> <p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The best choice at this time is:')}</p>
{/if} {elseif $count_bests > 1}
<div class="col-sm-12"><h3>{__('Poll results', 'Best choices')}</h3></div>
<div class="col-sm-6 col-sm-offset-3 alert alert-success">
<p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The bests choices at this time are:')}</p>
{/if}
{$i = 0} {$i = 0}
<ul style="list-style:none"> <ul style="list-style:none">
{foreach $slots as $slot} {foreach $slots as $slot}
{if $best_choices[$i] == $max} {if $best_choices[$i] == $max}
<li><strong>{$slot->title|html|markdown:true}</strong></li> <li><strong>{$slot->title|html|markdown:true}</strong></li>
{/if} {/if}
{$i = $i+1} {$i = $i+1}
{/foreach} {/foreach}
</ul> </ul>
<p>{__('Generic', 'with')} <b>{$max|html}</b> {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.</p> <p>{__('Generic', 'with')} <b>{$max|html}</b> {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.</p>
</div>
</div> </div>
</div> {/if}
{/if} {/if}

View File

@ -2,7 +2,7 @@
{$best_choices = [0]} {$best_choices = [0]}
{/if} {/if}
<h3>{__('Poll results', 'Votes of the poll')}</h3> <h3>{__('Poll results', 'Votes of the poll')} {if $hidden}<i>({__('PollInfo', 'Results are hidden.')})</i>{/if}</h3>
<div id="tableContainer" class="tableContainer"> <div id="tableContainer" class="tableContainer">
<form action="{poll_url id=$poll_id}" method="POST" id="poll_form"> <form action="{poll_url id=$poll_id}" method="POST" id="poll_form">
@ -115,7 +115,7 @@
</td> </td>
{/foreach} {/foreach}
<td style="padding:5px"><button type="submit" class="btn btn-success btn-xs" name="save" value="{$vote->id|html}" title="{__('Poll results', 'Save the choices')} {$vote->name|html}">{__('Generic', 'Save')}</button></td> <td style="padding:5px"><button type="submit" class="btn btn-success btn-xs" name="save" value="{$vote->id|html}" title="{__('Poll results', 'Save the choices')} {$vote->name|html}">{__('Generic', 'Save')}</button></td>
{else} {elseif !$hidden}
{* Voted line *} {* Voted line *}
@ -193,57 +193,60 @@
</tr> </tr>
{/if} {/if}
{* Line displaying best moments *} {if !$hidden}
{$count_bests = 0} {* Line displaying best moments *}
{$max = max($best_choices)} {$count_bests = 0}
{if $max > 0} {$max = max($best_choices)}
<tr id="addition"> {if $max > 0}
<td>{__('Poll results', 'Addition')}</td> <tr id="addition">
{foreach $best_choices as $best_moment} <td>{__('Poll results', 'Addition')}</td>
{if $max == $best_moment} {foreach $best_choices as $best_moment}
{$count_bests = $count_bests +1} {if $max == $best_moment}
<td><i class="glyphicon glyphicon-star text-warning"></i>{$best_moment|html}</td> {$count_bests = $count_bests +1}
{elseif $best_moment > 0} <td><i class="glyphicon glyphicon-star text-warning"></i>{$best_moment|html}</td>
<td>{$best_moment|html}</td> {elseif $best_moment > 0}
{else} <td>{$best_moment|html}</td>
<td></td> {else}
{/if} <td></td>
{/foreach} {/if}
</tr> {/foreach}
</tr>
{/if}
{/if} {/if}
</tbody> </tbody>
</table> </table>
</form> </form>
</div> </div>
{* Best votes listing *} {if !$hidden}
{* Best votes listing *}
{$max = max($best_choices)} {$max = max($best_choices)}
{if $max > 0} {if $max > 0}
<div class="row"> <div class="row">
{if $count_bests == 1} {if $count_bests == 1}
<div class="col-sm-12"><h3>{__('Poll results', 'Best choice')}</h3></div> <div class="col-sm-12"><h3>{__('Poll results', 'Best choice')}</h3></div>
<div class="col-sm-6 col-sm-offset-3 alert alert-success">
<p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The best choice at this time is:')}</p>
{elseif $count_bests > 1}
<div class="col-sm-12"><h3>{__('Poll results', 'Best choices')}</h3></div>
<div class="col-sm-6 col-sm-offset-3 alert alert-success"> <div class="col-sm-6 col-sm-offset-3 alert alert-success">
<p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The bests choices at this time are:')}</p> <p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The best choice at this time is:')}</p>
{/if} {elseif $count_bests > 1}
<div class="col-sm-12"><h3>{__('Poll results', 'Best choices')}</h3></div>
<div class="col-sm-6 col-sm-offset-3 alert alert-success">
<p><span class="glyphicon glyphicon-star text-warning"></span>{__('Poll results', 'The bests choices at this time are:')}</p>
{/if}
{$i = 0} {$i = 0}
<ul style="list-style:none"> <ul style="list-style:none">
{foreach $slots as $slot} {foreach $slots as $slot}
{foreach $slot->moments as $moment} {foreach $slot->moments as $moment}
{if $best_choices[$i] == $max} {if $best_choices[$i] == $max}
<li><strong>{$slot->day|date_format:$date_format.txt_full|html} - {$moment|html}</strong></li> <li><strong>{$slot->day|date_format:$date_format.txt_full|html} - {$moment|html}</strong></li>
{/if} {/if}
{$i = $i+1} {$i = $i+1}
{/foreach}
{/foreach} {/foreach}
{/foreach} </ul>
</ul> <p>{__('Generic', 'with')} <b>{$max|html}</b> {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.</p>
<p>{__('Generic', 'with')} <b>{$max|html}</b> {if $max==1}{__('Generic', 'vote')}{else}{__('Generic', 'votes')}{/if}.</p> </div>
</div> </div>
</div> {/if}
{/if} {/if}