fb6584ce677a2390757d4917b32a39b660753afb
[org.fsf.memberdashboard.git] / CRM / Admin / Form / Setting / MemberDashboard.php
1 <?php
2 /**
3 * FSF Member Dashboard
4 * Copyright © 2014 Free Software Foundation, Inc.
5 *
6 * This file is a part of FSF Member Dashboard.
7 *
8 * FSF Member Dashboard is free software; you can copy, modify, and
9 * distribute it under the terms of the GNU Affero General Public
10 * License Version 3, 19 November 2007 and the CiviCRM Licensing
11 * Exception.
12 *
13 * FSF Member Dashboard is distributed in the hope that it will be
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with FSF Member Dashboard. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23 class CRM_Admin_Form_Setting_MemberDashboard extends CRM_Admin_Form_Setting {
24 protected $_values;
25
26 function setDefaultValues() {
27 return CRM_Core_BAO_Setting::getItem(MEMBERDASHBOARD_SETTINGS_GROUP);
28 }
29
30 /**
31 * Fetch the names and ids of all unreserved profiles.
32 */
33 function fetchProfiles() {
34 $sql = 'SELECT id, title FROM civicrm_uf_group WHERE is_reserved=0';
35 $dao = CRM_Core_DAO::executeQuery($sql);
36 $profiles = array();
37
38 while($dao->fetch()) {
39 $profiles[$dao->id] = $dao->title;
40 }
41
42 return $profiles;
43 }
44
45 public function buildQuickForm() {
46 $this->add('select', 'memberdashboard_info_profile_id',
47 'Member Info Profile', $this->fetchProfiles());
48 $this->applyFilter('__ALL__', 'trim');
49 $this->addButtons(array(
50 array(
51 'type' => 'submit',
52 'name' => ts('Save'),
53 'isDefault' => TRUE,
54 ),
55 ));
56 }
57
58 public function postProcess() {
59 $params = $this->exportValues();
60 $key = 'memberdashboard_info_profile_id';
61 $value = $params[$key];
62
63 civicrm_api3('setting', 'create', array(
64 $key => $value
65 ));
66
67 CRM_Core_Session::setStatus(ts('Settings saved.'), '', 'success');
68 }
69 }