Merge branch '4.4' into master
authorColeman Watts <coleman@civicrm.org>
Sun, 27 Apr 2014 20:19:30 +0000 (13:19 -0700)
committerColeman Watts <coleman@civicrm.org>
Sun, 27 Apr 2014 20:19:30 +0000 (13:19 -0700)
Conflicts:
CRM/Core/BAO/CustomQuery.php

1  2 
CRM/Contact/BAO/Contact.php
CRM/Core/BAO/CustomQuery.php
CRM/Core/Session.php
api/v3/utils.php

index 236b3630f2836256c40f686a0fbd1ceb7a1eda99,3d54cde959363b677ea8f1ca2ca45375ef98eac5..a4c68daa91c9b4bb0aed6a817c63d06780f4543a
@@@ -2070,10 -2083,10 +2074,10 @@@ ORDER BY civicrm_email.is_primary DESC"
            if (($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 &&
              ($value == '' || !isset($value))) {
              continue;
-           } 
+           }
  
            $valueId = NULL;
 -          if (CRM_Utils_Array::value('customRecordValues', $params)) {
 +          if (!empty($params['customRecordValues'])) {
              if (is_array($params['customRecordValues']) && !empty($params['customRecordValues'])) {
                foreach ($params['customRecordValues'] as $recId => $customFields) {
                  if (is_array($customFields) && !empty($customFields)) {
index 0f15babbc5ae742ed4b2606a49060a3f00f91f14,60ac3c23f406320a941b43bbb2a94dfddddfbfb9..1665dd7bdeb709c78856a27c06034f77541420f8
@@@ -281,26 -276,52 +281,40 @@@ SELECT label, valu
          $joinTable = 'contact_a';
        }
        elseif ($field['extends'] == 'civicrm_contribution') {
 -        $joinTable = 'civicrm_contribution';
 -      }
 -      elseif ($field['extends'] == 'civicrm_participant') {
 -        $joinTable = 'civicrm_participant';
 -      }
 -      elseif ($field['extends'] == 'civicrm_membership') {
 -        $joinTable = 'civicrm_membership';
 -      }
 -      elseif ($field['extends'] == 'civicrm_pledge') {
 -        $joinTable = 'civicrm_pledge';
 -      }
 -      elseif ($field['extends'] == 'civicrm_activity') {
 -        $joinTable = 'civicrm_activity';
 +        $joinTable = $field['extends'];
        }
 -      elseif ($field['extends'] == 'civicrm_relationship') {
 -        $joinTable = 'civicrm_relationship';
 +      elseif (in_array($field['extends'], self::$extendsMap)) {
 +        $joinTable = $field['extends'];
        }
 -      elseif ($field['extends'] == 'civicrm_grant') {
 -        $joinTable = 'civicrm_grant';
 +      else {
 +        return;
        }
 -      elseif ($field['extends'] == 'civicrm_address') {
 -        $joinTable = 'civicrm_address';
 -      }
 -      elseif ($field['extends'] == 'civicrm_case') {
 -        $joinTable = 'civicrm_case';
 +
 +      $this->_tables[$name] = "\nLEFT JOIN $name ON $name.entity_id = $joinTable.id";
 +
 +      if ($this->_ids[$id]) {
 +        $this->_whereTables[$name] = $this->_tables[$name];
        }
  
-       if ($joinTable != 'contact_a') {
-         $this->_whereTables[$joinTable] = $this->_tables[$joinTable] = 1;
-       }
-       elseif ($this->_contactSearch) {
-         CRM_Contact_BAO_Query::$_openedPanes[ts('Custom Fields')] = TRUE;
+       if ($joinTable) {
+         $joinClause = 1;
+         $joinTableAlias = $joinTable;
+         // Set location-specific query
+         if (isset($this->_locationSpecificCustomFields[$id])) {
+           list($locationType, $locationTypeId) = $this->_locationSpecificCustomFields[$id];
+           $joinTableAlias = "$locationType-address";
+           $joinClause = "\nLEFT JOIN $joinTable `$locationType-address` ON (`$locationType-address`.contact_id = contact_a.id AND `$locationType-address`.location_type_id = $locationTypeId)";
+         }
+         $this->_tables[$name] = "\nLEFT JOIN $name ON $name.entity_id = `$joinTableAlias`.id";
+         if ($this->_ids[$id]) {
+           $this->_whereTables[$name] = $this->_tables[$name];
+         }
+         if ($joinTable != 'contact_a') {
+           $this->_whereTables[$joinTableAlias] = $this->_tables[$joinTableAlias] = $joinClause;
+         }
+         elseif ($this->_contactSearch) {
+           CRM_Contact_BAO_Query::$_openedPanes[ts('Custom Fields')] = TRUE;
+         }
        }
      }
    }
Simple merge
Simple merge