Commit | Line | Data |
---|---|---|
1720f579 M |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.4 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * | |
33 | */ | |
82ba21f9 | 34 | require_once 'CRM/Wci/DAO/ProgressBar.php'; |
1720f579 | 35 | |
e364fc74 | 36 | class CRM_Wci_BAO_ProgressBar extends CRM_Wci_DAO_ProgressBar { |
1720f579 | 37 | |
f00a3ea9 J |
38 | /** |
39 | * Returns array of progressbars | |
40 | * Fields : id, name, starting_amount, goal_amount | |
41 | * @return progressbar array | |
42 | * @access public | |
43 | */ | |
44 | public static function getProgressbarList() { | |
45 | $query = "SELECT * FROM civicrm_wci_progress_bar"; | |
46 | $params = array(); | |
47 | $pbList = array(); | |
48 | ||
e364fc74 | 49 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar'); |
f00a3ea9 J |
50 | |
51 | while ($dao->fetch()) { | |
52 | $pbList[$dao->id] = array(); | |
53 | CRM_Core_DAO::storeValues($dao, $pbList[$dao->id]); | |
54 | } | |
55 | ||
56 | return $pbList; | |
57 | } | |
58 | ||
0a3819f8 J |
59 | /** |
60 | * Returns percentage value of a progressbar | |
0a3819f8 | 61 | * @param integer progressbar id |
0a3819f8 J |
62 | * @return decimal percentage value |
63 | * @access public | |
64 | */ | |
94f5fffd | 65 | public static function getPBCollectedAmount($pbId) { |
47101c83 | 66 | $bp = 0; |
94f5fffd | 67 | $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $pbId; |
47101c83 J |
68 | $params = array(); |
69 | ||
e364fc74 | 70 | $daoPbf = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBarFormula'); |
47101c83 J |
71 | while ($daoPbf->fetch()) { |
72 | $for_page[$daoPbf->id] = array(); | |
73 | CRM_Core_DAO::storeValues($daoPbf, $for_page[$daoPbf->id]); | |
47101c83 | 74 | $px = $for_page[$daoPbf->id]['percentage']; |
47101c83 J |
75 | |
76 | $query = "SELECT * FROM civicrm_contribution where contribution_page_id =" . $for_page[$daoPbf->id]['contribution_page_id']; | |
77 | $params = array(); | |
78 | ||
47101c83 J |
79 | $daoCon = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_Contribution'); |
80 | ||
81 | while ($daoCon->fetch()) { | |
82 | $contributions[$daoCon->id] = array(); | |
83 | CRM_Core_DAO::storeValues($daoCon, $contributions[$daoCon->id]); | |
84 | $bx = $contributions[$daoCon->id]['total_amount']; | |
0a3819f8 | 85 | |
47101c83 J |
86 | $bp += $bx * $px / 100; |
87 | } | |
88 | } | |
94f5fffd J |
89 | return floor($bp); |
90 | } | |
91 | ||
92 | public static function getProgressbarInfo($pbId) { | |
93 | $ga = 0; | |
94 | $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $pbId; | |
95 | $params = array(); | |
96 | $pbInfo = array(); | |
97 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar'); | |
98 | ||
99 | while ($dao->fetch()) { | |
100 | $con_page[$dao->id] = array(); | |
101 | CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]); | |
102 | $pbInfo['name'] = $con_page[$dao->id]['name']; | |
103 | $pbInfo['starting_amount'] = $con_page[$dao->id]['starting_amount']; | |
104 | $pbInfo['goal_amount'] = $con_page[$dao->id]['goal_amount']; | |
105 | } | |
106 | ||
107 | return $pbInfo; | |
108 | } | |
109 | public static function getProgressbarPercentage($pbId, &$pbInfo) { | |
110 | ||
111 | $pbInfo = CRM_Wci_BAO_ProgressBar::getProgressbarInfo($pbId); | |
112 | $ga = $pbInfo['goal_amount']; | |
113 | $currAmnt = CRM_Wci_BAO_ProgressBar::getPBCollectedAmount($pbId) | |
114 | + $pbInfo['starting_amount']; | |
115 | (0 == $ga) ? $currAmt = 0: $perc = ($currAmnt / $ga ) * 100; | |
116 | if (100 < $perc){ | |
117 | $perc = 100; | |
118 | } | |
119 | ||
120 | return floor($perc); | |
47101c83 | 121 | } |
d6f51b17 J |
122 | public static function getProgressbarData($pbId, &$pbData) { |
123 | if(0 != $pbId) { | |
94f5fffd J |
124 | $pbInfo = array();//CRM_Wci_BAO_ProgressBar::getProgressbarInfo($pbId); |
125 | $pbData["pb_percentage"] = CRM_Wci_BAO_ProgressBar::getProgressbarPercentage($pbId, $pbInfo); | |
126 | $pbData["starting_amount"] = floor($pbInfo['starting_amount']); | |
127 | $pbData["goal_amount"] = ceil($pbInfo['goal_amount']); | |
d6f51b17 | 128 | |
94f5fffd J |
129 | ($pbData["show_pb_perc"]) ? $pbData["pb_caption"] = $pbData["pb_percentage"] |
130 | : $pbData["pb_caption"] = CRM_Wci_BAO_ProgressBar::getPBCollectedAmount($pbId) | |
131 | + $pbData["starting_amount"]; | |
132 | ||
d6f51b17 J |
133 | $pbData["no_pb"] = False; |
134 | } else { | |
135 | $pbData["no_pb"] = True; | |
143ff5a2 | 136 | } |
d6f51b17 | 137 | |
143ff5a2 J |
138 | return $pbData; |
139 | } | |
1720f579 | 140 | } |