_contributionIds as $key => $id) { $finTypeID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'financial_type_id'); if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($finTypeID))) { unset($this->_contributionIds[$key]); $count++; } // Now check for lineItems if ($lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id)) { foreach ($lineItems as $items) { if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($this->_contributionIds[$key]); $count++; break; } } } } } if ($count && empty($this->_contributionIds)) { CRM_Core_Session::setStatus(ts('1 contribution could not be deleted.', array('plural' => '%count contributions could not be deleted.', 'count' => $count)), ts('Error'), 'error'); $this->addButtons(array( array( 'type' => 'back', 'name' => ts('Cancel'), ), ) ); } elseif ($count && !empty($this->_contributionIds)) { CRM_Core_Session::setStatus(ts('1 contribution will not be deleted.', array('plural' => '%count contributions will not be deleted.', 'count' => $count)), ts('Warning'), 'warning'); $this->addDefaultButtons(ts('Delete Contributions'), 'done'); } else { $this->addDefaultButtons(ts('Delete Contributions'), 'done'); } } /** * Process the form after the input has been submitted and validated. */ public function postProcess() { $deleted = $failed = 0; foreach ($this->_contributionIds as $contributionId) { if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionId)) { $deleted++; } else { $failed++; } } if ($deleted) { $msg = ts('%count contribution deleted.', array('plural' => '%count contributions deleted.', 'count' => $deleted)); CRM_Core_Session::setStatus($msg, ts('Removed'), 'success'); } if ($failed) { CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error'); } } }