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
8 class CRM_Widget_Widget
{
11 function initialize() {
12 if (!self
::$_methodTable) {
13 self
::$_methodTable = array(
14 'getContributionPageData' =>
16 'description' => 'Gets all campaign related data and returns it as a std class.',
25 'description' => 'Gets embed code. Perhaps overkill, but we can track dropoffs in this case. by # of people reqeusting emebed code / number of unique instances.',
37 function &methodTable() {
40 return self
::$_methodTable;
44 * Not implemented - registers an action and unique widget ID. Useful for stats and debugging
46 * @param int $contributionPageID
47 * @param string $widgetID
48 * @param string $action
52 function registerRequest($contributionPageID, $widgetID, $action) {
53 return "I registered a request to $action on $contributionPageID from $widgetID";
57 * Gets all campaign related data and returns it as a std class.
59 * @param int $contributionPageID
60 * @param string $widgetID
64 public function getContributionPageData($contributionPageID, $widgetID) {
65 $config = CRM_Core_Config
::singleton();
67 self
::registerRequest($contributionPageID, $widgetID, __FUNCTION__
);
69 $data = new stdClass();
71 if (empty($contributionPageID) ||
72 CRM_Utils_Type
::validate($contributionPageID, 'Integer') == NULL
74 $data->is_error
= TRUE;
75 CRM_Core_Error
::debug_log_message("$contributionPageID is not set");
79 $widget = new CRM_Contribute_DAO_Widget();
80 $widget->contribution_page_id
= $contributionPageID;
81 if (!$widget->find(TRUE)) {
82 $data->is_error
= TRUE;
83 CRM_Core_Error
::debug_log_message("$contributionPageID is not found");
87 $data->is_error
= FALSE;
88 if (!$widget->is_active
) {
89 $data->is_active
= FALSE;
92 $data->is_active
= TRUE;
93 $data->title
= $widget->title
;
94 $data->logo
= $widget->url_logo
;
95 $data->button_title
= $widget->button_title
;
96 $data->button_url
= CRM_Utils_System
::url('civicrm/contribute/transact',
97 "reset=1&id=$contributionPageID",
98 TRUE, NULL, FALSE, TRUE
100 $data->about
= $widget->about
;
103 SELECT count( id ) as count,
104 sum( total_amount) as amount
105 FROM civicrm_contribution
107 AND contribution_status_id = 1
108 AND contribution_page_id = %1";
109 $params = array(1 => array($contributionPageID, 'Integer'));
110 $dao = CRM_Core_DAO
::executeQuery($query, $params);
112 $data->num_donors
= $dao->count
;
113 $data->money_raised
= $dao->amount
;
116 $data->num_donors
= $data->money_raised
= 0;
120 SELECT goal_amount, start_date, end_date, is_active
121 FROM civicrm_contribution_page
123 $params = array(1 => array($contributionPageID, 'Integer'));
124 $dao = CRM_Core_DAO
::executeQuery($query, $params);
126 $data->money_target
= $dao->goal_amount
;
127 $data->campaign_start
= CRM_Utils_Date
::customFormat($dao->start_date
, $config->dateformatFull
);
128 $data->campaign_end
= CRM_Utils_Date
::customFormat($dao->end_date
, $config->dateformatFull
);
130 // check for time being between start and end date
132 if ($dao->start_date
) {
133 $startDate = CRM_Utils_Date
::unixTime($dao->start_date
);
137 $data->is_active
= FALSE;
141 if ($dao->end_date
) {
142 $endDate = CRM_Utils_Date
::unixTime($dao->end_date
);
146 $data->is_active
= FALSE;
151 $data->is_active
= FALSE;
154 // if is_active is false, show this link and hide the contribute button
155 $data->homepage_link
= $widget->url_homepage
;
157 // movie clip colors, must be in '0xRRGGBB' format
158 $data->colors
= array();
161 $data->colors
["title"] = str_replace('#', $hexPrefix, $widget->color_title
);
162 $data->colors
["button"] = str_replace('#', $hexPrefix, $widget->color_button
);
163 $data->colors
["bar"] = str_replace('#', $hexPrefix, $widget->color_bar
);
164 $data->colors
["main_text"] = str_replace('#', $hexPrefix, $widget->color_main_text
);
165 $data->colors
["main"] = str_replace('#', $hexPrefix, $widget->color_main
);
166 $data->colors
["main_bg"] = str_replace('#', $hexPrefix, $widget->color_main_bg
);
167 $data->colors
["bg"] = str_replace('#', $hexPrefix, $widget->color_bg
);
169 // these two have colors as normal hex format
170 // because they're being used in a CSS object
171 $data->colors
["about_link"] = str_replace('#', $hexPrefix, $widget->color_about_link
);
172 $data->colors
["homepage_link"] = str_replace('#', $hexPrefix, $widget->color_homepage_link
);
178 * Gets embed code. Perhaps overkill, but we can track dropoffs in this case.
179 * by # of people reqeusting emebed code / number of unique instances.
181 * @param int $contributionPageID
182 * @param string $widgetID
183 * @param string $format - either myspace or normal
187 public function getEmbedCode($contributionPageID, $widgetID, $format = "normal") {
188 self
::registerRequest($contributionPageID, $widgetID, __FUNCTION__
);
189 return "<embed>.......................</embed>" . print_r(func_get_args(), 1);