From 4f895956c2b17edba10dae303684ea17500b8462 Mon Sep 17 00:00:00 2001 From: Jagadedes Date: Wed, 5 Nov 2014 17:10:59 +0530 Subject: [PATCH] #31000 added default widget and profile support --- CRM/Wci/BAO/Widget.php | 3 +- CRM/Wci/Form/WCISettings.php | 102 +++++++++++++++++++++++++ extern/wciwidget.php | 2 +- settings/wci.setting.php | 29 +++++++ templates/CRM/Wci/Form/WCISettings.tpl | 27 +++++++ wci.php | 15 +++- xml/Menu/wci.xml | 6 ++ 7 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 CRM/Wci/Form/WCISettings.php create mode 100644 settings/wci.setting.php create mode 100644 templates/CRM/Wci/Form/WCISettings.tpl diff --git a/CRM/Wci/BAO/Widget.php b/CRM/Wci/BAO/Widget.php index a5bb74f..f8980ac 100644 --- a/CRM/Wci/BAO/Widget.php +++ b/CRM/Wci/BAO/Widget.php @@ -161,7 +161,8 @@ class CRM_Wci_BAO_Widget extends CRM_Wci_DAO_Widget { $data["hide_border"] = $dao->hide_border; $data["hide_pbcap"] = $dao->hide_pbcap; $data["color_bar"] = $dao->color_progress_bar; - $data["emailSignupGroupFormURL"] = CRM_Utils_System::baseCMSURL() . '/civicrm/profile/create?reset=1&gid=15'; + $defProf = civicrm_api3('setting', 'getValue', array('group' => 'extensions', 'name' => 'default_wci_profile')); + $data["emailSignupGroupFormURL"] = CRM_Utils_System::baseCMSURL() . '/civicrm/profile/create?reset=1&gid=' . $defProf; } return $data; } diff --git a/CRM/Wci/Form/WCISettings.php b/CRM/Wci/Form/WCISettings.php new file mode 100644 index 0000000..5fb20fa --- /dev/null +++ b/CRM/Wci/Form/WCISettings.php @@ -0,0 +1,102 @@ +add( + 'select', // field type + 'default_profile', // field name + 'Default profile', // field label + $this->getProfiles(), // list of options + true // is required + );*/ + + $this->add( + 'select', // field type + 'default_widget', // field name + 'Default widget', // field label + $this->getWidgets(), // list of options + false // is required + ); + $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45); + $this->addButtons(array( + array( + 'type' => 'submit', + 'name' => ts('Submit'), + 'isDefault' => TRUE, + ), + )); + + $widgetId = civicrm_api3('setting', 'getValue', array('group' => 'extensions', 'name' => 'default_wci_widget')); + $defProf = civicrm_api3('setting', 'getValue', array('group' => 'extensions', 'name' => 'default_wci_profile')); + + $this->setDefaults(array( + 'default_widget' => $widgetId)); + $this->setDefaults(array( + 'default_profile' => $defProf)); + // export form elements + $this->assign('elementNames', $this->getRenderableElementNames()); + + CRM_Utils_System::setTitle(ts('WCI Settings')); + + parent::buildQuickForm(); + } + + function postProcess() { + $values = $this->exportValues(); + civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_widget' => $values['default_widget'],)); + civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_profile' => $values['default_profile'],)); + parent::postProcess(); + } + + function getProfiles() { + /*$params = array(); + $result = civicrm_api3('Profile', 'get', $params); + $result = civicrm_api('Profile', 'getcount', $params); + print_r($result);*/ + } + function getWidgets() { + $query = "SELECT * FROM civicrm_wci_widget"; + $params = array(); + + $widgetlist = array( + '' => ts('- select -'), + ); + + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget'); + + while ($dao->fetch()) { + $widgetlist[$dao->id] = $dao->title; + } + return $widgetlist; + } + + + /** + * Get the fields/elements defined in this form. + * + * @return array (string) + */ + function getRenderableElementNames() { + // The _elements list includes some items which should not be + // auto-rendered in the loop -- such as "qfKey" and "buttons". These + // items don't have labels. We'll identify renderable by filtering on + // the 'label'. + $elementNames = array(); + foreach ($this->_elements as $element) { + $label = $element->getLabel(); + if (!empty($label)) { + $elementNames[] = $element->getName(); + } + } + return $elementNames; + } +} diff --git a/extern/wciwidget.php b/extern/wciwidget.php index a6d8c26..761a965 100644 --- a/extern/wciwidget.php +++ b/extern/wciwidget.php @@ -46,7 +46,7 @@ require_once 'CRM/Utils/Request.php'; $config = CRM_Core_Config::singleton(); $template = CRM_Core_Smarty::singleton(); -$widgetId = CRM_Utils_Request::retrieve('widgetId', 'Positive', CRM_Core_DAO::$_nullObject); +$widgetId = civicrm_api3('setting', 'getValue', array('group' => 'extensions', 'name' => 'default_wci_widget')); $embed = CRM_Utils_Request::retrieve('embed', 'Positive', CRM_Core_DAO::$_nullObject); if (isset($format)) { diff --git a/settings/wci.setting.php b/settings/wci.setting.php new file mode 100644 index 0000000..15d7844 --- /dev/null +++ b/settings/wci.setting.php @@ -0,0 +1,29 @@ + array( + 'group_name' => 'extensions', + 'group' => 'extensions', + 'name' => 'default_wci_widget', + 'type' => 'Integer', + 'default' => 0, + 'add' => '4.3', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Default widget id', + 'help_text' => 'Sets default widget id', + ), + 'default_wci_profile' => array( + 'group_name' => 'extensions', + 'group' => 'extensions', + 'name' => 'default_wci_profile', + 'type' => 'Integer', + 'default' => 0, + 'add' => '4.3', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'Default profile id', + 'help_text' => 'Sets default profile id', + ), + ); + + diff --git a/templates/CRM/Wci/Form/WCISettings.tpl b/templates/CRM/Wci/Form/WCISettings.tpl new file mode 100644 index 0000000..c99bb1f --- /dev/null +++ b/templates/CRM/Wci/Form/WCISettings.tpl @@ -0,0 +1,27 @@ +{* HEADER *} + +
+{include file="CRM/common/formButtons.tpl" location="top"} +
+ +{* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *} + +{foreach from=$elementNames item=elementName} +
+
{$form.$elementName.label}
+
{$form.$elementName.html}
+
+
+{/foreach} + +{* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT) + +
+ {$form.favorite_color.label} + {$form.favorite_color.html} +
+ +{* FOOTER *} +
+{include file="CRM/common/formButtons.tpl" location="bottom"} +
diff --git a/wci.php b/wci.php index d24c29f..5b9fb66 100644 --- a/wci.php +++ b/wci.php @@ -175,9 +175,20 @@ function wci_civicrm_navigationMenu( &$params ) { 'separator' => 1, 'parentID' => $navId, 'navID' => $navId+4, - 'active' => 1)), + 'active' => 1)), + + '5' => array ( + 'attributes' => array ( + 'label' => ts('Wci Settings'), + 'name' => 'manage_progress_bar', + 'url' => 'civicrm/wci/settings?reset=1', + 'permission' => 'access CiviReport,access CiviContribute', + 'operator' => 'OR', + 'separator' => 1, + 'parentID' => $navId, + 'navID' => $navId+5, + 'active' => 1)), ), ); } - diff --git a/xml/Menu/wci.xml b/xml/Menu/wci.xml index f606843..0f0bf12 100644 --- a/xml/Menu/wci.xml +++ b/xml/Menu/wci.xml @@ -30,4 +30,10 @@ Widget List access CiviCRM + + civicrm/wci/settings + CRM_Wci_Form_WCISettings + WCISettings + access CiviCRM + -- 2.25.1