Merge pull request #5097 from PalanteJon/CRM-15917
[civicrm-core.git] / CRM / Utils / JSON.php
index 4c6cc1e265b5dea4b5fd9972704519f0ab23b028..adb349fb900ecbe40bda112f5839d95a0a751fb7 100644 (file)
@@ -23,7 +23,7 @@
  | 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();
   }
 
   /**
-   * 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']);
@@ -74,14 +76,18 @@ class CRM_Utils_JSON {
   /**
    * 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";
@@ -115,17 +121,21 @@ class CRM_Utils_JSON {
   }
 
   /**
-   * 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 . ', ';
@@ -144,7 +154,7 @@ class CRM_Utils_JSON {
         $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 .= "],";
@@ -154,5 +164,5 @@ class CRM_Utils_JSON {
 
     return $sOutput;
   }
-}
 
+}