3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | 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 and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
34 require_once 'CRM/Wci/DAO/ProgressBar.php';
36 class CRM_WCI_BAO_ProgressBar
extends CRM_WCI_DAO_ProgressBar
{
41 function __construct() {
42 parent
::__construct();
46 * Function to create a ProgressBar
47 * takes an associative array and creates a ProgressBar object
49 * This function is invoked from within the web form layer and also from the api layer
51 * @param array $params (reference ) an assoc array of name/value pairs
53 * @return object CRM_WCI_BAO_ProgressBar object
57 static function create(array $params) {
59 // check required params
60 if (!self
::dataExists($params)) {
61 CRM_Core_Error
::fatal('Not enough data to create a progress bar.');
64 $progress_bar = new CRM_WCI_BAO_ProgressBar();
65 $progress_bar->copyValues($params);
67 $progress_bar->save();
73 * Get a list of Widgets matching the params, where params keys are column
74 * names of civicrm_wci_widget.
76 * @param array $params
77 * @return array of CRM_WCI_BAO_ProgressBar objects
79 static function retrieve(array $params) {
82 $progress_bar = new CRM_WCI_BAO_ProgressBar();
83 $progress_bar->copyValues($params);
84 $progress_bar->find();
86 while ($progress_bar->fetch()) {
87 $result[(int) $progress_bar->id
] = clone $progress_bar;
90 $progress_bar->free();
96 * Wrapper method for retrieve
98 * @param mixed $id Int or int-like string representing widget ID
99 * @return CRM_WCI_BAO_ProgressBar
101 static function retrieveByID($id) {
102 if (!is_int($id) && !ctype_digit($id)) {
103 CRM_Core_Error
::fatal(__CLASS__
. '::' . __FUNCTION__
. ' expects an integer.');
107 $progress_bars = self
::retrieve(array('id' => $id));
109 if (!array_key_exists($id, $progress_bars)) {
110 CRM_Core_Error
::fatal("No Progress bar with ID $id exists.");
113 return $progress_bars[$id];
117 * Check if there is absolute minimum of data to add the object
119 * @param array $params (reference ) an assoc array of name/value pairs
124 public static function dataExists($params) {
125 if (CRM_Utils_Array
::value('name', $params)) {
131 public static function getProgressbarPercentage($idPB) {
133 $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $idPB;
135 //echo $query."<br>";
136 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBar');
138 while ($dao->fetch()) {
139 $con_page[$dao->id
] = array();
140 CRM_Core_DAO
::storeValues($dao, $con_page[$dao->id
]);
141 $con_page[$dao->id
]['name'];
142 $sa = $con_page[$dao->id
]['starting_amount'];
143 //echo "stat amount ".$sa.'<br>';
144 $ga = $con_page[$dao->id
]['goal_amount'];
145 //echo "goal amt ".$ga.'<br>';
148 $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $idPB;
151 //echo $query."<br>";
152 $daoPbf = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBarFormula');
153 while ($daoPbf->fetch()) {
154 $for_page[$daoPbf->id
] = array();
155 CRM_Core_DAO
::storeValues($daoPbf, $for_page[$daoPbf->id
]);
156 //echo "contribution_page_id ".$for_page[$daoPbf->id]['contribution_page_id'].'<br>';
157 $px = $for_page[$daoPbf->id
]['percentage'];
158 //echo "percentage ".$px.'<br>';
160 $query = "SELECT * FROM civicrm_contribution where contribution_page_id =" . $for_page[$daoPbf->id
]['contribution_page_id'];
163 //echo $query."<br>";
164 $daoCon = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_Contribution');
166 while ($daoCon->fetch()) {
167 $contributions[$daoCon->id
] = array();
168 CRM_Core_DAO
::storeValues($daoCon, $contributions[$daoCon->id
]);
169 $bx = $contributions[$daoCon->id
]['total_amount'];
170 //echo "total_amount".$bx ."<br>";
171 //echo "status".$contributions[$daoCon->id]['contribution_status_id'] ."<br>";
172 $bp +
= $bx * $px / 100;
175 $perc = (($sa +
$bp) / $ga ) * 100;
176 //echo "percentate " . . "<br>";