3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * This class generates form components for Option Group.
37 class CRM_Campaign_Form_SurveyType
extends CRM_Admin_Form
{
41 * The option group name
62 * Set variables up before form is built.
64 public function preProcess() {
65 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
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
);
71 $this->assign('action', $this->_action
);
72 $this->assign('id', $this->_id
);
74 $this->_BAOName
= 'CRM_Core_BAO_OptionValue';
75 $this->_gName
= 'activity_type';
76 $this->_gid
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName
, 'id', 'name');
78 $session = CRM_Core_Session
::singleton();
79 $url = CRM_Utils_System
::url('civicrm/admin/campaign/surveyType', 'reset=1');
80 $session->pushUserContext($url);
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) {
85 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
91 * Set default values for the form.
92 * the default values are retrieved from the database.
95 * array of default values
97 public function setDefaultValues() {
98 $defaults = parent
::setDefaultValues();
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);
109 * Build the form object.
111 public function buildQuickForm() {
112 parent
::buildQuickForm();
113 if ($this->_action
& CRM_Core_Action
::DELETE
) {
117 $this->applyFilter('__ALL__', 'trim');
118 $this->add('text', 'label', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
120 $this->add('wysiwyg', 'description',
122 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'description')
125 $this->add('checkbox', 'is_active', ts('Enabled?'));
127 if ($this->_action
== CRM_Core_Action
::UPDATE
&&
128 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id
, 'is_reserved')
130 $this->freeze(array('label', 'is_active'));
132 $this->add('text', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
134 $this->assign('id', $this->_id
);
138 * Process the form submission.
140 public function postProcess() {
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);
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');
151 $params = $ids = array();
152 $params = $this->exportValues();
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');
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
);
163 CRM_Core_Session
::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label
)), ts('Saved'), 'success');