From: deepak-srivastava Date: Sat, 8 Aug 2015 00:14:00 +0000 (+0100) Subject: use JSON::output instead of encodeDataTableSelector X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=22b232f3a1c35df528bf2c5b9c017350ae05a4e2;p=civicrm-core.git use JSON::output instead of encodeDataTableSelector --- diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index f03bc0d640..5d248649ab 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -864,10 +864,12 @@ LIMIT {$offset}, {$rowCount} $count++; } - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encodeDataTable($searchRows, $iTotal, $iFilteredTotal, $selectorElements); - - CRM_Utils_System::civiExit(); + $dupePairs = array( + 'data' => $searchRows, + 'recordsTotal' => $iTotal, + 'recordsFiltered' => $iFilteredTotal, + ); + CRM_Utils_JSON::output($dupePairs); } /** diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index 6df05ada6e..01e0b60bbf 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -94,38 +94,4 @@ class CRM_Utils_JSON { return $sOutput; } - /** - * This function is used to encode data for new dataTable plugin v1.10 and greater - * @return string - * - */ - public static function encodeDataTable($params, $iTotal, $iFilteredTotal, $selectorElements) { - $sOutput = '{'; - $sOutput .= '"recordsTotal": ' . $iTotal . ', '; - $sOutput .= '"recordsFiltered": ' . $iFilteredTotal . ', '; - $sOutput .= '"data": [ '; - foreach ($params as $key => $value) { - $addcomma = FALSE; - $sOutput .= "{"; - foreach ($selectorElements as $element) { - if ($addcomma) { - $sOutput .= ","; - } - //CRM-7130 --lets addslashes to only double quotes, - //since we are using it to quote the field value. - //str_replace helps to provide a break for new-line - $sOutput .= '"' . $element . '":' . '"' . addcslashes(str_replace(array("\r\n", "\n", "\r"), '
', $value[$element]), '"\\') . '"'; - - //remove extra spaces and tab character that breaks dataTable CRM-12551 - $sOutput = preg_replace("/\s+/", " ", $sOutput); - $addcomma = TRUE; - } - $sOutput .= "},"; - } - $sOutput = substr_replace($sOutput, "", -1); - $sOutput .= '] }'; - - return $sOutput; - } - }