Compute the total number of votes and the participation at the beginning
of the template instead of doing it inside the template itself.

Signed-off-by: Lukas Fleischer <[email protected]>
---
 web/template/tu_details.php | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/web/template/tu_details.php b/web/template/tu_details.php
index 4f291f0..61abab7 100644
--- a/web/template/tu_details.php
+++ b/web/template/tu_details.php
@@ -1,3 +1,12 @@
+<?php
+$yes = $row["Yes"];
+$no = $row["No"];
+$abstain = $row["Abstain"];
+$active_tus = $row["ActiveTUs"];
+
+$total = $yes + $no + $abstain;
+$participation = $total / $active_tus;
+?>
 <div class="box">
        <h2><?= __("Proposal Details") ?></h2>
 
@@ -37,10 +46,10 @@
                        <th><?= __('Participation') ?></th>
                </tr>
                <tr>
-                       <td><?= $row['Yes'] ?></td>
-                       <td><?= $row['No'] ?></td>
-                       <td><?= $row['Abstain'] ?></td>
-                       <td><?= ($row['Yes'] + $row['No'] + $row['Abstain']) 
?></td>
+                       <td><?= $yes ?></td>
+                       <td><?= $no ?></td>
+                       <td><?= $abstain ?></td>
+                       <td><?= $total ?></td>
                        <td>
                                <?php if ($hasvoted == 0): ?>
                                <span style="color: red; font-weight: bold"><?= 
__("No") ?></span>
@@ -48,8 +57,8 @@
                                <span style="color: green; font-weight: 
bold"><?= __("Yes") ?></span>
                                <?php endif; ?>
                        </td>
-                       <?php if ($row['ActiveTUs'] > 0): ?>
-                       <td><?= number_format(($row['Yes'] + $row['No'] + 
$row['Abstain']) / $row['ActiveTUs'] * 100, 2) ?>%</td>
+                       <?php if ($active_tus > 0): ?>
+                       <td><?= number_format($participation * 100, 2) ?>%</td>
                        <?php else: ?>
                        <td><?= __("unknown") ?></td>
                        <?php endif; ?>
-- 
1.8.4.rc3.500.gc3113b0

Reply via email to