[Jaws-commits] r12454 - in branches/0.8/html/gadgets/Poll: . languages templates

afz at jaws-project.com afz at jaws-project.com
Fri Jan 20 21:04:42 UTC 2012


Author: afz
Date: 2012-01-20 21:04:41 +0000 (Fri, 20 Jan 2012)
New Revision: 12454

Modified:
   branches/0.8/html/gadgets/Poll/LayoutHTML.php
   branches/0.8/html/gadgets/Poll/languages/en.php
   branches/0.8/html/gadgets/Poll/languages/fa.php
   branches/0.8/html/gadgets/Poll/templates/Poll.html
Log:
ticket #993 implemented

Modified: branches/0.8/html/gadgets/Poll/LayoutHTML.php
===================================================================
--- branches/0.8/html/gadgets/Poll/LayoutHTML.php	2012-01-19 14:40:19 UTC (rev 12453)
+++ branches/0.8/html/gadgets/Poll/LayoutHTML.php	2012-01-20 21:04:41 UTC (rev 12454)
@@ -133,44 +133,54 @@
         $tpl->Load('Poll.html');
         $tpl->SetBlock('Poll');
         $tpl->SetVariable('title', _t('POLL_ACTION_POLL_TITLE'));
-        $tpl->SetVariable('base_script', BASE_SCRIPT);
 
         $xss = $GLOBALS['app']->loadClass('XSS', 'Jaws_XSS');
         $tpl->SetVariable('pid', $poll['id']);
         $tpl->SetVariable('question', $xss->filter($poll['question']));
-        $btnVote =& Piwi::CreateWidget('Button', 'btn_vote', _t('POLL_POLLS_VOTE'));
-        $btnVote->SetSubmit();
-        $tpl->SetVariable('btn_vote', $btnVote->Get());
+        $voting = ($poll['poll_type'] == 1) || (!Jaws_Session_Web::GetCookie('poll_'.$poll['id']));
+        if ($voting || $poll['result_view']) {
+            //print the answers or results
+            $answers = $model->GetPollAnswers($poll['id']);
+            if (!Jaws_Error::IsError($answers)) {
+                $block = $voting? 'answer' : 'result';
+                $total_votes = array_sum(array_map(create_function('$row','return $row["votes"];'), $answers));
+                foreach ($answers as $answer) {
+                    $tpl->SetBlock("Poll/{$block}");
+                    $tpl->SetVariable('aid', $answer['id']);
+                    $tpl->SetVariable('answer', $xss->filter($answer['answer']));
+                    if ($poll['select_type'] == 1) {
+                        $rb = '<input type="checkbox" name="answers[]" id="poll-answer-input-'.
+                              $answer['id'].'" value="' .$answer['id']. '"/>';
+                    } else {
+                        $rb = '<input type="radio" name="answers[]" id="poll-answer-input-'.
+                              $answer['id'].'" value="' .$answer['id']. '"/>';
+                    }
 
-        $link = $GLOBALS['app']->Map->GetURLFor('Poll', 'ViewResult', array('id' => $poll['id']));
-        if ($poll['result_view']) {
-            $viewRes =& Piwi::CreateWidget('Link', _t('POLL_REPORTS_RESULTS'), $link);
-            $tpl->SetVariable('result_link', $viewRes->Get());
-        }
-
-        //print the answers
-        $answers = $model->GetPollAnswers($poll['id']);
-        if (!Jaws_Error::IsError($answers)) {
-            foreach ($answers as $answer) {
-                $tpl->SetBlock('Poll/answer');
-                $tpl->SetVariable('answer', $xss->filter($answer['answer']));
-                $tpl->SetVariable('aid', $answer['id']);
-                if ($poll['select_type'] == 1) {
-                    $rb = '<input type="checkbox" name="answers[]" id="answer_'.$answer['id'].'" value="' .$answer['id']. '"/>';
-                } else {
-                    $rb = '<input type="radio" name="answers[]" id="answer_'.$answer['id'].'" value="' .$answer['id']. '"/>';
+                    $tpl->SetVariable('input', $rb);
+                    $percent = (($total_votes==0)? 0 : floor(($answer['votes']/$total_votes)*100));
+                    $tpl->SetVariable('percent', $percent);
+                    $tpl->SetVariable('txt-percent', _t('POLL_REPORTS_PERCENT', $percent));
+                    $tpl->ParseBlock("Poll/{$block}");
                 }
-                $tpl->SetVariable('input', $rb);
-                $tpl->ParseBlock('Poll/answer');
             }
         }
 
-        if ($poll['poll_type'] == 0) {
-            $tpl->SetBlock('Poll/cookie');
-            $tpl->SetVariable('pid', $poll['id']);
-            $tpl->ParseBlock('Poll/cookie');
+        if ($voting) {
+            $btnVote =& Piwi::CreateWidget('Button', 'btn_vote', _t('POLL_POLLS_VOTE'));
+            $btnVote->SetSubmit();
+            $tpl->SetVariable('btn-vote', $btnVote->Get());
+        } else {
+            $tpl->SetVariable('already-message', _t('POLL_POLLS_ALREADY_VOTED'));
         }
 
+        $link = $GLOBALS['app']->Map->GetURLFor('Poll', 'ViewResult', array('id' => $poll['id']));
+        if ($poll['result_view']) {
+            $viewRes =& Piwi::CreateWidget('Link', _t('POLL_REPORTS_RESULTS'), $link);
+            $tpl->SetVariable('result-link', $viewRes->Get());
+        } else {
+            $tpl->SetVariable('disabled-message', _t('POLL_REPORTS_DISABLED_RESULT'));
+        }
+
         $tpl->ParseBlock('Poll');
         return $tpl->Get();
     }

Modified: branches/0.8/html/gadgets/Poll/languages/en.php
===================================================================
--- branches/0.8/html/gadgets/Poll/languages/en.php	2012-01-19 14:40:19 UTC (rev 12453)
+++ branches/0.8/html/gadgets/Poll/languages/en.php	2012-01-20 21:04:41 UTC (rev 12454)
@@ -44,6 +44,7 @@
 define('_EN_POLL_POLLS_ANSWERS_TITLE', "Edit Answers");
 define('_EN_POLL_POLLS_CONFIRM_DELETE', "Delete this Poll?");
 define('_EN_POLL_POLLS_INCOMPLETE_FIELDS', "Some fields haven't been (correctly) filled in.");
+define('_EN_POLL_POLLS_ALREADY_VOTED', "You have already voted on this poll");
 
 /* Polls Groups Management */
 define('_EN_POLL_GROUPS', "Poll Groups");
@@ -59,6 +60,7 @@
 define('_EN_POLL_REPORTS_RESULTS', "Poll Results");
 define('_EN_POLL_REPORTS_PERCENT', "{0}%");
 define('_EN_POLL_REPORTS_TOTAL_VOTES', "Total Votes");
+define('_EN_POLL_REPORTS_DISABLED_RESULT', "Poll results is disabled");
 
 /* Layout */
 define('_EN_POLL_LAYOUT_DISPLAY_LAST', "Last poll");

Modified: branches/0.8/html/gadgets/Poll/languages/fa.php
===================================================================
--- branches/0.8/html/gadgets/Poll/languages/fa.php	2012-01-19 14:40:19 UTC (rev 12453)
+++ branches/0.8/html/gadgets/Poll/languages/fa.php	2012-01-20 21:04:41 UTC (rev 12454)
@@ -38,6 +38,7 @@
 define('_FA_POLL_POLLS_ANSWERS_TITLE', "ویرایش جوابها");
 define('_FA_POLL_POLLS_CONFIRM_DELETE', "این نظرسنجی حذف شود؟");
 define('_FA_POLL_POLLS_INCOMPLETE_FIELDS', "برخی از فیلدها به درستی کامل نشده‌اند");
+define('_FA_POLL_POLLS_ALREADY_VOTED', "شما قبلا در این نظرسنجی رای داده اید");
 define('_FA_POLL_GROUPS', "دسته‌بندی‌ها");
 define('_FA_POLL_GROUPS_ADD', "دسته‌بندی جدید");
 define('_FA_POLL_GROUPS_ADD_TITLE', "دسته‌بندی جدید");
@@ -49,6 +50,7 @@
 define('_FA_POLL_REPORTS_RESULTS', "نتایج نظرسنجی");
 define('_FA_POLL_REPORTS_PERCENT', "%{0}");
 define('_FA_POLL_REPORTS_TOTAL_VOTES', "مجموع نظرات");
+define('_FA_POLL_REPORTS_DISABLED_RESULT', "نمایش نتایج این نظرسنجی غیرفعال شده است");
 define('_FA_POLL_LAYOUT_DISPLAY_LAST', "نمایش آخرین موضوع نظرسنجی");
 define('_FA_POLL_LAYOUT_DISPLAY_LAST_DESC', "نمایش آخرین نظرسنجی مطرح شده");
 define('_FA_POLL_LAYOUT_LIST_POLLS', "لیست موضوعات نظرسنجی");

Modified: branches/0.8/html/gadgets/Poll/templates/Poll.html
===================================================================
--- branches/0.8/html/gadgets/Poll/templates/Poll.html	2012-01-19 14:40:19 UTC (rev 12453)
+++ branches/0.8/html/gadgets/Poll/templates/Poll.html	2012-01-20 21:04:41 UTC (rev 12454)
@@ -1,26 +1,27 @@
 <!-- BEGIN Poll -->
 <div class="gadget poll">
   <h2>{title}</h2>
-  <form action="{base_script}" name="poll_form_{pid}" method="post">
+  <form action="{base-script}" name="poll_form_{pid}" method="post">
   <div class="content">
     <input type="hidden" name="gadget" value="Poll" />
     <input type="hidden" name="action" value="Vote" />
     <input type="hidden" name="pid" value="{pid}" />
     <h3>{question}</h3>
     <!-- BEGIN answer -->
-    <div>{input}<label for="answer_{aid}">{answer}</label></div>
+    <div class="poll-answer">
+      {input}<label for="poll-answer-input-{aid}">{answer}</label>
+    </div>
     <!-- END answer -->
+    <!-- BEGIN result -->
+    <div class="poll-inline-result" id="poll-answer-{aid}">
+      <label>{answer} - {txt-percent}</label>
+      <div style="width: {percent}%;"></div>
+    </div>
+    <!-- END result -->
+    <div class="poll-message">{already-message}</div>
+    <div class="poll-message">{disabled-message}</div>
   </div>
-  <div class="actions">{result_link} {btn_vote}</div>
+  <div class="actions">{result-link} {btn-vote}</div>
   </form>
-  <!-- BEGIN cookie -->
-  <script type="text/javascript">
-    if (-1 != document.cookie.indexOf('poll_' + {pid})) {
-        document.poll_form_{pid}.onsubmit = function() {
-            return false;
-        }
-    }
-  </script>
-  <!-- END cookie -->
 </div>
 <!-- END Poll -->



More information about the Jaws-commits mailing list