forked from CiviWare/com.dpci.constituentsonly
		
	
		
			
				
	
	
		
			112 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
class CRM_ConstituentsOnly_BAO_Query extends CRM_Contact_BAO_Query_Interface {
 | 
						|
 | 
						|
  static $_networkFields = array();
 | 
						|
 | 
						|
  public function &getFields() {
 | 
						|
    return self::$_networkFields;
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * @param $query
 | 
						|
   *
 | 
						|
   */
 | 
						|
  public function select(&$query) {
 | 
						|
    // hack for profile search
 | 
						|
    $url = CRM_Utils_Array::value('q', $_GET);
 | 
						|
    if (in_array($url, ['civicrm/profile', 'civicrm/contact/search/builder'])) {
 | 
						|
      if (empty($query->_params)) {
 | 
						|
        $query->_params[] = [
 | 
						|
          'entryURL',
 | 
						|
          '=',
 | 
						|
          0,
 | 
						|
          0,
 | 
						|
          1,
 | 
						|
        ];
 | 
						|
      }
 | 
						|
      $query->_paramLookup['entryURL'] = [
 | 
						|
        'entryURL',
 | 
						|
        '=',
 | 
						|
        0,
 | 
						|
        0,
 | 
						|
        1,
 | 
						|
      ];
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * @param $query
 | 
						|
   *
 | 
						|
   */
 | 
						|
  public function where(&$query) {
 | 
						|
    if (empty($query->_paramLookup['entryURL'])) {
 | 
						|
      return;
 | 
						|
    }
 | 
						|
 | 
						|
    if (CRM_Utils_Array::value('civicrm_contact', $query->_tables) && empty($query->_paramLookup['do_not_trade'])) {
 | 
						|
      $query->_where[0][] = "
 | 
						|
        IF (contact_a.do_not_trade = 1,
 | 
						|
        CASE
 | 
						|
          WHEN (cr.id IS NULL OR cc1.is_deleted = 1 OR cc1.do_not_trade = 1)
 | 
						|
            THEN 0
 | 
						|
          ELSE 1
 | 
						|
        END,
 | 
						|
        1)
 | 
						|
      ";
 | 
						|
      $query->_tables['civicrm_do_not_trade'] = 1;
 | 
						|
      $query->_whereTables['civicrm_do_not_trade'] = 1;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * @param string $name
 | 
						|
   * @param $mode
 | 
						|
   * @param $side
 | 
						|
   *
 | 
						|
   */
 | 
						|
  public function from($name, $mode, $side) {
 | 
						|
    if ($name == 'civicrm_do_not_trade') {
 | 
						|
      return " LEFT JOIN civicrm_relationship cr
 | 
						|
        ON (cr.contact_id_a = contact_a.id OR cr.contact_id_b = contact_a.id)
 | 
						|
       LEFT JOIN civicrm_contact cc1
 | 
						|
          ON (cr.contact_id_a = cc1.id OR cr.contact_id_b = cc1.id)
 | 
						|
          AND contact_a.id <> cc1.id";
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  /**
 | 
						|
   * @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) {
 | 
						|
  }
 | 
						|
 | 
						|
}
 |