Display the count of 'if need be'

This commit is contained in:
Olivier PEREZ 2015-04-23 23:18:31 +02:00
parent 7ed21ce9fa
commit 551b839292
4 changed files with 25 additions and 18 deletions

View File

@ -20,9 +20,8 @@ namespace Framadate\Services;
use Framadate\Form; use Framadate\Form;
use Framadate\FramaDB; use Framadate\FramaDB;
use Framadate\Utils;
use Framadate\Security\Token;
use Framadate\Repositories\RepositoryFactory; use Framadate\Repositories\RepositoryFactory;
use Framadate\Security\Token;
class PollService { class PollService {
@ -117,15 +116,19 @@ class PollService {
} }
function computeBestChoices($votes) { function computeBestChoices($votes) {
$result = []; $result = ['y' => [0], 'inb' => [0]];
foreach ($votes as $vote) { foreach ($votes as $vote) {
$choices = str_split($vote->choices); $choices = str_split($vote->choices);
foreach ($choices as $i => $choice) { foreach ($choices as $i => $choice) {
if (empty($result[$i])) { if (!isset($result['y'][$i])) {
$result[$i] = 0; $result['inb'][$i] = 0;
$result['y'][$i] = 0;
}
if ($choice == 1) {
$result['inb'][$i]++;
} }
if ($choice == 2) { if ($choice == 2) {
$result[$i]++; $result['y'][$i]++;
} }
} }
} }

View File

@ -88,6 +88,10 @@ header h1 {
border-radius: 2px; border-radius: 2px;
} }
.very-small {
font-size: 70%;
}
/* Effet sur les images en page d'accueil */ /* Effet sur les images en page d'accueil */
.opacity img { .opacity img {
opacity: 0.8; opacity: 0.8;

View File

@ -154,16 +154,16 @@
{if !$hidden} {if !$hidden}
{* Line displaying best moments *} {* Line displaying best moments *}
{$count_bests = 0} {$count_bests = 0}
{$max = max($best_choices)} {$max = max($best_choices['y'])}
{if $max > 0} {if $max > 0}
<tr id="addition"> <tr id="addition">
<td>{__('Poll results', 'Addition')}</td> <td>{__('Poll results', 'Addition')}</td>
{foreach $best_choices as $best_choice} {foreach $best_choices['y'] as $i=>$best_choice}
{if $max == $best_choice} {if $max == $best_choice}
{$count_bests = $count_bests +1} {$count_bests = $count_bests +1}
<td><span class="glyphicon glyphicon-star text-warning"></span>{$best_choice|html}</td> <td><span class="glyphicon glyphicon-star text-warning"></span>{$best_choice|html}{if $best_choices['inb'][$i]>0}<span class="very-small text-muted"> (+{$best_choices['inb'][$i]|html})</span>{/if}</td>
{elseif $best_choice > 0} {elseif $best_choice > 0}
<td>{$best_choice|html}</td> <td>{$best_choice|html}{if $best_choices['inb'][$i]>0}<span class="very-small text-muted"> (+{$best_choices['inb'][$i]|html})</span>{/if}</td>
{else} {else}
<td></td> <td></td>
{/if} {/if}
@ -178,7 +178,7 @@
{if !$hidden} {if !$hidden}
{* Best votes listing *} {* Best votes listing *}
{$max = max($best_choices)} {$max = max($best_choices['y'])}
{if $max > 0} {if $max > 0}
<div class="row"> <div class="row">
{if $count_bests == 1} {if $count_bests == 1}
@ -195,7 +195,7 @@
{$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['y'][$i] == $max}
<li><strong>{$slot->title|markdown:true}</strong></li> <li><strong>{$slot->title|markdown:true}</strong></li>
{/if} {/if}
{$i = $i+1} {$i = $i+1}

View File

@ -207,16 +207,16 @@
{if !$hidden} {if !$hidden}
{* Line displaying best moments *} {* Line displaying best moments *}
{$count_bests = 0} {$count_bests = 0}
{$max = max($best_choices)} {$max = max($best_choices['y'])}
{if $max > 0} {if $max > 0}
<tr id="addition"> <tr id="addition">
<td>{__('Poll results', 'Addition')}</td> <td>{__('Poll results', 'Addition')}</td>
{foreach $best_choices as $best_moment} {foreach $best_choices['y'] as $i=>$best_moment}
{if $max == $best_moment} {if $max == $best_moment}
{$count_bests = $count_bests +1} {$count_bests = $count_bests +1}
<td><i class="glyphicon glyphicon-star text-warning"></i>{$best_moment|html}</td> <td class="text-danger"><i class="glyphicon glyphicon-star text-warning"></i>{$best_moment|html}{if $best_choices['inb'][$i]>0}<span class="very-small text-muted"> (+{$best_choices['inb'][$i]|html})</span>{/if}</td>
{elseif $best_moment > 0} {elseif $best_moment > 0}
<td>{$best_moment|html}</td> <td>{$best_moment|html}{if $best_choices['inb'][$i]>0}<span class="very-small text-muted"> (+{$best_choices['inb'][$i]|html})</span>{/if}</td>
{else} {else}
<td></td> <td></td>
{/if} {/if}
@ -231,7 +231,7 @@
{if !$hidden} {if !$hidden}
{* Best votes listing *} {* Best votes listing *}
{$max = max($best_choices)} {$max = max($best_choices['y'])}
{if $max > 0} {if $max > 0}
<div class="row"> <div class="row">
{if $count_bests == 1} {if $count_bests == 1}
@ -249,7 +249,7 @@
<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['y'][$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}