Merge pull request #18704 from mlutfy/partListingOutput
[civicrm-core.git] / CRM / Contact / BAO / Query.php
index 95d8cb474b88f00f1c5f06672ffc4d9cbbb7a866..3fe9a97fc22241580994ed26bd2d46541be9cbb4 100644 (file)
@@ -1121,6 +1121,9 @@ class CRM_Contact_BAO_Query {
         }
 
         $field = $this->_fields[$elementName] ?? NULL;
+        if (isset($this->_pseudoConstantsSelect[$field['name']])) {
+          $this->_pseudoConstantsSelect[$name . '-' . $field['name']] = $this->_pseudoConstantsSelect[$field['name']];
+        }
 
         // hack for profile, add location id
         if (!$field) {
@@ -1742,7 +1745,7 @@ class CRM_Contact_BAO_Query {
     }
 
     if (!$likeNames) {
-      $likeNames = ['sort_name', 'first_name', 'last_name', 'email', 'note', 'display_name'];
+      $likeNames = ['sort_name', 'email', 'note', 'display_name'];
     }
 
     // email comes in via advanced search
@@ -2186,7 +2189,7 @@ class CRM_Contact_BAO_Query {
         $name, $op, $value, $grouping,
         'CRM_Contact_DAO_Contact',
         $field,
-        $field['title'],
+        $field['html']['label'] ?? $field['title'],
         CRM_Utils_Type::typeToString($dataType)
       );
       if ($name === 'gender_id') {
@@ -4989,10 +4992,7 @@ civicrm_relationship.start_date > {$today}
     $sqlParts = $this->getSearchSQLParts(NULL, NULL, NULL, FALSE, FALSE, TRUE);
     $query = "SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name
       {$sqlParts['from']}
-      {$sqlParts['where']}
-      {$sqlParts['having']}
-      GROUP BY sort_name
-      ORDER BY sort_name asc";
+      {$sqlParts['where']}";
     $dao = CRM_Core_DAO::executeQuery($query);
     return $dao;
   }
@@ -6941,6 +6941,17 @@ AND   displayRelType.is_active = 1
     return $field;
   }
 
+  /**
+   * Get the field datatype, using the type in the database rather than the pseudofield, if a pseudofield.
+   *
+   * @param string $fieldName
+   *
+   * @return string
+   */
+  public function getDataTypeForRealField($fieldName) {
+    return CRM_Utils_Type::typeToString($this->getMetadataForRealField($fieldName)['type']);
+  }
+
   /**
    * If we have a field that is better rendered via the pseudoconstant handled them here.
    *