Merge pull request #19 from Jagadees-zyxware/master
[com.zyxware.civiwci.git] / CRM / Wci / DAO / Widget.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM Widget Creation Interface (WCI) Version 1.0 |
5 +--------------------------------------------------------------------+
6 | Copyright Zyxware Technologies (c) 2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM WCI. |
9 | |
10 | CiviCRM WCI is free software; you can copy, modify, and distribute |
11 | it under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
13 | |
14 | CiviCRM WCI is distributed in the hope that it will be useful, |
15 | but 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 along with this program; if not, contact Zyxware |
21 | Technologies at info[AT]zyxware[DOT]com. |
22 +--------------------------------------------------------------------+
23 */
24
25 /**
26 *
27 * @package CRM
28 * @copyright CiviCRM LLC (c) 2004-2013
29 */
30 class CRM_Wci_DAO_Widget extends CRM_Core_DAO
31 {
32 /**
33 * static instance to hold the table name
34 *
35 * @var string
36 * @static
37 */
38 static $_tableName = 'civicrm_wci_widget';
39 /**
40 * static instance to hold the field values
41 *
42 * @var array
43 * @static
44 */
45 static $_fields = null;
46 /**
47 * static instance to hold the keys used in $_fields for each field.
48 *
49 * @var array
50 * @static
51 */
52 static $_fieldKeys = null;
53 /**
54 * static instance to hold the FK relationships
55 *
56 * @var string
57 * @static
58 */
59 static $_links = null;
60 /**
61 * static instance to hold the values that can
62 * be imported
63 *
64 * @var array
65 * @static
66 */
67 static $_import = null;
68 /**
69 * static instance to hold the values that can
70 * be exported
71 *
72 * @var array
73 * @static
74 */
75 static $_export = null;
76 /**
77 * static value to see if we should log any modifications to
78 * this table in the civicrm_log table
79 *
80 * @var boolean
81 * @static
82 */
83 static $_log = true;
84 /**
85 * Widget Id
86 *
87 * @var int unsigned
88 */
89 public $id;
90 /**
91 * Widget title
92 *
93 * @var string
94 */
95 public $title;
96 /**
97 * Widget title logo
98 *
99 * @var string
100 */
101 public $logo_image;
102 /**
103 * Widget image
104 *
105 * @var string
106 */
107 public $image;
108 /**
109 * Widget contribute/donate button title
110 *
111 * @var string
112 */
113 public $button_title;
114 /**
115 * Contribution/donate page reference id
116 *
117 * @var int unsigned
118 */
119 public $button_link_to;
120 /**
121 * WCI Progress bar reference id
122 *
123 * @var int unsigned
124 */
125 public $progress_bar_id;
126 /**
127 * Widget description
128 *
129 * @var string
130 */
131 public $description;
132 /**
133 * Newsletter signup group reference id
134 *
135 * @var int unsigned
136 */
137 public $email_signup_group_id;
138 /**
139 * Widget size (Thin/Normal/Wide)
140 *
141 * @var string
142 */
143 public $size_variant;
144 /**
145 * Widget title color
146 *
147 * @var string
148 */
149 public $color_title;
150 /**
151 * Widget title background color
152 *
153 * @var string
154 */
155 public $color_title_bg;
156 /**
157 * Widget progress bar color
158 *
159 * @var string
160 */
161 public $color_progress_bar;
162 /**
163 * Widget progress bar background color
164 *
165 * @var string
166 */
167 public $color_progress_bar_bg;
168
169 /**
170 * Widget background color
171 *
172 * @var string
173 */
174 public $color_widget_bg;
175 /**
176 * Widget description color
177 *
178 * @var string
179 */
180 public $color_description;
181 /**
182 * Widget border color
183 *
184 * @var string
185 */
186 public $color_border;
187 /**
188 * Widget button color
189 *
190 * @var string
191 */
192 public $color_button;
193 /**
194 * Widget button background color
195 *
196 * @var string
197 */
198 public $color_button_bg;
199 /**
200 * Additional custom style rules
201 *
202 * @var int unsigned
203 */
204 public $style_rules;
205 /**
206 * Flag to override default widget template
207 *
208 * @var boolean
209 */
210 public $override;
211 /**
212 * Flag to Hide title
213 *
214 * @var boolean
215 */
216 public $hide_title;
217 /**
218 * Flag to Hide widget border
219 *
220 * @var boolean
221 */
222 public $hide_border;
223 /**
224 * Flag to Hide pb caption
225 *
226 * @var boolean
227 */
228 public $hide_pbcap;
229 /**
230 * if true then shows pb in % else in collected amount
231 *
232 * @var boolean
233 */
234 public $show_pb_perc;
235 /**
236 * Custom template
237 *
238 * @var string
239 */
240 public $custom_template;
241
242 /**
243 * Newsletter Button text color
244 *
245 * @var string
246 */
247 public $color_btn_newsletter;
248
249 /**
250 * Newsletter Button color
251 *
252 * @var string
253 */
254 public $color_btn_newsletter_bg;
255
256 /**
257 * Newsletter text
258 *
259 * @var string
260 */
261 public $newsletter_text;
262
263 /**
264 * Newsletter msg text color
265 *
266 * @var string
267 */
268 public $color_newsletter_text;
269
270 function __construct()
271 {
272 $this->__table = 'civicrm_wci_widget';
273 parent::__construct();
274 }
275 /**
276 * return foreign keys and entity references
277 *
278 * @static
279 * @access public
280 * @return array of CRM_Core_EntityReference
281 */
282 static function getReferenceColumns()
283 {
284 if (!self::$_links) {
285 self::$_links = array(
286 new CRM_Core_EntityReference(self::getTableName() , 'button_link_to', 'civicrm_contribution_page', 'id') ,
287 new CRM_Core_EntityReference(self::getTableName() , 'progress_bar_id', 'civicrm_wci_progress_bar', 'id') ,
288 new CRM_Core_EntityReference(self::getTableName() , 'email_signup_group_id', 'civicrm_group', 'id') ,
289 );
290 }
291 return self::$_links;
292 }
293 /**
294 * returns all the column names of this table
295 *
296 * @access public
297 * @return array
298 */
299 static function &fields()
300 {
301 if (!(self::$_fields)) {
302 self::$_fields = array(
303 'widget_id' => array(
304 'name' => 'id',
305 'type' => CRM_Utils_Type::T_INT,
306 'title' => ts('WCI Widget Id', array('domain' => 'com.zyxware.civiwci')) ,
307 'required' => true,
308 ) ,
309 'title' => array(
310 'name' => 'title',
311 'type' => CRM_Utils_Type::T_STRING,
312 'title' => ts('Widget title', array('domain' => 'com.zyxware.civiwci')) ,
313 'required' => true,
314 'maxlength' => 64,
315 ) ,
316 'logo_image' => array(
317 'name' => 'logo_image',
318 'type' => CRM_Utils_Type::T_STRING,
319 'title' => ts('Image url of widget logo image', array('domain' => 'com.zyxware.civiwci')) ,
320 'required' => false,
321 'maxlength' => 255,
322 ) ,
323 'image' => array(
324 'name' => 'image',
325 'type' => CRM_Utils_Type::T_STRING,
326 'title' => ts('Url of widget image', array('domain' => 'com.zyxware.civiwci')) ,
327 'required' => false,
328 'maxlength' => 255,
329 ) ,
330 'button_title' => array(
331 'name' => 'button_title',
332 'type' => CRM_Utils_Type::T_STRING,
333 'title' => ts('Contribute/Donate button title', array('domain' => 'com.zyxware.civiwci')) ,
334 'required' => false,
335 'maxlength' => 64,
336 ) ,
337 'button_link_to' => array(
338 'name' => 'button_link_to',
339 'type' => CRM_Utils_Type::T_INT,
340 'title' => ts('Contribution/Donation page reference', array('domain' => 'com.zyxware.civiwci')) ,
341 'required' => false,
342 ) ,
343 'progress_bar_id' => array(
344 'name' => 'id',
345 'type' => CRM_Utils_Type::T_INT,
346 'title' => ts('WCI Progress Bar Reference Id', array('domain' => 'com.zyxware.civiwci')) ,
347 'required' => false,
348 ) ,
349 'description' => array(
350 'name' => 'description',
351 'type' => CRM_Utils_Type::T_TEXT,
352 'title' => ts('Widget description', array('domain' => 'com.zyxware.civiwci')) ,
353 'required' => false,
354 ) ,
355 'email_signup_group_id' => array(
356 'name' => 'email_signup_group_id',
357 'type' => CRM_Utils_Type::T_INT,
358 'title' => ts('Group reference for email newsletter signup', array('domain' => 'com.zyxware.civiwci')) ,
359 'required' => false,
360 ) ,
361 'size_variant' => array(
362 'name' => 'id',
363 'type' => CRM_Utils_Type::T_STRING,
364 'title' => ts('Widget size variant', array('domain' => 'com.zyxware.civiwci')) ,
365 'required' => true,
366 'maxlength' => 10,
367 ) ,
368 'color_title' => array(
369 'name' => 'color_title',
370 'type' => CRM_Utils_Type::T_STRING,
371 'title' => ts('Widget title color', array('domain' => 'com.zyxware.civiwci')) ,
372 'required' => true,
373 'maxlength' => 10,
374 ) ,
375 'color_title_bg' => array(
376 'name' => 'color_title_bg',
377 'type' => CRM_Utils_Type::T_STRING,
378 'title' => ts('Widget title background color', array('domain' => 'com.zyxware.civiwci')) ,
379 'required' => true,
380 'maxlength' => 10,
381 ) ,
382 'color_progress_bar' => array(
383 'name' => 'color_progress_bar',
384 'type' => CRM_Utils_Type::T_STRING,
385 'title' => ts('Progress bar color', array('domain' => 'com.zyxware.civiwci')) ,
386 'required' => true,
387 'maxlength' => 10,
388 ) ,
389 'color_progress_bar_bg' => array(
390 'name' => 'color_progress_bar_bg',
391 'type' => CRM_Utils_Type::T_STRING,
392 'title' => ts('Progress bar background color', array('domain' => 'com.zyxware.civiwci')) ,
393 'required' => true,
394 'maxlength' => 10,
395 ) ,
396 'color_widget_bg' => array(
397 'name' => 'color_widget_bg',
398 'type' => CRM_Utils_Type::T_STRING,
399 'title' => ts('Widget background color', array('domain' => 'com.zyxware.civiwci')) ,
400 'required' => true,
401 'maxlength' => 10,
402 ) ,
403 'color_description' => array(
404 'name' => 'color_description',
405 'type' => CRM_Utils_Type::T_STRING,
406 'title' => ts('Widget description color', array('domain' => 'com.zyxware.civiwci')) ,
407 'required' => true,
408 'maxlength' => 10,
409 ) ,
410 'color_border' => array(
411 'name' => 'color_border',
412 'type' => CRM_Utils_Type::T_STRING,
413 'title' => ts('Widget border color', array('domain' => 'com.zyxware.civiwci')) ,
414 'required' => true,
415 'maxlength' => 10,
416 ) ,
417 'color_button' => array(
418 'name' => 'color_button',
419 'type' => CRM_Utils_Type::T_STRING,
420 'title' => ts('Widget button text color', array('domain' => 'com.zyxware.civiwci')) ,
421 'required' => true,
422 'maxlength' => 10,
423 ) ,
424 'color_button_bg' => array(
425 'name' => 'color_button_bg',
426 'type' => CRM_Utils_Type::T_STRING,
427 'title' => ts('Widget button background color', array('domain' => 'com.zyxware.civiwci')) ,
428 'required' => true,
429 'maxlength' => 10,
430 ) ,
431 'style_rules' => array(
432 'name' => 'style_rules',
433 'type' => CRM_Utils_Type::T_TEXT,
434 'title' => ts('Additional style rules', array('domain' => 'com.zyxware.civiwci')) ,
435 'required' => false,
436 ) ,
437 'override' => array(
438 'name' => 'override',
439 'type' => CRM_Utils_Type::T_BOOLEAN,
440 'title' => ts('Override default template', array('domain' => 'com.zyxware.civiwci')) ,
441 'required' => false,
442 ) ,
443 'hide_title' => array(
444 'name' => 'hide_title',
445 'type' => CRM_Utils_Type::T_BOOLEAN,
446 'title' => ts('Hide title, if 1.', array('domain' => 'com.zyxware.civiwci')) ,
447 'required' => false,
448 ) ,
449 'hide_border' => array(
450 'name' => 'hide_border',
451 'type' => CRM_Utils_Type::T_BOOLEAN,
452 'title' => ts('Hide widget border, if 1.', array('domain' => 'com.zyxware.civiwci')) ,
453 'required' => false,
454 ) ,
455 'hide_pbcap' => array(
456 'name' => 'hide_pbcap',
457 'type' => CRM_Utils_Type::T_BOOLEAN,
458 'title' => ts('Hide pb caption, if 1.', array('domain' => 'com.zyxware.civiwci')) ,
459 'required' => false,
460 ) ,
461 'show_pb_perc' => array(
462 'name' => 'show_pb_perc',
463 'type' => CRM_Utils_Type::T_BOOLEAN,
464 'title' => ts('pb in %(1) or amount(0).', array('domain' => 'com.zyxware.civiwci')) ,
465 'required' => false,
466 ) ,
467 'custom_template' => array(
468 'name' => 'custom_template',
469 'type' => CRM_Utils_Type::T_TEXT,
470 'title' => ts('Widget custom template', array('domain' => 'com.zyxware.civiwci')) ,
471 'required' => false,
472 ) ,
473
474 'color_btn_newsletter' => array(
475 'name' => 'color_btn_newsletter',
476 'type' => CRM_Utils_Type::T_STRING,
477 'title' => ts('Newsletter Button text color', array('domain' => 'com.zyxware.civiwci')) ,
478 'required' => true,
479 'maxlength' => 10,
480 ) ,
481 'color_btn_newsletter_bg' => array(
482 'name' => 'color_btn_newsletter_bg',
483 'type' => CRM_Utils_Type::T_STRING,
484 'title' => ts('Newsletter Button color', array('domain' => 'com.zyxware.civiwci')) ,
485 'required' => true,
486 'maxlength' => 10,
487 ) ,
488 'newsletter_text' => array(
489 'name' => 'newsletter_text',
490 'type' => CRM_Utils_Type::T_STRING,
491 'title' => ts('Newsletter text', array('domain' => 'com.zyxware.civiwci')) ,
492 'required' => true,
493 'maxlength' => 64,
494 ) ,
495 'color_newsletter_text' => array(
496 'name' => 'color_newsletter_text',
497 'type' => CRM_Utils_Type::T_STRING,
498 'title' => ts('Newsletter text color', array('domain' => 'com.zyxware.civiwci')) ,
499 'required' => true,
500 'maxlength' => 10,
501 ) ,
502 );
503 }
504 return self::$_fields;
505 }
506 /**
507 * Returns an array containing, for each field, the arary key used for that
508 * field in self::$_fields.
509 *
510 * @access public
511 * @return array
512 */
513 static function &fieldKeys()
514 {
515 if (!(self::$_fieldKeys)) {
516 self::$_fieldKeys = array(
517 'id' => 'widget_id',
518 'title' => 'title',
519 'logo_image' => 'logo_image',
520 'image' => 'image',
521 'button_title' => 'button_title',
522 'button_link_to' => 'button_link_to',
523 'progress_bar_id' => 'progress_bar_id',
524 'description' => 'description',
525 'email_signup_group_id' => 'email_signup_group_id',
526 'size_variant' => 'size_variant',
527 'color_title' => 'color_title',
528 'color_title_bg' => 'color_title_bg',
529 'color_progress_bar' => 'color_progress_bar',
530 'color_progress_bar_bg' => 'color_progress_bar_bg',
531 'color_widget_bg' => 'color_widget_bg',
532 'color_description' => 'color_description',
533 'color_border' => 'color_border',
534 'color_button' => 'color_button',
535 'color_button_bg' => 'color_button_bg',
536 'style_rules' => 'style_rules',
537 'override' => 'override',
538 'hide_title' => 'hide_title',
539 'hide_border' => 'hide_border',
540 'hide_pbcap' => 'hide_pbcap',
541 'show_pb_perc' => 'show_pb_perc',
542 'custom_template' => 'custom_template',
543 );
544 }
545 return self::$_fieldKeys;
546 }
547 /**
548 * returns the names of this table
549 *
550 * @access public
551 * @static
552 * @return string
553 */
554 static function getTableName()
555 {
556 return self::$_tableName;
557 }
558 /**
559 * returns if this table needs to be logged
560 *
561 * @access public
562 * @return boolean
563 */
564 function getLog()
565 {
566 return self::$_log;
567 }
568 /**
569 * returns the list of fields that can be imported
570 *
571 * @access public
572 * return array
573 * @static
574 */
575 static function &import($prefix = false)
576 {
577 if (!(self::$_import)) {
578 self::$_import = array();
579 $fields = self::fields();
580 foreach($fields as $name => $field) {
581 if (CRM_Utils_Array::value('import', $field)) {
582 if ($prefix) {
583 self::$_import['wci_widget'] = & $fields[$name];
584 } else {
585 self::$_import[$name] = & $fields[$name];
586 }
587 }
588 }
589 }
590 return self::$_import;
591 }
592 /**
593 * returns the list of fields that can be exported
594 *
595 * @access public
596 * return array
597 * @static
598 */
599 static function &export($prefix = false)
600 {
601 if (!(self::$_export)) {
602 self::$_export = array();
603 $fields = self::fields();
604 foreach($fields as $name => $field) {
605 if (CRM_Utils_Array::value('export', $field)) {
606 if ($prefix) {
607 self::$_export['wci_widget'] = & $fields[$name];
608 } else {
609 self::$_export[$name] = & $fields[$name];
610 }
611 }
612 }
613 }
614 return self::$_export;
615 }
616 }