Fixed code to support contribution search for soft credit filter
This commit is contained in:
		@@ -20,20 +20,18 @@ class CRM_SoftCredit_SoftCreditQueryObject extends CRM_Contact_BAO_Query_Interfa
 | 
				
			|||||||
   *
 | 
					   *
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public function where(&$query) {
 | 
					  public function where(&$query) {
 | 
				
			||||||
    if (empty($query->_paramLookup['soft_credit_name'])) {
 | 
					    if (!empty($query->_paramLookup['soft_credit_name'])) {
 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (!in_array(CRM_Contribute_BAO_Query::$_contribOrSoftCredit, array("only_scredits", "both_related", "both"))) {
 | 
					 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
      list($name, $op, $value, $grouping, $wildcard) = reset($query->_paramLookup['soft_credit_name']);
 | 
					      list($name, $op, $value, $grouping, $wildcard) = reset($query->_paramLookup['soft_credit_name']);
 | 
				
			||||||
      if ($value) {
 | 
					      if ($value) {
 | 
				
			||||||
        $query->_where[$grouping][] = "civicrm_contact_creditee.sort_name LIKE '%{$value}%'";
 | 
					        $query->_where[$grouping][] = "civicrm_contact_creditee.sort_name LIKE '%{$value}%'";
 | 
				
			||||||
        $query->_whereTables['civicrm_contribution_soft_creditee_contact'] = 1;
 | 
					        $query->_whereTables['civicrm_contribution_soft_creditee_contact'] = 1;
 | 
				
			||||||
        $query->_tables['civicrm_contribution_soft_creditee_contact'] = 1;
 | 
					        $query->_tables['civicrm_contribution_soft_creditee_contact'] = 1;
 | 
				
			||||||
 | 
					        $query->_whereTables['civicrm_contribution_soft'] = 1;
 | 
				
			||||||
 | 
					        $query->_tables['civicrm_contribution_soft'] = 1;
 | 
				
			||||||
        $query->_qill[$grouping][] = ts("%1 %2 - '%3'", [1 => 'Soft Creditee\'s name', 2 => 'LIKE', 3 => $value]);
 | 
					        $query->_qill[$grouping][] = ts("%1 %2 - '%3'", [1 => 'Soft Creditee\'s name', 2 => 'LIKE', 3 => $value]);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * @param string $name
 | 
					   * @param string $name
 | 
				
			||||||
@@ -45,7 +43,6 @@ class CRM_SoftCredit_SoftCreditQueryObject extends CRM_Contact_BAO_Query_Interfa
 | 
				
			|||||||
    if ($name == 'civicrm_contribution_soft_creditee_contact') {
 | 
					    if ($name == 'civicrm_contribution_soft_creditee_contact') {
 | 
				
			||||||
      return " $side JOIN civicrm_contact civicrm_contact_creditee
 | 
					      return " $side JOIN civicrm_contact civicrm_contact_creditee
 | 
				
			||||||
        ON (civicrm_contribution_soft.contact_id = civicrm_contact_creditee.id)
 | 
					        ON (civicrm_contribution_soft.contact_id = civicrm_contact_creditee.id)
 | 
				
			||||||
        AND contribution_search_scredit_combined.scredit_id IS NOT NULL
 | 
					 | 
				
			||||||
      ";
 | 
					      ";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -335,3 +335,21 @@ function softcreditcustomfields_civicrm_queryObjects(&$queryObjects, $type) {
 | 
				
			|||||||
    $queryObjects[] = new CRM_SoftCredit_SoftCreditQueryObject();
 | 
					    $queryObjects[] = new CRM_SoftCredit_SoftCreditQueryObject();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Implements hook_civicrm_queryObjects().
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_queryObjects
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function softcreditcustomfields_civicrm_alterContent(&$content, $context, $tplName, &$object) {
 | 
				
			||||||
 | 
					  if (in_array($tplName, [
 | 
				
			||||||
 | 
					    'CRM/Contribute/Form/Search/AdvancedSearchPane.tpl',
 | 
				
			||||||
 | 
					    'CRM/Contribute/Form/Search.tpl'
 | 
				
			||||||
 | 
					  ])) {
 | 
				
			||||||
 | 
					    $content = str_replace(
 | 
				
			||||||
 | 
					      "cj('#contribution_soft_credit_type_id').val('');", 
 | 
				
			||||||
 | 
					      '', 
 | 
				
			||||||
 | 
					      $content
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,17 @@
 | 
				
			|||||||
    CRM.$(function($) {
 | 
					    CRM.$(function($) {
 | 
				
			||||||
      $('div#contribution_soft_credit_type_wrapper').append($('div.crm-softcredit-form-block-soft_credit_sort_name'));
 | 
					      $('div#contribution_soft_credit_type_wrapper').append($('div.crm-softcredit-form-block-soft_credit_sort_name'));
 | 
				
			||||||
      $('div#contribution_soft_credit_type_wrapper').append($('div.softcredit_custom_groups'));
 | 
					      $('div#contribution_soft_credit_type_wrapper').append($('div.softcredit_custom_groups'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      hideShowInMemoryOf();
 | 
				
			||||||
 | 
					      $('select#contribution_or_softcredits').change(hideShowInMemoryOf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      function hideShowInMemoryOf() {
 | 
				
			||||||
 | 
					        let softOption = $('select#contribution_or_softcredits').val();
 | 
				
			||||||
 | 
					        if (softOption == 'only_contribs') {
 | 
				
			||||||
 | 
					          $('div#contribution_soft_credit_type_wrapper').show();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  {/literal}
 | 
					  {/literal}
 | 
				
			||||||
  </script>
 | 
					  </script>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user