3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality to delete a group of contributions.
21 * This class provides functionality for the actual deletion.
23 class CRM_Contribute_Form_Task_Delete
extends CRM_Contribute_Form_Task
{
26 * Are we operating in "single mode", i.e. deleting one
27 * specific contribution?
31 protected $_single = FALSE;
34 * Build all the data structures needed to build the form.
36 public function preProcess() {
38 if (!CRM_Core_Permission
::checkActionPermission('CiviContribute', CRM_Core_Action
::DELETE
)) {
39 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
45 * Build the form object.
47 public function buildQuickForm() {
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]);
56 // Now check for lineItems
57 if ($lineItems = CRM_Price_BAO_LineItem
::getLineItemsByContributionID($id)) {
58 foreach ($lineItems as $items) {
59 if (!CRM_Core_Permission
::check('delete contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($items['financial_type_id']))) {
60 unset($this->_contributionIds
[$key]);
68 if ($count && empty($this->_contributionIds
)) {
69 CRM_Core_Session
::setStatus(ts('1 contribution could not be deleted.', ['plural' => '%count contributions could not be deleted.', 'count' => $count]), ts('Error'), 'error');
73 'name' => ts('Cancel'),
77 elseif ($count && !empty($this->_contributionIds
)) {
78 CRM_Core_Session
::setStatus(ts('1 contribution will not be deleted.', ['plural' => '%count contributions will not be deleted.', 'count' => $count]), ts('Warning'), 'warning');
79 $this->addDefaultButtons(ts('Delete Contributions'), 'done');
82 $this->addDefaultButtons(ts('Delete Contributions'), 'done');
87 * Process the form after the input has been submitted and validated.
89 public function postProcess() {
90 $deleted = $failed = 0;
91 foreach ($this->_contributionIds
as $contributionId) {
92 if (CRM_Contribute_BAO_Contribution
::deleteContribution($contributionId)) {
101 $msg = ts('%count contribution deleted.', ['plural' => '%count contributions deleted.', 'count' => $deleted]);
102 CRM_Core_Session
::setStatus($msg, ts('Removed'), 'success');
106 CRM_Core_Session
::setStatus(ts('1 could not be deleted.', ['plural' => '%count could not be deleted.', 'count' => $failed]), ts('Error'), 'error');