Add ability to search by creditee name
This commit is contained in:
		
							
								
								
									
										80
									
								
								CRM/SoftCredit/SoftCreditQueryObject.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								CRM/SoftCredit/SoftCreditQueryObject.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,80 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CRM_SoftCredit_SoftCreditQueryObject extends CRM_Contact_BAO_Query_Interface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  static $_networkFields = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public function &getFields() {
 | 
				
			||||||
 | 
					    return self::$_networkFields;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param $query
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function select(&$query) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param $query
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function where(&$query) {
 | 
				
			||||||
 | 
					    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']);
 | 
				
			||||||
 | 
					    if ($value) {
 | 
				
			||||||
 | 
					      $query->_where[$grouping][] = "civicrm_contact_d.sort_name LIKE '%{$value}%'";
 | 
				
			||||||
 | 
					      $query->_whereTables['civicrm_contribution_soft_contact'] = 1;
 | 
				
			||||||
 | 
					      $query->_tables['civicrm_contribution_soft_contact'] = 1;
 | 
				
			||||||
 | 
					      $query->_qill[$grouping][] = ts("%1 %2 - '%3'", [1 => 'Soft Creditee\'s name', 2 => 'LIKE', 3 => $value]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param string $name
 | 
				
			||||||
 | 
					   * @param $mode
 | 
				
			||||||
 | 
					   * @param $side
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function from($name, $mode, $side) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param $tables
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function setTableDependency(&$tables) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public function getPanesMapper(&$panes) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param $panes
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function registerAdvancedSearchPane(&$panes) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param CRM_Core_Form $form
 | 
				
			||||||
 | 
					   * @param $type
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function buildAdvancedSearchPaneForm(&$form, $type) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * @param $paneTemplatePathArray
 | 
				
			||||||
 | 
					   * @param $type
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -171,6 +171,7 @@ function softcreditcustomfields_civicrm_buildForm($formName, &$form) {
 | 
				
			|||||||
    || ('CRM_Contact_Form_Search_Advanced' == $formName && ('CiviContribute' == $form->_searchPane || $form->_flagSubmitted))
 | 
					    || ('CRM_Contact_Form_Search_Advanced' == $formName && ('CiviContribute' == $form->_searchPane || $form->_flagSubmitted))
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    CRM_Contribute_BAO_Query::addCustomFormFields($form, ['ContributionSoft']);
 | 
					    CRM_Contribute_BAO_Query::addCustomFormFields($form, ['ContributionSoft']);
 | 
				
			||||||
 | 
					    $form->add('text', 'soft_credit_name', ts('Soft Creditee\'s name'));
 | 
				
			||||||
    if ('CRM_Contact_Form_Search_Advanced' == $formName && 'CiviContribute' != $form->_searchPane) {
 | 
					    if ('CRM_Contact_Form_Search_Advanced' == $formName && 'CiviContribute' != $form->_searchPane) {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -323,3 +324,14 @@ function softcreditcustomfields_civicrm_postProcess($formName, &$form) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Implements hook_civicrm_queryObjects().
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_queryObjects
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function softcreditcustomfields_civicrm_queryObjects(&$queryObjects, $type) {
 | 
				
			||||||
 | 
					  if ($type == 'Contact') {
 | 
				
			||||||
 | 
					    $queryObjects[] = new CRM_SoftCredit_SoftCreditQueryObject();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,20 @@
 | 
				
			|||||||
 | 
					{if $form.soft_credit_name}
 | 
				
			||||||
 | 
					  <div class="crm-softcredit-form-block-soft_credit_sort_name">
 | 
				
			||||||
 | 
					    {$form.soft_credit_name.label}<br>
 | 
				
			||||||
 | 
					    {$form.soft_credit_name.html}
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					{/if}
 | 
				
			||||||
{if $contributionSoftGroupTree}
 | 
					{if $contributionSoftGroupTree}
 | 
				
			||||||
  <div class="softcredit_custom_groups">
 | 
					  <div class="softcredit_custom_groups">
 | 
				
			||||||
    <br>
 | 
					    <br>
 | 
				
			||||||
    {include file="CRM/Custom/Form/Search.tpl" groupTree=$contributionSoftGroupTree showHideLinks=false}
 | 
					    {include file="CRM/Custom/Form/Search.tpl" groupTree=$contributionSoftGroupTree showHideLinks=false}
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
 | 
					{/if}
 | 
				
			||||||
 | 
					{if $contributionSoftGroupTree OR $form.soft_credit_name}
 | 
				
			||||||
  <script type="text/javascript">
 | 
					  <script type="text/javascript">
 | 
				
			||||||
  {literal}
 | 
					  {literal}
 | 
				
			||||||
    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.softcredit_custom_groups'));
 | 
					      $('div#contribution_soft_credit_type_wrapper').append($('div.softcredit_custom_groups'));
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  {/literal}
 | 
					  {/literal}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user