Merge pull request #18302 from civicrm/5.29
[civicrm-core.git] / CRM / Campaign / Form / Survey / Delete.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class is to build the form for deleting a Survey.
20 */
21 class CRM_Campaign_Form_Survey_Delete extends CRM_Core_Form {
22
23 /**
24 * The id of the object being deleted
25 *
26 * @var int
27 */
28 protected $_surveyId;
29
30 /**
31 * SurveyTitle
32 *
33 * @var string
34 */
35 protected $_surveyTitle;
36
37 /**
38 * Set variables up before form is built.
39 */
40 public function preProcess() {
41 if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
42 CRM_Utils_System::permissionDenied();
43 }
44
45 $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
46 $params = ['id' => $this->_surveyId];
47 CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo);
48 $this->_surveyTitle = $surveyInfo['title'];
49 $this->assign('surveyTitle', $this->_surveyTitle);
50 CRM_Utils_System::setTitle(ts('Delete Survey') . ' - ' . $this->_surveyTitle);
51 }
52
53 /**
54 * Build the form object.
55 */
56 public function buildQuickForm() {
57 $this->addButtons([
58 [
59 'type' => 'next',
60 'name' => ts('Delete'),
61 'isDefault' => TRUE,
62 ],
63 [
64 'type' => 'cancel',
65 'name' => ts('Cancel'),
66 ],
67 ]);
68 }
69
70 /**
71 * Process the form when submitted.
72 */
73 public function postProcess() {
74 if ($this->_surveyId) {
75 CRM_Campaign_BAO_Survey::del($this->_surveyId);
76 CRM_Core_Session::setStatus('', ts("'%1' survey has been deleted.", [1 => $this->_surveyTitle]), 'success');
77 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
78 }
79 else {
80 CRM_Core_Error::statusBounce(ts('Delete action is missing expected survey ID.'));
81 }
82 }
83
84 }