Extract lines to add the pseudoconstant to the select
authoreileen <emcnaughton@wikimedia.org>
Thu, 28 Feb 2019 01:13:23 +0000 (14:13 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 28 Feb 2019 02:13:22 +0000 (15:13 +1300)
CRM/Contact/BAO/Query.php

index 139f041da0e4bd5aee7178a9ebadea324a8be87a..0674c815ecb56899cb35caf5dcf5594b2c2eea29 100644 (file)
@@ -871,20 +871,8 @@ class CRM_Contact_BAO_Query {
                 }
               }
               else {
-                // If we have an option group defined then rather than joining the option value table in
-                // (which is an unindexed join) we render the option value on output.
-                // @todo - extend this to other pseudoconstants.
                 if ($this->pseudoConstantNameIsInReturnProperties($field, $name)) {
-                  $pseudoFieldName = $field['pseudoconstant']['optionGroupName'];
-                  $this->_pseudoConstantsSelect[$pseudoFieldName] = array(
-                    'pseudoField' => $field['name'],
-                    'idCol' => $name,
-                    'field_name' => $field['name'],
-                    'bao' => $field['bao'],
-                    'pseudoconstant' => $field['pseudoconstant'],
-                  );
-                  $this->_tables[$tableName] = 1;
-                  $this->_element[$pseudoFieldName] = 1;
+                  $this->addPseudoconstantFieldToSelect($field, $name, $tableName);
                 }
                 $this->_select[$name] = str_replace('civicrm_contact.', 'contact_a.', "{$field['where']} as `$name`");
               }
@@ -6738,4 +6726,29 @@ AND   displayRelType.is_active = 1
     return empty($field['is_pseudofield_for']) ? $field : $this->getMetadataForField($field['is_pseudofield_for']);
   }
 
+  /**
+   * If we have a field that is better rendered via the pseudoconstant handled them here.
+   *
+   * Rather than joining in the additional table we render the option value on output.
+   *
+   * @todo - so far this applies to a narrow range of pseudocontants. We are adding them
+   * carefully with test coverage but aim to extend.
+   *
+   * @param array $field
+   * @param string $name
+   * @param string $tableName
+   */
+  protected function addPseudoconstantFieldToSelect($field, $name, $tableName) {
+    $pseudoFieldName = $field['pseudoconstant']['optionGroupName'];
+    $this->_pseudoConstantsSelect[$pseudoFieldName] = [
+      'pseudoField' => $field['name'],
+      'idCol' => $name,
+      'field_name' => $field['name'],
+      'bao' => $field['bao'],
+      'pseudoconstant' => $field['pseudoconstant'],
+    ];
+    $this->_tables[$tableName] = 1;
+    $this->_element[$pseudoFieldName] = 1;
+  }
+
 }