class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution

Constants

NOT_NULL

IS_NULL

DB_DAO_NOTNULL

VALUE_SEPARATOR

BULK_INSERT_COUNT

BULK_INSERT_HIGH_COUNT

QUERY_FORMAT_WILDCARD

QUERY_FORMAT_NO_QUOTES

SERIALIZE_SEPARATOR_BOOKEND

SERIALIZE_SEPARATOR_TRIMMED

SERIALIZE_JSON

SERIALIZE_PHP

SERIALIZE_COMMA

Properties

protected int $resultCopies How many times has this instance been cloned. from CRM_Core_DAO
static null $_nullObject from CRM_Core_DAO
static array $_nullArray from CRM_Core_DAO
static $_dbColumnValueCache from CRM_Core_DAO
static array $_testEntitiesToSkip Define entities that shouldn't be created or deleted when creating/ deleting test objects - this prevents world regions, countries etc from being added / deleted from CRM_Core_DAO
static object $_factory The factory class for this application. from CRM_Core_DAO
static $_checkedSqlFunctionsExist from CRM_Core_DAO
protected array $_options https://issues.civicrm.org/jira/browse/CRM-17748 internal variable for DAO to hold per-query settings from CRM_Core_DAO
static string $_tableName Static instance to hold the table name. from CRM_Contribute_DAO_Contribution
static bool $_log Should CiviCRM log any modifications to this table in the civicrm_log table. from CRM_Contribute_DAO_Contribution
int $id Contribution ID from CRM_Contribute_DAO_Contribution
int $contact_id FK to Contact ID from CRM_Contribute_DAO_Contribution
int $financial_type_id FK to Financial Type for (total_amount - non_deductible_amount). from CRM_Contribute_DAO_Contribution
int $contribution_page_id The Contribution Page which triggered this contribution from CRM_Contribute_DAO_Contribution
int $payment_instrument_id FK to Payment Instrument from CRM_Contribute_DAO_Contribution
datetime $receive_date Date contribution was received - not necessarily the creation date of the record from CRM_Contribute_DAO_Contribution
float $non_deductible_amount Portion of total amount which is NOT tax deductible. Equal to total_amount for non-deductible financial types. from CRM_Contribute_DAO_Contribution
float $total_amount Total amount of this contribution. Use market value for non-monetary gifts. from CRM_Contribute_DAO_Contribution
float $fee_amount actual processor fee if known - may be 0. from CRM_Contribute_DAO_Contribution
float $net_amount actual funds transfer amount. total less fees. if processor does not report actual fee during transaction, this is set to total_amount. from CRM_Contribute_DAO_Contribution
string $trxn_id unique transaction id. may be processor id, bank id + trans id, or account number + check number. from CRM_Contribute_DAO_Contribution
string $invoice_id unique invoice id, system generated or passed in from CRM_Contribute_DAO_Contribution
string $invoice_number Human readable invoice number from CRM_Contribute_DAO_Contribution
string $currency 3 character string, value from config setting or input via user. from CRM_Contribute_DAO_Contribution
datetime $cancel_date when was gift cancelled from CRM_Contribute_DAO_Contribution
text $cancel_reason from CRM_Contribute_DAO_Contribution
datetime $receipt_date when (if) receipt was sent. populated automatically for online donations w/ automatic receipting from CRM_Contribute_DAO_Contribution
datetime $thankyou_date when (if) was donor thanked from CRM_Contribute_DAO_Contribution
string $source Origin of this Contribution. from CRM_Contribute_DAO_Contribution
text $amount_level from CRM_Contribute_DAO_Contribution
int $contribution_recur_id Conditional foreign key to civicrm_contribution_recur id. Each contribution made in connection with a recurring contribution carries a foreign key to the recurring contribution record. This assumes we can track these processor initiated events. from CRM_Contribute_DAO_Contribution
bool $is_test from CRM_Contribute_DAO_Contribution
bool $is_pay_later from CRM_Contribute_DAO_Contribution
int $contribution_status_id from CRM_Contribute_DAO_Contribution
int $address_id Conditional foreign key to civicrm_address.id. We insert an address record for each contribution when we have associated billing name and address data. from CRM_Contribute_DAO_Contribution
string $check_number from CRM_Contribute_DAO_Contribution
int $campaign_id The campaign for which this contribution has been triggered. from CRM_Contribute_DAO_Contribution
string $creditnote_id unique credit note id, system generated or passed in from CRM_Contribute_DAO_Contribution
float $tax_amount Total tax amount of this contribution. from CRM_Contribute_DAO_Contribution
datetime $revenue_recognition_date Stores the date when revenue should be recognized. from CRM_Contribute_DAO_Contribution
bool $is_template Shows this is a template for recurring contributions. from CRM_Contribute_DAO_Contribution
static array $_importableFields Static field for all the contribution information that we can potentially import
static array $_exportableFields Static field for all the contribution information that we can potentially export
static array $_trxnIDs Static field to hold financial trxn id's.
CRM_Member_BAO_Membership|CRM_Event_BAO_Participant[] $_relatedObjects Field for all the objects related to this contribution
"event" $_component Field for the component - either 'event' (participant) or 'contribute' (any item related to a contribution page e.g. membership, pledge, contribution) This is used for composing messages because they have dependency on the contribution_page or event page - although over time we may eliminate that
string $trxn_result_code Possibly obsolete variable.

Methods

__construct()

Class constructor.

__clone()

No description

__destruct()

Class destructor.

static 
getTableName()

Returns the names of this table

static 
init(string $dsn)

Initialize the DAO object.

static DB_common
getConnection()

No description

static 
disableFullGroupByMode()

Disables usage of the ONLY_FULL_GROUP_BY Mode if necessary

static 
reenableFullGroupByMode()

Re-enables ONLY_FULL_GROUP_BY sql_mode as necessary.

assignTestFK(string $fieldName, $fieldDef, array $params)

No description

assignTestValue(string $fieldName, array $fieldDef, int $counter)

Assign Test Value.

reset()

Reset the DAO object.

static string
getLocaleTableName(string $tableName)

No description

object
query(string $query, bool $i18nRewrite = TRUE)

Execute a query by the current DAO, localizing it along the way (if needed).

static 
setFactory(object $factory)

Static function to set the factory instance for this class.

DataObject|PEAR_Error
factory(string $table = '')

Factory method to instantiate a new object from a table name.

initialize()

Initialization for all DAO objects. Since we access DB_DO programatically we need to set the links manually.

array
keys()

Defines the default key as 'id'.

array
sequenceKey()

Tells DB_DataObject which keys use autoincrement.

static array
getReferenceColumns()

Returns foreign keys and entity references.

static array
fields()

Returns all the column names of this table

array
table()

Get/set an associative array of table columns

save(bool $hook = TRUE)

Save DAO object.

delete(bool $useWhere = FALSE)

Deletes items from table which match current objects variables.

log(bool $created = FALSE)

No description

bool
copyValues(array $params, bool $serializeArrays = FALSE)

Given an associative array of name/value pairs, extract all the values that belong to this object and initialize the object with said values

static 
storeValues(object $object, array $values)

Store all the values from this object in an associative array this is a destructive store, calling function is responsible for keeping sanity of id's.

static array|null
makeAttribute(array $field)

Create an attribute for this specific field. We only do this for strings and text

static array
getAttribute(string $class, string $fieldName = NULL)

Get the size and maxLength attributes for this text field.

static bool
objectExists(string $value, string $daoName, string $daoID, string $fieldName = 'name', string $domainID = NULL)

Check if there is a record with the same name in the db.

static bool
checkFieldExists(string $tableName, string $columnName, bool $i18nRewrite = TRUE) deprecated

Check if there is a given column in a specific table.

static array
getTableNames()

Scans all the tables using a slow query and table name.

static bool
isDBMyISAM(int $maxTablesToCheck = 10)

No description

static string
getDatabaseName()

Get the name of the CiviCRM database.

static bool
checkConstraintExists(string $tableName, string $constraint)

Checks if a constraint exists for a specified table.

static bool
schemaRequiresRebuilding(array $tables = ["civicrm_contact"])

Checks if CONSTRAINT keyword exists for a specified table.

static bool
checkFKConstraintInFormat(string $tableName, string $columnName)

Checks if the FK constraint name is in the format 'FK_tableName_columnName' for a specified column of a table.

static bool
checkFieldHasAlwaysValue(string $tableName, string $columnName, string $columnValue)

Check whether a specific column in a specific table has always the same value.

static bool
checkFieldIsAlwaysNull(string $tableName, string $columnName)

Check whether a specific column in a specific table is always NULL.

static bool
checkTableExists(string $tableName)

Check if there is a given table in the database.

static bool
checkTableHasData(string $tableName)

Check if a given table has data.

bool
checkVersion($version)

No description

static CRM_Core_DAO
findById(int $id)

Find a DAO object for the given ID and return it.

array
fetchAll()

Returns all results as array-encoded records.

fetchGenerator(string $type = 'dao')

Return the results as PHP generator.

mixed|NULL
fetchValue()

Returns a singular value.

array
fetchMap(string $keyColumn, string $valueColumn)

Get all the result records as mapping between columns.

static string|null
getFieldValue(string $daoName, int $searchValue, string $returnColumn = 'name', string $searchColumn = 'id', bool $force = FALSE)

Given a DAO name, a column name and a column value, find the record and GET the value of another column in that record

static bool
setFieldValue(string $daoName, int $searchValue, string $setColumn, string $setValue, string $searchColumn = 'id')

Given a DAO name, a column name and a column value, find the record and SET the value of another column in that record

static string
getSortString(array|object $sort, string $default = NULL)

Get sort string.

static object
commonRetrieve(string $daoName, array $params, array $defaults, array $returnProperities = NULL)

Fetch object based on array of properties.

static 
deleteEntityContact(string $daoName, int $contactId)

Delete the object records that are associated with this contact.

static CRM_Core_DAO
executeUnbufferedQuery(string $query, array $params = [], bool $abort = TRUE, null $daoName = NULL, bool $freeDAO = FALSE, bool $i18nRewrite = TRUE, bool $trapException = FALSE)

Execute an unbuffered query.

static CRM_Core_DAO|object
executeQuery(string $query, array $params = [], bool $abort = TRUE, null $daoName = NULL, bool $freeDAO = FALSE, bool $i18nRewrite = TRUE, bool $trapException = FALSE, array $options = [])

Execute a query.

bool
isValidOption(array $options)

Wrapper to validate internal DAO options before passing to DB_mysql/DB_Common level

static string|null
singleValueQuery(string $query, array $params = [], bool $abort = TRUE, bool $i18nRewrite = TRUE)

Execute a query and get the single result.

static string
composeQuery(string $query, array $params = [], bool $abort = TRUE)

Compose the query by merging the parameters into it.

static 
freeResult(null $ids = NULL)

No description

static CRM_Core_DAO|bool
copyGeneric(string $daoName, array $criteria, array $newData = NULL, string $fieldsFix = NULL, string $blockCopyOfDependencies = NULL, bool $blockCopyofCustomValues = FALSE)

Make a shallow copy of an object and all the fields in the object.

copyCustomFields(int $entityID, int $newEntityID)

Method that copies custom fields values from an old entity to a new one.

static CRM_Core_DAO|null
cascadeUpdate(string $daoName, $fromId, $toId, array $newData = [])

Cascade update through related entities.

static array
getContactIDsFromComponent($componentIDs, string $tableName, string $idField = 'id')

Given the component id, compute the contact id since its used for things like send email

static object
commonRetrieveAll(string $daoName, string $fieldIdName = 'id', int $fieldId, $details, array $returnProperities = NULL)

Fetch object based on array of properties.

static 
dropAllTables()

Drop all CiviCRM tables.

static string
escapeString($string)

No description

static string
escapeStrings(array $strings, string $default = NULL)

Escape a list of strings for use with "WHERE X IN (.

static string
escapeWildCardString($string)

No description

static object|array|NULL
createTestObject(string $daoName, array $params = [], int $numObjects = 1, bool $createOnly = FALSE)

Creates a test object, including any required objects it needs via recursion createOnly: only create in database, do not store or return the objects (useful for perf testing) ONLY USE FOR TESTING

static 
deleteTestObjects(string $daoName, array $params = [])

Deletes the this object plus any dependent objects that are associated with it.

static 
setCreateDefaults(array $params, $defaults)

Set defaults when creating new entity.

static string
createTempTableName(string $prefix = 'civicrm', bool $addRandomString = TRUE, null $string = NULL) deprecated

No description

static bool
checkTriggerViewPermission(bool $view = TRUE, bool $trigger = TRUE)

No description

static 
debugPrint(null $message = NULL, bool $printDAO = TRUE)

No description

static 
triggerRebuild(string $tableName = NULL, bool $force = FALSE) deprecated

Build a list of triggers via hook and add them to (err, reconcile them with) the database.

static 
checkSqlFunctionsExist()

Because sql functions are sometimes lost, esp during db migration, we check here to avoid numerous support requests

static 
dropTriggers(string $tableName = NULL) deprecated

Wrapper function to drop triggers.

static 
createTriggers(array $info, string $onlyTableName = NULL) deprecated

No description

static array
createReferenceColumns(string $className)

Given a list of fields, create a list of references.

array
findReferences()

Find all records which refer to this entity.

array
getReferenceCounts()

No description

static array
getReferencesToTable(string $tableName)

List all tables which have hard foreign keys to this table.

static 
getReferencesToContactTable()

Get all references to contact table.

static 
appendCustomTablesExtendingContacts(array $cidRefs)

Add custom tables that extend contacts to the list of contact references.

static 
appendCustomContactReferenceFields(array $cidRefs)

Add custom ContactReference fields to the list of contact references

static mixed
getGlobalSetting(string $name, mixed $default = NULL)

Lookup the value of a MySQL global configuration variable.

static 
appendPseudoConstantsToFields(array $fields)

Update the fields array to also hold keys for pseudoconstant fields that relate to contained fields.

static array|bool
buildOptions(string $fieldName, string $context = NULL, array $props = [])

Get options for a given contribution field.

getOptionLabels()

Populate option labels for this object's fields.

static array
buildOptionsContext(string $context = NULL)

Provides documentation and validation for the buildOptions $context param

bool|array
getFieldSpec(string $fieldName)

No description

static NULL|string|array
createSQLFilter(string $fieldName, array $filter, string $type = NULL, string $alias = NULL, bool $returnSanitisedArray = FALSE)

Get SQL where clause for SQL filter syntax input parameters.

static array
acceptedSQLOperators()

No description

static string
shortenSQLName(string $string, int $length = 60, bool $makeRandom = FALSE)

SQL has a limit of 64 characters on various names: table name, trigger name, column name .

setOptions(array $options)

https://issues.civicrm.org/jira/browse/CRM-17748 Sets the internal options to be used on a query

_setDBOptions(array $options)

https://issues.civicrm.org/jira/browse/CRM-17748 wrapper to pass internal DAO options down to DB_mysql/DB_Common level

setApiFilter(array $params) deprecated

No description

array
addSelectWhereClause()

No description

static array
getSelectWhereClause(string $tableAlias = NULL)

This returns the final permissioned query string for this entity

static bool
requireSafeDBName($database)

ensure database name is 'safe', i.e. only contains word characters (includes underscores) and dashes, and contains at least one [a-z] case insenstive.

static string|null
serializeField(array|null $value, int $serializationType)

Transform an array to a serialized string for database storage.

static array|null
unSerializeField(string|null $value, $serializationType)

Transform a serialized string from the database into an array.

static array
getEntityRefFilters()

No description

static array
getExportableFieldsWithPseudoConstants(string $baoClass)

Get exportable fields with pseudoconstants rendered as an extra field.

static array
fieldKeys()

Return a mapping from field-name to the corresponding key (as used in fields()).

bool
getLog()

Returns if this table needs to be logged

static array
import(bool $prefix = FALSE)

Returns the list of fields that can be imported

static array
export(bool $prefix = FALSE)

Returns the list of fields that can be exported

static array
indices(bool $localize = TRUE)

Returns the list of indices

add(array $params, array $ids = [])

Takes an associative array and creates a contribution object.

static bool
isUpdateToRecurringContribution(array $params)

Is this contribution updating an existing recurring contribution.

static array
getDefaults()

Get defaults for new entity.

getValues(array $params, array $values = [], array $ids = [])

Fetch the object and store the values in the values array.

static array
getValuesWithMappings(array $params)

Get the values and resolve the most common mappings.

static 
calculateMissingAmountParams(array $params, int|null $contributionID)

Calculate net_amount & fee_amount if they are not set.

static array
getBillingAddressParams($params, $billingLocationTypeID)

No description

static array
getPaymentProcessorReadyAddressParams(array $params, int $billingLocationTypeID)

Get address params ready to be passed to the payment processor.

int
getNumTermsByContributionAndMembershipType(int $membershipTypeID, int $contributionID)

Get the number of terms for this contribution for a given membership type based on querying the line item table and relevant price field values Note that any one contribution should only be able to have one line item relating to a particular membership type

create(array $params, array $ids = [])

Takes an associative array and creates a contribution object.

static 
resolveDefaults(array $defaults, bool $reverse = FALSE)

Get the values for pseudoconstants for name->value and reverse.

static bool
lookupValue(array $defaults, string $property, array $lookup, bool $reverse)

Convert associative array names to values and vice-versa.

retrieve(array $params, array $defaults = [], array $ids = [])

Retrieve DB object based on input parameters.

static array
importableFields(string $contactType = 'Individual', bool $status = TRUE)

Combine all the importable fields from the lower levels object.

static array
exportableFields(bool $checkPermission = TRUE)

Combine all the exportable fields from the lower level objects.

static 
recordPaymentActivity(int $contributionId, int $participantId, string $totalAmount, string $currency, string $trxnDate)

Record an activity when a payment is received.

static int
getToFinancialAccount($contribution, $params)

Get the value for the To Financial Account.

static array
getRelatedMemberships(int $contributionID)

Get memberships realted to the contribution.

static array
cancel($processContributionObject, $memberships, $contributionId, $membershipStatuses, $updateResult, $participant, $oldStatus, $pledgePayment, $pledgeID, $pledgePaymentIDs, $contributionStatusId)

Cancel contribution.

static 
handleMembershipIDOverride(int $contributionID, array $input)

It is possible to override the membership id that is updated from the payment processor.

static array|null
getTotalAmountAndCount(null $status = NULL, null $startDate = NULL, null $endDate = NULL)

No description

static mixed|null
deleteContribution(int $id)

Delete the indirect records associated with this contribution first.

static 
failPayment(int $contributionID, int $contactID, string $message)

React to a financial transaction (payment) failure.

static bool
checkDuplicate(array $input, array $duplicates, int $id = NULL)

Check if there is a contribution with the same trxn_id or invoice_id.

addPremium(array $params)

Takes an associative array and creates a contribution_product object.

static array
getContributionFields(bool $addExtraFields = TRUE)

Get list of contribution fields for profile.

static 
getSpecialContributionFields()

Add extra fields specific to contribution.

static array
getCurrentandGoalAmount(int $pageID)

No description

static array
getHonorContacts(int $honorId)

Get list of contributions which credit the passed in contact ID.

static null|string
sortName(int $id)

Get the sort name of a contact for a particular contribution.

static array
annual(int|array $contactIDs)

Generate summary of amount received in the current fiscal year to date from the contact or contacts.

static array
checkDuplicateIds(array $params)

Check if there is a contribution with the params passed in.

static array
getContributionDetails(int $exportMode, array $componentIds)

Get the contribution details for component export.

static int
createAddress(array $params, int $billingLocationTypeID)

Create address associated with contribution record.

static 
deleteAddress(int $contributionId = NULL, int $contactId = NULL)

Delete billing address record related contribution.

static int
checkOnlinePendingContribution(int $componentId, string $componentName)

This function check online pending contribution associated w/ Online Event Registration or Online Membership signup.

static array
transitionComponents(array $params, bool $processContributionObject = FALSE) deprecated

Update contribution as well as related objects.

static array
getComponentDetails($contributionId)

Returns all contribution related object ids.

static null|string
contributionCount(int $contactId, bool $includeSoftCredit = TRUE)

No description

static bool
repeatTransaction(CRM_Contribute_BAO_Contribution $contribution, array $input, array $contributionParams, int $paymentProcessorID)

Repeat a transaction as part of a recurring series.

static array
getOnbehalfIds(int $contributionId, int $contributorId = NULL)

Get individual id for onbehalf contribution.

static array
getContributionDates()

No description

bool
loadRelatedObjects(array $input, array $ids, bool $loadAll = FALSE)

Load objects relations to contribution object.

array
composeMessageArray(array $input, array $ids, array $values, bool $returnMessageText = TRUE)

Create array of message information - ie. return html version, txt version, to field

array
_gatherMessageValues(array $input, array $values, array $ids = [])

Gather values for contribution mail - this function has been created as part of CRM-9996 refactoring as a step towards simplifying the composeMessage function Values related to the contribution in question are gathered

mixed
_assignMessageVariablesToTemplate($values, $input, bool $returnMessageText = TRUE)

Assign message variables to template but try to break the habit.

static bool
isCancelSubscriptionSupported(int $contributionId, bool $isNotCancelled = TRUE)

Check whether payment processor supports cancellation of contribution subscription

static string
isSubscriptionCancelled(int $contributionId)

Check whether subscription is already cancelled.

recordFinancialAccounts(array $params, array $financialTrxnValues = NULL)

Create all financial accounts entry.

static 
updateFinancialAccounts(array $params, string $context = NULL)

Update all financial accounts entry.

static bool
isContributionStatusNegative(int $status_id)

Is this contribution status a reversal.

static bool
checkStatusValidation(array $values, array $fields, array $errors)

Check status validation on update of a contribution.

static 
deleteContactContribution(int $contactId)

Delete contribution of contact.

static array|bool
validateFinancialType(int $financialTypeId, string $relationName = 'Expense Account is')

Validate financial type.

static 
addActivityForPayment(int $targetCid, $activityType, string $title, int $contributionId, string $totalAmount, string $currency, string $trxn_date)

No description

static mixed
getPaymentInfo(int $id, $component = 'contribution', bool $getTrxnInfo = FALSE, bool $usingLineTotal = FALSE)

Get list of payments displayed by Contribute_Page_PaymentInfo.

static float
getContributionBalance(int $contributionId, float $contributionTotal = NULL)

Get the outstanding balance on a contribution.

static array
checkTaxAmount(array $params, bool $isLineItem = FALSE)

Get the tax amount (misnamed function).

static void
checkFinancialTypeChange(int $financialTypeId, int $contributionId, array $errors)

Check financial type validation on update of a contribution.

static 
updateRelatedPledge(string $action, int $pledgePaymentID, int $contributionID, bool $adjustTotalAmount, float $total_amount, float $original_total_amount, int $contribution_status_id, int $original_contribution_status_id)

Update related pledge payment payments.

static array|null
computeStats(string $stat, string $sql, string $alias = NULL) deprecated

Compute the stats values

static bool
isSingleLineItem(int $id)

Is there only one line item attached to the contribution.

static array
completeOrder(array $input, array $ids, array $objects, CRM_Core_Transaction $transaction, int $recur, CRM_Contribute_BAO_Contribution $contribution, bool $isPostPaymentCreate = FALSE)

Complete an order.

static array
sendMail(array $input, array $ids, int $contributionID, array $values, bool $returnMessageText = FALSE)

Send receipt from contribution.

static array
generateFromEmailAndName(array $input, CRM_Contribute_BAO_Contribution $contribution)

Generate From email and from name in an array values

static string
createCreditNoteId()

Generate credit note id with next avaible number

array
loadRelatedMembershipObjects(array $ids = []) deprecated

Load related memberships.

recordPartialPayment(array $contribution, array $params)

This function is used to record partial payments for contribution

static string
getRecurringContributionDescription(CRM_Contribute_BAO_Contribution $contribution, CRM_Event_DAO_Event|null $event)

Get the description (source field) for the recurring contribution.

static 
addPayments(array $contributions, string $contributionStatusId = NULL)

Function to add payments for contribution for Partially Paid status

static 
assignProportionalLineItems(array $trxnParams, int $trxnId, float $contributionTotalAmount)

Function use to store line item proportionally in in entity financial trxn table

static 
checkLineItems(array $params)

Checks if line items total amounts match the contribution total amount.

static int
getFinancialAccountForStatusChangeTrxn(array $params, int $default)

Get the financial account for the item associated with the new transaction.

array
addContributionPageValuesToValuesHeavyHandedly(array $values)

ContributionPage values were being imposed onto values.

static string
checkContributeSettings(string $name = NULL, bool $checkInvoicing = FALSE)

Get values of CiviContribute Settings and check if its enabled or not.

static null|string
transitionComponentWithReturnMessage(int $contributionId, int $statusId, int|null $previousStatusId = NULL, string $receiveDate = NULL)

This function process contribution related objects.

static float
getFinancialItemAmountFromParams(array $params, string $context, array $lineItemDetails, bool $isARefund, int $previousLineItemTotal)

Get the amount for the financial item row.

static int
getMultiplier(int $contribution_status_id, string $context)

Get the multiplier for adjusting rows.

static bool
isPaymentInstrumentChange(array $params, array $pendingStatuses)

Does this transaction reflect a payment instrument change.

static 
updateMembershipBasedOnCompletionOfContribution(CRM_Contribute_BAO_Contribution $contribution, int $primaryContributionID, string $changeDate)

Update the memberships associated with a contribution if it has been completed.

static array
getContributionPaymentLinks(int $id, float $balance, string $contributionStatus)

Get payment links as they relate to a contribution.

static string
getAnnualQuery(array $contactIDs)

Get a query to determine the amount donated by the contact/s in the current financial year.

static bool
allowUpdateRevenueRecognitionDate(int $contributionId)

Check if contribution has participant/membership payment.

static null
recordAlwaysAccountsReceivable(array $trxnParams, array $contributionParams)

Create Accounts Receivable financial trxn entry for Completed Contribution.

static float
calculateFinancialItemAmount(array $params, array $amountParams, string $context)

Calculate financial item amount when contribution is updated.

static array
getSalesTaxFinancialAccounts()

Retrieve Sales Tax Financial Accounts.

static 
createProportionalEntry(array $entityParams, array $eftParams)

Create tax entry in civicrm_entity_financial_trxn table.

static array
getLastFinancialItemIds(int $contributionId)

Create array of last financial item id's.

static 
createProportionalFinancialEntries(array $entityParams, array $lineItems, array $ftIds, array $taxItems)

Create proportional entries in civicrm_entity_financial_trxn.

loadRelatedEntitiesByID(array $ids)

Load entities related to the contribution into $this->_relatedObjects.

mixed
isEmailReceipt(array $input)

Should an email receipt be sent for this contribution when complete.

static array
replaceContributionTokens(array $contributionIds, string $subject, array $subjectToken, string $text, string $html, array $messageToken, bool $escapeSmarty)

Function to replace contribution tokens.

static array
getContributionTokenValues(int $id, array $messageToken)

Get the contribution fields for $id and display labels where appropriate (if the token is present).

static string
getInvoiceNumber(int $contributionID)

Get invoice_number for contribution.

array
loadEventMessageTemplateParams(int $eventID, int $participantID, int|null $contributionID)

Load the values needed for the event message.

Details

at line 85
CRM_Core_DAO __construct()

Class constructor.

Return Value

CRM_Core_DAO

in CRM_Core_DAO at line 130
__clone()

in CRM_Core_DAO at line 139
__destruct()

Class destructor.

static getTableName()

Returns the names of this table

in CRM_Core_DAO at line 159
static init(string $dsn)

Initialize the DAO object.

Parameters

string $dsn The database connection string.

in CRM_Core_DAO at line 185
static DB_common getConnection()

Return Value

DB_common

in CRM_Core_DAO at line 194
static disableFullGroupByMode()

Disables usage of the ONLY_FULL_GROUP_BY Mode if necessary

in CRM_Core_DAO at line 206
static reenableFullGroupByMode()

Re-enables ONLY_FULL_GROUP_BY sql_mode as necessary.

.

in CRM_Core_DAO at line 219
protected assignTestFK(string $fieldName, $fieldDef, array $params)

Parameters

string $fieldName
$fieldDef
array $params

at line 5584
protected assignTestValue(string $fieldName, array $fieldDef, int $counter)

Assign Test Value.

Parameters

string $fieldName
array $fieldDef
int $counter The globally-unique ID of the test object.

in CRM_Core_DAO at line 376
reset()

Reset the DAO object.

DAO is kinda crappy in that there is an unwritten rule of one query per DAO.

We attempt to get around this crappy restriction by resetting some of DAO's internal fields. Use this with caution

in CRM_Core_DAO at line 396
static string getLocaleTableName(string $tableName)

Parameters

string $tableName

Return Value

string

in CRM_Core_DAO at line 418
object query(string $query, bool $i18nRewrite = TRUE)

Execute a query by the current DAO, localizing it along the way (if needed).

Parameters

string $query The SQL query for execution.
bool $i18nRewrite Whether to rewrite the query.

Return Value

object the current DAO object after the query execution

in CRM_Core_DAO at line 447
static setFactory(object $factory)

Static function to set the factory instance for this class.

Parameters

object $factory The factory application object.

in CRM_Core_DAO at line 457
DataObject|PEAR_Error factory(string $table = '')

Factory method to instantiate a new object from a table name.

Parameters

string $table

Return Value

DataObject|PEAR_Error

in CRM_Core_DAO at line 469
initialize()

Initialization for all DAO objects. Since we access DB_DO programatically we need to set the links manually.

in CRM_Core_DAO at line 484
array keys()

Defines the default key as 'id'.

Return Value

array

in CRM_Core_DAO at line 499
array sequenceKey()

Tells DB_DataObject which keys use autoincrement.

'id' is autoincrementing by default.

Return Value

array

static array getReferenceColumns()

Returns foreign keys and entity references.

Return Value

array Array of CRM_Core_Reference_Interface

static array fields()

Returns all the column names of this table

Return Value

array

in CRM_Core_DAO at line 535
array table()

Get/set an associative array of table columns

Return Value

array (associative)

in CRM_Core_DAO at line 558
CRM_Core_DAO save(bool $hook = TRUE)

Save DAO object.

Parameters

bool $hook

Return Value

CRM_Core_DAO

in CRM_Core_DAO at line 610
delete(bool $useWhere = FALSE)

Deletes items from table which match current objects variables.

Returns the true on success

for example

Designed to be extended

$object = new mytable(); $object->ID=123; echo $object->delete(); // builds a conditon

$object = new mytable(); $object->whereAdd('age > 12'); $object->limit(1); $object->orderBy('age DESC'); $object->delete(true); // dont use object vars, use the conditions, limit and order.

Parameters

bool $useWhere (optional) If DB_DATAOBJECT_WHEREADD_ONLY is passed in then we will build the condition only using the whereAdd's. Default is to build the condition only using the object parameters.

* @return mixed Int (No. of rows affected) on success, false on failure, 0 on no data affected

in CRM_Core_DAO at line 628
log(bool $created = FALSE)

Parameters

bool $created

in CRM_Core_DAO at line 669
bool copyValues(array $params, bool $serializeArrays = FALSE)

Given an associative array of name/value pairs, extract all the values that belong to this object and initialize the object with said values

Parameters

array $params (reference ) associative array of name/value pairs.
bool $serializeArrays Should arrays that are passed in be serialised according to the metadata. Eventually this should be always true / gone, but in the interests of caution it is being grandfathered in. In general an array is not valid on the DAO but there may be instances where this function is called & then some handling takes place on the would-be array.

Return Value

bool Did we copy all null values into the object

in CRM_Core_DAO at line 725
static storeValues(object $object, array $values)

Store all the values from this object in an associative array this is a destructive store, calling function is responsible for keeping sanity of id's.

Parameters

object $object The object that we are extracting data from.
array $values (reference ) associative array of name/value pairs.

in CRM_Core_DAO at line 747
static array|null makeAttribute(array $field)

Create an attribute for this specific field. We only do this for strings and text

Parameters

array $field The field under task.

Return Value

array|null the attributes for the object

in CRM_Core_DAO at line 800
static array getAttribute(string $class, string $fieldName = NULL)

Get the size and maxLength attributes for this text field.

(or for all text fields) in the DAO object.

Parameters

string $class Name of DAO class.
string $fieldName Field that i'm interested in or null if. you want the attributes for all DAO text fields

Return Value

array assoc array of name => attribute pairs

in CRM_Core_DAO at line 842
static bool objectExists(string $value, string $daoName, string $daoID, string $fieldName = 'name', string $domainID = NULL)

Check if there is a record with the same name in the db.

Parameters

string $value The value of the field we are checking.
string $daoName The dao object name.
string $daoID The id of the object being updated. u can change your name. as long as there is no conflict
string $fieldName The name of the field in the DAO.
string $domainID The id of the domain. Object exists only for the given domain.

Return Value

bool true if object exists

in CRM_Core_DAO at line 871
static bool checkFieldExists(string $tableName, string $columnName, bool $i18nRewrite = TRUE) deprecated

deprecated

Check if there is a given column in a specific table.

Parameters

string $tableName
string $columnName
bool $i18nRewrite Whether to rewrite the query on multilingual setups.

Return Value

bool true if exists, else false

See also

CRM_Core_BAO_SchemaHandler::checkIfFieldExists

in CRM_Core_DAO at line 880
static array getTableNames()

Scans all the tables using a slow query and table name.

Return Value

array

in CRM_Core_DAO at line 901
static bool isDBMyISAM(int $maxTablesToCheck = 10)

Parameters

int $maxTablesToCheck

Return Value

bool

in CRM_Core_DAO at line 919
static string getDatabaseName()

Get the name of the CiviCRM database.

Return Value

string

in CRM_Core_DAO at line 933
static bool checkConstraintExists(string $tableName, string $constraint)

Checks if a constraint exists for a specified table.

Parameters

string $tableName
string $constraint

Return Value

bool true if constraint exists, false otherwise

in CRM_Core_DAO at line 960
static bool schemaRequiresRebuilding(array $tables = ["civicrm_contact"])

Checks if CONSTRAINT keyword exists for a specified table.

Parameters

array $tables

Return Value

bool true if CONSTRAINT keyword exists, false otherwise

Exceptions

Exception

in CRM_Core_DAO at line 995
static bool checkFKConstraintInFormat(string $tableName, string $columnName)

Checks if the FK constraint name is in the format 'FK_tableName_columnName' for a specified column of a table.

Parameters

string $tableName
string $columnName

Return Value

bool true if in format, false otherwise

in CRM_Core_DAO at line 1023
static bool checkFieldHasAlwaysValue(string $tableName, string $columnName, string $columnValue)

Check whether a specific column in a specific table has always the same value.

Parameters

string $tableName
string $columnName
string $columnValue

Return Value

bool true if the value is always $columnValue, false otherwise

in CRM_Core_DAO at line 1039
static bool checkFieldIsAlwaysNull(string $tableName, string $columnName)

Check whether a specific column in a specific table is always NULL.

Parameters

string $tableName
string $columnName

Return Value

bool true if if the value is always NULL, false otherwise

in CRM_Core_DAO at line 1054
static bool checkTableExists(string $tableName)

Check if there is a given table in the database.

Parameters

string $tableName

Return Value

bool true if exists, else false

in CRM_Core_DAO at line 1073
static bool checkTableHasData(string $tableName)

Check if a given table has data.

Parameters

string $tableName

Return Value

bool TRUE if $tableName has at least one record.

in CRM_Core_DAO at line 1083
bool checkVersion($version)

Parameters

$version

Return Value

bool

in CRM_Core_DAO at line 1103
static CRM_Core_DAO findById(int $id)

Find a DAO object for the given ID and return it.

Parameters

int $id Id of the DAO object being searched for.

Return Value

CRM_Core_DAO Object of the type of the class that called this function.

Exceptions

Exception

in CRM_Core_DAO at line 1117
array fetchAll()

Returns all results as array-encoded records.

Return Value

array

in CRM_Core_DAO at line 1131
fetchGenerator(string $type = 'dao')

Return the results as PHP generator.

Parameters

string $type Whether the generator yields 'dao' objects or 'array's.

in CRM_Core_DAO at line 1153
mixed|NULL fetchValue()

Returns a singular value.

Return Value

mixed|NULL

in CRM_Core_DAO at line 1174
array fetchMap(string $keyColumn, string $valueColumn)

Get all the result records as mapping between columns.

Parameters

string $keyColumn Ex: "name"
string $valueColumn Ex: "label"

Return Value

array Ex: ["foo" => "The Foo Bar", "baz" => "The Baz Qux"]

in CRM_Core_DAO at line 1199
static string|null getFieldValue(string $daoName, int $searchValue, string $returnColumn = 'name', string $searchColumn = 'id', bool $force = FALSE)

Given a DAO name, a column name and a column value, find the record and GET the value of another column in that record

Parameters

string $daoName Name of the DAO (Example: CRM_Contact_DAO_Contact to retrieve value from a contact).
int $searchValue Value of the column you want to search by.
string $returnColumn Name of the column you want to GET the value of.
string $searchColumn Name of the column you want to search by.
bool $force Skip use of the cache.

Return Value

string|null Value of $returnColumn in the retrieved record

in CRM_Core_DAO at line 1252
static bool setFieldValue(string $daoName, int $searchValue, string $setColumn, string $setValue, string $searchColumn = 'id')

Given a DAO name, a column name and a column value, find the record and SET the value of another column in that record

Parameters

string $daoName Name of the DAO (Example: CRM_Contact_DAO_Contact to retrieve value from a contact).
int $searchValue Value of the column you want to search by.
string $setColumn Name of the column you want to SET the value of.
string $setValue SET the setColumn to this value.
string $searchColumn Name of the column you want to search by.

Return Value

bool true if we found and updated the object, else false

in CRM_Core_DAO at line 1277
static string getSortString(array|object $sort, string $default = NULL)

Get sort string.

Parameters

array|object $sort either array or CRM_Utils_Sort
string $default Default sort value.

Return Value

string

in CRM_Core_DAO at line 1310
static object commonRetrieve(string $daoName, array $params, array $defaults, array $returnProperities = NULL)

Fetch object based on array of properties.

Parameters

string $daoName Name of the dao object.
array $params (reference ) an assoc array of name/value pairs.
array $defaults (reference ) an assoc array to hold the flattened values.
array $returnProperities An assoc array of fields that need to be returned, eg array( 'first_name', 'last_name').

Return Value

object an object of type referenced by daoName

in CRM_Core_DAO at line 1335
static deleteEntityContact(string $daoName, int $contactId)

Delete the object records that are associated with this contact.

Parameters

string $daoName Name of the dao object.
int $contactId Id of the contact to delete.

in CRM_Core_DAO at line 1360
static CRM_Core_DAO executeUnbufferedQuery(string $query, array $params = [], bool $abort = TRUE, null $daoName = NULL, bool $freeDAO = FALSE, bool $i18nRewrite = TRUE, bool $trapException = FALSE)

Execute an unbuffered query.

This is a wrapper around new functionality exposed with CRM-17748.

Parameters

string $query query to be executed
array $params
bool $abort
null $daoName
bool $freeDAO
bool $i18nRewrite
bool $trapException

Return Value

CRM_Core_DAO Object that points to an unbuffered result set

in CRM_Core_DAO at line 1401
static CRM_Core_DAO|object executeQuery(string $query, array $params = [], bool $abort = TRUE, null $daoName = NULL, bool $freeDAO = FALSE, bool $i18nRewrite = TRUE, bool $trapException = FALSE, array $options = [])

Execute a query.

Parameters

string $query Query to be executed.
array $params
bool $abort
null $daoName
bool $freeDAO
bool $i18nRewrite
bool $trapException
array $options

Return Value

CRM_Core_DAO|object object that holds the results of the query NB - if this is defined as just returning a DAO phpstorm keeps pointing out all the properties that are not part of the DAO

in CRM_Core_DAO at line 1456
bool isValidOption(array $options)

Wrapper to validate internal DAO options before passing to DB_mysql/DB_Common level

Parameters

array $options

Return Value

bool Provided options are valid

in CRM_Core_DAO at line 1491
static string|null singleValueQuery(string $query, array $params = [], bool $abort = TRUE, bool $i18nRewrite = TRUE)

Execute a query and get the single result.

Parameters

string $query Query to be executed.
array $params
bool $abort
bool $i18nRewrite

Return Value

string|null the result of the query if any

in CRM_Core_DAO at line 1529
static string composeQuery(string $query, array $params = [], bool $abort = TRUE)

Compose the query by merging the parameters into it.

Parameters

string $query
array $params
bool $abort

Return Value

string

Exceptions

Exception

in CRM_Core_DAO at line 1576
static freeResult(null $ids = NULL)

Parameters

null $ids

in CRM_Core_DAO at line 1623
static CRM_Core_DAO|bool copyGeneric(string $daoName, array $criteria, array $newData = NULL, string $fieldsFix = NULL, string $blockCopyOfDependencies = NULL, bool $blockCopyofCustomValues = FALSE)

Make a shallow copy of an object and all the fields in the object.

Parameters

string $daoName Name of the dao.
array $criteria Array of all the fields & values. on which basis to copy
array $newData Array of all the fields & values. to be copied besides the other fields
string $fieldsFix Array of fields that you want to prefix/suffix/replace.
string $blockCopyOfDependencies Fields that you want to block from. getting copied
bool $blockCopyofCustomValues Case when you don't want to copy the custom values set in a template as it will override/ignore the submitted custom values

Return Value

CRM_Core_DAO|bool the newly created copy of the object. False if none created.

in CRM_Core_DAO at line 1713
copyCustomFields(int $entityID, int $newEntityID)

Method that copies custom fields values from an old entity to a new one.

Fixes bug CRM-19302, where if a custom field of File type was present, left both events using the same file, breaking download URL's for the old event.

Parameters

int $entityID
int $newEntityID

in CRM_Core_DAO at line 1768
static CRM_Core_DAO|null cascadeUpdate(string $daoName, $fromId, $toId, array $newData = [])

Cascade update through related entities.

Parameters

string $daoName
$fromId
$toId
array $newData

Return Value

CRM_Core_DAO|null

in CRM_Core_DAO at line 1813
static array getContactIDsFromComponent($componentIDs, string $tableName, string $idField = 'id')

Given the component id, compute the contact id since its used for things like send email

Parameters

$componentIDs
string $tableName
string $idField

Return Value

array

in CRM_Core_DAO at line 1848
static object commonRetrieveAll(string $daoName, string $fieldIdName = 'id', int $fieldId, $details, array $returnProperities = NULL)

Fetch object based on array of properties.

Parameters

string $daoName Name of the dao object.
string $fieldIdName
int $fieldId
$details
array $returnProperities An assoc array of fields that need to be returned, eg array( 'first_name', 'last_name').

Return Value

object an object of type referenced by daoName

in CRM_Core_DAO at line 1875
static dropAllTables()

Drop all CiviCRM tables.

Exceptions

CRM_Core_Exception

in CRM_Core_DAO at line 1897
static string escapeString($string)

Parameters

$string

Return Value

string

in CRM_Core_DAO at line 1926
static string escapeStrings(array $strings, string $default = NULL)

Escape a list of strings for use with "WHERE X IN (.

..)" queries.

Parameters

array $strings
string $default the value to use if $strings has no elements.

Return Value

string eg "abc","def","ghi"

in CRM_Core_DAO at line 1945
static string escapeWildCardString($string)

Parameters

$string

Return Value

string

in CRM_Core_DAO at line 1973
static object|array|NULL createTestObject(string $daoName, array $params = [], int $numObjects = 1, bool $createOnly = FALSE)

Creates a test object, including any required objects it needs via recursion createOnly: only create in database, do not store or return the objects (useful for perf testing) ONLY USE FOR TESTING

Parameters

string $daoName
array $params
int $numObjects
bool $createOnly

Return Value

object|array|NULL NULL if $createOnly. A single object if $numObjects==1. Otherwise, an array of multiple objects.

in CRM_Core_DAO at line 2062
static deleteTestObjects(string $daoName, array $params = [])

Deletes the this object plus any dependent objects that are associated with it.

ONLY USE FOR TESTING

Parameters

string $daoName
array $params

in CRM_Core_DAO at line 2110
static setCreateDefaults(array $params, $defaults)

Set defaults when creating new entity.

(don't call this set defaults as already in use with different signature in some places)

Parameters

array $params
$defaults

in CRM_Core_DAO at line 2130
static string createTempTableName(string $prefix = 'civicrm', bool $addRandomString = TRUE, null $string = NULL) deprecated

deprecated

Parameters

string $prefix
bool $addRandomString
null $string

Return Value

string

See also

CRM_Utils_SQL_TempTable

in CRM_Core_DAO at line 2150
static bool checkTriggerViewPermission(bool $view = TRUE, bool $trigger = TRUE)

Parameters

bool $view
bool $trigger

Return Value

bool

in CRM_Core_DAO at line 2198
static debugPrint(null $message = NULL, bool $printDAO = TRUE)

Parameters

null $message
bool $printDAO

in CRM_Core_DAO at line 2222
static triggerRebuild(string $tableName = NULL, bool $force = FALSE) deprecated

deprecated

Build a list of triggers via hook and add them to (err, reconcile them with) the database.

Parameters

string $tableName the specific table requiring a rebuild; or NULL to rebuild all tables.
bool $force

See also

CRM-9716

in CRM_Core_DAO at line 2233
static checkSqlFunctionsExist()

Because sql functions are sometimes lost, esp during db migration, we check here to avoid numerous support requests

See also

http://issues.civicrm.org/jira/browse/CRM-13822 TODO: Alternative solutions might be * Stop using functions and find another way to strip numeric characters from phones * Give better error messages (currently a missing fn fatals with "unknown error")

in CRM_Core_DAO at line 2250
static dropTriggers(string $tableName = NULL) deprecated

deprecated

Wrapper function to drop triggers.

Parameters

string $tableName the specific table requiring a rebuild; or NULL to rebuild all tables.

in CRM_Core_DAO at line 2261
static createTriggers(array $info, string $onlyTableName = NULL) deprecated

deprecated

Parameters

array $info per hook_civicrm_triggerInfo.
string $onlyTableName the specific table requiring a rebuild; or NULL to rebuild all tables.

in CRM_Core_DAO at line 2272
static array createReferenceColumns(string $className)

Given a list of fields, create a list of references.

Parameters

string $className BAO/DAO class name.

Return Value

array

in CRM_Core_DAO at line 2295
array findReferences()

Find all records which refer to this entity.

Return Value

array Array of objects referencing this

in CRM_Core_DAO at line 2324
array getReferenceCounts()

Return Value

array each item has keys: - name: string - type: string - count: int - table: string|null SQL table name - key: string|null SQL column name

in CRM_Core_DAO at line 2361
static array getReferencesToTable(string $tableName)

List all tables which have hard foreign keys to this table.

For now, this returns a description of every entity_id/entity_table reference. TODO: filter dynamic entity references on the $tableName, based on schema metadata in dynamicForeignKey which enumerates a restricted set of possible entity_table's.

Parameters

string $tableName Table referred to.

Return Value

array structure of table and column, listing every table with a foreign key reference to $tableName, and the column where the key appears.

in CRM_Core_DAO at line 2386
static getReferencesToContactTable()

Get all references to contact table.

This includes core tables, custom group tables, tables added by the merge hook and the entity_tag table.

Refer to CRM-17454 for information on the danger of querying the information schema to derive this.

in CRM_Core_DAO at line 2418
static appendCustomTablesExtendingContacts(array $cidRefs)

Add custom tables that extend contacts to the list of contact references.

CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity seems like a safe-ish function to be sure all are retrieved & we don't miss subtypes or inactive or multiples - the down side is it is not cached.

Further changes should be include tests in the CRM_Core_MergerTest class to ensure that disabled, subtype, multiple etc groups are still captured.

Parameters

array $cidRefs

in CRM_Core_DAO at line 2435
static appendCustomContactReferenceFields(array $cidRefs)

Add custom ContactReference fields to the list of contact references

This includes active and inactive fields/groups

Parameters

array $cidRefs

Exceptions

CiviCRM_API3_Exception

in CRM_Core_DAO at line 2453
static mixed getGlobalSetting(string $name, mixed $default = NULL)

Lookup the value of a MySQL global configuration variable.

Parameters

string $name E.g. "thread_stack".
mixed $default

Return Value

mixed

in CRM_Core_DAO at line 2477
static appendPseudoConstantsToFields(array $fields)

Update the fields array to also hold keys for pseudoconstant fields that relate to contained fields.

This is relevant where we want to offer both the ID field and the label field as an option, e.g. search builder.

It is currently limited for optionGroupName & id+ name+ FK combos for purposes keeping the scope of the change small, but is appropriate for other sorts of pseudoconstants.

Parameters

array $fields

at line 3924
static array|bool buildOptions(string $fieldName, string $context = NULL, array $props = [])

Get options for a given contribution field.

Parameters

string $fieldName
string $context
array $props whatever is known about this bao object.

Return Value

array|bool

See also

CRM_Core_DAO::buildOptions

in CRM_Core_DAO at line 2542
getOptionLabels()

Populate option labels for this object's fields.

Exceptions

exception if called directly on the base class

in CRM_Core_DAO at line 2568
static array buildOptionsContext(string $context = NULL)

Provides documentation and validation for the buildOptions $context param

Parameters

string $context

Return Value

array

Exceptions

Exception

in CRM_Core_DAO at line 2588
bool|array getFieldSpec(string $fieldName)

Parameters

string $fieldName

Return Value

bool|array

in CRM_Core_DAO at line 2631
static NULL|string|array createSQLFilter(string $fieldName, array $filter, string $type = NULL, string $alias = NULL, bool $returnSanitisedArray = FALSE)

Get SQL where clause for SQL filter syntax input parameters.

SQL version of api function to assign filters to the DAO based on the syntax $field => array('IN' => array(4,6,9)) OR $field => array('LIKE' => array('%me%)) etc

Parameters

string $fieldName Name of fields.
array $filter filter to be applied indexed by operator.
string $type type of field (not actually used - nor in api @todo ).
string $alias alternative field name ('as') @todo- not actually used.
bool $returnSanitisedArray Return a sanitised array instead of a clause. this is primarily so we can add filters @ the api level to the Query object based fields

Return Value

NULL|string|array a string is returned if $returnSanitisedArray is not set, otherwise and Array or NULL depending on whether it is supported as yet

Exceptions

Exception

in CRM_Core_DAO at line 2696
static array acceptedSQLOperators()

Return Value

array

See also

http://issues.civicrm.org/jira/browse/CRM-9150 support for other syntaxes is discussed in ticket but being put off for now

in CRM_Core_DAO at line 2733
static string shortenSQLName(string $string, int $length = 60, bool $makeRandom = FALSE)

SQL has a limit of 64 characters on various names: table name, trigger name, column name .

..

For custom groups and fields we generated names from user entered input which can be longer than this length, this function helps with creating strings that meet various criteria.

Parameters

string $string The string to be shortened.
int $length The max length of the string.
bool $makeRandom

Return Value

string

in CRM_Core_DAO at line 2759
setOptions(array $options)

https://issues.civicrm.org/jira/browse/CRM-17748 Sets the internal options to be used on a query

Parameters

array $options

in CRM_Core_DAO at line 2772
protected _setDBOptions(array $options)

https://issues.civicrm.org/jira/browse/CRM-17748 wrapper to pass internal DAO options down to DB_mysql/DB_Common level

Parameters

array $options

in CRM_Core_DAO at line 2787
setApiFilter(array $params) deprecated

deprecated

Parameters

array $params

at line 1320
array addSelectWhereClause()

Return Value

array

in CRM_Core_DAO at line 2845
static array getSelectWhereClause(string $tableAlias = NULL)

This returns the final permissioned query string for this entity

With acls from related entities + additional clauses from hook_civicrm_selectWhereClause

Parameters

string $tableAlias

Return Value

array

in CRM_Core_DAO at line 2868
static bool requireSafeDBName($database)

ensure database name is 'safe', i.e. only contains word characters (includes underscores) and dashes, and contains at least one [a-z] case insenstive.

Parameters

$database

Return Value

bool

in CRM_Core_DAO at line 2890
static string|null serializeField(array|null $value, int $serializationType)

Transform an array to a serialized string for database storage.

Parameters

array|null $value
int $serializationType

Return Value

string|null

Exceptions

Exception

in CRM_Core_DAO at line 2924
static array|null unSerializeField(string|null $value, $serializationType)

Transform a serialized string from the database into an array.

Parameters

string|null $value
$serializationType

Return Value

array|null

Exceptions

CRM_Core_Exception

in CRM_Core_DAO at line 2955
static array getEntityRefFilters()

Return Value

array

in CRM_Core_DAO at line 2966
static array getExportableFieldsWithPseudoConstants(string $baoClass)

Get exportable fields with pseudoconstants rendered as an extra field.

Parameters

string $baoClass

Return Value

array

static array fieldKeys()

Return a mapping from field-name to the corresponding key (as used in fields()).

Return Value

array Array(string $name => string $uniqueName).

bool getLog()

Returns if this table needs to be logged

Return Value

bool

static array import(bool $prefix = FALSE)

Returns the list of fields that can be imported

Parameters

bool $prefix

Return Value

array

static array export(bool $prefix = FALSE)

Returns the list of fields that can be exported

Parameters

bool $prefix

Return Value

array

static array indices(bool $localize = TRUE)

Returns the list of indices

Parameters

bool $localize

Return Value

array

at line 105
static CRM_Contribute_BAO_Contribution add(array $params, array $ids = [])

Takes an associative array and creates a contribution object.

the function extract all the params it needs to initialize the create a contribution object. the params array could contain additional unused name/value pairs

Parameters

array $params (reference ) an assoc array of name/value pairs.
array $ids The array that holds all the db ids.

Return Value

CRM_Contribute_BAO_Contribution

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception

at line 282
static bool isUpdateToRecurringContribution(array $params)

Is this contribution updating an existing recurring contribution.

We need to upd the status of the linked recurring contribution if we have a new payment against it, or the initial pending payment is being confirmed (or failing).

Parameters

array $params

Return Value

bool

at line 304
static array getDefaults()

Get defaults for new entity.

Return Value

array

at line 327
static CRM_Contribute_BAO_Contribution|null getValues(array $params, array $values = [], array $ids = [])

Fetch the object and store the values in the values array.

Parameters

array $params Input parameters to find object.
array $values Output values of the object.
array $ids The array that holds all the db ids.

Return Value

CRM_Contribute_BAO_Contribution|null The found object or null

at line 363
static array getValuesWithMappings(array $params)

Get the values and resolve the most common mappings.

Since contribution status is resolved in almost every function that calls getValues it makes sense to have an extra function to resolve it rather than repeat the code.

Think carefully before adding more mappings to be resolved as there could be performance implications if this function starts to be called from more iterative functions.

Parameters

array $params Input parameters to find object.

Return Value

array Array of the found contribution.

Exceptions

CRM_Core_Exception

at line 386
static calculateMissingAmountParams(array $params, int|null $contributionID)

Calculate net_amount & fee_amount if they are not set.

Net amount should be total - fee. This should only be called for new contributions.

Parameters

array $params Params for a new contribution before they are saved.
int|null $contributionID Contribution ID if we are dealing with an update.

Exceptions

CiviCRM_API3_Exception

at line 421
static protected array getBillingAddressParams($params, $billingLocationTypeID)

Parameters

$params
$billingLocationTypeID

Return Value

array

at line 461
static array getPaymentProcessorReadyAddressParams(array $params, int $billingLocationTypeID)

Get address params ready to be passed to the payment processor.

We need address params in a couple of formats. For the payment processor we wan state_province_id-5. To create an address we need state_province_id.

Parameters

array $params
int $billingLocationTypeID

Return Value

array

at line 483
int getNumTermsByContributionAndMembershipType(int $membershipTypeID, int $contributionID)

Get the number of terms for this contribution for a given membership type based on querying the line item table and relevant price field values Note that any one contribution should only be able to have one line item relating to a particular membership type

Parameters

int $membershipTypeID
int $contributionID

Return Value

int

at line 504
static CRM_Contribute_BAO_Contribution create(array $params, array $ids = [])

Takes an associative array and creates a contribution object.

Parameters

array $params (reference ) an assoc array of name/value pairs.
array $ids The array that holds all the db ids.

Return Value

CRM_Contribute_BAO_Contribution

at line 661
static resolveDefaults(array $defaults, bool $reverse = FALSE)

Get the values for pseudoconstants for name->value and reverse.

Parameters

array $defaults (reference) the default values, some of which need to be resolved.
bool $reverse True if we want to resolve the values in the reverse direction (value -> name).

at line 682
static bool lookupValue(array $defaults, string $property, array $lookup, bool $reverse)

Convert associative array names to values and vice-versa.

This function is used by both the web form layer and the api. Note that the api needs the name => value conversion, also the view layer typically requires value => name conversion

Parameters

array $defaults
string $property
array $lookup
bool $reverse

Return Value

bool

at line 718
static CRM_Contribute_BAO_Contribution retrieve(array $params, array $defaults = [], array $ids = [])

Retrieve DB object based on input parameters.

It also stores all the retrieved values in the default array.

Parameters

array $params (reference ) an assoc array of name/value pairs.
array $defaults (reference ) an assoc array to hold the name / value pairs. in a hierarchical manner
array $ids (reference) the array that holds all the db ids.

Return Value

CRM_Contribute_BAO_Contribution

at line 736
static array importableFields(string $contactType = 'Individual', bool $status = TRUE)

Combine all the importable fields from the lower levels object.

The ordering is important, since currently we do not have a weight scheme. Adding weight is super important and should be done in the next week or so, before this can be called complete.

Parameters

string $contactType
bool $status

Return Value

array array of importable Fields

at line 807
static array exportableFields(bool $checkPermission = TRUE)

Combine all the exportable fields from the lower level objects.

Parameters

bool $checkPermission

Return Value

array array of exportable Fields

at line 925
static recordPaymentActivity(int $contributionId, int $participantId, string $totalAmount, string $currency, string $trxnDate)

Record an activity when a payment is received.

Parameters

int $contributionId
int $participantId
string $totalAmount
string $currency
string $trxnDate

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception

at line 954
static int getToFinancialAccount($contribution, $params)

Get the value for the To Financial Account.

Parameters

$contribution
$params

Return Value

int

at line 975
static protected array getRelatedMemberships(int $contributionID)

Get memberships realted to the contribution.

Parameters

int $contributionID

Return Value

array

at line 1015
static protected array cancel($processContributionObject, $memberships, $contributionId, $membershipStatuses, $updateResult, $participant, $oldStatus, $pledgePayment, $pledgeID, $pledgePaymentIDs, $contributionStatusId)

Cancel contribution.

This function should only be called from transitioncomponents - it is an interim step in refactoring.

Parameters

$processContributionObject
$memberships
$contributionId
$membershipStatuses
$updateResult
$participant
$oldStatus
$pledgePayment
$pledgeID
$pledgePaymentIDs
$contributionStatusId

Return Value

array

at line 1212
static protected handleMembershipIDOverride(int $contributionID, array $input)

It is possible to override the membership id that is updated from the payment processor.

Historically Paypal does this & it still does if it determines data is messed up - see https://lab.civicrm.org/dev/membership/issues/13

Read the comment block on repeattransaction for more information about how things should work.

Parameters

int $contributionID
array $input

Exceptions

CiviCRM_API3_Exception

at line 1351
static array|null getTotalAmountAndCount(null $status = NULL, null $startDate = NULL, null $endDate = NULL)

Parameters

null $status
null $startDate
null $endDate

Return Value

array|null

at line 1422
static mixed|null deleteContribution(int $id)

Delete the indirect records associated with this contribution first.

Parameters

int $id

Return Value

mixed|null $results no of deleted Contribution on success, false otherwise

at line 1498
static failPayment(int $contributionID, int $contactID, string $message)

React to a financial transaction (payment) failure.

Prior to CRM-16417 these were simply removed from the database but it has been agreed that seeing attempted payments is important for forensic and outreach reasons.

Parameters

int $contributionID
int $contactID
string $message

Exceptions

CiviCRM_API3_Exception

at line 1526
static bool checkDuplicate(array $input, array $duplicates, int $id = NULL)

Check if there is a contribution with the same trxn_id or invoice_id.

Parameters

array $input An assoc array of name/value pairs.
array $duplicates (reference) store ids of duplicate contribs.
int $id

Return Value

bool true if duplicate, false otherwise

at line 1578
static CRM_Contribute_DAO_ContributionProduct addPremium(array $params)

Takes an associative array and creates a contribution_product object.

the function extract all the params it needs to initialize the create a contribution_product object. the params array could contain additional unused name/value pairs

Parameters

array $params (reference) an assoc array of name/value pairs.

Return Value

CRM_Contribute_DAO_ContributionProduct

at line 1595
static array getContributionFields(bool $addExtraFields = TRUE)

Get list of contribution fields for profile.

For now we only allow custom contribution fields to be in profile

Parameters

bool $addExtraFields True if special fields needs to be added.

Return Value

array the list of contribution fields

at line 1624
static getSpecialContributionFields()

Add extra fields specific to contribution.

at line 1666
static array getCurrentandGoalAmount(int $pageID)

Parameters

int $pageID

Return Value

array

at line 1703
static array getHonorContacts(int $honorId)

Get list of contributions which credit the passed in contact ID.

The returned array provides details about the original contribution & donor.

Parameters

int $honorId In Honor of Contact ID.

Return Value

array list of contribution fields

at line 1740
static null|string sortName(int $id)

Get the sort name of a contact for a particular contribution.

Parameters

int $id Id of the contribution.

Return Value

null|string sort name of the contact if found

at line 1759
static array annual(int|array $contactIDs)

Generate summary of amount received in the current fiscal year to date from the contact or contacts.

Parameters

int|array $contactIDs

Return Value

array

at line 1798
static array checkDuplicateIds(array $params)

Check if there is a contribution with the params passed in.

Used for trxn_id,invoice_id and contribution_id

Parameters

array $params An assoc array of name/value pairs.

Return Value

array contribution id if success else NULL

at line 1830
static array getContributionDetails(int $exportMode, array $componentIds)

Get the contribution details for component export.

Parameters

int $exportMode Export mode.
array $componentIds Component ids.

Return Value

array associated array

at line 1897
static int createAddress(array $params, int $billingLocationTypeID)

Create address associated with contribution record.

As long as there is one or more billing field in the parameters we will create the address.

(historically the decision to create or not was based on the payment 'type' but these lines are greyer than once thought).

Parameters

array $params
int $billingLocationTypeID

Return Value

int address id

at line 1913
static deleteAddress(int $contributionId = NULL, int $contactId = NULL)

Delete billing address record related contribution.

Parameters

int $contributionId
int $contactId

at line 1959
static int checkOnlinePendingContribution(int $componentId, string $componentName)

This function check online pending contribution associated w/ Online Event Registration or Online Membership signup.

Parameters

int $componentId Participant/membership id.
string $componentName Event/Membership.

Return Value

int pending contribution id.

at line 2025
static array transitionComponents(array $params, bool $processContributionObject = FALSE) deprecated

deprecated Use api contribute.completetransaction For failures use failPayment (preferably exposing by api in the process).

Update contribution as well as related objects.

This function by-passes hooks - to address this - don't use this function.

Parameters

array $params
bool $processContributionObject

Return Value

array

Exceptions

Exception

at line 2409
static array getComponentDetails($contributionId)

Returns all contribution related object ids.

Parameters

$contributionId

Return Value

array

at line 2472
static null|string contributionCount(int $contactId, bool $includeSoftCredit = TRUE)

Parameters

int $contactId
bool $includeSoftCredit

Return Value

null|string

at line 2550
static protected bool repeatTransaction(CRM_Contribute_BAO_Contribution $contribution, array $input, array $contributionParams, int $paymentProcessorID)

Repeat a transaction as part of a recurring series.

The ideal flow is 1) Processor calls contribution.repeattransaction with contribution_status_id = Pending 2) The repeattransaction loads the 'template contribution' and calls a hook to allow altering of it . 3) Repeat transaction calls order.create to create the pending contribution with correct line items and associated entities. 4) The calling code calls Payment.create which in turn calls CompleteOrder (if completing) which updates the various entities and sends appropriate emails.

Gaps in the above (@todo) 1) many processors still call repeattransaction with contribution_status_id = Completed 2) repeattransaction code is current munged into completeTransaction code for historical bad coding reasons 3) Repeat transaction duplicates rather than calls Order.create 4) Use of payment.create still limited - completetransaction is more common. 5) the template transaction is tricky - historically we used the first contribution linked to a recurring contribution. More recently that was changed to be the most recent. Ideally it would be an actual template - not a contribution used as a template which would give more appropriate flexibility. Note line_items have an entity so that table could be used for the line item template - the difficulty is the custom fields... 6) the determination of the membership to be linked is tricksy. The prioritised method is to load the membership(s) referred to via line items in the template transactions. Any other method is likely to lead to incorrect line items & related entities being created (as the line_item link is a required part of 'correct data'). However there are 3 other methods to determine it - membership_payment record - civicrm_membership.contribution_recur_id - input override. Passing in an input override WILL ensure the membership is extended to prevent regressions of historical processors since this has been handled 'forever' - specifically for paypal. albeit by an even nastier mechanism than the current input override. The count is out on how correct related entities wind up in this case.

Parameters

CRM_Contribute_BAO_Contribution $contribution
array $input
array $contributionParams
int $paymentProcessorID

Return Value

bool

Exceptions

CiviCRM_API3_Exception

at line 2623
static array getOnbehalfIds(int $contributionId, int $contributorId = NULL)

Get individual id for onbehalf contribution.

Parameters

int $contributionId Contribution id.
int $contributorId Contributor id.

Return Value

array containing organization id and individual id

at line 2690
static array getContributionDates()

Return Value

array

at line 2739
bool loadRelatedObjects(array $input, array $ids, bool $loadAll = FALSE)

Load objects relations to contribution object.

Objects are stored in the $_relatedObjects property In the first instance we are just moving functionality from BASEIpn -

Parameters

array $input Input as delivered from Payment Processor.
array $ids Ids as Loaded by Payment Processor.
bool $loadAll Load all related objects - even where id not passed in? (allows API to call this).

Return Value

bool

Exceptions

Exception

See also

http://issues.civicrm.org/jira/browse/CRM-9996 Note that the unit test for the BaseIPN class tests this function

at line 2883
array composeMessageArray(array $input, array $ids, array $values, bool $returnMessageText = TRUE)

Create array of message information - ie. return html version, txt version, to field

Parameters

array $input Incoming information. - is_recur - should this be treated as recurring (not sure why you wouldn't just check presence of recur object but maintaining legacy approach to be careful)
array $ids IDs of related objects.
array $values Any values that may have already been compiled by calling process. This is augmented by values 'gathered' by gatherMessageValues
bool $returnMessageText Distinguishes between whether to send message or return. message text. We are working towards this function ALWAYS returning message text & calling function doing emails / pdfs with it

Return Value

array messages

Exceptions

Exception

at line 3055
array _gatherMessageValues(array $input, array $values, array $ids = [])

Gather values for contribution mail - this function has been created as part of CRM-9996 refactoring as a step towards simplifying the composeMessage function Values related to the contribution in question are gathered

Parameters

array $input Input into function (probably from payment processor).
array $values
array $ids The set of ids related to the input.

Return Value

array

Exceptions

CRM_Core_Exception

at line 3178
mixed _assignMessageVariablesToTemplate($values, $input, bool $returnMessageText = TRUE)

Assign message variables to template but try to break the habit.

In order to get away from leaky variables it is better to ensure variables are set in values and assign them from the send function. Otherwise smarty variables can leak if this is called more than once - e.g. processing multiple recurring payments for processors like IATS that use tokens.

Apply variables for message to smarty template - this function is part of analysing what is in the huge function & breaking it down into manageable chunks. Eventually it will be refactored into something else Note we send directly from this function in some cases because it is only partly refactored.

Don't call this function directly as the signature will change.

Parameters

$values
$input
bool $returnMessageText

Return Value

mixed

at line 3400
static bool isCancelSubscriptionSupported(int $contributionId, bool $isNotCancelled = TRUE)

Check whether payment processor supports cancellation of contribution subscription

Parameters

int $contributionId Contribution id.
bool $isNotCancelled

Return Value

bool

at line 3431
static string isSubscriptionCancelled(int $contributionId)

Check whether subscription is already cancelled.

Parameters

int $contributionId Contribution id.

Return Value

string contribution status

at line 3457
static null|CRM_Core_BAO_FinancialTrxn recordFinancialAccounts(array $params, array $financialTrxnValues = NULL)

Create all financial accounts entry.

Parameters

array $params Contribution object, line item array and params for trxn.
array $financialTrxnValues

Return Value

null|CRM_Core_BAO_FinancialTrxn

at line 3817
static updateFinancialAccounts(array $params, string $context = NULL)

Update all financial accounts entry.

Parameters

array $params Contribution object, line item array and params for trxn.
string $context Update scenarios.

at line 3848
static bool isContributionStatusNegative(int $status_id)

Is this contribution status a reversal.

If so we would expect to record a negative value in the financial_trxn table.

Parameters

int $status_id

Return Value

bool

at line 3867
static bool checkStatusValidation(array $values, array $fields, array $errors)

Check status validation on update of a contribution.

Parameters

array $values Previous form values before submit.
array $fields The input form values.
array $errors List of errors.

Return Value

bool

at line 3904
static deleteContactContribution(int $contactId)

Delete contribution of contact.

CRM-12155

Parameters

int $contactId Contact id.

at line 3972
static array|bool validateFinancialType(int $financialTypeId, string $relationName = 'Expense Account is')

Validate financial type.

CRM-13231

Parameters

int $financialTypeId Financial Type id.
string $relationName

Return Value

array|bool

at line 3993
static addActivityForPayment(int $targetCid, $activityType, string $title, int $contributionId, string $totalAmount, string $currency, string $trxn_date)

Parameters

int $targetCid
$activityType
string $title
int $contributionId
string $totalAmount
string $currency
string $trxn_date

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception

at line 4031
static mixed getPaymentInfo(int $id, $component = 'contribution', bool $getTrxnInfo = FALSE, bool $usingLineTotal = FALSE)

Get list of payments displayed by Contribute_Page_PaymentInfo.

Parameters

int $id
$component
bool $getTrxnInfo
bool $usingLineTotal

Return Value

mixed

at line 4183
static float getContributionBalance(int $contributionId, float $contributionTotal = NULL)

Get the outstanding balance on a contribution.

Parameters

int $contributionId
float $contributionTotal Optional amount to override the saved amount paid (e.g if calculating what it WILL be).

Return Value

float

at line 4203
static array checkTaxAmount(array $params, bool $isLineItem = FALSE)

Get the tax amount (misnamed function).

Parameters

array $params
bool $isLineItem

Return Value

array

at line 4312
static void checkFinancialTypeChange(int $financialTypeId, int $contributionId, array $errors)

Check financial type validation on update of a contribution.

Parameters

int $financialTypeId Value of latest Financial Type.
int $contributionId Contribution Id.
array $errors List of errors.

Return Value

void

at line 4344
static updateRelatedPledge(string $action, int $pledgePaymentID, int $contributionID, bool $adjustTotalAmount, float $total_amount, float $original_total_amount, int $contribution_status_id, int $original_contribution_status_id)

Update related pledge payment payments.

This function has been refactored out of the back office contribution form and may still overlap with other functions.

Parameters

string $action
int $pledgePaymentID
int $contributionID
bool $adjustTotalAmount
float $total_amount
float $original_total_amount
int $contribution_status_id
int $original_contribution_status_id

at line 4413
static array|null computeStats(string $stat, string $sql, string $alias = NULL) deprecated

deprecated

Compute the stats values

Parameters

string $stat either 'mode' or 'median'
string $sql
string $alias of civicrm_contribution

Return Value

array|null

at line 4427
static bool isSingleLineItem(int $id)

Is there only one line item attached to the contribution.

Parameters

int $id Contribution ID.

Return Value

bool

Exceptions

CiviCRM_API3_Exception

at line 4456
static array completeOrder(array $input, array $ids, array $objects, CRM_Core_Transaction $transaction, int $recur, CRM_Contribute_BAO_Contribution $contribution, bool $isPostPaymentCreate = FALSE)

Complete an order.

Do not call this directly - use the contribution.completetransaction api as this function is being refactored.

Currently overloaded to complete a transaction & repeat a transaction - fix!

Moving it out of the BaseIPN class is just the first step.

Parameters

array $input
array $ids
array $objects
CRM_Core_Transaction $transaction
int $recur
CRM_Contribute_BAO_Contribution $contribution
bool $isPostPaymentCreate Is this being called from the payment.create api. If so the api has taken care of financial entities. Note that our goal is that this would only ever be called from payment.create and never handle financials (only transitioning related elements).

Return Value

array

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception

at line 4669
static array sendMail(array $input, array $ids, int $contributionID, array $values, bool $returnMessageText = FALSE)

Send receipt from contribution.

Do not call this directly - it is being refactored. use contribution.sendmessage api call.

Note that the compose message part has been moved to contribution In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it.

Parameters

array $input Incoming data from Payment processor.
array $ids Related object IDs.
int $contributionID
array $values Values related to objects that have already been loaded.
bool $returnMessageText Should text be returned instead of sent. This. is because the function is also used to generate pdfs

Return Value

array

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception
Exception

at line 4701
static array generateFromEmailAndName(array $input, CRM_Contribute_BAO_Contribution $contribution)

Generate From email and from name in an array values

Parameters

array $input
CRM_Contribute_BAO_Contribution $contribution

Return Value

array

at line 4731
static string createCreditNoteId()

Generate credit note id with next avaible number

Return Value

string Credit Note Id.

at line 4768
array loadRelatedMembershipObjects(array $ids = []) deprecated

deprecated Note that in theory it should be possible to retrieve these from the line_item table with the membership_payment table being deprecated. Attempting to do this here causes tests to fail as it seems the api is not correctly linking the line items when the contribution is created in the flow where the contribution is created in the API, followed by the membership (using the api) followed by the membership payment. The membership payment BAO does have code to address this but it doesn't appear to be working. I don't know if it never worked or broke as a result of https://issues.civicrm.org/jira/browse/CRM-14918.

Load related memberships.

Parameters

array $ids

Return Value

array $ids

Exceptions

Exception

at line 4810
static CRM_Financial_DAO_FinancialTrxn recordPartialPayment(array $contribution, array $params)

This function is used to record partial payments for contribution

Parameters

array $contribution
array $params

Return Value

CRM_Financial_DAO_FinancialTrxn

at line 4844
static protected string getRecurringContributionDescription(CRM_Contribute_BAO_Contribution $contribution, CRM_Event_DAO_Event|null $event)

Get the description (source field) for the recurring contribution.

Parameters

CRM_Contribute_BAO_Contribution $contribution
CRM_Event_DAO_Event|null $event

Return Value

string

Exceptions

CiviCRM_API3_Exception

at line 4872
static addPayments(array $contributions, string $contributionStatusId = NULL)

Function to add payments for contribution for Partially Paid status

Parameters

array $contributions
string $contributionStatusId

at line 4915
static assignProportionalLineItems(array $trxnParams, int $trxnId, float $contributionTotalAmount)

Function use to store line item proportionally in in entity financial trxn table

Parameters

array $trxnParams
int $trxnId
float $contributionTotalAmount

Exceptions

CiviCRM_API3_Exception

at line 4938
static checkLineItems(array $params)

Checks if line items total amounts match the contribution total amount.

Parameters

array $params array of order params.

Exceptions

API_Exception

at line 4975
static int getFinancialAccountForStatusChangeTrxn(array $params, int $default)

Get the financial account for the item associated with the new transaction.

Parameters

array $params
int $default

Return Value

int

at line 5013
protected array addContributionPageValuesToValuesHeavyHandedly(array $values)

ContributionPage values were being imposed onto values.

I have made this explicit and removed the couple (is_recur, is_pay_later) we REALLY didn't want superimposed. The rest are left there in their overkill out of cautiousness.

The rationale for making this explicit is that it was a case of carefully set values being seemingly randonly overwritten without much care. In general I think array randomly setting variables en mass is risky.

Parameters

array $values

Return Value

array

at line 5099
static string checkContributeSettings(string $name = NULL, bool $checkInvoicing = FALSE)

Get values of CiviContribute Settings and check if its enabled or not.

Note: The CiviContribute settings are stored as single entry in civicrm_setting in serialized form. Usually this should be stored as flat settings for each form fields as per CiviCRM standards. Since this would take more effort to change the current behaviour of CiviContribute settings we will live with an inconsistency because it's too hard to change for now. https://github.com/civicrm/civicrm-core/pull/8562#issuecomment-227874245

Parameters

string $name
bool $checkInvoicing

Return Value

string

at line 5123
static null|string transitionComponentWithReturnMessage(int $contributionId, int $statusId, int|null $previousStatusId = NULL, string $receiveDate = NULL)

This function process contribution related objects.

Parameters

int $contributionId
int $statusId
int|null $previousStatusId
string $receiveDate

Return Value

null|string

at line 5244
static protected float getFinancialItemAmountFromParams(array $params, string $context, array $lineItemDetails, bool $isARefund, int $previousLineItemTotal)

Get the amount for the financial item row.

Helper function to start to break down recordFinancialTransactions for readability.

The logic is more historical than .. logical. Paths other than the deprecated one are tested.

Codewise, several somewhat disimmilar things have been squished into recordFinancialAccounts for historical reasons. Going forwards we can hope to add tests & improve readibility of that function

Parameters

array $params Params as passed to contribution.create
string $context changeFinancialType| changedAmount
array $lineItemDetails Line items.
bool $isARefund Is this a refund / negative transaction.
int $previousLineItemTotal

Return Value

float

at line 5291
static protected int getMultiplier(int $contribution_status_id, string $context)

Get the multiplier for adjusting rows.

If we are dealing with a refund or cancellation then it will be a negative amount to reflect the negative transaction.

If we are changing Financial Type it will be a negative amount to adjust down the old type.

Parameters

int $contribution_status_id
string $context

Return Value

int

at line 5306
static protected bool isPaymentInstrumentChange(array $params, array $pendingStatuses)

Does this transaction reflect a payment instrument change.

Parameters

array $params
array $pendingStatuses

Return Value

bool

at line 5351
static updateMembershipBasedOnCompletionOfContribution(CRM_Contribute_BAO_Contribution $contribution, int $primaryContributionID, string $changeDate)

Update the memberships associated with a contribution if it has been completed.

Note that the way in which $memberships are loaded as objects is pretty messy & I think we could just load them in this function. Code clean up would compensate for any minor performance implication.

Parameters

CRM_Contribute_BAO_Contribution $contribution
int $primaryContributionID
string $changeDate

Exceptions

CRM_Core_Exception
CiviCRM_API3_Exception

Get payment links as they relate to a contribution.

If a payment can be made then include a payment link & if a refund is appropriate then a refund link.

Parameters

int $id
float $balance
string $contributionStatus

Return Value

array $actionLinks Links array containing: -url -title

at line 5507
static string getAnnualQuery(array $contactIDs)

Get a query to determine the amount donated by the contact/s in the current financial year.

Parameters

array $contactIDs

Return Value

string

at line 5610
static bool allowUpdateRevenueRecognitionDate(int $contributionId)

Check if contribution has participant/membership payment.

Parameters

int $contributionId Contribution ID

Return Value

bool

at line 5640
static null recordAlwaysAccountsReceivable(array $trxnParams, array $contributionParams)

Create Accounts Receivable financial trxn entry for Completed Contribution.

Parameters

array $trxnParams Financial trxn params
array $contributionParams Contribution Params

Return Value

null

at line 5679
static float calculateFinancialItemAmount(array $params, array $amountParams, string $context)

Calculate financial item amount when contribution is updated.

Parameters

array $params contribution params
array $amountParams
string $context

Return Value

float

at line 5706
static array getSalesTaxFinancialAccounts()

Retrieve Sales Tax Financial Accounts.

Return Value

array

at line 5729
static createProportionalEntry(array $entityParams, array $eftParams)

Create tax entry in civicrm_entity_financial_trxn table.

Parameters

array $entityParams
array $eftParams

Exceptions

CiviCRM_API3_Exception

at line 5746
static array getLastFinancialItemIds(int $contributionId)

Create array of last financial item id's.

Parameters

int $contributionId

Return Value

array

at line 5787
static createProportionalFinancialEntries(array $entityParams, array $lineItems, array $ftIds, array $taxItems)

Create proportional entries in civicrm_entity_financial_trxn.

Parameters

array $entityParams
array $lineItems
array $ftIds
array $taxItems

Exceptions

CiviCRM_API3_Exception

at line 5814
protected loadRelatedEntitiesByID(array $ids)

Load entities related to the contribution into $this->_relatedObjects.

Parameters

array $ids

Exceptions

CRM_Core_Exception

at line 5840
protected mixed isEmailReceipt(array $input)

Should an email receipt be sent for this contribution when complete.

Parameters

array $input

Return Value

mixed

at line 5870
static array replaceContributionTokens(array $contributionIds, string $subject, array $subjectToken, string $text, string $html, array $messageToken, bool $escapeSmarty)

Function to replace contribution tokens.

Parameters

array $contributionIds
string $subject
array $subjectToken
string $text
string $html
array $messageToken
bool $escapeSmarty

Return Value

array

Exceptions

CiviCRM_API3_Exception

at line 5900
static array getContributionTokenValues(int $id, array $messageToken)

Get the contribution fields for $id and display labels where appropriate (if the token is present).

Parameters

int $id
array $messageToken

Return Value

array

at line 5923
static string getInvoiceNumber(int $contributionID)

Get invoice_number for contribution.

Parameters

int $contributionID

Return Value

string

at line 5941
protected array loadEventMessageTemplateParams(int $eventID, int $participantID, int|null $contributionID)

Load the values needed for the event message.

Parameters

int $eventID
int $participantID
int|null $contributionID

Return Value

array

Exceptions

CRM_Core_Exception