3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class to retrieve information about a contribution page.
21 class CRM_Contribute_BAO_Widget
extends CRM_Contribute_DAO_Widget
{
24 * Gets all campaign related data and returns it as a std class.
26 * @param int $contributionPageID
27 * @param int $widgetID
28 * @param bool $includePending
32 public static function getContributionPageData($contributionPageID, $widgetID, $includePending = FALSE) {
33 $config = CRM_Core_Config
::singleton();
36 $data['currencySymbol'] = CRM_Core_BAO_Country
::defaultCurrencySymbol();
38 if (empty($contributionPageID) ||
39 CRM_Utils_Type
::validate($contributionPageID, 'Integer') == NULL
41 $data['is_error'] = TRUE;
42 CRM_Core_Error
::debug_log_message("$contributionPageID is not set");
46 $widget = new CRM_Contribute_DAO_Widget();
47 $widget->contribution_page_id
= $contributionPageID;
48 if (!$widget->find(TRUE)) {
49 $data['is_error'] = TRUE;
50 CRM_Core_Error
::debug_log_message("$contributionPageID is not found");
54 $data['is_error'] = FALSE;
55 if (!$widget->is_active
) {
56 $data['is_active'] = FALSE;
59 $data['is_active'] = TRUE;
60 $data['title'] = $widget->title
;
61 $data['logo'] = $widget->url_logo
;
62 $data['button_title'] = $widget->button_title
;
63 $data['about'] = $widget->about
;
65 //check if pending status needs to be included
67 if ($includePending) {
72 SELECT count( id ) as count,
73 sum( total_amount) as amount
74 FROM civicrm_contribution
76 AND contribution_status_id IN ({$status})
77 AND contribution_page_id = %1";
78 $params = [1 => [$contributionPageID, 'Integer']];
79 $dao = CRM_Core_DAO
::executeQuery($query, $params);
81 $data['num_donors'] = (int) $dao->count
;
82 $data['money_raised'] = (int) $dao->amount
;
85 $data['num_donors'] = $data['money_raised'] = $data->money_raised
= 0;
88 $data['money_raised_amount'] = CRM_Utils_Money
::format($data['money_raised']);
91 SELECT goal_amount, start_date, end_date, is_active
92 FROM civicrm_contribution_page
94 $params = [1 => [$contributionPageID, 'Integer']];
95 $dao = CRM_Core_DAO
::executeQuery($query, $params);
97 $data['campaign_start'] = '';
100 $data['money_target'] = (int) $dao->goal_amount
;
102 // conditions that needs to be handled
103 // 1. Campaign is not active - no text
104 // 2. Campaign start date greater than today - show start date
105 // 3. Campaign end date is set and greater than today - show end date
106 // 4. If no start and end date or no end date and start date greater than today, then it's ongoing
107 if ($dao->is_active
) {
108 $data['campaign_start'] = ts('Campaign is ongoing');
110 // check for time being between start and end date
112 if ($dao->start_date
) {
113 $startDate = CRM_Utils_Date
::unixTime($dao->start_date
);
114 $data['start_date'] = $dao->start_date
;
115 if ($startDate && $startDate >= $now) {
116 $data['is_active'] = FALSE;
117 $data['campaign_start'] = ts('Campaign starts on %1', [
118 1 => CRM_Utils_Date
::customFormat($dao->start_date
, $config->dateformatFull
),
123 if ($dao->end_date
) {
124 $endDate = CRM_Utils_Date
::unixTime($dao->end_date
);
125 $data['end_date'] = $dao->end_date
;
129 $data['is_active'] = FALSE;
130 $data['campaign_start'] = ts('Campaign ended on %1',
132 1 => CRM_Utils_Date
::customFormat($dao->end_date
, $config->dateformatFull
),
136 elseif ($startDate >= $now) {
137 $data['campaign_start'] = ts('Campaign starts on %1',
139 1 => CRM_Utils_Date
::customFormat($dao->start_date
, $config->dateformatFull
),
144 $data['campaign_start'] = ts('Campaign ends on %1',
146 1 => CRM_Utils_Date
::customFormat($dao->end_date
, $config->dateformatFull
),
153 $data['is_active'] = FALSE;
157 $data['is_active'] = FALSE;
160 $data['money_raised_percentage'] = 0;
161 if ($data['money_target'] > 0) {
162 $percent = $data['money_raised'] / $data['money_target'];
163 $data['money_raised_percentage'] = (round($percent, 2)) * 100 . "%";
164 $data['money_target_display'] = CRM_Utils_Money
::format($data['money_target']);
165 $data['money_raised'] = ts('Raised %1 of %2', [
166 1 => CRM_Utils_Money
::format($data['money_raised']),
167 2 => $data['money_target_display'],
171 $data['money_raised'] = ts('Raised %1', [1 => CRM_Utils_Money
::format($data['money_raised'])]);
174 $data['money_low'] = 0;
175 $data['num_donors'] = $data['num_donors'] . " " . ts('Donors');
176 $data['home_url'] = "<a href='{$config->userFrameworkBaseURL}' class='crm-home-url' style='color:" . $widget->color_homepage_link
. "'>" . ts('Learn more.') . "</a>";
178 // if is_active is false, show this link and hide the contribute button
179 $data['homepage_link'] = $widget->url_homepage
;
181 $data['colors'] = [];
183 $data['colors']["title"] = $widget->color_title
;
184 $data['colors']["button"] = $widget->color_button
;
185 $data['colors']["bar"] = $widget->color_bar
;
186 $data['colors']["main_text"] = $widget->color_main_text
;
187 $data['colors']["main"] = $widget->color_main
;
188 $data['colors']["main_bg"] = $widget->color_main_bg
;
189 $data['colors']["bg"] = $widget->color_bg
;
190 $data['colors']["about_link"] = $widget->color_about_link
;