From 3a6eb174843be1f6ed22764fd76940fbb36a2cc5 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 6 Jan 2015 20:25:32 +0530 Subject: [PATCH] Api test failures fix round4 --- CRM/Contact/BAO/Query.php | 2 +- CRM/Contribute/BAO/Query.php | 35 ++++++++++++++----- CRM/Event/BAO/Query.php | 23 ++++++++---- CRM/Event/Form/Search.php | 19 ++-------- api/v3/utils.php | 14 ++++++-- .../CRM/Contribute/Form/Search/Common.tpl | 4 +-- templates/CRM/Event/Form/Search/Common.tpl | 2 +- 7 files changed, 60 insertions(+), 39 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 5abf9ea27e..5cab9eedff 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -613,7 +613,7 @@ class CRM_Contact_BAO_Query { (substr($name, 0, 12) == 'participant_') || (substr($name, 0, 7) == 'pledge_') || (substr($name, 0, 5) == 'case_') || - (substr($name, 0, 13) == 'contribution_') || + (substr($name, 0, 13) == 'contribution_' && strpos($name, 'source') === FALSE) || (substr($name, 0, 8) == 'payment_') ) { continue; diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index dd80019691..6b564a81a7 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -138,6 +138,14 @@ class CRM_Contribute_BAO_Query { $query->_tables['contribution_payment_instrument'] = 1; } + // get payment instrument id + if (!empty($query->_returnProperties['payment_instrument_id'])) { + $query->_select['payment_instrument_id'] = "contribution_payment_instrument.value as payment_instrument_id"; + $query->_element['payment_instrument_id'] = 1; + $query->_tables['civicrm_contribution'] = 1; + $query->_tables['contribution_payment_instrument'] = 1; + } + if (!empty($query->_returnProperties['check_number'])) { $query->_select['contribution_check_number'] = "civicrm_contribution.check_number as contribution_check_number"; $query->_element['contribution_check_number'] = 1; @@ -320,6 +328,7 @@ class CRM_Contribute_BAO_Query { case 'contribution_currency': case 'contribution_source': case 'contribution_trxn_id': + case 'contribution_check_number': case (strpos($name, '_amount') !== FALSE): case (strpos($name, '_date') !== FALSE): $qillName = $name; @@ -370,9 +379,15 @@ class CRM_Contribute_BAO_Query { return; case 'payment_instrument': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("contribution_payment_instrument.value", $op, $value, 'Int'); + case 'payment_instrument_id': + if ($name == 'payment_instrument') { + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("contribution_payment_instrument.label", $op, $value); + } + else { + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("contribution_payment_instrument.value", $op, $value, 'Int'); + } list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', 'payment_instrument_id', $value, $op); - $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value)); + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields['payment_instrument']['title'], 2 => $op, 3 => $value)); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; $query->_tables['contribution_payment_instrument'] = $query->_whereTables['contribution_payment_instrument'] = 1; return; @@ -427,6 +442,12 @@ class CRM_Contribute_BAO_Query { return; case 'contribution_is_test': + // By default is Contribution Search form we choose is_test = 0 in otherwords always show active contribution + // so in case if any one choose any Yes/No avoid the default clause otherwise it will be conflict in whereClause + $key = array_search('civicrm_contribution.is_test = 0', $query->_where[$grouping]); + if (!empty($key)) { + unset($query->_where[$grouping][$key]); + } case 'contribution_test': // We dont want to include all tests for sql OR CRM-7827 if (!$value || $query->getOperator() != 'OR') { @@ -786,6 +807,7 @@ class CRM_Contribute_BAO_Query { 'total_amount' => 1, 'accounting_code' => 1, 'payment_instrument' => 1, + 'payment_instrument_id' => 1, 'check_number' => 1, 'non_deductible_amount' => 1, 'fee_amount' => 1, @@ -873,13 +895,8 @@ class CRM_Contribute_BAO_Query { FALSE, array('class' => 'crm-select2') ); - $form->add('select', 'payment_instrument', - ts('Payment Instrument'), - array( - '' => ts('- any -') - ) + - CRM_Contribute_PseudoConstant::paymentInstrument(), - FALSE, array('class' => 'crm-select2') + $form->addSelect('payment_instrument_id', + array('entity' => 'contribution', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')) ); $form->add('select', 'contribution_pcp_made_through_id', diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 76559b8281..4485a06a86 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -297,6 +297,11 @@ class CRM_Event_BAO_Query { $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1; return; + case 'participant_is_test': + $key = array_search('civicrm_participant.is_test = 0', $query->_where[$grouping]); + if (!empty($key)) { + unset($query->_where[$grouping][$key]); + } case 'participant_test': // We dont want to include all tests for sql OR CRM-7827 if (!$value || $query->getOperator() != 'OR') { @@ -336,16 +341,18 @@ class CRM_Event_BAO_Query { case 'participant_source': case 'participant_id': case 'participant_contact_id': - case 'participant_pay_later': + case 'participant_is_pay_later': case 'participant_fee_amount': case 'participant_fee_level': $qillName = $name; - if (in_array($name, array('participant_status_id', 'participant_role_id', 'participant_source', 'participant_id', 'participant_contact_id', 'participant_fee_amount', 'participant_fee_level'))) { + if (in_array($name, array('participant_status_id', 'participant_role_id', 'participant_source', 'participant_id', 'participant_contact_id', 'participant_fee_amount', 'participant_fee_level', 'participant_is_pay_later'))) { $name = str_replace('participant_', '', $name); - } - if ($name == 'participant_pay_later') { - $name = str_replace('participant', 'is', $name); - $qillName = 'participant_' . $name; + if ($name == 'is_pay_later') { + $qillName = $name; + } + if ($name == 'participant_role_id') { + $qillName = str_replace('_id', '', $name); + } } $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; @@ -368,6 +375,8 @@ class CRM_Event_BAO_Query { return; case 'event_id': + case 'participant_event_id': + $name = str_replace('participant_', '', $name); case 'event_is_public': case 'event_type_id': @@ -545,7 +554,7 @@ class CRM_Event_BAO_Query { ); $form->addYesNo('participant_test', ts('Participant is a Test?'), TRUE); - $form->addYesNo('participant_pay_later', ts('Participant is Pay Later?'), TRUE); + $form->addYesNo('participant_is_pay_later', ts('Participant is Pay Later?'), TRUE); $form->addElement('text', 'participant_fee_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8)); $form->addElement('text', 'participant_fee_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 147b093206..481b650590 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -193,28 +193,13 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); - // Filter on is_test if specified in search form - if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { - $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; - } - if (!empty($this->_formValues['participant_status_id'])) { - $statuses = array_keys($this->_formValues['participant_status_id']); - $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )'; - } - if (!empty($this->_formValues['participant_role_id'])) { - $roles = array_keys($this->_formValues['participant_role_id']); - $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )'; - } // CRM-15379 + $clause = NULL; if (!empty($this->_formValues['participant_fee_id'])) { $participant_fee_id = $this->_formValues['participant_fee_id']; $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label'); $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); - $seatClause[] = "( participant.fee_level LIKE '%$feeLabel%' )"; - } - $clause = NULL; - if (!empty($seatClause)) { - $clause = implode(' AND ', $seatClause); + $clause = " ( participant.fee_level LIKE '%$feeLabel%' ) "; } $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $clause); diff --git a/api/v3/utils.php b/api/v3/utils.php index 64cdbe3767..ef950a98c9 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1425,9 +1425,19 @@ function _civicrm_api3_validate_fields($entity, $action, &$params, $fields, $err if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) { break; } - if (!CRM_Utils_Rule::money($fieldValue) && !empty($fieldValue)) { - throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]); + if (is_array($fieldValue)) { + foreach($fieldValue as $fieldvalue) { + if (!CRM_Utils_Rule::money($fieldvalue) && !empty($fieldvalue)) { + throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]); + } + } } + else { + if (!CRM_Utils_Rule::money($fieldValue) && !empty($fieldValue)) { + throw new Exception($fieldName . " is not a valid amount: " . $params[$fieldName]); + } + } + break; } // intensive checks - usually only called after DB level fail diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 9cf89c97a8..b053a3c7f3 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -40,8 +40,8 @@
-
- {$form.payment_instrument.html|crmAddClass:twenty} +
+ {$form.payment_instrument_id.html|crmAddClass:twenty}
{$form.contribution_check_number.label}
diff --git a/templates/CRM/Event/Form/Search/Common.tpl b/templates/CRM/Event/Form/Search/Common.tpl index 4335d6a939..b5fcd87226 100644 --- a/templates/CRM/Event/Form/Search/Common.tpl +++ b/templates/CRM/Event/Form/Search/Common.tpl @@ -52,7 +52,7 @@   {$form.participant_test.html} - {$form.participant_pay_later.label} {$form.participant_pay_later.html} + {$form.participant_is_pay_later.label} {$form.participant_is_pay_later.html} -- 2.25.1