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