/** * Function to delete the pledge * * @param int $id pledge id * * @access public * @static * */ static function deletePledge($id) { CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //check for no Completed Payment records with the pledge $payment = new CRM_Pledge_DAO_PledgePayment(); $payment->pledge_id = $id; $payment->find(); while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } $dao = new CRM_Pledge_DAO_Pledge(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Pledge', $dao->id, $dao); // delete the recently created Pledge $pledgeRecent = array('id' => $id, 'type' => 'Pledge'); CRM_Utils_Recent::del($pledgeRecent); return $results; }
/** * Delete all pledge payments. * * @param int $id * Pledge id. * * @return bool */ public static function deletePayments($id) { if (!CRM_Utils_Rule::positiveInteger($id)) { return FALSE; } $transaction = new CRM_Core_Transaction(); $payment = new CRM_Pledge_DAO_PledgePayment(); $payment->pledge_id = $id; if ($payment->find()) { while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } } $transaction->commit(); return TRUE; }