<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
class CRM_Utils_JSON {
/**
- * Output json to the client
+ * Output json to the client.
* @param mixed $input
*/
- static function output($input) {
+ public static function output($input) {
header('Content-Type: application/json');
echo json_encode($input);
CRM_Utils_System::civiExit();
}
/**
- * Function to create JSON object
+ * Create JSON object.
* @deprecated
*
- * @param array $params associated array, that needs to be
+ * @param array $params
+ * Associated array, that needs to be.
* converted to JSON array
- * @param string $identifier identifier for the JSON array
+ * @param string $identifier
+ * Identifier for the JSON array.
*
- * @return string $jsonObject JSON array
- * @static
+ * @return string
+ * JSON array
*/
- static function encode($params, $identifier = 'id') {
+ public static function encode($params, $identifier = 'id') {
$buildObject = array();
foreach ($params as $value) {
$name = addslashes($value['name']);
}
/**
- * Function to encode json format for flexigrid, NOTE: "id" should be present in $params for each row
+ * Encode json format for flexigrid, NOTE: "id" should be present in $params for each row
*
- * @param array $params associated array of values rows
- * @param int $page page no for selector
+ * @param array $params
+ * Associated array of values rows.
+ * @param int $page
+ * Page no for selector.
* @param $total
- * @param array $selectorElements selector rows
+ * @param array $selectorElements
+ * Selector rows.
*
- * @return json encode string
+ * @return string
+ * json encoded string
*/
- static function encodeSelector(&$params, $page, $total, $selectorElements) {
+ public static function encodeSelector(&$params, $page, $total, $selectorElements) {
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
}
/**
- * This function is used to encode data for dataTable plugin
+ * encode data for dataTable plugin.
*
- * @param array $params associated array of row elements
- * @param int $sEcho datatable needs this to make it more secure
- * @param int $iTotal total records
- * @param int $iFilteredTotal total records on a page
- * @param array $selectorElements selector elements
+ * @param array $params
+ * Associated array of row elements.
+ * @param int $sEcho
+ * Datatable needs this to make it more secure.
+ * @param int $iTotal
+ * Total records.
+ * @param int $iFilteredTotal
+ * Total records on a page.
+ * @param array $selectorElements
+ * Selector elements.
* @return string
- *
*/
- static function encodeDataTableSelector($params, $sEcho, $iTotal, $iFilteredTotal, $selectorElements) {
+ public static function encodeDataTableSelector($params, $sEcho, $iTotal, $iFilteredTotal, $selectorElements) {
$sOutput = '{';
$sOutput .= '"sEcho": ' . intval($sEcho) . ', ';
$sOutput .= '"iTotalRecords": ' . $iTotal . ', ';
$sOutput .= '"' . addcslashes(str_replace(array("\r\n", "\n", "\r"), '<br />', $value[$element]), '"\\') . '"';
//remove extra spaces and tab character that breaks dataTable CRM-12551
- $sOutput = preg_replace("/\s+/", " ", $sOutput);
+ $sOutput = preg_replace("/\s+/", " ", $sOutput);
$addcomma = TRUE;
}
$sOutput .= "],";
return $sOutput;
}
-}
+}