Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Option Group | |
38 | * | |
39 | */ | |
40 | class CRM_Campaign_Form_SurveyType extends CRM_Admin_Form { | |
41 | protected $_gid; | |
42 | ||
43 | /** | |
44 | * The option group name | |
45 | * | |
46 | * @var string | |
6a488035 TO |
47 | */ |
48 | protected $_gName; | |
49 | ||
50 | /** | |
100fef9d | 51 | * Id |
6a488035 TO |
52 | * |
53 | * @var int | |
54 | */ | |
55 | protected $_id; | |
56 | ||
57 | /** | |
100fef9d | 58 | * Action |
6a488035 TO |
59 | * |
60 | * @var int | |
61 | */ | |
62 | protected $_action; | |
63 | ||
64 | /** | |
100fef9d | 65 | * Set variables up before form is built |
6a488035 TO |
66 | * |
67 | * @param null | |
68 | * | |
69 | * @return void | |
95ea96be EM |
70 | */ |
71 | function preProcess() { | |
6a488035 TO |
72 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); |
73 | ||
74 | if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) { | |
75 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); | |
76 | $this->assign('id', $this->_id); | |
77 | } | |
78 | $this->assign('action', $this->_action); | |
79 | $this->assign('id', $this->_id); | |
80 | ||
81 | $this->_BAOName = 'CRM_Core_BAO_OptionValue'; | |
353ffa53 TO |
82 | $this->_gName = 'activity_type'; |
83 | $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName, 'id', 'name'); | |
6a488035 TO |
84 | |
85 | $session = CRM_Core_Session::singleton(); | |
86 | $url = CRM_Utils_System::url('civicrm/admin/campaign/surveyType', 'reset=1'); | |
87 | $session->pushUserContext($url); | |
88 | ||
89 | if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) { | |
90 | $domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id'); | |
91 | if (CRM_Core_Config::domainID() != $domainID) { | |
0499b0ad | 92 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
93 | } |
94 | } | |
95 | } | |
96 | ||
97 | /** | |
c490a46a | 98 | * Set default values for the form. |
6a488035 TO |
99 | * the default values are retrieved from the database. |
100 | * | |
101 | * @param null | |
102 | * | |
a6c01b45 CW |
103 | * @return array |
104 | * array of default values | |
6a488035 | 105 | */ |
00be9182 | 106 | public function setDefaultValues() { |
6a488035 TO |
107 | $defaults = parent::setDefaultValues(); |
108 | ||
109 | if (!isset($defaults['weight']) || !$defaults['weight']) { | |
110 | $fieldValues = array('option_group_id' => $this->_gid); | |
111 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues); | |
112 | } | |
113 | ||
114 | return $defaults; | |
115 | } | |
116 | ||
117 | /** | |
c490a46a | 118 | * Build the form object |
6a488035 | 119 | * |
355ba699 | 120 | * @return void |
6a488035 TO |
121 | */ |
122 | public function buildQuickForm() { | |
123 | parent::buildQuickForm(); | |
124 | if ($this->_action & CRM_Core_Action::DELETE) { | |
125 | return; | |
126 | } | |
127 | ||
128 | $this->applyFilter('__ALL__', 'trim'); | |
129 | $this->add('text', 'label', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE); | |
130 | ||
131 | $this->addWysiwyg('description', | |
132 | ts('Description'), | |
133 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description') | |
134 | ); | |
135 | ||
6a488035 TO |
136 | $this->add('checkbox', 'is_active', ts('Enabled?')); |
137 | ||
138 | if ($this->_action == CRM_Core_Action::UPDATE && | |
139 | CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id, 'is_reserved') | |
140 | ) { | |
141 | $this->freeze(array('label', 'is_active')); | |
142 | } | |
7ecddde4 | 143 | $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE); |
6a488035 TO |
144 | |
145 | $this->assign('id', $this->_id); | |
146 | } | |
147 | ||
148 | /** | |
c490a46a | 149 | * Process the form submission |
6a488035 | 150 | * |
6a488035 | 151 | * |
355ba699 | 152 | * @return void |
6a488035 TO |
153 | */ |
154 | public function postProcess() { | |
155 | ||
156 | if ($this->_action & CRM_Core_Action::DELETE) { | |
157 | $fieldValues = array('option_group_id' => $this->_gid); | |
158 | $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); | |
159 | ||
160 | if (CRM_Core_BAO_OptionValue::del($this->_id)) { | |
161 | CRM_Core_Session::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success'); | |
162 | } | |
163 | } | |
164 | else { | |
165 | $params = $ids = array(); | |
166 | $params = $this->exportValues(); | |
167 | ||
168 | // set db value of filter in params if filter is non editable | |
169 | if ($this->_id && !array_key_exists('filter', $params)) { | |
170 | $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); | |
171 | } | |
172 | ||
173 | $groupParams = array('name' => ($this->_gName)); | |
174 | $params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign'); | |
175 | $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); | |
176 | ||
177 | CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success'); | |
178 | } | |
179 | } | |
180 | } |