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
39 * Set variables up before form is built.
41 * @throws \CRM_Core_Exception
43 public function preProcess() {
44 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this);
46 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::DELETE
)) {
47 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
48 $this->assign('id', $this->_id
);
50 $this->assign('action', $this->_action
);
51 $this->assign('id', $this->_id
);
53 $this->_BAOName
= 'CRM_Core_BAO_OptionValue';
54 $this->_gName
= 'activity_type';
55 $this->_gid
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName
, 'id', 'name');
57 $session = CRM_Core_Session
::singleton();
58 $url = CRM_Utils_System
::url('civicrm/admin/campaign/surveyType', 'reset=1');
59 $session->pushUserContext($url);
61 if ($this->_id
&& in_array($this->_gName
, CRM_Core_OptionGroup
::$_domainIDGroups)) {
62 $domainID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'domain_id', 'id');
63 if (CRM_Core_Config
::domainID() != $domainID) {
64 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
70 * Set default values for the form.
71 * the default values are retrieved from the database.
74 * array of default values
76 public function setDefaultValues() {
77 $defaults = parent
::setDefaultValues();
79 if (!isset($defaults['weight']) ||
!$defaults['weight']) {
80 $fieldValues = ['option_group_id' => $this->_gid
];
81 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
88 * Build the form object.
90 public function buildQuickForm() {
91 parent
::buildQuickForm();
92 if ($this->_action
& CRM_Core_Action
::DELETE
) {
96 $this->applyFilter('__ALL__', 'trim');
97 $this->add('text', 'label', ts('Title'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
99 $this->add('wysiwyg', 'description',
101 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'description')
104 $this->add('checkbox', 'is_active', ts('Enabled?'));
106 if ($this->_action
== CRM_Core_Action
::UPDATE
&&
107 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id
, 'is_reserved')
109 $this->freeze(['label', 'is_active']);
111 $this->add('number', 'weight', ts('Order'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
113 $this->assign('id', $this->_id
);
117 * Process the form submission.
119 public function postProcess() {
121 if ($this->_action
& CRM_Core_Action
::DELETE
) {
122 $fieldValues = ['option_group_id' => $this->_gid
];
123 $wt = CRM_Utils_Weight
::delWeight('CRM_Core_DAO_OptionValue', $this->_id
, $fieldValues);
125 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
126 CRM_Core_Session
::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
131 $params = $this->exportValues();
133 // set db value of filter in params if filter is non editable
134 if ($this->_id
&& !array_key_exists('filter', $params)) {
135 $params['filter'] = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id
, 'filter', 'id');
138 $params['component_id'] = CRM_Core_Component
::getComponentID('CiviCampaign');
139 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, $this->_gName
, $this->_action
, $this->_id
);
141 CRM_Core_Session
::setStatus(ts('The Survey type \'%1\' has been saved.', [1 => $optionValue->label
]), ts('Saved'), 'success');