Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
95cdcc0f | 19 | * This class is to build the form for Deleting Group. |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Form_ContributionPage_Delete extends CRM_Contribute_Form_ContributionPage { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Page title. |
6a488035 TO |
25 | * |
26 | * @var string | |
6a488035 TO |
27 | */ |
28 | protected $_title; | |
29 | ||
30 | /** | |
fe482240 | 31 | * Check if there are any related contributions. |
1330f57a | 32 | * @var bool |
6a488035 TO |
33 | */ |
34 | protected $_relatedContributions; | |
35 | ||
36 | /** | |
fe482240 | 37 | * Set variables up before form is built. |
6a488035 TO |
38 | */ |
39 | public function preProcess() { | |
40 | //Check if there are contributions related to Contribution Page | |
41 | ||
42 | parent::preProcess(); | |
43 | ||
44 | //check for delete | |
45 | if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { | |
beb414cc | 46 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
6a488035 TO |
47 | } |
48 | ||
49 | $dao = new CRM_Contribute_DAO_Contribution(); | |
50 | $dao->contribution_page_id = $this->_id; | |
51 | ||
52 | if ($dao->find(TRUE)) { | |
53 | $this->_relatedContributions = TRUE; | |
54 | $this->assign('relatedContributions', TRUE); | |
55 | } | |
56 | } | |
57 | ||
58 | /** | |
fe482240 | 59 | * Build the form object. |
6a488035 TO |
60 | */ |
61 | public function buildQuickForm() { | |
62 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); | |
63 | $this->assign('title', $this->_title); | |
64 | ||
65 | //if there are contributions related to Contribution Page | |
66 | //then onle cancel button is displayed | |
be2fb01f | 67 | $buttons = []; |
6a488035 | 68 | if (!$this->_relatedContributions) { |
be2fb01f | 69 | $buttons[] = [ |
6a488035 TO |
70 | 'type' => 'next', |
71 | 'name' => ts('Delete Contribution Page'), | |
72 | 'isDefault' => TRUE, | |
be2fb01f | 73 | ]; |
6a488035 TO |
74 | } |
75 | ||
be2fb01f | 76 | $buttons[] = [ |
6a488035 TO |
77 | 'type' => 'cancel', |
78 | 'name' => ts('Cancel'), | |
be2fb01f | 79 | ]; |
6a488035 TO |
80 | |
81 | $this->addButtons($buttons); | |
82 | } | |
83 | ||
84 | /** | |
fe482240 | 85 | * Process the form when submitted. |
6a488035 TO |
86 | */ |
87 | public function postProcess() { | |
88 | $transaction = new CRM_Core_Transaction(); | |
89 | ||
90 | // first delete the join entries associated with this contribution page | |
91 | $dao = new CRM_Core_DAO_UFJoin(); | |
92 | ||
be2fb01f | 93 | $params = [ |
6a488035 TO |
94 | 'entity_table' => 'civicrm_contribution_page', |
95 | 'entity_id' => $this->_id, | |
be2fb01f | 96 | ]; |
6a488035 TO |
97 | $dao->copyValues($params); |
98 | $dao->delete(); | |
99 | ||
100 | //next delete the membership block fields | |
353ffa53 | 101 | $dao = new CRM_Member_DAO_MembershipBlock(); |
6a488035 | 102 | $dao->entity_table = 'civicrm_contribution_page'; |
353ffa53 | 103 | $dao->entity_id = $this->_id; |
6a488035 TO |
104 | $dao->delete(); |
105 | ||
106 | //next delete the pcp block fields | |
353ffa53 | 107 | $dao = new CRM_PCP_DAO_PCPBlock(); |
6a488035 | 108 | $dao->entity_table = 'civicrm_contribution_page'; |
353ffa53 | 109 | $dao->entity_id = $this->_id; |
6a488035 TO |
110 | $dao->delete(); |
111 | ||
112 | // need to delete premiums. CRM-4586 | |
113 | CRM_Contribute_BAO_Premium::deletePremium($this->_id); | |
114 | ||
115 | // price set cleanup, CRM-5527 | |
9da8dc8c | 116 | CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id); |
6a488035 TO |
117 | |
118 | // finally delete the contribution page | |
119 | $dao = new CRM_Contribute_DAO_ContributionPage(); | |
120 | $dao->id = $this->_id; | |
121 | $dao->delete(); | |
122 | ||
123 | $transaction->commit(); | |
124 | ||
be2fb01f | 125 | CRM_Core_Session::setStatus(ts("The contribution page '%1' has been deleted.", [1 => $this->_title]), ts('Deleted'), 'success'); |
6a488035 | 126 | } |
96025800 | 127 | |
6a488035 | 128 | } |