From 26a9b6ab5e5012a0c46813f8ff6f1ba74d7c0507 Mon Sep 17 00:00:00 2001 From: CiviCRM Date: Thu, 29 May 2014 17:03:06 +0530 Subject: [PATCH] CRM-14107 additional fixes ---------------------------------------- * CRM-14107: Implement Previous / Next navigation on contact summary pages when accessed from a custom search https://issues.civicrm.org/jira/browse/CRM-14107 --- CRM/Contact/BAO/GroupContactCache.php | 1 + CRM/Contact/Form/Search/Custom/ActivitySearch.php | 5 ++++- CRM/Contact/Form/Search/Custom/DateAdded.php | 10 ++++++++-- CRM/Contact/Form/Search/Custom/MultipleValues.php | 7 +++++++ templates/CRM/Contact/Form/Search/Custom.tpl | 2 +- .../CRM/Contact/Form/Search/Custom/ActivitySearch.tpl | 2 +- .../CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl | 2 +- .../Form/Search/Custom/ContributionAggregate.tpl | 2 +- .../CRM/Contact/Form/Search/Custom/MultipleValues.tpl | 2 +- templates/CRM/Contact/Form/Search/Custom/Proximity.tpl | 2 +- 10 files changed, 26 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index e69b6815c6..cfa4282e1f 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -442,6 +442,7 @@ WHERE id = %1 $customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID); $searchSQL = $customClass->contactIDs(); + $searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL); $idName = 'contact_id'; } else { diff --git a/CRM/Contact/Form/Search/Custom/ActivitySearch.php b/CRM/Contact/Form/Search/Custom/ActivitySearch.php index cefe9d2d41..8b774ad1dd 100644 --- a/CRM/Contact/Form/Search/Custom/ActivitySearch.php +++ b/CRM/Contact/Form/Search/Custom/ActivitySearch.php @@ -222,7 +222,10 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch implements CRM_Contact_Form_ } } else { - $sql .= ' ORDER BY contact_a.sort_name'; + //CRM-14107, since there could be multiple activities against same contact, + //we need to provide GROUP BY on contact id to prevent duplicacy on prev/next entries + $sql .= 'GROUP BY contact_a.id +ORDER BY contact_a.sort_name'; } if ($rowcount > 0 && $offset >= 0) { diff --git a/CRM/Contact/Form/Search/Custom/DateAdded.php b/CRM/Contact/Form/Search/Custom/DateAdded.php index c762cd79d0..f1d145cb4e 100644 --- a/CRM/Contact/Form/Search/Custom/DateAdded.php +++ b/CRM/Contact/Form/Search/Custom/DateAdded.php @@ -109,6 +109,10 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C return NULL; } + function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) { + return $this->all($offset, $rowcount, $sort, FALSE, TRUE); + } + /** * @param int $offset * @param int $rowcount @@ -140,16 +144,18 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C } if ($justIDs) { - $select = "contact_a.id as contact_id"; + $selectClause = "contact_a.id as contact_id"; + $groupBy = " GROUP BY contact_a.id"; + $sort = "contact_a.id"; } else { $selectClause = "contact_a.id as contact_id, contact_a.contact_type as contact_type, contact_a.sort_name as sort_name, d.date_added as date_added"; + $groupBy = " GROUP BY contact_id "; } - $groupBy = " GROUP BY contact_id "; return $this->sql($selectClause, $offset, $rowcount, $sort, $includeContactIDs, $groupBy diff --git a/CRM/Contact/Form/Search/Custom/MultipleValues.php b/CRM/Contact/Form/Search/Custom/MultipleValues.php index 4e9831db0b..caf43231ed 100644 --- a/CRM/Contact/Form/Search/Custom/MultipleValues.php +++ b/CRM/Contact/Form/Search/Custom/MultipleValues.php @@ -141,6 +141,10 @@ class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Sea return NULL; } + function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) { + return $this->all($offset, $rowcount, $sort, FALSE, TRUE); + } + /** * @param int $offset * @param int $rowcount @@ -163,6 +167,9 @@ class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Sea if ($justIDs) { $selectClause = "contact_a.id as contact_id"; + $sort = "contact_a.id"; + + return $this->sql($selectClause, $offset, $rowcount, $sort, $includeContactIDs, NULL); } else { $selectClause = " diff --git a/templates/CRM/Contact/Form/Search/Custom.tpl b/templates/CRM/Contact/Form/Search/Custom.tpl index 2c986fcca7..03c96bacef 100644 --- a/templates/CRM/Contact/Form/Search/Custom.tpl +++ b/templates/CRM/Contact/Form/Search/Custom.tpl @@ -107,7 +107,7 @@ {foreach from=$columnHeaders item=header} {assign var=fName value=$header.sort} {if $fName eq 'sort_name'} - {$row.sort_name} + {$row.sort_name} {else} {$row.$fName} {/if} diff --git a/templates/CRM/Contact/Form/Search/Custom/ActivitySearch.tpl b/templates/CRM/Contact/Form/Search/Custom/ActivitySearch.tpl index 9df39c842f..e1c5053433 100644 --- a/templates/CRM/Contact/Form/Search/Custom/ActivitySearch.tpl +++ b/templates/CRM/Contact/Form/Search/Custom/ActivitySearch.tpl @@ -107,7 +107,7 @@ {if ($header.sort eq 'sort_name') or ($header.sort eq 'activity_status') or ($header.sort eq 'activity_type') or ($header.sort eq 'activity_subject') or ($header.sort eq 'source_contact') or ($header.SORT eq 'activity_date') or ($header.name eq null) } {assign var=fName value=$header.sort} {if $fName eq 'sort_name'} - {$row.sort_name} + {$row.sort_name} {elseif $fName eq 'activity_subject'} {if $row.case_id } diff --git a/templates/CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl b/templates/CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl index abea0492d0..62b592ed35 100644 --- a/templates/CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl +++ b/templates/CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl @@ -128,7 +128,7 @@ {foreach from=$columnHeaders item=header} {assign var=fName value=$header.sort} {if $fName eq 'sort_name'} - {$row.sort_name} + {$row.sort_name} {else} {$row.$fName} {/if} diff --git a/templates/CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl b/templates/CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl index e30e8e6dc8..6b2d135c18 100644 --- a/templates/CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl +++ b/templates/CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl @@ -117,7 +117,7 @@ {foreach from=$columnHeaders item=header} {assign var=fName value=$header.sort} {if $fName eq 'sort_name'} - {$row.sort_name} + {$row.sort_name} {else} {$row.$fName} {/if} diff --git a/templates/CRM/Contact/Form/Search/Custom/MultipleValues.tpl b/templates/CRM/Contact/Form/Search/Custom/MultipleValues.tpl index 310214196c..a63b70cb36 100644 --- a/templates/CRM/Contact/Form/Search/Custom/MultipleValues.tpl +++ b/templates/CRM/Contact/Form/Search/Custom/MultipleValues.tpl @@ -83,7 +83,7 @@ {foreach from=$columnHeaders item=header} {assign var=fName value=$header.sort} {if $fName eq 'sort_name'} - {$row.sort_name} + {$row.sort_name} {else} {$row.$fName} {/if} diff --git a/templates/CRM/Contact/Form/Search/Custom/Proximity.tpl b/templates/CRM/Contact/Form/Search/Custom/Proximity.tpl index ba28bf771b..3b4af91228 100644 --- a/templates/CRM/Contact/Form/Search/Custom/Proximity.tpl +++ b/templates/CRM/Contact/Form/Search/Custom/Proximity.tpl @@ -102,7 +102,7 @@ {foreach from=$columnHeaders item=header} {assign var=fName value=$header.sort} {if $fName eq 'sort_name'} - {$row.sort_name} + {$row.sort_name} {else} {$row.$fName} {/if} -- 2.25.1