Skip to content

Commit

Permalink
Merge pull request #13886 from eileenmcnaughton/clean_fn
Browse files Browse the repository at this point in the history
Remove switch statement that no longer switches
  • Loading branch information
eileenmcnaughton authored Mar 25, 2019
2 parents 5b66765 + 1ddfb09 commit f9a6d90
Showing 1 changed file with 40 additions and 47 deletions.
87 changes: 40 additions & 47 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -6339,53 +6339,46 @@ protected function prepareOrderBy($sort, $sortOrder) {
}

}
switch ($field) {

case 'placeholder-will-remove-next-pr-but-jenkins-will-not-accept-without-and-removing-switch-will-make-hard-to-read':
break;

default:
$cfID = CRM_Core_BAO_CustomField::getKeyID($field);
// add to cfIDs array if not present
if (!empty($cfID) && !array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE, $this->_locationSpecificCustomFields);
$this->_customQuery->query();
$this->_select = array_merge($this->_select, $this->_customQuery->_select);
$this->_tables = array_merge($this->_tables, $this->_customQuery->_tables);
}

// By replacing the join to the option value table with the mysql construct
// ORDER BY field('contribution_status_id', 2,1,4)
// we can remove a join. In the case of the option value join it is
/// a join known to cause slow queries.
// @todo cover other pseudoconstant types. Limited to option group ones & Foreign keys
// matching an id+name parrern in the
// first instance for scope reasons. They require slightly different handling as the column (label)
// is not declared for them.
// @todo so far only integer fields are being handled. If we add string fields we need to look at
// escaping.
$pseudoConstantMetadata = CRM_Utils_Array::value('pseudoconstant', $fieldSpec, FALSE);
if (!empty($pseudoConstantMetadata)
) {
if (!empty($pseudoConstantMetadata['optionGroupName'])
|| $this->isPseudoFieldAnFK($fieldSpec)
) {
$sortedOptions = $fieldSpec['bao']::buildOptions($fieldSpec['name'], NULL, [
'orderColumn' => CRM_Utils_Array::value('labelColumn', $pseudoConstantMetadata, 'label'),
]);
$fieldIDsInOrder = implode(',', array_keys($sortedOptions));
// Pretty sure this validation ALSO happens in the order clause & this can't be reached but...
// this might give some early warning.
CRM_Utils_Type::validate($fieldIDsInOrder, 'CommaSeparatedIntegers');
$order = str_replace("$field", "field({$fieldSpec['name']},$fieldIDsInOrder)", $order);
}
//CRM-12565 add "`" around $field if it is a pseudo constant
// This appears to be for 'special' fields like locations with appended numbers or hyphens .. maybe.
if (!empty($pseudoConstantMetadata['element']) && $pseudoConstantMetadata['element'] == $field) {
$order = str_replace($field, "`{$field}`", $order);
}
}
$cfID = CRM_Core_BAO_CustomField::getKeyID($field);
// add to cfIDs array if not present
if (!empty($cfID) && !array_key_exists($cfID, $this->_cfIDs)) {
$this->_cfIDs[$cfID] = array();
$this->_customQuery = new CRM_Core_BAO_CustomQuery($this->_cfIDs, TRUE, $this->_locationSpecificCustomFields);
$this->_customQuery->query();
$this->_select = array_merge($this->_select, $this->_customQuery->_select);
$this->_tables = array_merge($this->_tables, $this->_customQuery->_tables);
}

// By replacing the join to the option value table with the mysql construct
// ORDER BY field('contribution_status_id', 2,1,4)
// we can remove a join. In the case of the option value join it is
/// a join known to cause slow queries.
// @todo cover other pseudoconstant types. Limited to option group ones & Foreign keys
// matching an id+name parrern in the
// first instance for scope reasons. They require slightly different handling as the column (label)
// is not declared for them.
// @todo so far only integer fields are being handled. If we add string fields we need to look at
// escaping.
$pseudoConstantMetadata = CRM_Utils_Array::value('pseudoconstant', $fieldSpec, FALSE);
if (!empty($pseudoConstantMetadata)
) {
if (!empty($pseudoConstantMetadata['optionGroupName'])
|| $this->isPseudoFieldAnFK($fieldSpec)
) {
$sortedOptions = $fieldSpec['bao']::buildOptions($fieldSpec['name'], NULL, [
'orderColumn' => CRM_Utils_Array::value('labelColumn', $pseudoConstantMetadata, 'label'),
]);
$fieldIDsInOrder = implode(',', array_keys($sortedOptions));
// Pretty sure this validation ALSO happens in the order clause & this can't be reached but...
// this might give some early warning.
CRM_Utils_Type::validate($fieldIDsInOrder, 'CommaSeparatedIntegers');
$order = str_replace("$field", "field({$fieldSpec['name']},$fieldIDsInOrder)", $order);
}
//CRM-12565 add "`" around $field if it is a pseudo constant
// This appears to be for 'special' fields like locations with appended numbers or hyphens .. maybe.
if (!empty($pseudoConstantMetadata['element']) && $pseudoConstantMetadata['element'] == $field) {
$order = str_replace($field, "`{$field}`", $order);
}
}
}

Expand Down

0 comments on commit f9a6d90

Please sign in to comment.