Commit | Line | Data |
---|---|---|
1720f579 M |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.4 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * | |
33 | */ | |
34 | ||
e364fc74 | 35 | class CRM_Wci_BAO_Widget extends CRM_Wci_DAO_Widget { |
1720f579 M |
36 | |
37 | /** | |
38 | * class constructor | |
39 | */ | |
40 | function __construct() { | |
41 | parent::__construct(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Function to create a Widget | |
46 | * takes an associative array and creates a Widget object | |
47 | * | |
48 | * This function is invoked from within the web form layer and also from the api layer | |
49 | * | |
50 | * @param array $params (reference ) an assoc array of name/value pairs | |
51 | * | |
e364fc74 | 52 | * @return object CRM_Wci_BAO_Widget object |
1720f579 M |
53 | * @access public |
54 | * @static | |
55 | */ | |
56 | static function create(array $params) { | |
57 | ||
58 | // check required params | |
59 | if (!self::dataExists($params)) { | |
60 | CRM_Core_Error::fatal('Not enough data to create a widget.'); | |
61 | } | |
62 | ||
e364fc74 | 63 | $widget = new CRM_Wci_BAO_Widget(); |
1720f579 M |
64 | $widget->copyValues($params); |
65 | ||
66 | $widget->save(); | |
67 | ||
68 | return $widget; | |
69 | } | |
70 | ||
71 | /** | |
72 | * Get a list of Widgets matching the params, where params keys are column | |
73 | * names of civicrm_wci_widget. | |
74 | * | |
75 | * @param array $params | |
e364fc74 | 76 | * @return array of CRM_Wci_BAO_Widget objects |
1720f579 M |
77 | */ |
78 | static function retrieve(array $params) { | |
79 | $result = array(); | |
80 | ||
e364fc74 | 81 | $widget = new CRM_Wci_BAO_Widget(); |
1720f579 M |
82 | $widget->copyValues($params); |
83 | $widget->find(); | |
84 | ||
85 | while ($widget->fetch()) { | |
86 | $result[(int) $widget->id] = clone $widget; | |
87 | } | |
88 | ||
89 | $widget->free(); | |
90 | ||
91 | return $result; | |
92 | } | |
93 | ||
94 | /** | |
95 | * Wrapper method for retrieve | |
96 | * | |
97 | * @param mixed $id Int or int-like string representing widget ID | |
e364fc74 | 98 | * @return CRM_Wci_BAO_Widget |
1720f579 M |
99 | */ |
100 | static function retrieveByID($id) { | |
101 | if (!is_int($id) && !ctype_digit($id)) { | |
102 | CRM_Core_Error::fatal(__CLASS__ . '::' . __FUNCTION__ . ' expects an integer.'); | |
103 | } | |
104 | $id = (int) $id; | |
105 | ||
106 | $widgets = self::retrieve(array('id' => $id)); | |
107 | ||
108 | if (!array_key_exists($id, $widgets)) { | |
109 | CRM_Core_Error::fatal("No widget with ID $id exists."); | |
110 | } | |
111 | ||
112 | return $widgets[$id]; | |
113 | } | |
114 | ||
115 | /** | |
116 | * Check if there is absolute minimum of data to add the object | |
117 | * | |
118 | * @param array $params (reference ) an assoc array of name/value pairs | |
119 | * | |
120 | * @return boolean | |
121 | * @access public | |
122 | */ | |
123 | public static function dataExists($params) { | |
124 | if (CRM_Utils_Array::value('title', $params)) { | |
125 | return TRUE; | |
126 | } | |
127 | return FALSE; | |
128 | } | |
a946a2b6 J |
129 | public static function getWidgetData($widgetId) { |
130 | ||
131 | $query = "SELECT * FROM civicrm_wci_widget where id=".$widgetId; | |
132 | $params = array(); | |
133 | ||
134 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget'); | |
135 | ||
136 | $data = array(); | |
137 | while ($dao->fetch()) { | |
cb59e7c2 | 138 | $data["title"] = $dao->title; |
a946a2b6 J |
139 | $data["logo_image"] = $dao->logo_image; |
140 | $data["image"] = $dao->image; | |
141 | $data["button_title"] = $dao->button_title; | |
d12b4a2c M |
142 | $data["button_link_to"] = $dao->button_link_to; |
143 | $data["progress_bar_id"] = $dao->progress_bar_id; | |
46dee7f2 | 144 | $data["description"] = $dao->description; |
7602edcd | 145 | $data["email_signup_group_id"] = $dao->email_signup_group_id; |
a946a2b6 J |
146 | $data["size_variant"] = $dao->size_variant; |
147 | $data["color_title"] = $dao->color_title; | |
148 | $data["color_title_bg"] = $dao->color_title_bg; | |
149 | $data["color_progress_bar"] = $dao->color_progress_bar; | |
150 | $data["color_widget_bg"] = $dao->color_widget_bg; | |
151 | $data["color_description"] = $dao->color_description; | |
152 | $data["color_border"] = $dao->color_border; | |
153 | $data["color_button"] = $dao->color_button; | |
154 | $data["color_button_bg"] = $dao->color_button_bg; | |
58bba978 | 155 | $data['style_rules'] = $dao->style_rules; |
7d8ac5b7 | 156 | $data["pb_percentage"] = CRM_Wci_BAO_ProgressBar::getProgressbarPercentage($dao->progress_bar_id); |
851c37a8 J |
157 | $data["custom_template"] = $dao->custom_template; |
158 | $data["widgetId"] = $widgetId; | |
159 | $data["override"] = $dao->override; | |
6d608c2b J |
160 | $data["hide_title"] = $dao->hide_title; |
161 | $data["hide_border"] = $dao->hide_border; | |
162 | $data["hide_pbcap"] = $dao->hide_pbcap; | |
96bd4503 | 163 | $data["color_bar"] = $dao->color_progress_bar; |
68f8aff6 | 164 | $defProf = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_profile')); |
4f895956 | 165 | $data["emailSignupGroupFormURL"] = CRM_Utils_System::baseCMSURL() . '/civicrm/profile/create?reset=1&gid=' . $defProf; |
c1a7ee1f J |
166 | $data["color_btn_newsletter"] = $dao->color_btn_newsletter; |
167 | $data["color_btn_newsletter_bg"] = $dao->color_btn_newsletter_bg; | |
168 | $data["newsletter_text"] = $dao->newsletter_text; | |
169 | $data["color_newsletter_text"] = $dao->color_newsletter_text; | |
a946a2b6 | 170 | } |
a946a2b6 J |
171 | return $data; |
172 | } | |
1720f579 | 173 | } |