From 6ffab5b7aaef6ddcdf8a50f9a307f59dcb0494e0 Mon Sep 17 00:00:00 2001 From: Web Access Date: Tue, 23 Jun 2015 16:22:20 +0530 Subject: [PATCH] CRM-16713 Find Contributions: Search by Premium --- CRM/Contact/BAO/Query.php | 3 +++ CRM/Contact/Form/Search/Advanced.php | 1 + CRM/Contribute/BAO/Contribution.php | 12 +++++++++++- CRM/Contribute/BAO/Query.php | 17 +++++++++++++++++ CRM/Contribute/Form/Search.php | 1 + templates/CRM/Contribute/Form/Search/Common.tpl | 4 ++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 4869a8bb3c..e5a242289a 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -5695,6 +5695,9 @@ AND displayRelType.is_active = 1 elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') { $pseduoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, TRUE, TRUE); } + elseif ($fieldName == 'contribution_product_id') { + $pseduoOptions = CRM_Contribute_PseudoConstant::products(); + } elseif ($daoName) { $pseduoOptions = CRM_Core_PseudoConstant::get($daoName, $fieldName, $pseduoExtraParam = array()); } diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 84ff204258..61d1444e52 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -375,6 +375,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { 'status_id', 'activity_subject', 'contribution_page_id', + 'contribution_product_id', ); foreach ($specialParams as $element) { $value = CRM_Utils_Array::value($element, $this->_formValues); diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0d2b995222..7874f2c758 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -718,8 +718,18 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { ), ); + // CRM-16713 - contribution search by Premiums on 'Find Contribution' form. + $premiums = array( + 'contribution_product_id' => array( + 'title' => ts('Premium'), + 'name' => 'contribution_product_id', + 'where' => 'civicrm_product.id', + 'data_type' => CRM_Utils_Type::T_INT, + ), + ); + $fields = array_merge($impFields, $typeField, $contributionStatus, $contributionPage, $optionField, $expFieldProduct, - $expFieldsContrib, $contributionNote, $contributionRecurId, $extraFields, $softCreditFields, $financialAccount, + $expFieldsContrib, $contributionNote, $contributionRecurId, $extraFields, $softCreditFields, $financialAccount, $premiums, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution') ); diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index c1e8d616cc..0e431d80df 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -521,6 +521,15 @@ class CRM_Contribute_BAO_Query { $query->_tables['contribution_batch'] = $query->_whereTables['contribution_batch'] = 1; return; + case 'contribution_product_id': + // CRM-16713 - contribution search by premiums on 'Find Contribution' form. + $qillName = $name; + list($operator, $productValue) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Product', $name, $value, $op); + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $operator, 3 => $productValue)); + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_product.id", $op, $value); + $query->_tables['civicrm_product'] = $query->_whereTables['civicrm_product'] = 1; + return; + default: //all other elements are handle in this case $fldName = substr($name, 13); @@ -816,6 +825,7 @@ class CRM_Contribute_BAO_Query { 'contribution_batch' => 1, 'contribution_campaign_title' => 1, 'contribution_campaign_id' => 1, + 'contribution_product_id' => 1, ); if (self::isSoftCreditOptionEnabled()) { $properties = array_merge($properties, self::softCreditReturnProperties()); @@ -936,6 +946,13 @@ class CRM_Contribute_BAO_Query { ) ); + // CRM-16713 - contribution search by premiums on 'Find Contribution' form. + $form->add('select', 'contribution_product_id', + ts('Premium'), + CRM_Contribute_PseudoConstant::products(), + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')) + ); + // Add all the custom searchable fields $contribution = array('Contribution'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution); diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 79ed6de8b3..a0e769d3cb 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -276,6 +276,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { 'contribution_source', 'contribution_trxn_id', 'contribution_page_id', + 'contribution_product_id', ); foreach ($specialParams as $element) { $value = CRM_Utils_Array::value($element, $this->_formValues); diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 59702b860b..046a94a19c 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -124,6 +124,10 @@ {$form.contribution_source.label}
{$form.contribution_source.html|crmAddClass:twenty} + + {$form.contribution_product_id.label}
+ {$form.contribution_product_id.html|crmAddClass:twenty} + -- 2.25.1