#31000 added default widget and profile support
authorJagadedes <jagadees.pillai@zyxware.com>
Wed, 5 Nov 2014 11:40:59 +0000 (17:10 +0530)
committerJagadedes <jagadees.pillai@zyxware.com>
Wed, 5 Nov 2014 11:40:59 +0000 (17:10 +0530)
CRM/Wci/BAO/Widget.php
CRM/Wci/Form/WCISettings.php [new file with mode: 0644]
extern/wciwidget.php
settings/wci.setting.php [new file with mode: 0644]
templates/CRM/Wci/Form/WCISettings.tpl [new file with mode: 0644]
wci.php
xml/Menu/wci.xml

index a5bb74f3803fd80e1a013749f298a978fb140100..f8980ac914b617b7854475e18dd51dfd16126927 100644 (file)
@@ -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&amp;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&amp;gid=' . $defProf;
     }
     return $data;
   }
diff --git a/CRM/Wci/Form/WCISettings.php b/CRM/Wci/Form/WCISettings.php
new file mode 100644 (file)
index 0000000..5fb20fa
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+
+require_once 'CRM/Core/Form.php';
+
+/**
+ * Form controller class
+ *
+ * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
+ */
+class CRM_Wci_Form_WCISettings extends CRM_Core_Form {
+  function buildQuickForm() {
+
+    // add form elements
+    /*$this->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;
+  }
+}
index a6d8c26021588e657da05a856eb691d9c73d639b..761a9656610be70240aa018da61c5551ff44210d 100644 (file)
@@ -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 (file)
index 0000000..15d7844
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+return array(
+  'default_wci_widget' => 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 (file)
index 0000000..c99bb1f
--- /dev/null
@@ -0,0 +1,27 @@
+{* HEADER *}
+
+<div class="crm-submit-buttons">
+{include file="CRM/common/formButtons.tpl" location="top"}
+</div>
+
+{* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *}
+
+{foreach from=$elementNames item=elementName}
+  <div class="crm-section">
+    <div class="label">{$form.$elementName.label}</div>
+    <div class="content">{$form.$elementName.html}</div>
+    <div class="clear"></div>
+  </div>
+{/foreach}
+
+{* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
+
+  <div>
+    <span>{$form.favorite_color.label}</span>
+    <span>{$form.favorite_color.html}</span>
+  </div>
+
+{* FOOTER *}
+<div class="crm-submit-buttons">
+{include file="CRM/common/formButtons.tpl" location="bottom"}
+</div>
diff --git a/wci.php b/wci.php
index d24c29fbcacf492bf9be05942b1a8b690dbd1178..5b9fb663c18864258fb948e6a286f343865f3311 100644 (file)
--- 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)),
         ),
   );
 }
 
-
index f6068437d0ae97e85910d5b8a9f52b5a2cfb0266..0f0bf12999f2062d8aca69e71810c6d28b9c7d07 100644 (file)
     <title>Widget List</title>
     <access_arguments>access CiviCRM</access_arguments>
   </item>
+  <item>
+    <path>civicrm/wci/settings</path>
+    <page_callback>CRM_Wci_Form_WCISettings</page_callback>
+    <title>WCISettings</title>
+    <access_arguments>access CiviCRM</access_arguments>
+  </item>
 </menu>