CRM-18988 - multi custom data: after sorting, unable to edit
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Thu, 23 Jun 2016 13:23:23 +0000 (18:53 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Thu, 23 Jun 2016 13:23:23 +0000 (18:53 +0530)
CRM/Core/BAO/CustomValueTable.php
CRM/Profile/Page/MultipleRecordFieldsListing.php

index e71e106fffbba1c8ca6c6bbe776bc6d0914e61aa..4c4c4a03631d135cb00fcb5cbce0b599ac1aad23 100644 (file)
@@ -468,8 +468,17 @@ AND    $cond
       $file[$dao->table_name][$dao->fieldID] = $dao->fieldDataType;
     }
 
-    $result = array();
+    $result = $sortedResult = array();
     foreach ($select as $tableName => $clauses) {
+      if (!empty($DTparams['sort'])) {
+        $query = CRM_Core_DAO::executeQuery("SELECT id FROM {$tableName} WHERE entity_id = {$entityID}");
+        $count = 1;
+        while ($query->fetch()) {
+          $sortedResult["{$query->id}"] = $count;
+          $count++;
+        }
+      }
+
       $query = "SELECT SQL_CALC_FOUND_ROWS id, " . implode(', ', $clauses) . " FROM $tableName WHERE entity_id = $entityID {$orderBy} {$limit}";
       $dao = CRM_Core_DAO::executeQuery($query);
       if (!empty($DTparams)) {
@@ -492,6 +501,9 @@ AND    $cond
         }
       }
     }
+    if (!empty($DTparams)) {
+      return array($result, $sortedResult);
+    }
     return $result;
   }
 
index 88410a1d2f24a9129a89cf3cc6fd299c44c3f8bf..f2db4ba0eb78dd21c03542c82100a60922811eef 100644 (file)
@@ -262,7 +262,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
 
       $DTparams = !empty($this->_DTparams) ? $this->_DTparams : NULL;
       // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
-      $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE, $DTparams);
+      list($result, $sortedResult) = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE, $DTparams);
       $resultCount = !empty($result['count']) ? $result['count'] : count($result);
       unset($result['count']);
 
@@ -389,7 +389,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
                 $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId;
                 $actionParams['recId'] = $recId;
                 $actionParams['type'] = $this->_contactType;
-                $actionParams['cgcount'] = empty($DTparams['sort']) ? $cgcount : $recId;
+                $actionParams['cgcount'] = empty($DTparams['sort']) ? $cgcount : $sortedResult[$recId];
                 $actionParams['newCgCount'] = $newCgCount;
 
                 // DELETE action links