31453 31498 code cleanup
[com.zyxware.civiwci.git] / CRM / Wci / Form / WCISettings.php
CommitLineData
4f895956 1<?php
bccdda02
J
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM Widget Creation Interface (WCI) Version 1.0 |
5 +--------------------------------------------------------------------+
6 | Copyright Zyxware Technologies (c) 2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM WCI. |
9 | |
10 | CiviCRM WCI is free software; you can copy, modify, and distribute |
11 | it under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
13 | |
14 | CiviCRM WCI is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact Zyxware |
21 | Technologies at info[AT]zyxware[DOT]com. |
22 +--------------------------------------------------------------------+
23*/
4f895956
J
24require_once 'CRM/Core/Form.php';
25
26/**
27 * Form controller class
28 *
29 * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
30 */
31class CRM_Wci_Form_WCISettings extends CRM_Core_Form {
32 function buildQuickForm() {
4f895956 33 $this->add('text', 'default_profile', ts('Default profile'),true)->setSize(45);
1008246f 34 $this->add('text', 'widget_cache_timeout', ts('Widget cache timeout'),true)->setSize(45);
4f895956
J
35 $this->addButtons(array(
36 array(
37 'type' => 'submit',
8966f337 38 'name' => ts('Save'),
4f895956
J
39 'isDefault' => TRUE,
40 ),
41 ));
3ebd2f4b 42$cacheTime = 1;
1008246f 43 $cacheTime = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout'));
3ebd2f4b 44 $defProf = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_profile'));
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'));
bccdda02 54
4f895956
J
55 parent::buildQuickForm();
56 }
57
58 function postProcess() {
59 $values = $this->exportValues();
3ebd2f4b
VJ
60 civicrm_api3('setting', 'create', array('sequential' => 1, 'default_wci_profile' => $values['default_profile']));
61 civicrm_api3('setting', 'create', array('sequential' => 1, 'widget_cache_timeout' => $values['widget_cache_timeout']));
8966f337 62 CRM_Core_Session::setStatus(ts('Widget settings are saved to database'), '', 'success');
4f895956
J
63 parent::postProcess();
64 }
bccdda02 65
4f895956 66 function getProfiles() {
bccdda02
J
67 /* not API to get all profiles now.
68 $params = array();
69 $result = civicrm_api3('Profile', 'get', $params);
4f895956
J
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 );
bccdda02 80
4f895956
J
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
4f895956
J
89 /**
90 * Get the fields/elements defined in this form.
91 *
92 * @return array (string)
93 */
94 function getRenderableElementNames() {
95 // The _elements list includes some items which should not be
96 // auto-rendered in the loop -- such as "qfKey" and "buttons". These
97 // items don't have labels. We'll identify renderable by filtering on
98 // the 'label'.
99 $elementNames = array();
100 foreach ($this->_elements as $element) {
101 $label = $element->getLabel();
102 if (!empty($label)) {
103 $elementNames[] = $element->getName();
104 }
105 }
106 return $elementNames;
107 }
108}