Fix visibility on legacy functions
[civicrm-core.git] / CRM / Campaign / Form / SurveyType.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | 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 and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
32 */
33
34/**
3819f101 35 * This class generates form components for Option Group.
6a488035
TO
36 */
37class CRM_Campaign_Form_SurveyType extends CRM_Admin_Form {
38 protected $_gid;
39
40 /**
41 * The option group name
42 *
43 * @var string
6a488035
TO
44 */
45 protected $_gName;
46
47 /**
100fef9d 48 * Id
6a488035
TO
49 *
50 * @var int
51 */
52 protected $_id;
53
54 /**
100fef9d 55 * Action
6a488035
TO
56 *
57 * @var int
58 */
3a936dab 59 public $_action;
6a488035
TO
60
61 /**
fe482240 62 * Set variables up before form is built.
95ea96be 63 */
28a04ea9 64 public function preProcess() {
6a488035
TO
65 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
66
67 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
68 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
69 $this->assign('id', $this->_id);
70 }
71 $this->assign('action', $this->_action);
72 $this->assign('id', $this->_id);
73
74 $this->_BAOName = 'CRM_Core_BAO_OptionValue';
353ffa53
TO
75 $this->_gName = 'activity_type';
76 $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName, 'id', 'name');
6a488035
TO
77
78 $session = CRM_Core_Session::singleton();
79 $url = CRM_Utils_System::url('civicrm/admin/campaign/surveyType', 'reset=1');
80 $session->pushUserContext($url);
81
82 if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) {
83 $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id');
84 if (CRM_Core_Config::domainID() != $domainID) {
0499b0ad 85 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
6a488035
TO
86 }
87 }
88 }
89
90 /**
c490a46a 91 * Set default values for the form.
6a488035
TO
92 * the default values are retrieved from the database.
93 *
a6c01b45
CW
94 * @return array
95 * array of default values
6a488035 96 */
00be9182 97 public function setDefaultValues() {
6a488035
TO
98 $defaults = parent::setDefaultValues();
99
100 if (!isset($defaults['weight']) || !$defaults['weight']) {
101 $fieldValues = array('option_group_id' => $this->_gid);
102 $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
103 }
104
105 return $defaults;
106 }
107
108 /**
fe482240 109 * Build the form object.
6a488035
TO
110 */
111 public function buildQuickForm() {
112 parent::buildQuickForm();
113 if ($this->_action & CRM_Core_Action::DELETE) {
114 return;
115 }
116
117 $this->applyFilter('__ALL__', 'trim');
118 $this->add('text', 'label', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
119
5d51a2f9 120 $this->add('wysiwyg', 'description',
6a488035
TO
121 ts('Description'),
122 CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description')
123 );
124
6a488035
TO
125 $this->add('checkbox', 'is_active', ts('Enabled?'));
126
127 if ($this->_action == CRM_Core_Action::UPDATE &&
128 CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id, 'is_reserved')
129 ) {
130 $this->freeze(array('label', 'is_active'));
131 }
7ecddde4 132 $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
6a488035
TO
133
134 $this->assign('id', $this->_id);
135 }
136
137 /**
fe482240 138 * Process the form submission.
6a488035
TO
139 */
140 public function postProcess() {
141
142 if ($this->_action & CRM_Core_Action::DELETE) {
143 $fieldValues = array('option_group_id' => $this->_gid);
144 $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
145
146 if (CRM_Core_BAO_OptionValue::del($this->_id)) {
147 CRM_Core_Session::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
148 }
149 }
150 else {
151 $params = $ids = array();
152 $params = $this->exportValues();
153
154 // set db value of filter in params if filter is non editable
155 if ($this->_id && !array_key_exists('filter', $params)) {
156 $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
157 }
158
159 $groupParams = array('name' => ($this->_gName));
160 $params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign');
161 $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
162
163 CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success');
164 }
165 }
96025800 166
6a488035 167}