forked from CiviWare/com.dpci.constituentsonly
		
	fixed sql
This commit is contained in:
		@@ -56,16 +56,18 @@ class CRM_ConstituentsOnly_BAO_Query extends CRM_Contact_BAO_Query_Interface {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (CRM_Utils_Array::value('civicrm_contact', $query->_tables) && empty($query->_paramLookup['do_not_trade'])) {
 | 
					    if (CRM_Utils_Array::value('civicrm_contact', $query->_tables) && empty($query->_paramLookup['do_not_trade'])) {
 | 
				
			||||||
      $query->_where[0][] = "
 | 
					      $query->_where[0][] = "
 | 
				
			||||||
        IF (contact_a.do_not_trade = 1,
 | 
					        contact_a.id NOT IN (SELECT contact_a.id
 | 
				
			||||||
        CASE
 | 
					          FROM civicrm_contact contact_a
 | 
				
			||||||
          WHEN (cr.id IS NULL OR cc1.is_deleted = 1 OR cc1.do_not_trade = 1)
 | 
					          LEFT JOIN civicrm_relationship cr
 | 
				
			||||||
            THEN 0
 | 
					            ON (cr.contact_id_a = contact_a.id OR cr.contact_id_b = contact_a.id)
 | 
				
			||||||
          ELSE 1
 | 
					            AND cr.is_active = 1
 | 
				
			||||||
        END,
 | 
					          LEFT JOIN civicrm_contact cc1
 | 
				
			||||||
        1)
 | 
					            ON (cr.contact_id_a = cc1.id OR cr.contact_id_b = cc1.id)
 | 
				
			||||||
 | 
					            AND contact_a.id <> cc1.id AND cr.is_active = 1
 | 
				
			||||||
 | 
					          WHERE contact_a.do_not_trade = 1 AND (cr.id IS NULL OR cc1.is_deleted = 1 OR cc1.do_not_trade = 1)
 | 
				
			||||||
 | 
					          GROUP by contact_a.id
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
      ";
 | 
					      ";
 | 
				
			||||||
      $query->_tables['civicrm_do_not_trade'] = 1;
 | 
					 | 
				
			||||||
      $query->_whereTables['civicrm_do_not_trade'] = 1;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -76,13 +78,6 @@ class CRM_ConstituentsOnly_BAO_Query extends CRM_Contact_BAO_Query_Interface {
 | 
				
			|||||||
   *
 | 
					   *
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public function from($name, $mode, $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";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user