3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Option Group.
21 class CRM_Campaign_Form_SurveyType
extends CRM_Admin_Form
{
25 * The option group name
46 * Set variables up before form is built.
48 * @throws \CRM_Core_Exception
50 public function preProcess() {
51 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
53 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::DELETE
)) {
54 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
55 $this->assign('id', $this->_id
);
57 $this->assign('action', $this->_action
);
58 $this->assign('id', $this->_id
);
60 $this->_BAOName
= 'CRM_Core_BAO_OptionValue';
61 $this->_gName
= 'activity_type';
62 $this->_gid
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName
, 'id', 'name');
64 $session = CRM_Core_Session
::singleton();
65 $url = CRM_Utils_System
::url('civicrm/admin/campaign/surveyType', 'reset=1');
66 $session->pushUserContext($url);
68 if ($this->_id
&& in_array($this->_gName
, CRM_Core_OptionGroup
::$_domainIDGroups)) {
69 $domainID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'domain_id', 'id');
70 if (CRM_Core_Config
::domainID() != $domainID) {
71 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
77 * Set default values for the form.
78 * the default values are retrieved from the database.
81 * array of default values
83 public function setDefaultValues() {
84 $defaults = parent
::setDefaultValues();
86 if (!isset($defaults['weight']) ||
!$defaults['weight']) {
87 $fieldValues = ['option_group_id' => $this->_gid
];
88 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
95 * Build the form object.
97 public function buildQuickForm() {
98 parent
::buildQuickForm();
99 if ($this->_action
& CRM_Core_Action
::DELETE
) {
103 $this->applyFilter('__ALL__', 'trim');
104 $this->add('text', 'label', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
106 $this->add('wysiwyg', 'description',
108 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'description')
111 $this->add('checkbox', 'is_active', ts('Enabled?'));
113 if ($this->_action
== CRM_Core_Action
::UPDATE
&&
114 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id
, 'is_reserved')
116 $this->freeze(['label', 'is_active']);
118 $this->add('number', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
120 $this->assign('id', $this->_id
);
124 * Process the form submission.
126 public function postProcess() {
128 if ($this->_action
& CRM_Core_Action
::DELETE
) {
129 $fieldValues = ['option_group_id' => $this->_gid
];
130 $wt = CRM_Utils_Weight
::delWeight('CRM_Core_DAO_OptionValue', $this->_id
, $fieldValues);
132 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
133 CRM_Core_Session
::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
138 $params = $this->exportValues();
140 // set db value of filter in params if filter is non editable
141 if ($this->_id
&& !array_key_exists('filter', $params)) {
142 $params['filter'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'filter', 'id');
145 $params['component_id'] = CRM_Core_Component
::getComponentID('CiviCampaign');
146 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, $this->_gName
, $this->_action
, $this->_id
);
148 CRM_Core_Session
::setStatus(ts('The Survey type \'%1\' has been saved.', [1 => $optionValue->label
]), ts('Saved'), 'success');