Commit | Line | Data |
---|---|---|
4f895956 J |
1 | <?php |
2 | ||
3 | require_once 'CRM/Core/Form.php'; | |
4 | ||
5 | /** | |
6 | * Form controller class | |
7 | * | |
8 | * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference | |
9 | */ | |
10 | class 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 | ||
fbe9a7d4 | 22 | /*$this->add( |
4f895956 J |
23 | 'select', // field type |
24 | 'default_widget', // field name | |
25 | 'Default widget', // field label | |
26 | $this->getWidgets(), // list of options | |
27 | false // is required | |
fbe9a7d4 J |
28 | );*/ |
29 | ||
4f895956 J |
30 | $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45); |
31 | $this->addButtons(array( | |
32 | array( | |
33 | 'type' => 'submit', | |
8966f337 | 34 | 'name' => ts('Save'), |
4f895956 J |
35 | 'isDefault' => TRUE, |
36 | ), | |
37 | )); | |
38 | ||
68f8aff6 J |
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')); | |
4f895956 J |
41 | |
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()); | |
48 | ||
8966f337 | 49 | CRM_Utils_System::setTitle(ts('Widget Settings')); |
4f895956 J |
50 | |
51 | parent::buildQuickForm(); | |
52 | } | |
53 | ||
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'],)); | |
8966f337 | 58 | CRM_Core_Session::setStatus(ts('Widget settings are saved to database'), '', 'success'); |
4f895956 J |
59 | parent::postProcess(); |
60 | } | |
61 | ||
62 | function getProfiles() { | |
63 | /*$params = array(); | |
64 | $result = civicrm_api3('Profile', 'get', $params); | |
65 | $result = civicrm_api('Profile', 'getcount', $params); | |
66 | print_r($result);*/ | |
67 | } | |
68 | function getWidgets() { | |
69 | $query = "SELECT * FROM civicrm_wci_widget"; | |
70 | $params = array(); | |
71 | ||
72 | $widgetlist = array( | |
73 | '' => ts('- select -'), | |
74 | ); | |
75 | ||
76 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget'); | |
77 | ||
78 | while ($dao->fetch()) { | |
79 | $widgetlist[$dao->id] = $dao->title; | |
80 | } | |
81 | return $widgetlist; | |
82 | } | |
83 | ||
84 | ||
85 | /** | |
86 | * Get the fields/elements defined in this form. | |
87 | * | |
88 | * @return array (string) | |
89 | */ | |
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 | |
94 | // the 'label'. | |
95 | $elementNames = array(); | |
96 | foreach ($this->_elements as $element) { | |
97 | $label = $element->getLabel(); | |
98 | if (!empty($label)) { | |
99 | $elementNames[] = $element->getName(); | |
100 | } | |
101 | } | |
102 | return $elementNames; | |
103 | } | |
104 | } |