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 processing a survey.
21 class CRM_Campaign_Form_Survey
extends CRM_Core_Form
{
24 * The id of the object being edited.
42 protected $_surveyTitle;
45 * Explicitly declare the entity api name.
47 public function getDefaultEntity() {
52 * Get the entity id being edited.
56 public function getEntityId() {
57 return $this->_surveyId
;
60 public function preProcess() {
61 if (!CRM_Campaign_BAO_Campaign
::accessCampaign()) {
62 CRM_Utils_System
::permissionDenied();
65 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
66 $this->_surveyId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
68 if ($this->_surveyId
) {
69 $this->_single
= TRUE;
71 $params = ['id' => $this->_surveyId
];
72 CRM_Campaign_BAO_Survey
::retrieve($params, $surveyInfo);
73 $this->_surveyTitle
= $surveyInfo['title'];
74 $this->assign('surveyTitle', $this->_surveyTitle
);
75 CRM_Utils_System
::setTitle(ts('Configure Survey - %1', [1 => $this->_surveyTitle
]));
78 $this->assign('action', $this->_action
);
79 $this->assign('surveyId', $this->_surveyId
);
81 // Add custom data to form
82 CRM_Custom_Form_CustomData
::addToForm($this);
84 // CRM-11480, CRM-11682
85 // Preload libraries required by the "Questions" tab
86 CRM_UF_Page_ProfileEditor
::registerProfileScripts();
87 CRM_UF_Page_ProfileEditor
::registerSchemas(['IndividualModel', 'ActivityModel']);
89 CRM_Campaign_Form_Survey_TabHeader
::build($this);
93 * Build the form object.
95 public function buildQuickForm() {
96 $session = CRM_Core_Session
::singleton();
97 if ($this->_surveyId
) {
101 'name' => ts('Save'),
106 'name' => ts('Save and Done'),
111 'name' => ts('Save and Next'),
112 'spacing' => ' ',
121 'name' => ts('Continue'),
122 'spacing' => ' ',
129 'name' => ts('Cancel'),
131 $this->addButtons($buttons);
133 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
134 $session->replaceUserContext($url);
137 public function endPostProcess() {
138 // make submit buttons keep the current working tab opened.
139 if ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
140 $tabTitle = $className = CRM_Utils_String
::getClassName($this->_name
);
141 if ($tabTitle == 'Main') {
142 $tabTitle = 'Main settings';
144 $subPage = strtolower($className);
145 CRM_Core_Session
::setStatus(ts("'%1' have been saved.", [1 => $tabTitle]), ts('Saved'), 'success');
147 $this->postProcessHook();
149 if ($this->_action
& CRM_Core_Action
::ADD
) {
150 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/survey/configure/questions",
151 "action=update&reset=1&id={$this->_surveyId}"));
153 if ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_done") {
154 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey'));
156 elseif ($this->controller
->getButtonName('submit') == "_qf_{$className}_upload_next") {
157 $subPage = CRM_Campaign_Form_Survey_TabHeader
::getNextTab($this);
158 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/survey/configure/{$subPage}",
159 "action=update&reset=1&id={$this->_surveyId}"));
162 CRM_Utils_System
::redirect(CRM_Utils_System
::url("civicrm/survey/configure/{$subPage}",
163 "action=update&reset=1&id={$this->_surveyId}"));
171 public function getTemplateFileName() {
172 if ($this->controller
->getPrint() ||
$this->getVar('_surveyId') <= 0) {
173 return parent
::getTemplateFileName();
176 // hack lets suppress the form rendering for now
177 self
::$_template->assign('isForm', FALSE);
178 return 'CRM/Campaign/Form/Survey/Tab.tpl';