*
* @return array
*/
- public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE) {
+ static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL) {
$params = array();
if (empty($formValues)) {
return $params;
}
}
else {
- $values = CRM_Contact_BAO_Query::fixWhereValues($id, $values, $wildcard, $useEquals);
+ $values = CRM_Contact_BAO_Query::fixWhereValues($id, $values, $wildcard, $useEquals, $apiEntity);
if (!$values) {
continue;
*
* @return array|null
*/
- public static function &fixWhereValues($id, &$values, $wildcard = 0, $useEquals = FALSE) {
+ static function &fixWhereValues($id, &$values, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL) {
// skip a few search variables
static $skipWhere = NULL;
static $likeNames = NULL;
return $result;
}
+ if ($apiEntity) {
+ $id = $apiEntity . '_' . $id;
+ }
+
if (!$likeNames) {
$likeNames = array('sort_name', 'email', 'note', 'display_name');
}
}
}
- // CRM-13848
- $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues);
- if ($financialType && is_array($financialType)) {
- unset($this->_formValues['financial_type_id']);
- foreach ($financialType as $notImportant => $typeID) {
- $this->_formValues['financial_type_id'][$typeID] = 1;
+ foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status') as $element) {
+ $value = CRM_Utils_Array::value($element, $this->_formValues);
+ if ($value && is_array($value)) {
+ $this->_formValues[$element] = array('IN' => $value);
}
}
+ foreach (array('contribution_source', 'contribution_trxn_id') as $element) {
+ $value = CRM_Utils_Array::value($element, $this->_formValues);
+ $this->_formValues[$element] = array('LIKE' => "%$value%");
+ }
+
$taglist = CRM_Utils_Array::value('contact_taglist', $this->_formValues);
if ($taglist && is_array($taglist)) {
),
);
+ $contributionPage = array(
+ 'contribution_page' => array(
+ 'title' => ts('Contribution Page'),
+ 'name' => 'contribution_page',
+ 'where' => 'civicrm_contribution_page.title',
+ 'data_type' => CRM_Utils_Type::T_STRING
+ ));
+
$contributionNote = array(
'contribution_note' =>
array(
),
);
- $fields = array_merge($impFields, $typeField, $contributionStatus, $optionField, $expFieldProduct,
+ $fields = array_merge($impFields, $typeField, $contributionStatus, $contributionPage, $optionField, $expFieldProduct,
$expFieldsContrib, $contributionNote, $contributionRecurId, $extraFields, $softCreditFields, $financialAccount,
CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')
);
);
return;
- case 'contribution_total_amount':
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.total_amount",
- $op, $value, "Money"
- );
- $query->_qill[$grouping][] = ts('Contribution Total Amount %1 %2', array(1 => $op, 2 => $value));
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
case 'contribution_thankyou_date_is_not_null':
if ($value) {
$op = "IS NOT NULL";
case 'financial_type_id':
case 'financial_type':
- // The financial_type_id might be an array (from aggregate contributions custom search)
- // In this case, we need to change the query.
- if (is_array($value)) {
- $val = array();
- // Rebuild the array to get the data we're interested in as array
- // values not array keys.
- foreach ($value as $k => $v) {
- if ($v) {
- $val[] = $k;
- }
- }
- if (count($val) > 0) {
- // Overwrite $value so it works with an IN where statement.
- $op = 'IN';
- $value = '(' . implode(',', $val) . ')';
- }
- else {
- // If we somehow have an empty array, just return
- return;
- }
+ case 'contribution_page_id':
+ case 'contribution_status':
+ case 'contribution_status_id':
+ case 'contribution_id':
+ case 'contribution_currency_type':
+ case 'contribution_currency':
+ case 'contribution_source':
+ case 'contribution_payment_instrument_id':
+ case 'contribution_payment_instrument':
+ case 'contribution_trxn_id':
+ case (strpos($name, '_amount') !== FALSE):
+ case (strpos($name, '_date') !== FALSE):
+ $qillName = $name;
+ $pseudoExtraParam = NULL;
+ if (in_array($name, array('financial_type', 'contribution_status', 'contribution_payment_instrument'))) {
+ $name = $name . "_id";
}
-
- $types = CRM_Contribute_PseudoConstant::financialType();
-
- // Ensure we have a sensible string to display to the user.
- $names = array();
- if (isset($val) && is_array($val)) {
- foreach ($val as $id) {
- $names[] = CRM_Utils_Array::value($id, $types);
- }
+ if (in_array($name, array('financial_type_id', 'contribution_payment_instrument_id'))) {
+ $qillName = str_replace('_id', '', $name);
}
- else {
- if (!empty($value)) {
- $names[] = $types[$value];
+ if ((strpos($name, '_amount') !== FALSE) || (strpos($name, '_date') !== FALSE) || in_array($name,
+ array(
+ 'contribution_id',
+ 'contribution_currency',
+ 'contribution_payment_instrument_id',
+ 'contribution_payment_instrument',
+ 'contribution_source',
+ 'contribution_trxn_id',
+ 'contribution_check_number'
+ )
+ )
+ ) {
+ $name = str_replace('contribution_', '', $name);
+ if ($name != 'source') {
+ $qillName = str_replace('contribution_', '', $qillName);
}
}
+ if (in_array($name, array('contribution_currency', 'contribution_currency_type'))) {
+ $qillName = $name = 'currency';
+ $pseudoExtraParam = array('labelColumn' => 'name');
+ }
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.financial_type_id",
- $op, $value, "Integer"
- );
- $query->_qill[$grouping][] = ts('Financial Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
+ $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
+
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.$name", $op, $value, $dataType);
+ list($op, $value) = self::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op, $pseudoExtraParam);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
- case 'contribution_page_id':
- $cPage = $value;
- $pages = CRM_Contribute_PseudoConstant::contributionPage();
- $query->_where[$grouping][] = "civicrm_contribution.contribution_page_id = $cPage";
- $query->_qill[$grouping][] = ts('Contribution Page - %1', array(1 => $pages[$cPage]));
+ case 'contribution_page':
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fields[$name]['where'], $op, $value, 'String');
+ list($op, $value) = self::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
+ $query->_tables['civicrm_contribution_page'] = $query->_whereTables['civicrm_contribution_page'] = 1;
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
case 'contribution_pcp_made_through_id':
- $pcPage = $value;
- $pcpages = CRM_Contribute_PseudoConstant::pcPage();
- $query->_where[$grouping][] = "civicrm_contribution_soft.pcp_id = $pcPage";
- $query->_qill[$grouping][] = ts('Personal Campaign Page - %1', array(1 => $pcpages[$pcPage]));
+ case 'contribution_soft_credit_type_id':
+ $qillName = $name;
+ if ($name == 'contribution_pcp_made_through_id') {
+ $qillName = $name = 'pcp_id';
+ $fields[$name] = array('title' => ts('Personal Campaign Page'), 'type' => 2);
+ }
+ if ($name == 'contribution_soft_credit_type_id') {
+ $qillName = str_replace('_id', '', $qillName);
+ $fields[$qillName]['type'] = $fields[$qillName]['data_type'];
+ $name = str_replace('contribution_', '', $name);
+ }
+ $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_soft.$name",
+ $op, $value, CRM_Utils_Type::typeToString($fields[$qillName]['type'])
+ );
+ list($op, $value) = self::buildQillForFieldValue('CRM_Contribute_DAO_ContributionSoft', $name, $value, $op);
+ $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
$query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
return;
// default option: $value == 'only_contribs'
return;
- case 'contribution_soft_credit_type_id':
- $names = array();
- $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type");
- if (is_array($value)) {
- $val = array();
- foreach ($value as $k => $v) {
- if ($v) {
- $val[$k] = $v;
- $names[] = $softCreditTypes[$v];
- }
- }
- $scTypes = (count($val) > 0) ? implode(',', $val) : '';
- if ($scTypes) {
- $op = 'IN';
- $scTypes = "({$scTypes})";
- }
- }
- else {
- $scTypes = $value;
- $names[] = $softCreditTypes[$value];
- }
- $query->_qill[$grouping][] = ts('Soft Credit Type %1', array(1 => $op)) . " '" . implode("' " . ts('or') . " '", $names) . "'";
- $query->_where[$grouping][] =
- CRM_Contact_BAO_Query::buildClause(
- "civicrm_contribution_soft.soft_credit_type_id",
- $op,
- $scTypes,
- "Integer"
- );
- $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
- return;
-
- case 'contribution_payment_instrument_id':
- case 'contribution_payment_instrument':
- $pi = array();
- $pis = CRM_Contribute_PseudoConstant::paymentInstrument();
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- if ($v) {
- $op = 'IN';
- $pi[] = $pis[$v];
- }
- }
- }
- else {
- if (!empty($value)) {
- $pi[] = $pis[$value];
- }
- }
-
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.payment_instrument_id",
- $op, $value, "Integer"
- );
-
- $query->_qill[$grouping][] = ts('Paid By - %1', array(1 => $op)) . " '" . implode("' " . ts('or') . " '", $pi) . "'";
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
- case 'contribution_status':
- case 'contribution_status_id':
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- if ($v) {
- $val[$k] = $k;
- }
- }
-
- $status = implode(',', $val);
-
- if (count($val) > 0) {
- $op = 'IN';
- $status = "({$status})";
- }
- }
- else {
- $status = $value;
- }
-
- $statusValues = CRM_Core_OptionGroup::values("contribution_status");
-
- $names = array();
- if (isset($val) &&
- is_array($val)
- ) {
- foreach ($val as $id => $dontCare) {
- $names[] = $statusValues[$id];
- }
- }
- else {
- if (!empty($value)) {
- $names[] = $statusValues[$value];
- }
- }
-
- $query->_qill[$grouping][] = ts('Contribution Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.contribution_status_id",
- $op,
- $status,
- "Integer"
- );
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
- case 'contribution_source':
- $value = $strtolower(CRM_Core_DAO::escapeString($value));
- if ($wildcard) {
- $value = "%$value%";
- $op = 'LIKE';
- }
- $wc = ($op != 'LIKE') ? "LOWER(civicrm_contribution.source)" : "civicrm_contribution.source";
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($wc, $op, $value, "String");
- $query->_qill[$grouping][] = ts('Contribution Source %1 %2', array(1 => $op, 2 => $quoteValue));
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
- case 'contribution_trxn_id':
- case 'contribution_transaction_id':
- $wc = ($op != 'LIKE') ? "LOWER(civicrm_contribution.trxn_id)" : "civicrm_contribution.trxn_id";
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($wc, $op, $value, "String");
- $query->_qill[$grouping][] = ts('Transaction ID %1 %2', array(1 => $op, 2 => $quoteValue));
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
- case 'contribution_check_number':
- $wc = ($op != 'LIKE') ? "LOWER(civicrm_contribution.check_number)" : "civicrm_contribution.check_number";
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($wc, $op, $value, "String");
- $query->_qill[$grouping][] = ts('Check Number %1 %2', array(1 => $op, 2 => $quoteValue));
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
case 'contribution_is_test':
case 'contribution_test':
// We dont want to include all tests for sql OR CRM-7827
$query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
return;
- case 'contribution_id':
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.id", $op, $value, "Integer");
- $query->_qill[$grouping][] = ts('Contribution ID %1 %2', array(1 => $op, 2 => $quoteValue));
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
case 'contribution_note':
$value = $strtolower(CRM_Core_DAO::escapeString($value));
if ($wildcard) {
$query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1;
return;
- // Supporting search for currency type -- CRM-4711
-
- case 'contribution_currency_type':
- $currencySymbol = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name'));
- $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution.currency",
- $op, $currencySymbol[$value], "String"
- );
- $query->_qill[$grouping][] = ts('Currency Type - %1', array(1 => $currencySymbol[$value]));
- $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1;
- return;
-
case 'contribution_campaign_id':
$campParams = array(
'op' => $op,
$whereTable = $fields[$fldName];
$value = trim($value);
- //contribution fields (decimal fields) which don't require a quote in where clause.
- $moneyFields = array('non_deductible_amount', 'fee_amount', 'net_amount');
- //date fields
- $dateFields = array('receive_date', 'cancel_date', 'receipt_date', 'thankyou_date', 'fulfilled_date');
-
- if (in_array($fldName, $dateFields)) {
- $dataType = "Date";
- }
- elseif (in_array($fldName, $moneyFields)) {
- $dataType = "Money";
- }
- else {
- $dataType = "String";
+ $dataType = "String";
+ if (!empty($whereTable['type'])) {
+ $dataType = CRM_Utils_Type::typeToString($whereTable['type']);
}
$wc = ($op != 'LIKE' && $dataType != 'Date') ? "LOWER($whereTable[where])" : "$whereTable[where]";
break;
case 'civicrm_contribution_page':
- $from = " $side JOIN civicrm_contribution_page ON civicrm_contribution.contribution_page ON civicrm_contribution.contribution_page.id";
+ $from = " $side JOIN civicrm_contribution_page ON civicrm_contribution.contribution_page_id = civicrm_contribution_page.id";
break;
case 'civicrm_product':
$status = array();
- $statusValues = CRM_Core_OptionGroup::values("contribution_status");
+ $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status');
// Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue).
unset($statusValues['5'], $statusValues['6']);
- foreach ($statusValues as $key => $val) {
- $status[] = $form->createElement('advcheckbox', $key, NULL, $val);
- }
-
- $form->addGroup($status, 'contribution_status_id', ts('Contribution Status'));
+ $form->addSelect('contribution_status',
+ array('entity' => 'contribution', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
+ );
// Add fields for thank you and receipt
$form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?'), TRUE);
$form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE);
// Add field for transaction ID search
- $form->addElement('text', 'contribution_transaction_id', ts("Transaction ID"));
+ $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID"));
$form->addElement('text', 'contribution_check_number', ts('Check Number'));
'contribution_recur_failure_retry_date' => ts('Failed Recurring Contribution Retry Date'),
);
}
+
+ static function buildQillForFieldValue($daoName, $fieldName, $fieldValue, $op, $pseduoExtraParam = array()) {
+ $pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array());
+
+ //For those $fieldName which don't have any associated pseudoconstant defined
+ if (empty($pseduoOptions)) {
+ if (is_array($fieldValue)) {
+ $op = key($fieldValue);
+ $fieldValue = $fieldValue[$op];
+ }
+ return array($op, $fieldValue);
+ }
+ elseif (is_array($fieldValue)) {
+ $qillString = array();
+ if (in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
+ $op = key($fieldValue);
+ $fieldValue = $fieldValue[$op];
+ }
+ foreach ((array)$fieldValue as $val) {
+ $qillString[] = $pseduoOptions[$val];
+ }
+ return array($op, implode(', ', $qillString));
+ }
+ else {
+ if (array_key_exists($fieldValue, $pseduoOptions)) {
+ $fieldValue = $pseduoOptions[$fieldValue];
+ }
+ return array($op, $fieldValue);
+ }
+ }
}
);
}
- $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
+ $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 1);
$selector = new CRM_Contribute_Selector_Search($this->_queryParams,
$this->_action,
NULL,
$config = CRM_Core_Config::singleton();
if (!empty($_POST)) {
- // CRM-13848
- $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues);
- if ($financialType && is_array($financialType)) {
- unset($this->_formValues['financial_type_id']);
- foreach ($financialType as $notImportant => $typeID) {
- $this->_formValues['financial_type_id'][$typeID] = 1;
+ foreach (array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status') as $element) {
+ $value = CRM_Utils_Array::value($element, $this->_formValues);
+ if ($value && is_array($value)) {
+ $this->_formValues[$element] = array('IN' => $value);
+ }
+ }
+
+ foreach (array('contribution_source', 'contribution_trxn_id') as $element) {
+ $value = CRM_Utils_Array::value($element, $this->_formValues);
+ if ($value) {
+ $this->_formValues[$element] = array('LIKE' => "%$value%");
}
}
if (CRM_Core_Permission::access('CiviContribute')) {
$fields['Contribution'] = CRM_Contribute_BAO_Contribution::exportableFields();
unset($fields['Contribution']['contribution_contact_id']);
- unset($fields['Contribution']['contribution_status_id']);
$compArray['Contribution'] = ts('Contribution');
}
}
$returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode);
}
- $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
+ $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams, 0, FALSE, $entity);
$query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL,
FALSE, FALSE, $mode,
empty($params['check_permissions'])
function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $errorMode = FALSE) {
$fields = array_intersect_key($fields, $params);
foreach ($fields as $fieldName => $fieldInfo) {
+ //In some case $params[$fieldName] holds Array value in this format Array([operator] => [value])
+ $fieldValue = CRM_Utils_Array::value($fieldName, $params);
+ $op = NULL;
+ if (!empty($fieldValue) && is_array($fieldValue) && in_array(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators())) {
+ $op = key($fieldValue);
+ $fieldValue = CRM_Utils_Array::value($op, $fieldValue);;
+ }
switch (CRM_Utils_Array::value('type', $fieldInfo)) {
case CRM_Utils_Type::T_INT:
//field is of type integer
- _civicrm_api3_validate_integer($params, $fieldName, $fieldInfo, $entity);
+ _civicrm_api3_validate_integer($fieldValue, $fieldName, $fieldInfo, $entity);
break;
case 4:
case 12:
case CRM_Utils_Type::T_TIMESTAMP:
//field is of type date or datetime
- _civicrm_api3_validate_date($params, $fieldName, $fieldInfo);
+ _civicrm_api3_validate_date($params, $fieldName, $fieldValue, $fieldInfo);
break;
- case 32://blob
- _civicrm_api3_validate_html($params, $fieldName, $fieldInfo);
+ case 32://blob
+ _civicrm_api3_validate_html($fieldValue, $fieldName, $fieldInfo);
break;
case CRM_Utils_Type::T_STRING:
- _civicrm_api3_validate_string($params, $fieldName, $fieldInfo, $entity);
+ _civicrm_api3_validate_string($fieldValue, $fieldName, $fieldInfo, $entity);
break;
case CRM_Utils_Type::T_MONEY:
- if (!CRM_Utils_Rule::money($params[$fieldName]) && !empty($params[$fieldName])) {
+ if (!CRM_Utils_Rule::money($fieldValue) && !empty($fieldValue)) {
throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]);
}
}
// intensive checks - usually only called after DB level fail
if (!empty($errorMode) && strtolower($action) == 'create') {
if (!empty($fieldInfo['FKClassName'])) {
- if (!empty($params[$fieldName])) {
+ if (!empty($fieldValue)) {
_civicrm_api3_validate_constraint($params, $fieldName, $fieldInfo);
}
elseif (!empty($fieldInfo['required'])) {
}
if (!empty($fieldInfo['api.unique'])) {
$params['entity'] = $entity;
- _civicrm_api3_validate_uniquekey($params, $fieldName, $fieldInfo);
+ _civicrm_api3_validate_uniquekey($params, $fieldName, $fieldValue, $fieldInfo);
}
}
+
+ $params[$fieldName] = $fieldValue;
+ if (!is_null($op)) {
+ $params[$fieldName] = array($op => $fieldValue);
+ }
}
}
* Array of fields from getfields function.
* @throws Exception
*/
-function _civicrm_api3_validate_date(&$params, &$fieldName, &$fieldInfo) {
+function _civicrm_api3_validate_date(&$params, &$fieldName, &$fieldValue, &$fieldInfo) {
//should we check first to prevent it from being copied if they have passed in sql friendly format?
if (!empty($params[$fieldInfo['name']])) {
- $params[$fieldInfo['name']] = _civicrm_api3_getValidDate($params[$fieldInfo['name']], $fieldInfo['name'], $fieldInfo['type']);
+ $fieldValue = _civicrm_api3_getValidDate($fieldValue, $fieldInfo['name'], $fieldInfo['type']);
}
- if ((CRM_Utils_Array::value('name', $fieldInfo) != $fieldName) && !empty($params[$fieldName])) {
- $params[$fieldName] = _civicrm_api3_getValidDate($params[$fieldName], $fieldName, $fieldInfo['type']);
+ if ((CRM_Utils_Array::value('name', $fieldInfo) != $fieldName) && !empty($fieldValue)) {
+ $fieldValue = _civicrm_api3_getValidDate($fieldValue, $fieldName, $fieldInfo['type']);
}
}
* Array of fields from getfields function.
* @throws Exception
*/
-function _civicrm_api3_validate_constraint(&$params, &$fieldName, &$fieldInfo) {
+function _civicrm_api3_validate_constraint(&$fieldValue, &$fieldName, &$fieldInfo) {
$dao = new $fieldInfo['FKClassName'];
- $dao->id = $params[$fieldName];
+ $dao->id = $fieldValue;
$dao->selectAdd();
$dao->selectAdd('id');
if (!$dao->find()) {
- throw new Exception("$fieldName is not valid : " . $params[$fieldName]);
+ throw new Exception("$fieldName is not valid : " . $fieldValue);
}
}
* Array of fields from getfields function.
* @throws Exception
*/
-function _civicrm_api3_validate_uniquekey(&$params, &$fieldName, &$fieldInfo) {
+function _civicrm_api3_validate_uniquekey(&$params, &$fieldName, &$fieldValue, &$fieldInfo) {
$existing = civicrm_api($params['entity'], 'get', array(
'version' => $params['version'],
- $fieldName => $params[$fieldName],
+ $fieldName => $fieldValue,
));
// an entry already exists for this unique field
if ($existing['count'] == 1) {
* @param string $entity
* @throws API_Exception
*/
-function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $entity) {
- if (!empty($params[$fieldName])) {
+function _civicrm_api3_validate_integer(&$fieldValue, &$fieldName, &$fieldInfo, $entity) {
+ if (!empty($fieldValue)) {
// if value = 'user_contact_id' (or similar), replace value with contact id
- if (!is_numeric($params[$fieldName]) && is_scalar($params[$fieldName])) {
- $realContactId = _civicrm_api3_resolve_contactID($params[$fieldName]);
+ if (!is_numeric($fieldValue) && is_scalar($fieldValue)) {
+ $realContactId = _civicrm_api3_resolve_contactID($fieldValue);
if ('unknown-user' === $realContactId) {
throw new API_Exception("\"$fieldName\" \"{$params[$fieldName]}\" cannot be resolved to a contact ID", 2002, array('error_field' => $fieldName, "type" => "integer"));
- }
- elseif (is_numeric($realContactId)) {
- $params[$fieldName] = $realContactId;
+ } elseif (is_numeric($realContactId)) {
+ $fieldValue = $realContactId;
}
}
if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
- _civicrm_api3_api_match_pseudoconstant($params, $entity, $fieldName, $fieldInfo);
+ _civicrm_api3_api_match_pseudoconstant($fieldValue, $entity, $fieldName, $fieldInfo);
}
// After swapping options, ensure we have an integer(s)
- foreach ((array) ($params[$fieldName]) as $value) {
+ foreach ((array) ($fieldValue) as $value) {
if ($value && !is_numeric($value) && $value !== 'null' && !is_array($value)) {
throw new API_Exception("$fieldName is not a valid integer", 2001, array('error_field' => $fieldName, "type" => "integer"));
}
}
// Check our field length
- if (is_string($params[$fieldName]) && !empty($fieldInfo['maxlength']) && strlen($params[$fieldName]) > $fieldInfo['maxlength']
- ) {
- throw new API_Exception($params[$fieldName] . " is " . strlen($params[$fieldName]) . " characters - longer than $fieldName length" . $fieldInfo['maxlength'] . ' characters',
- 2100, array('field' => $fieldName, "max_length" => $fieldInfo['maxlength'])
+ if(is_string($fieldValue) && !empty($fieldInfo['maxlength']) && strlen($fieldValue) > $fieldInfo['maxlength']
+ ){
+ throw new API_Exception( $fieldValue . " is " . strlen($fieldValue) . " characters - longer than $fieldName length" . $fieldInfo['maxlength'] . ' characters',
+ 2100, array('field' => $fieldName, "max_length"=>$fieldInfo['maxlength'])
);
}
}
*
* @throws API_Exception
*/
-function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) {
- if ($value = CRM_Utils_Array::value($fieldName, $params)) {
- if (!CRM_Utils_Rule::xssString($value)) {
- throw new API_Exception(ts('Illegal characters in input (potential scripting attack)'), array("field" => $fieldName, "error_code" => "xss"));
+function _civicrm_api3_validate_html(&$fieldValue, &$fieldName, $fieldInfo) {
+ if ($fieldValue) {
+ if (!CRM_Utils_Rule::xssString($fieldValue)) {
+ throw new API_Exception('Illegal characters in input (potential scripting attack)', array("field"=>$fieldName,"error_code"=>"xss"));
}
}
}
* @throws API_Exception
* @throws Exception
*/
-function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $entity) {
+function _civicrm_api3_validate_string(&$fieldValue, &$fieldName, &$fieldInfo, $entity) {
// If fieldname exists in params
- $value = CRM_Utils_Array::value($fieldName, $params, '');
- if (!is_array($value)) {
- $value = (string) $value;
+ $fieldValue = !empty($fieldValue) ? $fieldValue : '';
+ if(!is_array($fieldValue)){
+ $fieldValue = (string) $fieldValue;
}
else {
//@todo what do we do about passed in arrays. For many of these fields
// the missing piece of functionality is separating them to a separated string
// & many save incorrectly. But can we change them wholesale?
}
- if ($value) {
- if (!CRM_Utils_Rule::xssString($value)) {
- throw new Exception(ts('Illegal characters in input (potential scripting attack)'));
+ if ($fieldValue) {
+ if (!CRM_Utils_Rule::xssString($fieldValue)) {
+ throw new Exception('Illegal characters in input (potential scripting attack)');
}
if ($fieldName == 'currency') {
- if (!CRM_Utils_Rule::currencyCode($value)) {
- throw new Exception("Currency not a valid code: $value");
+ //When using IN operator $fieldValue is a array of currency codes
+ if (is_array($fieldValue)) {
+ foreach ($fieldValue as $currency) {
+ if (!CRM_Utils_Rule::currencyCode($currency)) {
+ throw new Exception("Currency not a valid code: $currency");
+ }
+ }
+ }
+ else {
+ if (!CRM_Utils_Rule::currencyCode($fieldValue)) {
+ throw new Exception("Currency not a valid code: $fieldValue");
+ }
}
}
if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
- _civicrm_api3_api_match_pseudoconstant($params, $entity, $fieldName, $fieldInfo);
+ _civicrm_api3_api_match_pseudoconstant($fieldValue, $entity, $fieldName, $fieldInfo);
}
// Check our field length
- elseif (is_string($value) && !empty($fieldInfo['maxlength']) && strlen(utf8_decode($value)) > $fieldInfo['maxlength']) {
+ elseif (is_string($fieldValue) && !empty($fieldInfo['maxlength']) && strlen(utf8_decode($fieldValue)) > $fieldInfo['maxlength']) {
throw new API_Exception("Value for $fieldName is " . strlen(utf8_decode($value)) . " characters - This field has a maxlength of {$fieldInfo['maxlength']} characters.",
2100, array('field' => $fieldName)
);
* @param string $fieldName: field name used in api call (not necessarily the canonical name)
* @param array $fieldInfo: getfields meta-data
*/
-function _civicrm_api3_api_match_pseudoconstant(&$params, $entity, $fieldName, $fieldInfo) {
+function _civicrm_api3_api_match_pseudoconstant(&$fieldValue, $entity, $fieldName, $fieldInfo) {
$options = CRM_Utils_Array::value('options', $fieldInfo);
if (!$options) {
if (strtolower($entity) == 'profile' && !empty($fieldInfo['entity'])) {
// If passed a value-separated string, explode to an array, then re-implode after matching values
$implode = FALSE;
- if (is_string($params[$fieldName]) && strpos($params[$fieldName], CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
- $params[$fieldName] = CRM_Utils_Array::explodePadded($params[$fieldName]);
+ if (is_string($fieldValue) && strpos($fieldValue, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) {
+ $fieldValue = CRM_Utils_Array::explodePadded($fieldValue);
$implode = TRUE;
}
// If passed multiple options, validate each
- if (is_array($params[$fieldName])) {
- foreach ($params[$fieldName] as &$value) {
+ if (is_array($fieldValue)) {
+ foreach ($fieldValue as &$value) {
if (!is_array($value)) {
_civicrm_api3_api_match_pseudoconstant_value($value, $options, $fieldName);
}
// need to verify that this is safe and doesn't break anything though.
// Better yet would be to leave it as an array and ensure that every dao/bao can handle array input
if ($implode) {
- CRM_Utils_Array::implodePadded($params[$fieldName]);
+ CRM_Utils_Array::implodePadded($fieldValue);
}
}
else {
- _civicrm_api3_api_match_pseudoconstant_value($params[$fieldName], $options, $fieldName);
+ _civicrm_api3_api_match_pseudoconstant_value($fieldValue, $options, $fieldName);
}
}
{$form.contribution_amount_high.label}
{$form.contribution_amount_high.html} </td>
<td><label>{ts}Contribution Status{/ts}</label> <br />
- {$form.contribution_status_id.html} </td>
+ {$form.contribution_status.html} </td>
</tr>
<tr>
<td>
</div>
</td>
<td>
- {$form.contribution_transaction_id.label} <br />
- {$form.contribution_transaction_id.html}
+ {$form.contribution_trxn_id.label} <br />
+ {$form.contribution_trxn_id.html}
</td>
</tr>
<tr>
</foreignKey>
<field>
<name>contribution_page_id</name>
- <title>Contribution Page</title>
+ <title>Contribution Page ID</title>
<type>int unsigned</type>
<import>true</import>
<comment>The Contribution Page which triggered this contribution</comment>
</field>
<field>
<name>contribution_status_id</name>
- <title>Contribution Status</title>
+ <title>Contribution Status ID</title>
<type>int unsigned</type>
<default>1</default>
<import>true</import>
<default>NULL</default>
<comment>FK to civicrm_pcp.id</comment>
<add>2.2</add>
+ <pseudoconstant>
+ <table>civicrm_pcp</table>
+ <keyColumn>id</keyColumn>
+ <labelColumn>title</labelColumn>
+ </pseudoconstant>
</field>
<foreignKey>
<name>pcp_id</name>