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 | 30 | $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45); |
1008246f | 31 | $this->add('text', 'widget_cache_timeout', ts('Widget cache timeout'),true)->setSize(45); |
4f895956 J |
32 | $this->addButtons(array( |
33 | array( | |
34 | 'type' => 'submit', | |
8966f337 | 35 | 'name' => ts('Save'), |
4f895956 J |
36 | 'isDefault' => TRUE, |
37 | ), | |
38 | )); | |
39 | ||
1008246f | 40 | $cacheTime = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); |
68f8aff6 | 41 | $defProf = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_profile')); |
4f895956 | 42 | |
6e2488b3 J |
43 | /*$this->setDefaults(array( |
44 | 'default_widget' => $widgetId));*/ | |
4f895956 J |
45 | $this->setDefaults(array( |
46 | 'default_profile' => $defProf)); | |
1008246f J |
47 | $this->setDefaults(array( |
48 | 'widget_cache_timeout' => $cacheTime)); | |
49 | ||
4f895956 J |
50 | // export form elements |
51 | $this->assign('elementNames', $this->getRenderableElementNames()); | |
52 | ||
8966f337 | 53 | CRM_Utils_System::setTitle(ts('Widget Settings')); |
4f895956 J |
54 | |
55 | parent::buildQuickForm(); | |
56 | } | |
57 | ||
58 | function postProcess() { | |
59 | $values = $this->exportValues(); | |
6e2488b3 | 60 | /*civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_widget' => $values['default_widget'],));*/ |
4f895956 | 61 | civicrm_api3('setting', 'create', array('domain_id' => 1, 'default_wci_profile' => $values['default_profile'],)); |
1008246f | 62 | civicrm_api3('setting', 'create', array('domain_id' => 1, 'widget_cache_timeout' => $values['widget_cache_timeout'],)); |
8966f337 | 63 | CRM_Core_Session::setStatus(ts('Widget settings are saved to database'), '', 'success'); |
4f895956 J |
64 | parent::postProcess(); |
65 | } | |
66 | ||
67 | function getProfiles() { | |
68 | /*$params = array(); | |
69 | $result = civicrm_api3('Profile', 'get', $params); | |
70 | $result = civicrm_api('Profile', 'getcount', $params); | |
71 | print_r($result);*/ | |
72 | } | |
73 | function getWidgets() { | |
74 | $query = "SELECT * FROM civicrm_wci_widget"; | |
75 | $params = array(); | |
76 | ||
77 | $widgetlist = array( | |
78 | '' => ts('- select -'), | |
79 | ); | |
80 | ||
81 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget'); | |
82 | ||
83 | while ($dao->fetch()) { | |
84 | $widgetlist[$dao->id] = $dao->title; | |
85 | } | |
86 | return $widgetlist; | |
87 | } | |
88 | ||
89 | ||
90 | /** | |
91 | * Get the fields/elements defined in this form. | |
92 | * | |
93 | * @return array (string) | |
94 | */ | |
95 | function getRenderableElementNames() { | |
96 | // The _elements list includes some items which should not be | |
97 | // auto-rendered in the loop -- such as "qfKey" and "buttons". These | |
98 | // items don't have labels. We'll identify renderable by filtering on | |
99 | // the 'label'. | |
100 | $elementNames = array(); | |
101 | foreach ($this->_elements as $element) { | |
102 | $label = $element->getLabel(); | |
103 | if (!empty($label)) { | |
104 | $elementNames[] = $element->getName(); | |
105 | } | |
106 | } | |
107 | return $elementNames; | |
108 | } | |
109 | } |