/** * Get Gift Aid declaration record for Individual. * * @param int $contactID - the Individual for whom we retrieve declaration * @param date $date - date for which we retrieve declaration (in ISO date format) * - e.g. the date for which you would like to check if the contact has a valid * declaration * @return array - declaration record as associative array, * else empty array. * @access public * @static */ static function getDeclaration($contactID, $date = null, $contributionID) { if (is_null($date)) { $date = date('Y-m-d H:i:s'); } // Get current declaration: start_date in past, end_date in future or null // - if > 1, pick latest end_date $currentDeclaration = array(); $sql = "\n SELECT *\n FROM civicrm_value_direct_debit_details dd JOIN civicrm_value_bank_details bd ON dd.mandate_id = bd.id \n WHERE dd.entity_id = %1\n "; $sqlParams = array(1 => array($contributionID, 'Integer')); // allow query to be modified via hook DirectDebit_Utils_Hook::alterDeclarationQuery($sql, $sqlParams); $dao = CRM_Core_DAO::executeQuery($sql, $sqlParams); if ($dao->fetch()) { $currentDeclaration['id'] = $dao->id; $currentDeclaration['mandate_id'] = $dao->mandate_id; $currentDeclaration['entity_id'] = $dao->entity_id; $currentDeclaration['eligible_for_direct_debit'] = 1; } //CRM_Core_Error::debug('currentDeclaration', $currentDeclaration); return $currentDeclaration; }