From e88186f40740083754c08a690a79112b0c9ebfa6 Mon Sep 17 00:00:00 2001 From: Deepak Srivastava Date: Wed, 26 Feb 2014 16:41:11 +0530 Subject: [PATCH] CRM-12467 - advanced search, soft credit type filter ---------------------------------------- * CRM-12467: Include Soft Credits in contribution search http://issues.civicrm.org/jira/browse/CRM-12467 --- CRM/Contribute/BAO/Query.php | 47 +++++++++++++++++-- .../CRM/Contribute/Form/Search/Common.tpl | 4 +- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index e0d5c9d2c9..da9c4ad1fd 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -355,6 +355,39 @@ 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 { + $op = '='; + $scTypes = $value; + $names[] = $softCreditTypes[$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_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 = $value; @@ -882,13 +915,21 @@ class CRM_Contribute_BAO_Query { // Soft credit related fields $options = array( - 'only_scredits' => ts('Soft Credits Only'), 'only_contribs' => ts('Contributions Only'), + 'only_scredits' => ts('Soft Credits Only'), 'both' => ts('Both'), ); $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2")); - $form->addSelect('soft_credit_type_id', - array('entity' => 'contribution_soft', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); + $form->addSelect( + 'contribution_soft_credit_type_id', + array( + 'entity' => 'contribution_soft', + 'field' => 'soft_credit_type_id', + 'multiple' => 'multiple', + 'option_url' => NULL, + 'placeholder' => ts('- any -') + ) + ); // Add all the custom searchable fields $contribution = array('Contribution'); diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 18a211ef17..f0f44724fb 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -133,8 +133,8 @@ {$form.contribution_or_softcredits.html} - {$form.soft_credit_type_id.label}
- {$form.soft_credit_type_id.html|crmAddClass:twenty} + {$form.contribution_soft_credit_type_id.label}
+ {$form.contribution_soft_credit_type_id.html|crmAddClass:twenty} -- 2.25.1