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 public function preProcess() {
49 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
51 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::DELETE
)) {
52 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
53 $this->assign('id', $this->_id
);
55 $this->assign('action', $this->_action
);
56 $this->assign('id', $this->_id
);
58 $this->_BAOName
= 'CRM_Core_BAO_OptionValue';
59 $this->_gName
= 'activity_type';
60 $this->_gid
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName
, 'id', 'name');
62 $session = CRM_Core_Session
::singleton();
63 $url = CRM_Utils_System
::url('civicrm/admin/campaign/surveyType', 'reset=1');
64 $session->pushUserContext($url);
66 if ($this->_id
&& in_array($this->_gName
, CRM_Core_OptionGroup
::$_domainIDGroups)) {
67 $domainID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'domain_id', 'id');
68 if (CRM_Core_Config
::domainID() != $domainID) {
69 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
75 * Set default values for the form.
76 * the default values are retrieved from the database.
79 * array of default values
81 public function setDefaultValues() {
82 $defaults = parent
::setDefaultValues();
84 if (!isset($defaults['weight']) ||
!$defaults['weight']) {
85 $fieldValues = ['option_group_id' => $this->_gid
];
86 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
93 * Build the form object.
95 public function buildQuickForm() {
96 parent
::buildQuickForm();
97 if ($this->_action
& CRM_Core_Action
::DELETE
) {
101 $this->applyFilter('__ALL__', 'trim');
102 $this->add('text', 'label', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
104 $this->add('wysiwyg', 'description',
106 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'description')
109 $this->add('checkbox', 'is_active', ts('Enabled?'));
111 if ($this->_action
== CRM_Core_Action
::UPDATE
&&
112 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id
, 'is_reserved')
114 $this->freeze(['label', 'is_active']);
116 $this->add('number', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
118 $this->assign('id', $this->_id
);
122 * Process the form submission.
124 public function postProcess() {
126 if ($this->_action
& CRM_Core_Action
::DELETE
) {
127 $fieldValues = ['option_group_id' => $this->_gid
];
128 $wt = CRM_Utils_Weight
::delWeight('CRM_Core_DAO_OptionValue', $this->_id
, $fieldValues);
130 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
131 CRM_Core_Session
::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
136 $params = $this->exportValues();
138 // set db value of filter in params if filter is non editable
139 if ($this->_id
&& !array_key_exists('filter', $params)) {
140 $params['filter'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'filter', 'id');
143 $params['component_id'] = CRM_Core_Component
::getComponentID('CiviCampaign');
144 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, $this->_gName
, $this->_action
, $this->_id
);
146 CRM_Core_Session
::setStatus(ts('The Survey type \'%1\' has been saved.', [1 => $optionValue->label
]), ts('Saved'), 'success');