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