Skip to content

Commit

Permalink
[REF] Further divide savedSearchParam loading into the sql functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 26, 2021
1 parent d96f798 commit c3f7cb2
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions CRM/Contact/BAO/GroupContactCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,19 @@ protected static function getApiSQL(array $savedSearch, string $addSelect, strin
* so temp tables are not destroyed if they are used
*
* @param int $savedSearchID
* @param array $ssParams
* @param array $savedSearch
* @param string $addSelect
* @param string $excludeClause
*
* @return string
* @throws CRM_Core_Exception
*/
protected static function getCustomSearchSQL($savedSearchID, array $ssParams, string $addSelect, string $excludeClause) {
protected static function getCustomSearchSQL($savedSearchID, array $savedSearch, string $addSelect, string $excludeClause) {
$ssParams = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
// CRM-7021 rectify params to what proximity search expects if there is a value for prox_distance
if (!empty($ssParams)) {
CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
}
$searchSQL = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID)->contactIDs();
$searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL);
if (strpos($searchSQL, 'WHERE') === FALSE) {
Expand All @@ -577,15 +582,28 @@ protected static function getCustomSearchSQL($savedSearchID, array $ssParams, st
* Get array of sql from a saved query object group.
*
* @param int $savedSearchID
* @param array $ssParams
* @param array $savedSearch
* @param string $addSelect
* @param string $excludeClause
*
* @return string
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected static function getQueryObjectSQL($savedSearchID, array $ssParams, string $addSelect, string $excludeClause) {
protected static function getQueryObjectSQL($savedSearchID, array $savedSearch, string $addSelect, string $excludeClause): string {
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
//check if the saved search has mapping id
if ($savedSearch['mapping_id']) {
$ssParams = CRM_Core_BAO_Mapping::formattedFields($fv);
}
else {
$ssParams = CRM_Contact_BAO_Query::convertFormValues($fv);
}
// CRM-7021 rectify params to what proximity search expects if there is a value for prox_distance
if (!empty($ssParams)) {
CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
}

$returnProperties = NULL;
if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
Expand Down Expand Up @@ -799,6 +817,7 @@ protected static function insertGroupContactsIntoTempTable(string $tempTableName
if ($savedSearchID) {
$savedSearch = SavedSearch::get(FALSE)
->addWhere('id', '=', $savedSearchID)
->addSelect('*')
->execute()
->first();

Expand All @@ -808,31 +827,15 @@ protected static function insertGroupContactsIntoTempTable(string $tempTableName
AND civicrm_group_contact.group_id = $groupID )";
$addSelect = "$groupID AS group_id";

if (!empty($savedSearch['api_entity'])) {
if ($savedSearch['api_entity']) {
$sql = self::getApiSQL($savedSearch, $addSelect, $excludeClause);
}
else {
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
//check if the saved search has mapping id
if ($savedSearch['mapping_id']) {
$ssParams = CRM_Core_BAO_Mapping::formattedFields($fv);
}
elseif (!empty($fv['customSearchID'])) {
$ssParams = $fv;
}
else {
$ssParams = CRM_Contact_BAO_Query::convertFormValues($fv);
}

// CRM-7021 rectify params to what proximity search expects if there is a value for prox_distance
if (!empty($ssParams)) {
CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
}
if (isset($ssParams['customSearchID'])) {
$sql = self::getCustomSearchSQL($savedSearchID, $ssParams, $addSelect, $excludeClause);
if (!empty($savedSearch['form_values']['customSearchID'])) {
$sql = self::getCustomSearchSQL($savedSearchID, $savedSearch, $addSelect, $excludeClause);
}
else {
$sql = self::getQueryObjectSQL($savedSearchID, $ssParams, $addSelect, $excludeClause);
$sql = self::getQueryObjectSQL($savedSearchID, $savedSearch, $addSelect, $excludeClause);
}
}
}
Expand Down

0 comments on commit c3f7cb2

Please sign in to comment.