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
{
16 public function initialize() {
17 if (!self
::$_methodTable) {
18 self
::$_methodTable = array(
19 'getContributionPageData' => array(
20 'description' => 'Gets all campaign related data and returns it as a std class.',
27 'getEmbedCode' => array(
28 'description' => 'Gets embed code. Perhaps overkill, but we can track dropoffs in this case. by # of people reqeusting emebed code / number of unique instances.',
40 public function &methodTable() {
43 return self
::$_methodTable;
47 * Not implemented - registers an action and unique widget ID. Useful for stats and debugging
49 * @param int $contributionPageID
50 * @param string $widgetID
51 * @param string $action
55 public function registerRequest($contributionPageID, $widgetID, $action) {
56 return "I registered a request to $action on $contributionPageID from $widgetID";
60 * Gets all campaign related data and returns it as a std class.
62 * @param int $contributionPageID
63 * @param string $widgetID
67 public function getContributionPageData($contributionPageID, $widgetID) {
68 $config = CRM_Core_Config
::singleton();
70 self
::registerRequest($contributionPageID, $widgetID, __FUNCTION__
);
72 $data = new stdClass();
74 if (empty($contributionPageID) ||
75 CRM_Utils_Type
::validate($contributionPageID, 'Integer') == NULL
77 $data->is_error
= TRUE;
78 CRM_Core_Error
::debug_log_message("$contributionPageID is not set");
82 $widget = new CRM_Contribute_DAO_Widget();
83 $widget->contribution_page_id
= $contributionPageID;
84 if (!$widget->find(TRUE)) {
85 $data->is_error
= TRUE;
86 CRM_Core_Error
::debug_log_message("$contributionPageID is not found");
90 $data->is_error
= FALSE;
91 if (!$widget->is_active
) {
92 $data->is_active
= FALSE;
95 $data->is_active
= TRUE;
96 $data->title
= $widget->title
;
97 $data->logo
= $widget->url_logo
;
98 $data->button_title
= $widget->button_title
;
99 $data->button_url
= CRM_Utils_System
::url('civicrm/contribute/transact',
100 "reset=1&id=$contributionPageID",
101 TRUE, NULL, FALSE, TRUE
103 $data->about
= $widget->about
;
106 SELECT count( id ) as count,
107 sum( total_amount) as amount
108 FROM civicrm_contribution
110 AND contribution_status_id = 1
111 AND contribution_page_id = %1";
112 $params = array(1 => array($contributionPageID, 'Integer'));
113 $dao = CRM_Core_DAO
::executeQuery($query, $params);
115 $data->num_donors
= $dao->count
;
116 $data->money_raised
= $dao->amount
;
119 $data->num_donors
= $data->money_raised
= 0;
123 SELECT goal_amount, start_date, end_date, is_active
124 FROM civicrm_contribution_page
126 $params = array(1 => array($contributionPageID, 'Integer'));
127 $dao = CRM_Core_DAO
::executeQuery($query, $params);
129 $data->money_target
= $dao->goal_amount
;
130 $data->campaign_start
= CRM_Utils_Date
::customFormat($dao->start_date
, $config->dateformatFull
);
131 $data->campaign_end
= CRM_Utils_Date
::customFormat($dao->end_date
, $config->dateformatFull
);
133 // check for time being between start and end date
135 if ($dao->start_date
) {
136 $startDate = CRM_Utils_Date
::unixTime($dao->start_date
);
140 $data->is_active
= FALSE;
144 if ($dao->end_date
) {
145 $endDate = CRM_Utils_Date
::unixTime($dao->end_date
);
149 $data->is_active
= FALSE;
154 $data->is_active
= FALSE;
157 // if is_active is false, show this link and hide the contribute button
158 $data->homepage_link
= $widget->url_homepage
;
160 // movie clip colors, must be in '0xRRGGBB' format
161 $data->colors
= array();
164 $data->colors
["title"] = str_replace('#', $hexPrefix, $widget->color_title
);
165 $data->colors
["button"] = str_replace('#', $hexPrefix, $widget->color_button
);
166 $data->colors
["bar"] = str_replace('#', $hexPrefix, $widget->color_bar
);
167 $data->colors
["main_text"] = str_replace('#', $hexPrefix, $widget->color_main_text
);
168 $data->colors
["main"] = str_replace('#', $hexPrefix, $widget->color_main
);
169 $data->colors
["main_bg"] = str_replace('#', $hexPrefix, $widget->color_main_bg
);
170 $data->colors
["bg"] = str_replace('#', $hexPrefix, $widget->color_bg
);
172 // these two have colors as normal hex format
173 // because they're being used in a CSS object
174 $data->colors
["about_link"] = str_replace('#', $hexPrefix, $widget->color_about_link
);
175 $data->colors
["homepage_link"] = str_replace('#', $hexPrefix, $widget->color_homepage_link
);
181 * Gets embed code. Perhaps overkill, but we can track dropoffs in this case.
182 * by # of people reqeusting emebed code / number of unique instances.
184 * @param int $contributionPageID
185 * @param string $widgetID
186 * @param string $format
187 * Either myspace or normal.
191 public function getEmbedCode($contributionPageID, $widgetID, $format = "normal") {
192 self
::registerRequest($contributionPageID, $widgetID, __FUNCTION__
);
193 return "<embed>.......................</embed>" .
194 print_r(func_get_args(), 1);