a18348f2b4ae2f90c7649d76cf6e4d976ab48bf4
3 require_once 'CRM/Core/Form.php';
6 * Form controller class
8 * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
10 class CRM_Wci_Form_WCISettings
extends CRM_Core_Form
{
11 function buildQuickForm() {
15 'select', // field type
16 'default_profile', // field name
17 'Default profile', // field label
18 $this->getProfiles(), // list of options
23 'select', // field type
24 'default_widget', // field name
25 'Default widget', // field label
26 $this->getWidgets(), // list of options
29 $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45);
30 $this->addButtons(array(
38 $widgetId = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_widget'));
39 $defProf = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_profile'));
41 $this->setDefaults(array(
42 'default_widget' => $widgetId));
43 $this->setDefaults(array(
44 'default_profile' => $defProf));
45 // export form elements
46 $this->assign('elementNames', $this->getRenderableElementNames());
48 CRM_Utils_System
::setTitle(ts('Widget Settings'));
50 parent
::buildQuickForm();
53 function postProcess() {
54 $values = $this->exportValues();
55 civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_widget' => $values['default_widget'],));
56 civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_profile' => $values['default_profile'],));
57 CRM_Core_Session
::setStatus(ts('Widget settings are saved to database'), '', 'success');
58 parent
::postProcess();
61 function getProfiles() {
63 $result = civicrm_api3('Profile', 'get', $params);
64 $result = civicrm_api('Profile', 'getcount', $params);
67 function getWidgets() {
68 $query = "SELECT * FROM civicrm_wci_widget";
72 '' => ts('- select -'),
75 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
77 while ($dao->fetch()) {
78 $widgetlist[$dao->id
] = $dao->title
;
85 * Get the fields/elements defined in this form.
87 * @return array (string)
89 function getRenderableElementNames() {
90 // The _elements list includes some items which should not be
91 // auto-rendered in the loop -- such as "qfKey" and "buttons". These
92 // items don't have labels. We'll identify renderable by filtering on
94 $elementNames = array();
95 foreach ($this->_elements
as $element) {
96 $label = $element->getLabel();
98 $elementNames[] = $element->getName();
101 return $elementNames;