3 +--------------------------------------------------------------------+
4 | CiviCRM Widget Creation Interface (WCI) Version 1.0 |
5 +--------------------------------------------------------------------+
6 | Copyright Zyxware Technologies (c) 2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM WCI. |
10 | CiviCRM WCI is free software; you can copy, modify, and distribute |
11 | it under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
14 | CiviCRM WCI is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact Zyxware |
21 | Technologies at info[AT]zyxware[DOT]com. |
22 +--------------------------------------------------------------------+
28 * @copyright CiviCRM LLC (c) 2004-2013
31 require_once 'CRM/Wci/DAO/ProgressBar.php';
33 class CRM_Wci_BAO_ProgressBar
extends CRM_Wci_DAO_ProgressBar
{
36 * Returns array of progressbars
37 * Fields : id, name, starting_amount, goal_amount
38 * @return progressbar array
41 public static function getProgressbarList() {
42 $query = "SELECT * FROM civicrm_wci_progress_bar";
46 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
48 while ($dao->fetch()) {
49 $pbList[$dao->id
] = array();
50 CRM_Core_DAO
::storeValues($dao, $pbList[$dao->id
]);
57 * Returns percentage value of a progressbar
58 * @param integer progressbar id
59 * @return decimal percentage value
62 public static function getPBCollectedAmount($pbId) {
64 $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $pbId;
67 $daoPbf = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBarFormula');
68 while ($daoPbf->fetch()) {
69 $for_page[$daoPbf->id
] = array();
70 CRM_Core_DAO
::storeValues($daoPbf, $for_page[$daoPbf->id
]);
71 $px = $for_page[$daoPbf->id
]['percentage'];
73 $query = "SELECT * FROM civicrm_contribution where contribution_page_id =" . $for_page[$daoPbf->id
]['contribution_page_id'];
76 $daoCon = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_Contribution');
78 while ($daoCon->fetch()) {
79 $contributions[$daoCon->id
] = array();
80 CRM_Core_DAO
::storeValues($daoCon, $contributions[$daoCon->id
]);
81 $bx = $contributions[$daoCon->id
]['total_amount'];
83 $bp +
= $bx * $px / 100;
89 public static function getProgressbarInfo($pbId) {
91 $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $pbId;
94 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
96 while ($dao->fetch()) {
97 $con_page[$dao->id
] = array();
98 CRM_Core_DAO
::storeValues($dao, $con_page[$dao->id
]);
99 $pbInfo['name'] = $con_page[$dao->id
]['name'];
100 $pbInfo['starting_amount'] = $con_page[$dao->id
]['starting_amount'];
101 $pbInfo['goal_amount'] = $con_page[$dao->id
]['goal_amount'];
107 public static function getProgressbarPercentage($pbId, &$pbInfo) {
109 $pbInfo = CRM_Wci_BAO_ProgressBar
::getProgressbarInfo($pbId);
110 $ga = $pbInfo['goal_amount'];
111 $currAmnt = CRM_Wci_BAO_ProgressBar
::getPBCollectedAmount($pbId)
112 +
$pbInfo['starting_amount'];
113 (0 == $ga) ?
$currAmt = 0: $perc = ($currAmnt / $ga ) * 100;
121 public static function getProgressbarData($pbId, &$pbData) {
124 $pbData["pb_percentage"] = CRM_Wci_BAO_ProgressBar
::getProgressbarPercentage($pbId, $pbInfo);
125 $pbData["starting_amount"] = floor($pbInfo['starting_amount']);
126 $pbData["goal_amount"] = ceil($pbInfo['goal_amount']);
128 ($pbData["show_pb_perc"]) ?
$pbData["pb_caption"] = $pbData["pb_percentage"]
129 : $pbData["pb_caption"] = CRM_Wci_BAO_ProgressBar
::getPBCollectedAmount($pbId)
130 +
$pbData["starting_amount"];
132 $pbData["no_pb"] = False;
134 $pbData["no_pb"] = True;