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
30 $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45);
31 $this->addButtons(array(
39 $widgetId = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_widget'));
40 $defProf = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_profile'));
42 /*$this->setDefaults(array(
43 'default_widget' => $widgetId));*/
44 $this->setDefaults(array(
45 'default_profile' => $defProf));
46 // export form elements
47 $this->assign('elementNames', $this->getRenderableElementNames());
49 CRM_Utils_System
::setTitle(ts('Widget Settings'));
51 parent
::buildQuickForm();
54 function postProcess() {
55 $values = $this->exportValues();
56 /*civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_widget' => $values['default_widget'],));*/
57 civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_profile' => $values['default_profile'],));
58 CRM_Core_Session
::setStatus(ts('Widget settings are saved to database'), '', 'success');
59 parent
::postProcess();
62 function getProfiles() {
64 $result = civicrm_api3('Profile', 'get', $params);
65 $result = civicrm_api('Profile', 'getcount', $params);
68 function getWidgets() {
69 $query = "SELECT * FROM civicrm_wci_widget";
73 '' => ts('- select -'),
76 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
78 while ($dao->fetch()) {
79 $widgetlist[$dao->id
] = $dao->title
;
86 * Get the fields/elements defined in this form.
88 * @return array (string)
90 function getRenderableElementNames() {
91 // The _elements list includes some items which should not be
92 // auto-rendered in the loop -- such as "qfKey" and "buttons". These
93 // items don't have labels. We'll identify renderable by filtering on
95 $elementNames = array();
96 foreach ($this->_elements
as $element) {
97 $label = $element->getLabel();
99 $elementNames[] = $element->getName();
102 return $elementNames;