Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
f299f7db | 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates form components for processing a survey. |
6a488035 TO |
36 | */ |
37 | class CRM_Campaign_Form_Survey extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * The id of the object being edited. |
6a488035 TO |
41 | * |
42 | * @var int | |
43 | */ | |
44 | protected $_surveyId; | |
45 | ||
46 | /** | |
fe482240 | 47 | * Action. |
6a488035 TO |
48 | * |
49 | * @var int | |
50 | */ | |
3a936dab | 51 | public $_action; |
6a488035 TO |
52 | |
53 | /** | |
fe482240 | 54 | * SurveyTitle. |
6a488035 TO |
55 | * |
56 | * @var string | |
57 | */ | |
58 | protected $_surveyTitle; | |
59 | ||
14c67729 MWMC |
60 | /** |
61 | * Explicitly declare the entity api name. | |
62 | */ | |
63 | public function getDefaultEntity() { | |
64 | return 'Survey'; | |
65 | } | |
66 | ||
67 | /** | |
68 | * Get the entity id being edited. | |
69 | * | |
70 | * @return int|null | |
71 | */ | |
72 | public function getEntityId() { | |
73 | return $this->_surveyId; | |
74 | } | |
75 | ||
6a488035 TO |
76 | public function preProcess() { |
77 | if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { | |
78 | CRM_Utils_System::permissionDenied(); | |
79 | } | |
80 | ||
353ffa53 | 81 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); |
6a488035 TO |
82 | $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); |
83 | ||
84 | if ($this->_surveyId) { | |
85 | $this->_single = TRUE; | |
86 | ||
be2fb01f | 87 | $params = ['id' => $this->_surveyId]; |
6a488035 TO |
88 | CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo); |
89 | $this->_surveyTitle = $surveyInfo['title']; | |
90 | $this->assign('surveyTitle', $this->_surveyTitle); | |
be2fb01f | 91 | CRM_Utils_System::setTitle(ts('Configure Survey - %1', [1 => $this->_surveyTitle])); |
6a488035 TO |
92 | } |
93 | ||
94 | $this->assign('action', $this->_action); | |
95 | $this->assign('surveyId', $this->_surveyId); | |
96 | ||
14c67729 MWMC |
97 | // Add custom data to form |
98 | CRM_Custom_Form_CustomData::addToForm($this); | |
98c54bff | 99 | |
6a488035 TO |
100 | // CRM-11480, CRM-11682 |
101 | // Preload libraries required by the "Questions" tab | |
102 | CRM_UF_Page_ProfileEditor::registerProfileScripts(); | |
be2fb01f | 103 | CRM_UF_Page_ProfileEditor::registerSchemas(['IndividualModel', 'ActivityModel']); |
6a488035 TO |
104 | |
105 | CRM_Campaign_Form_Survey_TabHeader::build($this); | |
106 | } | |
107 | ||
108 | /** | |
fe482240 | 109 | * Build the form object. |
6a488035 TO |
110 | */ |
111 | public function buildQuickForm() { | |
112 | $session = CRM_Core_Session::singleton(); | |
113 | if ($this->_surveyId) { | |
be2fb01f CW |
114 | $buttons = [ |
115 | [ | |
6a488035 TO |
116 | 'type' => 'upload', |
117 | 'name' => ts('Save'), | |
118 | 'isDefault' => TRUE, | |
be2fb01f CW |
119 | ], |
120 | [ | |
6a488035 TO |
121 | 'type' => 'upload', |
122 | 'name' => ts('Save and Done'), | |
123 | 'subName' => 'done', | |
be2fb01f CW |
124 | ], |
125 | [ | |
6a488035 TO |
126 | 'type' => 'upload', |
127 | 'name' => ts('Save and Next'), | |
128 | 'spacing' => ' ', | |
129 | 'subName' => 'next', | |
be2fb01f CW |
130 | ], |
131 | ]; | |
6a488035 TO |
132 | } |
133 | else { | |
be2fb01f CW |
134 | $buttons = [ |
135 | [ | |
6a488035 | 136 | 'type' => 'upload', |
f212d37d | 137 | 'name' => ts('Continue'), |
6a488035 TO |
138 | 'spacing' => ' ', |
139 | 'isDefault' => TRUE, | |
be2fb01f CW |
140 | ], |
141 | ]; | |
6a488035 | 142 | } |
be2fb01f | 143 | $buttons[] = [ |
28a04ea9 | 144 | 'type' => 'cancel', |
145 | 'name' => ts('Cancel'), | |
be2fb01f | 146 | ]; |
6a488035 TO |
147 | $this->addButtons($buttons); |
148 | ||
149 | $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); | |
150 | $session->replaceUserContext($url); | |
151 | } | |
152 | ||
00be9182 | 153 | public function endPostProcess() { |
6a488035 TO |
154 | // make submit buttons keep the current working tab opened. |
155 | if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
156 | $tabTitle = $className = CRM_Utils_String::getClassName($this->_name); | |
157 | if ($tabTitle == 'Main') { | |
158 | $tabTitle = 'Main settings'; | |
159 | } | |
353ffa53 | 160 | $subPage = strtolower($className); |
be2fb01f | 161 | CRM_Core_Session::setStatus(ts("'%1' have been saved.", [1 => $tabTitle]), ts('Saved'), 'success'); |
6a488035 TO |
162 | |
163 | $this->postProcessHook(); | |
164 | ||
28a04ea9 | 165 | if ($this->_action & CRM_Core_Action::ADD) { |
6a488035 | 166 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/questions", |
353ffa53 | 167 | "action=update&reset=1&id={$this->_surveyId}")); |
28a04ea9 | 168 | } |
6a488035 TO |
169 | if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") { |
170 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); | |
171 | } | |
4c9b6178 | 172 | elseif ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_next") { |
6a488035 TO |
173 | $subPage = CRM_Campaign_Form_Survey_TabHeader::getNextTab($this); |
174 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}", | |
353ffa53 | 175 | "action=update&reset=1&id={$this->_surveyId}")); |
6a488035 TO |
176 | } |
177 | else { | |
178 | CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}", | |
353ffa53 | 179 | "action=update&reset=1&id={$this->_surveyId}")); |
6a488035 TO |
180 | } |
181 | } | |
182 | } | |
183 | ||
30c4e065 EM |
184 | /** |
185 | * @return string | |
186 | */ | |
00be9182 | 187 | public function getTemplateFileName() { |
481a74f4 | 188 | if ($this->controller->getPrint() || $this->getVar('_surveyId') <= 0) { |
6a488035 TO |
189 | return parent::getTemplateFileName(); |
190 | } | |
191 | else { | |
192 | // hack lets suppress the form rendering for now | |
193 | self::$_template->assign('isForm', FALSE); | |
194 | return 'CRM/Campaign/Form/Survey/Tab.tpl'; | |
195 | } | |
196 | } | |
96025800 | 197 | |
6a488035 | 198 | } |