minor phpcs updates
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage / Delete.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34/**
35 * This class is to build the form for Deleting Group
36 */
37class CRM_Contribute_Form_ContributionPage_Delete extends CRM_Contribute_Form_ContributionPage {
38
39 /**
fe482240 40 * Page title.
6a488035
TO
41 *
42 * @var string
6a488035
TO
43 */
44 protected $_title;
45
46 /**
fe482240 47 * Check if there are any related contributions.
6a488035
TO
48 */
49 protected $_relatedContributions;
50
51 /**
fe482240 52 * Set variables up before form is built.
6a488035
TO
53 *
54 * @return void
6a488035
TO
55 */
56 public function preProcess() {
57 //Check if there are contributions related to Contribution Page
58
59 parent::preProcess();
60
61 //check for delete
62 if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
0499b0ad 63 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
6a488035
TO
64 }
65
66 $dao = new CRM_Contribute_DAO_Contribution();
67 $dao->contribution_page_id = $this->_id;
68
69 if ($dao->find(TRUE)) {
70 $this->_relatedContributions = TRUE;
71 $this->assign('relatedContributions', TRUE);
72 }
73 }
74
75 /**
fe482240 76 * Build the form object.
6a488035 77 *
355ba699 78 * @return void
6a488035
TO
79 */
80 public function buildQuickForm() {
81 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
82 $this->assign('title', $this->_title);
83
84 //if there are contributions related to Contribution Page
85 //then onle cancel button is displayed
86 $buttons = array();
87 if (!$this->_relatedContributions) {
88 $buttons[] = array(
89 'type' => 'next',
90 'name' => ts('Delete Contribution Page'),
91 'isDefault' => TRUE,
92 );
93 }
94
95 $buttons[] = array(
96 'type' => 'cancel',
97 'name' => ts('Cancel'),
98 );
99
100 $this->addButtons($buttons);
101 }
102
103 /**
fe482240 104 * Process the form when submitted.
6a488035
TO
105 */
106 public function postProcess() {
107 $transaction = new CRM_Core_Transaction();
108
109 // first delete the join entries associated with this contribution page
110 $dao = new CRM_Core_DAO_UFJoin();
111
112 $params = array(
113 'entity_table' => 'civicrm_contribution_page',
114 'entity_id' => $this->_id,
115 );
116 $dao->copyValues($params);
117 $dao->delete();
118
119 //next delete the membership block fields
353ffa53 120 $dao = new CRM_Member_DAO_MembershipBlock();
6a488035 121 $dao->entity_table = 'civicrm_contribution_page';
353ffa53 122 $dao->entity_id = $this->_id;
6a488035
TO
123 $dao->delete();
124
125 //next delete the pcp block fields
353ffa53 126 $dao = new CRM_PCP_DAO_PCPBlock();
6a488035 127 $dao->entity_table = 'civicrm_contribution_page';
353ffa53 128 $dao->entity_id = $this->_id;
6a488035
TO
129 $dao->delete();
130
131 // need to delete premiums. CRM-4586
132 CRM_Contribute_BAO_Premium::deletePremium($this->_id);
133
134 // price set cleanup, CRM-5527
9da8dc8c 135 CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
6a488035
TO
136
137 // finally delete the contribution page
138 $dao = new CRM_Contribute_DAO_ContributionPage();
139 $dao->id = $this->_id;
140 $dao->delete();
141
142 $transaction->commit();
143
144 CRM_Core_Session::setStatus(ts("The contribution page '%1' has been deleted.", array(1 => $this->_title)), ts('Deleted'), 'success');
145 }
96025800 146
6a488035 147}