Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
07f8d162 EM |
19 | * This class provides the functionality to delete a group of contributions. |
20 | * | |
21 | * This class provides functionality for the actual deletion. | |
6a488035 TO |
22 | */ |
23 | class CRM_Contribute_Form_Task_Delete extends CRM_Contribute_Form_Task { | |
24 | ||
25 | /** | |
26 | * Are we operating in "single mode", i.e. deleting one | |
27 | * specific contribution? | |
28 | * | |
b67daa72 | 29 | * @var bool |
6a488035 TO |
30 | */ |
31 | protected $_single = FALSE; | |
32 | ||
33 | /** | |
fe482240 | 34 | * Build all the data structures needed to build the form. |
95ea96be | 35 | */ |
389bcebf | 36 | public function preProcess() { |
6a488035 TO |
37 | //check for delete |
38 | if (!CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { | |
beb414cc | 39 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
6a488035 TO |
40 | } |
41 | parent::preProcess(); | |
42 | } | |
43 | ||
44 | /** | |
fe482240 | 45 | * Build the form object. |
6a488035 | 46 | */ |
00be9182 | 47 | public function buildQuickForm() { |
58eb6eb8 | 48 | $count = 0; |
66af7c48 PN |
49 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { |
50 | foreach ($this->_contributionIds as $key => $id) { | |
51 | $finTypeID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'financial_type_id'); | |
52 | if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($finTypeID))) { | |
53 | unset($this->_contributionIds[$key]); | |
54 | $count++; | |
55 | } | |
56 | // Now check for lineItems | |
57 | if ($lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id)) { | |
40c655aa | 58 | foreach ($lineItems as $items) { |
66af7c48 PN |
59 | if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { |
60 | unset($this->_contributionIds[$key]); | |
61 | $count++; | |
62 | break; | |
63 | } | |
58eb6eb8 E |
64 | } |
65 | } | |
66 | } | |
67 | } | |
68 | if ($count && empty($this->_contributionIds)) { | |
be2fb01f CW |
69 | CRM_Core_Session::setStatus(ts('1 contribution could not be deleted.', ['plural' => '%count contributions could not be deleted.', 'count' => $count]), ts('Error'), 'error'); |
70 | $this->addButtons([ | |
71 | [ | |
58eb6eb8 E |
72 | 'type' => 'back', |
73 | 'name' => ts('Cancel'), | |
be2fb01f | 74 | ], |
1330f57a | 75 | ]); |
58eb6eb8 E |
76 | } |
77 | elseif ($count && !empty($this->_contributionIds)) { | |
be2fb01f | 78 | CRM_Core_Session::setStatus(ts('1 contribution will not be deleted.', ['plural' => '%count contributions will not be deleted.', 'count' => $count]), ts('Warning'), 'warning'); |
58eb6eb8 E |
79 | $this->addDefaultButtons(ts('Delete Contributions'), 'done'); |
80 | } | |
81 | else { | |
82 | $this->addDefaultButtons(ts('Delete Contributions'), 'done'); | |
83 | } | |
6a488035 TO |
84 | } |
85 | ||
86 | /** | |
fe482240 | 87 | * Process the form after the input has been submitted and validated. |
6a488035 TO |
88 | */ |
89 | public function postProcess() { | |
99483ce8 | 90 | $deleted = $failed = 0; |
6a488035 TO |
91 | foreach ($this->_contributionIds as $contributionId) { |
92 | if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionId)) { | |
99483ce8 | 93 | $deleted++; |
6a488035 | 94 | } |
99483ce8 CW |
95 | else { |
96 | $failed++; | |
97 | } | |
98 | } | |
99 | ||
100 | if ($deleted) { | |
be2fb01f | 101 | $msg = ts('%count contribution deleted.', ['plural' => '%count contributions deleted.', 'count' => $deleted]); |
99483ce8 CW |
102 | CRM_Core_Session::setStatus($msg, ts('Removed'), 'success'); |
103 | } | |
104 | ||
105 | if ($failed) { | |
be2fb01f | 106 | CRM_Core_Session::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error'); |
6a488035 | 107 | } |
6a488035 | 108 | } |
96025800 | 109 | |
6a488035 | 110 | } |