3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * Class to retrieve information about a contribution page
39 class CRM_Contribute_BAO_Widget
extends CRM_Contribute_DAO_Widget
{
42 * Gets all campaign related data and returns it as a std class.
44 * @param int $contributionPageID
45 * @param string $widgetID
49 public static function getContributionPageData($contributionPageID, $widgetID) {
50 $config = CRM_Core_Config
::singleton();
53 $data['currencySymbol'] = $config->defaultCurrencySymbol
;
55 if (empty($contributionPageID) ||
56 CRM_Utils_Type
::validate($contributionPageID, 'Integer') == NULL
58 $data['is_error'] = TRUE;
59 CRM_Core_Error
::debug_log_message("$contributionPageID is not set");
63 $widget = new CRM_Contribute_DAO_Widget();
64 $widget->contribution_page_id
= $contributionPageID;
65 if (!$widget->find(TRUE)) {
66 $data['is_error'] = TRUE;
67 CRM_Core_Error
::debug_log_message("$contributionPageID is not found");
71 $data['is_error'] = FALSE;
72 if (!$widget->is_active
) {
73 $data['is_active'] = FALSE;
76 $data['is_active'] = TRUE;
77 $data['title'] = $widget->title
;
78 $data['logo'] = $widget->url_logo
;
79 $data['button_title'] = $widget->button_title
;
80 $data['about'] = $widget->about
;
83 SELECT count( id ) as count,
84 sum( total_amount) as amount
85 FROM civicrm_contribution
87 AND contribution_status_id = 1
88 AND contribution_page_id = %1";
89 $params = array(1 => array($contributionPageID, 'Integer'));
90 $dao = CRM_Core_DAO
::executeQuery($query, $params);
92 $data['num_donors'] = (int)$dao->count
;
93 $data['money_raised'] = (int)$dao->amount
;
96 $data['num_donors'] = $data['money_raised'] = $data->money_raised
= 0;
100 SELECT goal_amount, start_date, end_date, is_active
101 FROM civicrm_contribution_page
103 $params = array(1 => array($contributionPageID, 'Integer'));
104 $dao = CRM_Core_DAO
::executeQuery($query, $params);
106 $data['campaign_start'] = '';
109 $data['money_target'] = (int)$dao->goal_amount
;
111 // conditions that needs to be handled
112 // 1. Campaign is not active - no text
113 // 2. Campaign start date greater than today - show start date
114 // 3. Campaign end date is set and greater than today - show end date
115 // 4. If no start and end date or no end date and start date greater than today, then it's ongoing
116 if ($dao->is_active
) {
117 $data['campaign_start'] = ts('Campaign is ongoing');
119 // check for time being between start and end date
121 if ($dao->start_date
) {
122 $startDate = CRM_Utils_Date
::unixTime($dao->start_date
);
126 $data['is_active'] = FALSE;
127 $data['campaign_start'] = ts('Campaign starts on %1', array(
128 1 => CRM_Utils_Date
::customFormat($dao->start_date
,
129 $config->dateformatFull
134 if ($dao->end_date
) {
135 $endDate = CRM_Utils_Date
::unixTime($dao->end_date
);
139 $data['is_active'] = FALSE;
140 $data['campaign_start'] = ts('Campaign ended on %1', array(
141 1 => CRM_Utils_Date
::customFormat($dao->end_date
,
142 $config->dateformatFull
145 elseif ($startDate >= $now) {
146 $data['campaign_start'] = ts('Campaign starts on %1', array(
147 1 => CRM_Utils_Date
::customFormat($dao->start_date
,
148 $config->dateformatFull
152 $data['campaign_start'] = ts('Campaign ends on %1', array(
153 1 => CRM_Utils_Date
::customFormat($dao->end_date
,
154 $config->dateformatFull
160 $data['is_active'] = FALSE;
164 $data['is_active'] = FALSE;
167 $data['money_raised_percentage'] = 0;
168 if ($data['money_target'] > 0) {
169 $percent = $data['money_raised'] / $data['money_target'];
170 $data['money_raised_percentage'] = (round($percent, 2)) * 100 . "%";
171 $data['money_target_display'] = CRM_Utils_Money
::format($data['money_target']);
172 $data['money_raised'] = ts('Raised %1 of %2', array(1 => CRM_Utils_Money
::format($data['money_raised']), 2 => $data['money_target_display']));
175 $data['money_raised'] = ts('Raised %1', array(1 => CRM_Utils_Money
::format($data['money_raised'])));
178 $data['money_low'] = 0;
179 $data['num_donors'] = $data['num_donors'] . " " . ts('Donors');
180 $data['home_url'] = "<a href='{$config->userFrameworkBaseURL}' class='crm-home-url' style='color:" . $widget->color_homepage_link
. "'>" . ts('Learn more.') . "</a>";
182 // if is_active is false, show this link and hide the contribute button
183 $data['homepage_link'] = $widget->url_homepage
;
185 $data['colors'] = array();
187 $data['colors']["title"] = $widget->color_title
;
188 $data['colors']["button"] = $widget->color_button
;
189 $data['colors']["bar"] = $widget->color_bar
;
190 $data['colors']["main_text"] = $widget->color_main_text
;
191 $data['colors']["main"] = $widget->color_main
;
192 $data['colors']["main_bg"] = $widget->color_main_bg
;
193 $data['colors']["bg"] = $widget->color_bg
;
194 $data['colors']["about_link"] = $widget->color_about_link
;