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