From 1720f5792ba1afeb538c7fd13bc46599ca8e721f Mon Sep 17 00:00:00 2001 From: Manoj K Date: Thu, 11 Sep 2014 18:42:25 +0530 Subject: [PATCH] #29521 - Add DAO and BAO class files. Created skeleton widget creation form. --- CRM/Wci/BAO/ProgressBar.php | 129 ++++++++ CRM/Wci/BAO/ProgressBarFormula.php | 129 ++++++++ CRM/Wci/BAO/Widget.php | 129 ++++++++ CRM/Wci/DAO/ProgressBar.php | 241 ++++++++++++++ CRM/Wci/DAO/ProgressBarFormula.php | 260 +++++++++++++++ CRM/Wci/DAO/Widget.php | 495 +++++++++++++++++++++++++++++ CRM/Wci/Form/CreateWidget.php | 125 ++++++-- sql/install.sql | 10 +- 8 files changed, 1493 insertions(+), 25 deletions(-) create mode 100644 CRM/Wci/BAO/ProgressBar.php create mode 100644 CRM/Wci/BAO/ProgressBarFormula.php create mode 100644 CRM/Wci/BAO/Widget.php create mode 100644 CRM/Wci/DAO/ProgressBar.php create mode 100644 CRM/Wci/DAO/ProgressBarFormula.php create mode 100644 CRM/Wci/DAO/Widget.php diff --git a/CRM/Wci/BAO/ProgressBar.php b/CRM/Wci/BAO/ProgressBar.php new file mode 100644 index 0000000..f4674a9 --- /dev/null +++ b/CRM/Wci/BAO/ProgressBar.php @@ -0,0 +1,129 @@ +copyValues($params); + + $progress_bar->save(); + + return $progress_bar; + } + + /** + * Get a list of Widgets matching the params, where params keys are column + * names of civicrm_wci_widget. + * + * @param array $params + * @return array of CRM_WCI_BAO_ProgressBar objects + */ + static function retrieve(array $params) { + $result = array(); + + $progress_bar = new CRM_WCI_BAO_ProgressBar(); + $progress_bar->copyValues($params); + $progress_bar->find(); + + while ($progress_bar->fetch()) { + $result[(int) $progress_bar->id] = clone $progress_bar; + } + + $progress_bar->free(); + + return $result; + } + + /** + * Wrapper method for retrieve + * + * @param mixed $id Int or int-like string representing widget ID + * @return CRM_WCI_BAO_ProgressBar + */ + static function retrieveByID($id) { + if (!is_int($id) && !ctype_digit($id)) { + CRM_Core_Error::fatal(__CLASS__ . '::' . __FUNCTION__ . ' expects an integer.'); + } + $id = (int) $id; + + $progress_bars = self::retrieve(array('id' => $id)); + + if (!array_key_exists($id, $progress_bars)) { + CRM_Core_Error::fatal("No Progress bar with ID $id exists."); + } + + return $progress_bars[$id]; + } + + /** + * Check if there is absolute minimum of data to add the object + * + * @param array $params (reference ) an assoc array of name/value pairs + * + * @return boolean + * @access public + */ + public static function dataExists($params) { + if (CRM_Utils_Array::value('name', $params)) { + return TRUE; + } + return FALSE; + } +} diff --git a/CRM/Wci/BAO/ProgressBarFormula.php b/CRM/Wci/BAO/ProgressBarFormula.php new file mode 100644 index 0000000..547d95a --- /dev/null +++ b/CRM/Wci/BAO/ProgressBarFormula.php @@ -0,0 +1,129 @@ +copyValues($params); + + $progress_bar_formula->save(); + + return $progress_bar_formula; + } + + /** + * Get a list of Widgets matching the params, where params keys are column + * names of civicrm_wci_widget. + * + * @param array $params + * @return array of CRM_WCI_BAO_ProgressBarFormula objects + */ + static function retrieve(array $params) { + $result = array(); + + $progress_bar_formula = new CRM_WCI_BAO_ProgressBarFormula(); + $progress_bar_formula->copyValues($params); + $progress_bar_formula->find(); + + while ($progress_bar_formula->fetch()) { + $result[(int) $progress_bar_formula->id] = clone $progress_bar_formula; + } + + $progress_bar_formula->free(); + + return $result; + } + + /** + * Wrapper method for retrieve + * + * @param mixed $id Int or int-like string representing widget ID + * @return CRM_WCI_BAO_ProgressBarFormula + */ + static function retrieveByID($id) { + if (!is_int($id) && !ctype_digit($id)) { + CRM_Core_Error::fatal(__CLASS__ . '::' . __FUNCTION__ . ' expects an integer.'); + } + $id = (int) $id; + + $progress_bar_formulas = self::retrieve(array('id' => $id)); + + if (!array_key_exists($id, $progress_bar_formulas)) { + CRM_Core_Error::fatal("No formula entry with ID $id exists."); + } + + return $progress_bar_formulas[$id]; + } + + /** + * Check if there is absolute minimum of data to add the object + * + * @param array $params (reference ) an assoc array of name/value pairs + * + * @return boolean + * @access public + */ + public static function dataExists($params) { + if (CRM_Utils_Array::value('contribution_page_id', $params) && CRM_Utils_Array::value('progress_bar_id', $params)) { + return TRUE; + } + return FALSE; + } +} diff --git a/CRM/Wci/BAO/Widget.php b/CRM/Wci/BAO/Widget.php new file mode 100644 index 0000000..f6cca9c --- /dev/null +++ b/CRM/Wci/BAO/Widget.php @@ -0,0 +1,129 @@ +copyValues($params); + + $widget->save(); + + return $widget; + } + + /** + * Get a list of Widgets matching the params, where params keys are column + * names of civicrm_wci_widget. + * + * @param array $params + * @return array of CRM_WCI_BAO_Widget objects + */ + static function retrieve(array $params) { + $result = array(); + + $widget = new CRM_WCI_BAO_Widget(); + $widget->copyValues($params); + $widget->find(); + + while ($widget->fetch()) { + $result[(int) $widget->id] = clone $widget; + } + + $widget->free(); + + return $result; + } + + /** + * Wrapper method for retrieve + * + * @param mixed $id Int or int-like string representing widget ID + * @return CRM_WCI_BAO_Widget + */ + static function retrieveByID($id) { + if (!is_int($id) && !ctype_digit($id)) { + CRM_Core_Error::fatal(__CLASS__ . '::' . __FUNCTION__ . ' expects an integer.'); + } + $id = (int) $id; + + $widgets = self::retrieve(array('id' => $id)); + + if (!array_key_exists($id, $widgets)) { + CRM_Core_Error::fatal("No widget with ID $id exists."); + } + + return $widgets[$id]; + } + + /** + * Check if there is absolute minimum of data to add the object + * + * @param array $params (reference ) an assoc array of name/value pairs + * + * @return boolean + * @access public + */ + public static function dataExists($params) { + if (CRM_Utils_Array::value('title', $params)) { + return TRUE; + } + return FALSE; + } +} diff --git a/CRM/Wci/DAO/ProgressBar.php b/CRM/Wci/DAO/ProgressBar.php new file mode 100644 index 0000000..2becc61 --- /dev/null +++ b/CRM/Wci/DAO/ProgressBar.php @@ -0,0 +1,241 @@ +__table = 'civicrm_wci_progress_bar'; + parent::__construct(); + } + /** + * return foreign keys and entity references + * + * @static + * @access public + * @return array of CRM_Core_EntityReference + */ + static function getReferenceColumns() + { + return self::$_links; + } + /** + * returns all the column names of this table + * + * @access public + * @return array + */ + static function &fields() + { + if (!(self::$_fields)) { + self::$_fields = array( + 'progress_bar_id' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('WCI Progress Bar Id', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + ) , + 'name' => array( + 'name' => 'name', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Progress Bar Name', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 64, + ) , + 'starting_amount' => array( + 'name' => 'starting_amount', + 'type' => CRM_Utils_Type::T_FLOAT, + 'required' => false, + ) , + ); + } + return self::$_fields; + } + /** + * Returns an array containing, for each field, the arary key used for that + * field in self::$_fields. + * + * @access public + * @return array + */ + static function &fieldKeys() + { + if (!(self::$_fieldKeys)) { + self::$_fieldKeys = array( + 'id' => 'progress_bar_id', + 'name' => 'name', + 'starting_amount' => 'starting_amount', + ); + } + return self::$_fieldKeys; + } + /** + * returns the names of this table + * + * @access public + * @static + * @return string + */ + static function getTableName() + { + return self::$_tableName; + } + /** + * returns if this table needs to be logged + * + * @access public + * @return boolean + */ + function getLog() + { + return self::$_log; + } + /** + * returns the list of fields that can be imported + * + * @access public + * return array + * @static + */ + static function &import($prefix = false) + { + if (!(self::$_import)) { + self::$_import = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('import', $field)) { + if ($prefix) { + self::$_import['wci_progress_bar'] = & $fields[$name]; + } else { + self::$_import[$name] = & $fields[$name]; + } + } + } + } + return self::$_import; + } + /** + * returns the list of fields that can be exported + * + * @access public + * return array + * @static + */ + static function &export($prefix = false) + { + if (!(self::$_export)) { + self::$_export = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('export', $field)) { + if ($prefix) { + self::$_export['wci_progress_bar'] = & $fields[$name]; + } else { + self::$_export[$name] = & $fields[$name]; + } + } + } + } + return self::$_export; + } +} diff --git a/CRM/Wci/DAO/ProgressBarFormula.php b/CRM/Wci/DAO/ProgressBarFormula.php new file mode 100644 index 0000000..46d5ea7 --- /dev/null +++ b/CRM/Wci/DAO/ProgressBarFormula.php @@ -0,0 +1,260 @@ +__table = 'civicrm_wci_progress_bar_formula'; + parent::__construct(); + } + /** + * return foreign keys and entity references + * + * @static + * @access public + * @return array of CRM_Core_EntityReference + */ + static function getReferenceColumns() + { + if (!self::$_links) { + self::$_links = array( + new CRM_Core_EntityReference(self::getTableName() , 'progress_bar_id', 'civicrm_wci_progress_bar', 'id') , + new CRM_Core_EntityReference(self::getTableName() , 'contribution_page_id', 'civicrm_contribution_page', 'id') , + ); + } + return self::$_links; + } + /** + * returns all the column names of this table + * + * @access public + * @return array + */ + static function &fields() + { + if (!(self::$_fields)) { + self::$_fields = array( + 'progress_bar_formula_id' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('WCI Progress Bar Formula Entry Id', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + ) , + 'contribution_page_id' => array( + 'name' => 'contribution_page_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Contribution Page Reference Id', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + ) , + 'progress_bar_id' => array( + 'name' => 'progress_bar_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Progress Bar Reference Id', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + ) , + 'percentage' => array( + 'name' => 'percentage', + 'type' => CRM_Utils_Type::T_FLOAT, + 'title' => ts('Percentage Amount', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + ) , + ); + } + return self::$_fields; + } + /** + * Returns an array containing, for each field, the arary key used for that + * field in self::$_fields. + * + * @access public + * @return array + */ + static function &fieldKeys() + { + if (!(self::$_fieldKeys)) { + self::$_fieldKeys = array( + 'id' => 'progress_bar_formula_id', + 'contribution_page_id' => 'contribution_page_id', + 'progress_bar_id' => 'progress_bar_id', + 'percentage' => 'percentage', + ); + } + return self::$_fieldKeys; + } + /** + * returns the names of this table + * + * @access public + * @static + * @return string + */ + static function getTableName() + { + return self::$_tableName; + } + /** + * returns if this table needs to be logged + * + * @access public + * @return boolean + */ + function getLog() + { + return self::$_log; + } + /** + * returns the list of fields that can be imported + * + * @access public + * return array + * @static + */ + static function &import($prefix = false) + { + if (!(self::$_import)) { + self::$_import = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('import', $field)) { + if ($prefix) { + self::$_import['wci_progress_bar_formula'] = & $fields[$name]; + } else { + self::$_import[$name] = & $fields[$name]; + } + } + } + } + return self::$_import; + } + /** + * returns the list of fields that can be exported + * + * @access public + * return array + * @static + */ + static function &export($prefix = false) + { + if (!(self::$_export)) { + self::$_export = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('export', $field)) { + if ($prefix) { + self::$_export['wci_progress_bar_formula'] = & $fields[$name]; + } else { + self::$_export[$name] = & $fields[$name]; + } + } + } + } + return self::$_export; + } +} diff --git a/CRM/Wci/DAO/Widget.php b/CRM/Wci/DAO/Widget.php new file mode 100644 index 0000000..2cb0aad --- /dev/null +++ b/CRM/Wci/DAO/Widget.php @@ -0,0 +1,495 @@ +__table = 'civicrm_wci_widget'; + parent::__construct(); + } + /** + * return foreign keys and entity references + * + * @static + * @access public + * @return array of CRM_Core_EntityReference + */ + static function getReferenceColumns() + { + if (!self::$_links) { + self::$_links = array( + new CRM_Core_EntityReference(self::getTableName() , 'button_link_to', 'civicrm_contribution_page', 'id') , + new CRM_Core_EntityReference(self::getTableName() , 'progress_bar_id', 'civicrm_wci_progress_bar', 'id') , + new CRM_Core_EntityReference(self::getTableName() , 'email_signup_group_id', 'civicrm_group', 'id') , + ); + } + return self::$_links; + } + /** + * returns all the column names of this table + * + * @access public + * @return array + */ + static function &fields() + { + if (!(self::$_fields)) { + self::$_fields = array( + 'widget_id' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('WCI Widget Id', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + ) , + 'title' => array( + 'name' => 'title', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget title', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 64, + ) , + 'logo_image' => array( + 'name' => 'logo_image', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Image url of widget logo image', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + 'maxlength' => 255, + ) , + 'image' => array( + 'name' => 'image', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Url of widget image', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + 'maxlength' => 255, + ) , + 'button_title' => array( + 'name' => 'button_title', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Contribute/Donate button title', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + 'maxlength' => 64, + ) , + 'button_link_to' => array( + 'name' => 'button_link_to', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Contribution/Donation page reference', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + 'progress_bar_id' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('WCI Progress Bar Reference Id', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + 'description' => array( + 'name' => 'description', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Widget description', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + 'email_signup_group_id' => array( + 'name' => 'email_signup_group_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Group reference for email newsletter signup', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + 'size_variant' => array( + 'name' => 'id', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget size variant', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_title' => array( + 'name' => 'color_title', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget title color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_title_bg' => array( + 'name' => 'color_title_bg', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget title background color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_progress_bar' => array( + 'name' => 'color_progress_bar', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Progress bar color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_widget_bg' => array( + 'name' => 'color_widget_bg', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget background color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_description' => array( + 'name' => 'color_description', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget description color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_border' => array( + 'name' => 'color_border', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget border color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_button' => array( + 'name' => 'color_button', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget button text color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'color_button_bg' => array( + 'name' => 'color_button_bg', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Widget button background color', array('domain' => 'org.civicrm.wci')) , + 'required' => true, + 'maxlength' => 10, + ) , + 'style_rules' => array( + 'name' => 'style_rules', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Additional style rules', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + 'override' => array( + 'name' => 'override', + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'title' => ts('Override default template', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + 'custom_template' => array( + 'name' => 'custom_template', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => ts('Widget custom template', array('domain' => 'org.civicrm.wci')) , + 'required' => false, + ) , + ); + } + return self::$_fields; + } + /** + * Returns an array containing, for each field, the arary key used for that + * field in self::$_fields. + * + * @access public + * @return array + */ + static function &fieldKeys() + { + if (!(self::$_fieldKeys)) { + self::$_fieldKeys = array( + 'id' => 'widget_id', + 'title' => 'title', + 'logo_image' => 'logo_image', + 'image' => 'image', + 'button_title' => 'button_title', + 'button_link_to' => 'button_link_to', + 'progress_bar_id' => 'progress_bar_id', + 'description' => 'description', + 'email_signup_group_id' => 'email_signup_group_id', + 'size_variant' => 'size_variant', + 'color_title' => 'color_title', + 'color_title_bg' => 'color_title_bg', + 'color_progress_bar' => 'color_progress_bar', + 'color_widget_bg' => 'color_widget_bg', + 'color_description' => 'color_description', + 'color_border' => 'color_border', + 'color_button' => 'color_button', + 'color_button_bg' => 'color_button_bg', + 'style_rules' => 'style_rules', + 'override' => 'override', + 'custom_template' => 'custom_template', + ); + } + return self::$_fieldKeys; + } + /** + * returns the names of this table + * + * @access public + * @static + * @return string + */ + static function getTableName() + { + return self::$_tableName; + } + /** + * returns if this table needs to be logged + * + * @access public + * @return boolean + */ + function getLog() + { + return self::$_log; + } + /** + * returns the list of fields that can be imported + * + * @access public + * return array + * @static + */ + static function &import($prefix = false) + { + if (!(self::$_import)) { + self::$_import = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('import', $field)) { + if ($prefix) { + self::$_import['wci_widget'] = & $fields[$name]; + } else { + self::$_import[$name] = & $fields[$name]; + } + } + } + } + return self::$_import; + } + /** + * returns the list of fields that can be exported + * + * @access public + * return array + * @static + */ + static function &export($prefix = false) + { + if (!(self::$_export)) { + self::$_export = array(); + $fields = self::fields(); + foreach($fields as $name => $field) { + if (CRM_Utils_Array::value('export', $field)) { + if ($prefix) { + self::$_export['wci_widget'] = & $fields[$name]; + } else { + self::$_export[$name] = & $fields[$name]; + } + } + } + } + return self::$_export; + } +} diff --git a/CRM/Wci/Form/CreateWidget.php b/CRM/Wci/Form/CreateWidget.php index 98a6ec4..aa79a6f 100644 --- a/CRM/Wci/Form/CreateWidget.php +++ b/CRM/Wci/Form/CreateWidget.php @@ -8,20 +8,85 @@ require_once 'CRM/Core/Form.php'; * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference */ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { - function buildQuickForm() { + + function preProcess() { + parent::preProcess(); - // add form elements - $this->add( - 'select', // field type - 'favorite_color', // field name - 'Favorite Color', // field label - $this->getColorOptions(), // list of options - true // is required + $this->_colorFields = array('color_title' => array(ts('Title Text Color'), + 'text', + FALSE, + '#2786C2', + ), + 'color_bar' => array(ts('Progress Bar Color'), + 'text', + FALSE, + '#FFFFFF', + ), + 'color_main_text' => array(ts('Additional Text Color'), + 'text', + FALSE, + '#FFFFFF', + ), + 'color_main' => array(ts('Background Color'), + 'text', + FALSE, + '#96C0E7', + ), + 'color_main_bg' => array(ts('Background Color Top Area'), + 'text', + FALSE, + '#B7E2FF', + ), + 'color_bg' => array(ts('Border Color'), + 'text', + FALSE, + '#96C0E7', + ), + 'color_about_link' => array(ts('Button Link Color'), + 'text', + FALSE, + '#556C82', + ), + 'color_button' => array(ts('Button Background Color'), + 'text', + FALSE, + '#FFFFFF', + ), + 'color_homepage_link' => array(ts('Homepage Link Color'), + 'text', + FALSE, + '#FFFFFF', + ), ); + } + + function buildQuickForm() { + + // add form elements + $this->add('text', 'title', ts('Title'),true); + $this->add('text', 'logo_image', ts('Logo image')); + $this->add('text', 'image', ts('Image')); + $this->add('select', 'button_link_to', ts('Contribution button'), $this->getContributionPageOptions()); + $this->add('text', 'button_title', ts('Contribution button title')); + $this->add('select', 'progress_bar', ts('Progress bar'), array('' => '- select -')); + $this->add('textarea', 'description', ts('Description')); + $this->add('select', 'email_signup_group_id', ts('Newsletter signup'), $this->getGroupOptions()); + $this->add('select', 'size_variant', ts('Size variant'), $this->getSizeOptions()); + foreach ($this->_colorFields as $name => $val) { + $this->add($val[1], + $name, + $val[0], + $name, + $val[2] + ); + } + $this->add('textarea', 'style_rules', ts('Additional Style Rules')); + $this->add('checkbox', 'override', ts('Override default template')); + $this->add('textarea', 'custom_template', ts('Custom template')); $this->addButtons(array( array( 'type' => 'submit', - 'name' => ts('Submit'), + 'name' => ts('Save'), 'isDefault' => TRUE, ), )); @@ -33,24 +98,44 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { function postProcess() { $values = $this->exportValues(); - $options = $this->getColorOptions(); - CRM_Core_Session::setStatus(ts('You picked color "%1"', array( - 1 => $options[$values['favorite_color']] - ))); + parent::postProcess(); } - function getColorOptions() { + function getContributionPageOptions() { + $options = array( + '' => ts('- select -'), + ); + + $result = civicrm_api3('contribution_page', 'get'); + foreach ($result['values'] as $contribution_page) { + $options[$contribution_page['id']] = $contribution_page['title']; + } + + return $options; + } + + function getGroupOptions() { $options = array( '' => ts('- select -'), - '#f00' => ts('Red'), - '#0f0' => ts('Green'), - '#00f' => ts('Blue'), - '#f0f' => ts('Purple'), ); - foreach (array('1','2','3','4','5','6','7','8','9','a','b','c','d','e') as $f) { - $options["#{$f}{$f}{$f}"] = ts('Grey (%1)', array(1 => $f)); + + $result = civicrm_api3('group', 'get'); + foreach ($result['values'] as $group) { + $options[$group['id']] = $group['title']; } + + return $options; + } + + function getSizeOptions() { + $options = array( + '' => ts('- select -'), + 'thin' => ts('Thin'), + 'normal' => ts('Normal'), + 'wide' => ts('Wide'), + ); + return $options; } diff --git a/sql/install.sql b/sql/install.sql index 8cd9b71..7ee2858 100644 --- a/sql/install.sql +++ b/sql/install.sql @@ -1,6 +1,6 @@ -- WCI progress bar. CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar ( - id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Custom Progress bar Id', + id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Custom Progress bar Id.', name varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Name of progress bar.', starting_amount float unsigned NULL COMMENT 'Arbitrary starting amount for progress bar.', PRIMARY KEY (`id`), @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar ( -- WCI progress bar formula CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar_formula ( - id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Formula entry Id', + id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Formula entry Id.', contribution_page_id int(10) unsigned NOT NULL COMMENT 'Reference contribution page id.', progress_bar_id int(10) unsigned DEFAULT NULL COMMENT 'Custom Progress bar reference id.', percentage float unsigned NULL COMMENT 'Percentage amount.', @@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar_formula ( -- WCI widget CREATE TABLE IF NOT EXISTS civicrm_wci_widget ( - id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Widget Id', + id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Widget Id.', title varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget title.', logo_image varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Image url of widget logo image.', image varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Url of widget image.', @@ -30,9 +30,9 @@ CREATE TABLE IF NOT EXISTS civicrm_wci_widget ( email_signup_group_id int(10) unsigned DEFAULT NULL COMMENT 'Group reference for email newsletter signup.', size_variant varchar(25) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget size variant.', color_title varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget title color.', - color_title_background varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget title background color.', + color_title_bg varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget title background color.', color_progress_bar varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Progress bar color.', - color_widget_bg varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget title color.', + color_widget_bg varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget background color.', color_description varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget description color.', color_border varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget border color.', color_button varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Widget button text color.', -- 2.25.1