From 6364e1a18a072d1a299bfc3f46323a1b3f37655a Mon Sep 17 00:00:00 2001 From: Vimal Joseph Date: Tue, 16 Dec 2014 20:37:51 +0530 Subject: [PATCH] Fix progress bar formating. 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 | 16 +++++++--------- CRM/Wci/Form/ProgressBar.php | 10 ++++------ CRM/Wci/Upgrader.php | 9 +++++++++ sql/install.sql | 2 +- templates/CRM/Wci/Page/WCIWidget.tpl | 24 ++++++++++++++---------- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/CRM/Wci/BAO/ProgressBar.php b/CRM/Wci/BAO/ProgressBar.php index 182b7d6..0096450 100644 --- a/CRM/Wci/BAO/ProgressBar.php +++ b/CRM/Wci/BAO/ProgressBar.php @@ -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; diff --git a/CRM/Wci/Form/ProgressBar.php b/CRM/Wci/Form/ProgressBar.php index 55acfa8..4c3da1f 100644 --- a/CRM/Wci/Form/ProgressBar.php +++ b/CRM/Wci/Form/ProgressBar.php @@ -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"; diff --git a/CRM/Wci/Upgrader.php b/CRM/Wci/Upgrader.php index 4188ee1..43c3b61 100644 --- a/CRM/Wci/Upgrader.php +++ b/CRM/Wci/Upgrader.php @@ -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; + } } diff --git a/sql/install.sql b/sql/install.sql index 8bb2804..c20c27f 100644 --- a/sql/install.sql +++ b/sql/install.sql @@ -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`) diff --git a/templates/CRM/Wci/Page/WCIWidget.tpl b/templates/CRM/Wci/Page/WCIWidget.tpl index cf089e2..f43550e 100644 --- a/templates/CRM/Wci/Page/WCIWidget.tpl +++ b/templates/CRM/Wci/Page/WCIWidget.tpl @@ -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; @@ -89,7 +88,13 @@ -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; @@ -221,20 +226,19 @@ {/if} {if false == $wciform.no_pb} - {if (false == $wciform.hide_pbcap)} +
+
+
+ {if (false == $wciform.hide_pbcap)}
-
${$wciform.goal_amount}
-
${$wciform.starting_amount}
+
Goal: ${$wciform.goal_amount|number_format}
{if (true == $wciform.show_pb_perc)} -
{$wciform.pb_caption}%
+
{$wciform.pb_percentage}% raised
{else} -
${$wciform.pb_caption}
+
${$wciform.pb_collected|number_format} raised
{/if}
{/if} -
-
-
{/if} -- 2.25.1