From: monishdeb Date: Mon, 24 Nov 2014 05:14:42 +0000 (+0530) Subject: Api Break fixes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3c151c7080b819b569ea60bfdaef351e5e203cc6;p=civicrm-core.git Api Break fixes --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 8933683827..9b799de370 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1443,7 +1443,7 @@ class CRM_Contact_BAO_Query { * * @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; @@ -1494,7 +1494,7 @@ class CRM_Contact_BAO_Query { } } 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; @@ -1513,7 +1513,7 @@ class CRM_Contact_BAO_Query { * * @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; @@ -1542,6 +1542,10 @@ class CRM_Contact_BAO_Query { return $result; } + if ($apiEntity) { + $id = $apiEntity . '_' . $id; + } + if (!$likeNames) { $likeNames = array('sort_name', 'email', 'note', 'display_name'); } diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 530c9284a6..1437662b39 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -364,15 +364,18 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { } } - // 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)) { diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6d83725bef..46f640b116 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -648,6 +648,14 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { ), ); + $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( @@ -699,7 +707,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { ), ); - $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') ); diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index a4448dd253..9b8564d543 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -281,14 +281,6 @@ class CRM_Contribute_BAO_Query { ); 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"; @@ -317,63 +309,81 @@ class CRM_Contribute_BAO_Query { 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; @@ -398,136 +408,6 @@ class CRM_Contribute_BAO_Query { // 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 @@ -571,12 +451,6 @@ class CRM_Contribute_BAO_Query { $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) { @@ -611,17 +485,6 @@ class CRM_Contribute_BAO_Query { $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, @@ -655,19 +518,9 @@ class CRM_Contribute_BAO_Query { $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]"; @@ -740,7 +593,7 @@ class CRM_Contribute_BAO_Query { 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': @@ -1023,15 +876,13 @@ class CRM_Contribute_BAO_Query { $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); @@ -1052,7 +903,7 @@ class CRM_Contribute_BAO_Query { $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')); @@ -1177,4 +1028,34 @@ class CRM_Contribute_BAO_Query { '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); + } + } } diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 5e85dc1e5f..b8bafbf584 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -130,7 +130,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { ); } - $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, @@ -269,12 +269,17 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $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%"); } } diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 3f1c33bc1f..d44fee1f76 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -404,7 +404,6 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping { 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'); } } diff --git a/api/v3/utils.php b/api/v3/utils.php index 32562b13d5..8d72eaa2d9 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -555,7 +555,7 @@ function _civicrm_api3_get_query_object($params, $mode, $entity) { $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']) @@ -1399,29 +1399,36 @@ function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $grou 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]); } } @@ -1429,7 +1436,7 @@ function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $err // 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'])) { @@ -1438,9 +1445,14 @@ function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $err } 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); + } } } @@ -1462,13 +1474,13 @@ function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $err * 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']); } } @@ -1508,13 +1520,13 @@ function _civicrm_api3_getValidDate($dateValue, $fieldName, $fieldType) { * 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); } } @@ -1529,10 +1541,10 @@ function _civicrm_api3_validate_constraint(&$params, &$fieldName, &$fieldInfo) { * 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) { @@ -1795,34 +1807,33 @@ function _civicrm_api3_swap_out_aliases(&$apiRequest, $fields) { * @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']) ); } } @@ -1866,10 +1877,10 @@ function _civicrm_api3_resolve_contactID($contactIdExpr) { * * @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")); } } } @@ -1886,31 +1897,41 @@ function _civicrm_api3_validate_html(&$params, &$fieldName, $fieldInfo) { * @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) ); @@ -1926,7 +1947,7 @@ function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $enti * @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'])) { @@ -1939,13 +1960,13 @@ function _civicrm_api3_api_match_pseudoconstant(&$params, $entity, $fieldName, $ // 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); } @@ -1954,11 +1975,11 @@ function _civicrm_api3_api_match_pseudoconstant(&$params, $entity, $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); } } diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index a83e4abdc8..5e1a1208fd 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -35,7 +35,7 @@ {$form.contribution_amount_high.label} {$form.contribution_amount_high.html}
- {$form.contribution_status_id.html} + {$form.contribution_status.html} @@ -49,8 +49,8 @@ - {$form.contribution_transaction_id.label}
- {$form.contribution_transaction_id.html} + {$form.contribution_trxn_id.label}
+ {$form.contribution_trxn_id.html} diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index 600d12b025..3844d56f73 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -99,7 +99,7 @@ contribution_page_id - Contribution Page + Contribution Page ID int unsigned true The Contribution Page which triggered this contribution @@ -377,7 +377,7 @@ contribution_status_id - Contribution Status + Contribution Status ID int unsigned 1 true diff --git a/xml/schema/Contribute/ContributionSoft.xml b/xml/schema/Contribute/ContributionSoft.xml index 311f4512f3..d20febd64c 100644 --- a/xml/schema/Contribute/ContributionSoft.xml +++ b/xml/schema/Contribute/ContributionSoft.xml @@ -91,6 +91,11 @@ NULL FK to civicrm_pcp.id 2.2 + + civicrm_pcp
+ id + title +
pcp_id