Fix progress bar formating.
authorVimal Joseph <vimal.joseph@zyxware.com>
Tue, 16 Dec 2014 15:07:51 +0000 (20:37 +0530)
committerVimal Joseph <vimal.joseph@zyxware.com>
Tue, 16 Dec 2014 15:08:12 +0000 (20:38 +0530)
Changed the position of the progress bar caption. Now it is just beneath the progressbar.
Removed starting amount from the template.
Now negative amounts are allowed for starting amount.
Formated the amount raised and goal amount.

CRM/Wci/BAO/ProgressBar.php
CRM/Wci/Form/ProgressBar.php
CRM/Wci/Upgrader.php
sql/install.sql
templates/CRM/Wci/Page/WCIWidget.tpl

index 182b7d62b2af8e6ca173ad79d959dc1af672b2fc..00964505713d68afb9be51cbb39f894725880dc5 100644 (file)
@@ -112,15 +112,13 @@ class CRM_Wci_BAO_ProgressBar extends CRM_Wci_DAO_ProgressBar {
 
   public static function getProgressbarData($pbId, &$pbData) {
     if(0 != $pbId) {
-      $pbInfo = array();
-      $pbData["pb_percentage"] = CRM_Wci_BAO_ProgressBar::getProgressbarPercentage($pbId, $pbInfo);
-      $pbData["starting_amount"] = floor($pbInfo['starting_amount']);
-      $pbData["goal_amount"] = ceil($pbInfo['goal_amount']);
-
-      ($pbData["show_pb_perc"]) ? $pbData["pb_caption"] = $pbData["pb_percentage"]
-        : $pbData["pb_caption"] = CRM_Wci_BAO_ProgressBar::getPBCollectedAmount($pbId)
-        + $pbData["starting_amount"];
-
+      $pbInfo = CRM_Wci_BAO_ProgressBar::getProgressbarInfo($pbId);
+      $amount_collected = CRM_Wci_BAO_ProgressBar::getPBCollectedAmount($pbId);
+      $amount_raised = $amount_collected + $pbInfo['starting_amount'];
+      $goal = $pbInfo['goal_amount'];
+      $pbData['pb_collected'] = $amount_raised;
+      $pbData["pb_percentage"] = ($amount_raised / $goal) * 100;
+      $pbData["goal_amount"] = $goal;
       $pbData["no_pb"] = False;
     } else {
       $pbData["no_pb"] = True;
index 55acfa88fdc5a5decc21279a8c492c70476d7337..4c3da1fead659301707adf6c11fcba43d9a03ebf 100644 (file)
@@ -49,15 +49,13 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
 
       $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
 
-      while ($dao->fetch()) {
-        $con_page[$dao->id] = array();
-        CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
+      if ($dao->fetch()) {
         $this->setDefaults(array(
-              'progressbar_name' => $con_page[$dao->id]['name']));
+          'progressbar_name' => $dao->name));
         $this->setDefaults(array(
-              'starting_amount' => $con_page[$dao->id]['starting_amount']));
+          'starting_amount' => $dao->starting_amount));
         $this->setDefaults(array(
-              'goal_amount' => $con_page[$dao->id]['goal_amount']));
+          'goal_amount' => $dao->goal_amount));
       }
 
       $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =%1";
index 4188ee1e83bb92d91c9e77846b71e49a717fbc9f..43c3b61a6707d852b3615f3b711c2b8555a7d3a9 100644 (file)
@@ -113,4 +113,13 @@ class CRM_Wci_Upgrader extends CRM_Wci_Upgrader_Base {
     return TRUE;
   }
 
+  public function upgrade_1003() {
+    $this->ctx->log->info('Applying update to allow -ve values to sarting amount');
+    CRM_Core_DAO::executeQuery('
+      ALTER TABLE `civicrm_wci_progress_bar`
+      CHANGE `starting_amount` `starting_amount` FLOAT NULL DEFAULT NULL
+      COMMENT "Arbitrary starting amount for progress bar."'
+    );
+    return TRUE;
+  }
 }
index 8bb280406694f8b52acbb8f1304b90fbf23b3d81..c20c27fcf475644c4ca135c541d7262ca22d772e 100644 (file)
@@ -2,7 +2,7 @@
 CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar (
   id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Custom Progress bar Id.',
   name varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Name of progress bar.',
-  starting_amount float unsigned NULL COMMENT 'Arbitrary starting amount for progress bar.',
+  starting_amount float NULL COMMENT 'Arbitrary starting amount for progress bar.',
   goal_amount float unsigned NULL COMMENT 'Goal amount for progress bar.',
   PRIMARY KEY (`id`),
   UNIQUE KEY `unique_wci_name` (`name`)
index cf089e2ced2d8e0c55d91327115364d1b528804c..f43550e0f431a0af887141b87efa03e9942e2635 100644 (file)
@@ -73,7 +73,6 @@
         -khtml-border-radius:   4px;
         border-radius:      4px;
         margin-top:.8em;
-        margin-bottom:.8em;
         /*text-align:left;*/
         margin-left: auto;
         margin-right: auto;
         -khtml-border-radius:   4px;
         border-radius:      4px;
         text-align:left;
-        width: {/literal}{$wciform.pb_percentage}{literal}%; /* progress bar percentage */
+        {/literal}
+        {if $wciform.pb_percentage > 100}
+          width:100%
+        {else}
+          width:{$wciform.pb_percentage}%
+        {/if}
+        {literal}
     }
     .crm-amount-raised-wrapper {
         margin-bottom:.8em;
     </div>
   {/if}
   {if false == $wciform.no_pb}
-  {if (false == $wciform.hide_pbcap)}
+    <div class="crm-amount-bar">
+        <div class="crm-amount-fill" id="crm_wid_{$wciform.widgetId}_amt_fill"></div>
+    </div>
+    {if (false == $wciform.hide_pbcap)}
     <div class="crm-amounts">
-        <div id="crm_wid_{$wciform.widgetId}_amt_hi" class="crm-amount-high">${$wciform.goal_amount}</div>
-        <div id="crm_wid_{$wciform.widgetId}_amt_low" class="crm-amount-low">${$wciform.starting_amount}</div>
+        <div id="crm_wid_{$wciform.widgetId}_amt_hi" class="crm-amount-high">Goal: ${$wciform.goal_amount|number_format}</div>
         {if (true == $wciform.show_pb_perc)}
-        <div id="crm_wid_{$wciform.widgetId}_percentage" class="crm-percentage">{$wciform.pb_caption}%</div>
+        <div id="crm_wid_{$wciform.widgetId}_low" class="crm-amount-low">{$wciform.pb_percentage}% raised</div>
         {else}
-        <div id="crm_wid_{$wciform.widgetId}_percentage" class="crm-percentage">${$wciform.pb_caption}</div>
+        <div id="crm_wid_{$wciform.widgetId}_low" class="crm-amount-low">${$wciform.pb_collected|number_format} raised</div>
         {/if}
     </div>
   {/if}
-    <div class="crm-amount-bar">
-        <div class="crm-amount-fill" id="crm_wid_{$wciform.widgetId}_amt_fill"></div>
-    </div>
     <div id="crm_wid_{$wciform.widgetId}_donors" class="crm-donors">
     </div>
     {/if}