3 * Copyright (C) 2007 Jacob Singh, Sam Lerner
4 * Licensed to CiviCRM under the Academic Free License version 3.0.
6 * Modified and improved upon by CiviCRM LLC (c) 2007
10 * Class CRM_Widget_Widget
12 class CRM_Widget_Widget
{
15 function initialize() {
16 if (!self
::$_methodTable) {
17 self
::$_methodTable = array(
18 'getContributionPageData' =>
20 'description' => 'Gets all campaign related data and returns it as a std class.',
29 'description' => 'Gets embed code. Perhaps overkill, but we can track dropoffs in this case. by # of people reqeusting emebed code / number of unique instances.',
41 function &methodTable() {
44 return self
::$_methodTable;
48 * Not implemented - registers an action and unique widget ID. Useful for stats and debugging
50 * @param int $contributionPageID
51 * @param string $widgetID
52 * @param string $action
56 function registerRequest($contributionPageID, $widgetID, $action) {
57 return "I registered a request to $action on $contributionPageID from $widgetID";
61 * Gets all campaign related data and returns it as a std class.
63 * @param int $contributionPageID
64 * @param string $widgetID
68 public function getContributionPageData($contributionPageID, $widgetID) {
69 $config = CRM_Core_Config
::singleton();
71 self
::registerRequest($contributionPageID, $widgetID, __FUNCTION__
);
73 $data = new stdClass();
75 if (empty($contributionPageID) ||
76 CRM_Utils_Type
::validate($contributionPageID, 'Integer') == NULL
78 $data->is_error
= TRUE;
79 CRM_Core_Error
::debug_log_message("$contributionPageID is not set");
83 $widget = new CRM_Contribute_DAO_Widget();
84 $widget->contribution_page_id
= $contributionPageID;
85 if (!$widget->find(TRUE)) {
86 $data->is_error
= TRUE;
87 CRM_Core_Error
::debug_log_message("$contributionPageID is not found");
91 $data->is_error
= FALSE;
92 if (!$widget->is_active
) {
93 $data->is_active
= FALSE;
96 $data->is_active
= TRUE;
97 $data->title
= $widget->title
;
98 $data->logo
= $widget->url_logo
;
99 $data->button_title
= $widget->button_title
;
100 $data->button_url
= CRM_Utils_System
::url('civicrm/contribute/transact',
101 "reset=1&id=$contributionPageID",
102 TRUE, NULL, FALSE, TRUE
104 $data->about
= $widget->about
;
107 SELECT count( id ) as count,
108 sum( total_amount) as amount
109 FROM civicrm_contribution
111 AND contribution_status_id = 1
112 AND contribution_page_id = %1";
113 $params = array(1 => array($contributionPageID, 'Integer'));
114 $dao = CRM_Core_DAO
::executeQuery($query, $params);
116 $data->num_donors
= $dao->count
;
117 $data->money_raised
= $dao->amount
;
120 $data->num_donors
= $data->money_raised
= 0;
124 SELECT goal_amount, start_date, end_date, is_active
125 FROM civicrm_contribution_page
127 $params = array(1 => array($contributionPageID, 'Integer'));
128 $dao = CRM_Core_DAO
::executeQuery($query, $params);
130 $data->money_target
= $dao->goal_amount
;
131 $data->campaign_start
= CRM_Utils_Date
::customFormat($dao->start_date
, $config->dateformatFull
);
132 $data->campaign_end
= CRM_Utils_Date
::customFormat($dao->end_date
, $config->dateformatFull
);
134 // check for time being between start and end date
136 if ($dao->start_date
) {
137 $startDate = CRM_Utils_Date
::unixTime($dao->start_date
);
141 $data->is_active
= FALSE;
145 if ($dao->end_date
) {
146 $endDate = CRM_Utils_Date
::unixTime($dao->end_date
);
150 $data->is_active
= FALSE;
155 $data->is_active
= FALSE;
158 // if is_active is false, show this link and hide the contribute button
159 $data->homepage_link
= $widget->url_homepage
;
161 // movie clip colors, must be in '0xRRGGBB' format
162 $data->colors
= array();
165 $data->colors
["title"] = str_replace('#', $hexPrefix, $widget->color_title
);
166 $data->colors
["button"] = str_replace('#', $hexPrefix, $widget->color_button
);
167 $data->colors
["bar"] = str_replace('#', $hexPrefix, $widget->color_bar
);
168 $data->colors
["main_text"] = str_replace('#', $hexPrefix, $widget->color_main_text
);
169 $data->colors
["main"] = str_replace('#', $hexPrefix, $widget->color_main
);
170 $data->colors
["main_bg"] = str_replace('#', $hexPrefix, $widget->color_main_bg
);
171 $data->colors
["bg"] = str_replace('#', $hexPrefix, $widget->color_bg
);
173 // these two have colors as normal hex format
174 // because they're being used in a CSS object
175 $data->colors
["about_link"] = str_replace('#', $hexPrefix, $widget->color_about_link
);
176 $data->colors
["homepage_link"] = str_replace('#', $hexPrefix, $widget->color_homepage_link
);
182 * Gets embed code. Perhaps overkill, but we can track dropoffs in this case.
183 * by # of people reqeusting emebed code / number of unique instances.
185 * @param int $contributionPageID
186 * @param string $widgetID
187 * @param string $format - either myspace or normal
191 public function getEmbedCode($contributionPageID, $widgetID, $format = "normal") {
192 self
::registerRequest($contributionPageID, $widgetID, __FUNCTION__
);
193 return "<embed>.......................</embed>" . print_r(func_get_args(), 1);