#31000 changed grpup name
[com.zyxware.civiwci.git] / CRM / Wci / Form / WCISettings.php
CommitLineData
4f895956
J
1<?php
2
3require_once 'CRM/Core/Form.php';
4
5/**
6 * Form controller class
7 *
8 * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
9 */
10class CRM_Wci_Form_WCISettings extends CRM_Core_Form {
11 function buildQuickForm() {
12
13 // add form elements
14 /*$this->add(
15 'select', // field type
16 'default_profile', // field name
17 'Default profile', // field label
18 $this->getProfiles(), // list of options
19 true // is required
20 );*/
21
22 $this->add(
23 'select', // field type
24 'default_widget', // field name
25 'Default widget', // field label
26 $this->getWidgets(), // list of options
27 false // is required
28 );
29 $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45);
30 $this->addButtons(array(
31 array(
32 'type' => 'submit',
33 'name' => ts('Submit'),
34 'isDefault' => TRUE,
35 ),
36 ));
37
68f8aff6
J
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'));
4f895956
J
40
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());
47
48 CRM_Utils_System::setTitle(ts('WCI Settings'));
49
50 parent::buildQuickForm();
51 }
52
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 parent::postProcess();
58 }
59
60 function getProfiles() {
61 /*$params = array();
62 $result = civicrm_api3('Profile', 'get', $params);
63 $result = civicrm_api('Profile', 'getcount', $params);
64 print_r($result);*/
65 }
66 function getWidgets() {
67 $query = "SELECT * FROM civicrm_wci_widget";
68 $params = array();
69
70 $widgetlist = array(
71 '' => ts('- select -'),
72 );
73
74 $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
75
76 while ($dao->fetch()) {
77 $widgetlist[$dao->id] = $dao->title;
78 }
79 return $widgetlist;
80 }
81
82
83 /**
84 * Get the fields/elements defined in this form.
85 *
86 * @return array (string)
87 */
88 function getRenderableElementNames() {
89 // The _elements list includes some items which should not be
90 // auto-rendered in the loop -- such as "qfKey" and "buttons". These
91 // items don't have labels. We'll identify renderable by filtering on
92 // the 'label'.
93 $elementNames = array();
94 foreach ($this->_elements as $element) {
95 $label = $element->getLabel();
96 if (!empty($label)) {
97 $elementNames[] = $element->getName();
98 }
99 }
100 return $elementNames;
101 }
102}