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