CRM-14107 additional fixes
authorCiviCRM <info@civicrm.org>
Thu, 29 May 2014 11:33:06 +0000 (17:03 +0530)
committerCiviCRM <info@civicrm.org>
Thu, 29 May 2014 11:33:06 +0000 (17:03 +0530)
----------------------------------------
* 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
CRM/Contact/Form/Search/Custom/ActivitySearch.php
CRM/Contact/Form/Search/Custom/DateAdded.php
CRM/Contact/Form/Search/Custom/MultipleValues.php
templates/CRM/Contact/Form/Search/Custom.tpl
templates/CRM/Contact/Form/Search/Custom/ActivitySearch.tpl
templates/CRM/Contact/Form/Search/Custom/ContribSYBNT.tpl
templates/CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl
templates/CRM/Contact/Form/Search/Custom/MultipleValues.tpl
templates/CRM/Contact/Form/Search/Custom/Proximity.tpl

index e69b6815c6fad57842856250a79c6562c6984c85..cfa4282e1f679def80188ef34e5dee1a001068ad 100644 (file)
@@ -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 {
index cefe9d2d4101586c164955b8b088beed8157e10f..8b774ad1ddc0634d207a651de3bbc04f9bcdbdbb 100644 (file)
@@ -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) {
index c762cd79d05558067e510a883b6f9f28847a1ee5..f1d145cb4e07884aea62745b4951558b83739a8c 100644 (file)
@@ -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
index 4e9831db0b4bdd1d05a62a355c90707cd4bb02bc..caf43231edd249416ed7b2b3e5f9e77eff482b4f 100644 (file)
@@ -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 = "
index 2c986fcca77a4aa0fa6b4e543e0d7103c06ff307..03c96bacef8eaebdc76ee950898846c082fd674c 100644 (file)
                     {foreach from=$columnHeaders item=header}
                         {assign var=fName value=$header.sort}
                         {if $fName eq 'sort_name'}
-                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
+                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`"}">{$row.sort_name}</a></td>
                         {else}
                             <td>{$row.$fName}</td>
                         {/if}
index 9df39c842f3c95eea5113eaacd7deae71e1919e8..e1c5053433c523aa8a67448c336cdfc4993cad4e 100644 (file)
                     {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'}
-                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
+                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`"}">{$row.sort_name}</a></td>
                         {elseif $fName eq 'activity_subject'}
                             <td>
                                 {if $row.case_id }
index abea0492d0d505788f1b94b4f67951540de90739..62b592ed350cc5d576c21f6f6832efe3c286f6f0 100644 (file)
                     {foreach from=$columnHeaders item=header}
                         {assign var=fName value=$header.sort}
                         {if $fName eq 'sort_name'}
-                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
+                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`"}">{$row.sort_name}</a></td>
                         {else}
                             <td>{$row.$fName}</td>
                         {/if}
index e30e8e6dc8f22634d86b5ec323dd569f0d1ad3cf..6b2d135c1833db96b88cde992be82e4c1a5fb6e2 100644 (file)
                     {foreach from=$columnHeaders item=header}
                         {assign var=fName value=$header.sort}
                         {if $fName eq 'sort_name'}
-                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
+                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`"}">{$row.sort_name}</a></td>
                         {else}
                             <td>{$row.$fName}</td>
                         {/if}
index 310214196caff8f25b1dce394a2e0c40dbada881..a63b70cb365f5e262c243de0df3c5f045214c44f 100644 (file)
@@ -83,7 +83,7 @@
                     {foreach from=$columnHeaders item=header}
                         {assign var=fName value=$header.sort}
                         {if $fName eq 'sort_name'}
-                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
+                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`"}">{$row.sort_name}</a></td>
                         {else}
                             <td>{$row.$fName}</td>
                         {/if}
index ba28bf771bf4799d2dfb26889821325152464231..3b4af91228d111da8fe4ec5d4c8fe04a59511102 100644 (file)
                     {foreach from=$columnHeaders item=header}
                         {assign var=fName value=$header.sort}
                         {if $fName eq 'sort_name'}
-                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
+                            <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`&key=`$qfKey`"}">{$row.sort_name}</a></td>
                         {else}
                             <td>{$row.$fName}</td>
                         {/if}