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 is to build the form for Deleting Group.
21 class CRM_Contribute_Form_ContributionPage_Delete
extends CRM_Contribute_Form_ContributionPage
{
31 * Check if there are any related contributions.
34 protected $_relatedContributions;
37 * Set variables up before form is built.
39 public function preProcess() {
40 //Check if there are contributions related to Contribution Page
45 if (!CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
46 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
49 $dao = new CRM_Contribute_DAO_Contribution();
50 $dao->contribution_page_id
= $this->_id
;
52 if ($dao->find(TRUE)) {
53 $this->_relatedContributions
= TRUE;
54 $this->assign('relatedContributions', TRUE);
59 * Build the form object.
61 public function buildQuickForm() {
62 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
63 $this->assign('title', $this->_title
);
65 //if there are contributions related to Contribution Page
66 //then onle cancel button is displayed
68 if (!$this->_relatedContributions
) {
71 'name' => ts('Delete Contribution Page'),
78 'name' => ts('Cancel'),
81 $this->addButtons($buttons);
85 * Process the form when submitted.
87 public function postProcess() {
88 $transaction = new CRM_Core_Transaction();
90 // first delete the join entries associated with this contribution page
91 $dao = new CRM_Core_DAO_UFJoin();
94 'entity_table' => 'civicrm_contribution_page',
95 'entity_id' => $this->_id
,
97 $dao->copyValues($params);
100 //next delete the membership block fields
101 $dao = new CRM_Member_DAO_MembershipBlock();
102 $dao->entity_table
= 'civicrm_contribution_page';
103 $dao->entity_id
= $this->_id
;
106 //next delete the pcp block fields
107 $dao = new CRM_PCP_DAO_PCPBlock();
108 $dao->entity_table
= 'civicrm_contribution_page';
109 $dao->entity_id
= $this->_id
;
112 // need to delete premiums. CRM-4586
113 CRM_Contribute_BAO_Premium
::deletePremium($this->_id
);
115 // price set cleanup, CRM-5527
116 CRM_Price_BAO_PriceSet
::removeFrom('civicrm_contribution_page', $this->_id
);
118 // finally delete the contribution page
119 $dao = new CRM_Contribute_DAO_ContributionPage();
120 $dao->id
= $this->_id
;
123 $transaction->commit();
125 CRM_Core_Session
::setStatus(ts("The contribution page '%1' has been deleted.", [1 => $this->_title
]), ts('Deleted'), 'success');