Advertisement
gotopa

Datatables.php

Jan 13th, 2016
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 20.69 KB | None | 0 0
  1. <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
  2.   /**
  3.   * Ignited Datatables
  4.   *
  5.   * This is a wrapper class/library based on the native Datatables server-side implementation by Allan Jardine
  6.   * found at http://datatables.net/examples/data_sources/server_side.html for CodeIgniter
  7.   *
  8.   * @package    CodeIgniter
  9.   * @subpackage libraries
  10.   * @category   library
  11.   * @version    1.16.2
  12.   * @author     Vincent Bambico <metal.conspiracy@gmail.com>
  13.   *             Yusuf Ozdemir <yusuf@ozdemir.be>
  14.   * @modified   Mustopa Amin <mustopaamin@ymail.com>
  15.   * @link       http://ellislab.com/forums/viewthread/160896/
  16.   * @using      DataTables 1.10.7
  17.   */
  18.   class Datatables
  19.   {
  20.     /**
  21.     * Global container variables for chained argument results
  22.     *
  23.     */
  24.     private $ci;
  25.     private $table;
  26.     private $distinct;
  27.     private $group_by       = array();
  28.     private $select         = array();
  29.     private $joins          = array();
  30.     private $columns        = array();
  31.     private $where          = array();
  32.     private $where_in       = array();
  33.     private $or_where       = array();
  34.     private $like           = array();
  35.     private $filter         = array();
  36.     private $add_columns    = array();
  37.     private $edit_columns   = array();
  38.     private $unset_columns  = array();
  39.  
  40.     /**
  41.     * Copies an instance of CI
  42.     */
  43.     public function __construct()
  44.     {
  45.       $this->ci =& get_instance();
  46.     }
  47.  
  48.     /**
  49.     * If you establish multiple databases in config/database.php this will allow you to
  50.     * set the database (other than $active_group) - more info: http://ellislab.com/forums/viewthread/145901/#712942
  51.     */
  52.     public function set_database($db_name)
  53.     {
  54.       $db_data = $this->ci->load->database($db_name, TRUE);
  55.       $this->ci->db = $db_data;
  56.     }
  57.  
  58.     /**
  59.     * Generates the SELECT portion of the query
  60.     *
  61.     * @param string $columns
  62.     * @param bool $backtick_protect
  63.     * @return mixed
  64.     */
  65.     public function select($columns, $backtick_protect = TRUE)
  66.     {
  67.       foreach($this->explode(',', $columns) as $val)
  68.       {
  69.         $column = trim(preg_replace('/(.*)\s+as\s+(\w*)/i', '$2', $val));
  70.         $this->columns[] =  $column;
  71.         $this->select[$column] =  trim(preg_replace('/(.*)\s+as\s+(\w*)/i', '$1', $val));
  72.       }
  73.  
  74.       $this->ci->db->select($columns, $backtick_protect);
  75.       return $this;
  76.     }
  77.  
  78.     /**
  79.     * Generates the DISTINCT portion of the query
  80.     *
  81.     * @param string $column
  82.     * @return mixed
  83.     */
  84.     public function distinct($column)
  85.     {
  86.       $this->distinct = $column;
  87.       $this->ci->db->distinct($column);
  88.       return $this;
  89.     }
  90.  
  91.     /**
  92.     * Generates a custom GROUP BY portion of the query
  93.     *
  94.     * @param string $val
  95.     * @return mixed
  96.     */
  97.     public function group_by($val)
  98.     {
  99.       $this->group_by[] = $val;
  100.       $this->ci->db->group_by($val);
  101.       return $this;
  102.     }
  103.  
  104.     /**
  105.     * Generates the FROM portion of the query
  106.     *
  107.     * @param string $table
  108.     * @return mixed
  109.     */
  110.     public function from($table)
  111.     {
  112.       $this->table = $table;
  113.       return $this;
  114.     }
  115.  
  116.     /**
  117.     * Generates the JOIN portion of the query
  118.     *
  119.     * @param string $table
  120.     * @param string $fk
  121.     * @param string $type
  122.     * @return mixed
  123.     */
  124.     public function join($table, $fk, $type = NULL)
  125.     {
  126.       $this->joins[] = array($table, $fk, $type);
  127.       $this->ci->db->join($table, $fk, $type);
  128.       return $this;
  129.     }
  130.  
  131.     /**
  132.     * Generates the WHERE portion of the query
  133.     *
  134.     * @param mixed $key_condition
  135.     * @param string $val
  136.     * @param bool $backtick_protect
  137.     * @return mixed
  138.     */
  139.     public function where($key_condition, $val = NULL, $backtick_protect = TRUE)
  140.     {
  141.       $this->where[] = array($key_condition, $val, $backtick_protect);
  142.       $this->ci->db->where($key_condition, $val, $backtick_protect);
  143.       return $this;
  144.     }
  145.  
  146.     /**
  147.     * Generates the WHERE portion of the query
  148.     *
  149.     * @param mixed $key_condition
  150.     * @param string $val
  151.     * @param bool $backtick_protect
  152.     * @return mixed
  153.     */
  154.     public function or_where($key_condition, $val = NULL, $backtick_protect = TRUE)
  155.     {
  156.       $this->or_where[] = array($key_condition, $val, $backtick_protect);
  157.       $this->ci->db->or_where($key_condition, $val, $backtick_protect);
  158.       return $this;
  159.     }
  160.  
  161.     /**
  162.      * WHERE IN
  163.      *
  164.      * Generates a WHERE field IN('item', 'item') SQL query,
  165.      * joined with 'AND' if appropriate.
  166.      *
  167.      * @param   string  $key    The field to search
  168.      * @param   array   $values The values searched on
  169.      * @param   bool    $escape
  170.      * @return  CI_DB_query_builder
  171.      */
  172.     public function where_in($key = NULL, $values = NULL, $escape = NULL)
  173.     {
  174.       $this->where_in[] = array($key, $values , $escape);
  175.       $this->ci->db->where_in($key, $values , $escape);
  176.       return $this;
  177.     }
  178.    
  179.     /**
  180.     * Generates the Order portion of the query
  181.     *
  182.     * @param string $orderby
  183.     * @param string $direction
  184.     * @return mixed
  185.     */
  186.     public function order_by($orderby, $direction = '')
  187.     {
  188.       $this->ci->db->order_by($orderby, $direction);
  189.       return $this;
  190.     }
  191.  
  192.     /**
  193.     * Generates the WHERE portion of the query
  194.     *
  195.     * @param mixed $key_condition
  196.     * @param string $val
  197.     * @param bool $backtick_protect
  198.     * @return mixed
  199.     */
  200.     public function filter($key_condition, $val = NULL, $backtick_protect = TRUE)
  201.     {
  202.       $this->filter[] = array($key_condition, $val, $backtick_protect);
  203.       return $this;
  204.     }
  205.  
  206.     /**
  207.     * Generates a %LIKE% portion of the query
  208.     *
  209.     * @param mixed $key_condition
  210.     * @param string $val
  211.     * @param bool $backtick_protect
  212.     * @return mixed
  213.     */
  214.     public function like($key_condition, $val = NULL, $backtick_protect = TRUE)
  215.     {
  216.       $this->like[] = array($key_condition, $val, $backtick_protect);
  217.       $this->ci->db->like($key_condition, $val, $backtick_protect);
  218.       return $this;
  219.     }
  220.  
  221.     /**
  222.     * Sets additional column variables for adding custom columns
  223.     *
  224.     * @param string $column
  225.     * @param string $content
  226.     * @param string $match_replacement
  227.     * @return mixed
  228.     */
  229.     public function add_column($column, $content, $match_replacement = NULL)
  230.     {
  231.       $this->add_columns[$column] = array('content' => $content, 'replacement' => $this->explode(',', $match_replacement));
  232.       return $this;
  233.     }
  234.  
  235.     /**
  236.     * Sets additional column variables for editing columns
  237.     *
  238.     * @param string $column
  239.     * @param string $content
  240.     * @param string $match_replacement
  241.     * @return mixed
  242.     */
  243.     public function edit_column($column, $content, $match_replacement)
  244.     {
  245.       $this->edit_columns[$column][] = array('content' => $content, 'replacement' => $this->explode(',', $match_replacement));
  246.       return $this;
  247.     }
  248.  
  249.     /**
  250.     * Unset column
  251.     *
  252.     * @param string $column
  253.     * @return mixed
  254.     */
  255.     public function unset_column($column)
  256.     {
  257.       $column=explode(',',$column);
  258.       $this->unset_columns=array_merge($this->unset_columns,$column);
  259.       return $this;
  260.     }
  261.  
  262.     /**
  263.     * Builds all the necessary query segments and performs the main query based on results set from chained statements
  264.     *
  265.     * @param string $output
  266.     * @param string $charset
  267.     * @return string
  268.     */
  269.     public function generate($output = 'json', $charset = 'UTF-8')
  270.     {
  271.       if(strtolower($output) == 'json')
  272.         $this->get_paging();
  273.  
  274.       $this->get_ordering();
  275.       $this->get_filtering();
  276.       return $this->produce_output(strtolower($output), strtolower($charset));
  277.     }
  278.  
  279.     /**
  280.     * Generates the LIMIT portion of the query
  281.     *
  282.     * @return mixed
  283.     */
  284.     private function get_paging()
  285.     {
  286.       $iStart = $this->ci->input->post('iDisplayStart');
  287.       $iLength = $this->ci->input->post('iDisplayLength');
  288.  
  289.       if($iLength != '' && $iLength != '-1')
  290.         $this->ci->db->limit($iLength, ($iStart)? $iStart : 0);
  291.     }
  292.  
  293.     /**
  294.     * Generates the ORDER BY portion of the query
  295.     *
  296.     * @return mixed
  297.     */
  298.     private function get_ordering()
  299.     {
  300.       if($this->check_mDataprop())
  301.       {
  302.         $mColArray = $this->get_mDataprop();
  303.       }
  304.       elseif($this->ci->input->post('sColumns'))
  305.       {
  306.         $sColumns = str_replace(',','',$this->ci->input->post('sColumns'));
  307.         if($sColumns != '')
  308.             $mColArray = explode(',', $this->ci->input->post('sColumns'));
  309.         else
  310.             $mColArray = $this->columns;
  311.       }
  312.       else
  313.       {
  314.         $mColArray = $this->columns;
  315.       }
  316.  
  317.       $mColArray = array_values(array_diff($mColArray, $this->unset_columns));
  318.       $columns = array_values(array_diff($this->columns, $this->unset_columns));
  319.  
  320.       for($i = 0; $i < intval($this->ci->input->post('iSortingCols')); $i++)
  321.         if(isset($mColArray[intval($this->ci->input->post('iSortCol_' . $i))]) && in_array($mColArray[intval($this->ci->input->post('iSortCol_' . $i))], $columns) && $this->ci->input->post('bSortable_'.intval($this->ci->input->post('iSortCol_' . $i))) == 'true')
  322.           $this->ci->db->order_by($mColArray[intval($this->ci->input->post('iSortCol_' . $i))], $this->ci->input->post('sSortDir_' . $i));
  323.     }
  324.  
  325.     /**
  326.     * Generates a %LIKE% portion of the query
  327.     *
  328.     * @return mixed
  329.     */
  330.     private function get_filtering()
  331.     {
  332.       /*
  333.        * Start Modified
  334.        * mustopaamin@@ymail.com
  335.        */
  336.       if($this->check_mDataprop())  {
  337.         $mColArray = $this->get_mDataprop();
  338.       }
  339.       elseif($this->ci->input->post('sColumns'))    {
  340.         $sColumns = str_replace(',','',$this->ci->input->post('sColumns'));
  341.         if($sColumns != '')
  342.             $mColArray = explode(',', $this->ci->input->post('sColumns'));
  343.         else
  344.             $mColArray = $this->columns;
  345.       }
  346.       else {
  347.         $mColArray = $this->columns;
  348.       }
  349.       /*
  350.        * End Modified
  351.        */
  352.  
  353.       $sWhere = '';
  354.       $sSearch = $this->ci->db->escape_like_str($this->ci->input->post('sSearch'));
  355.       $mColArray = array_values(array_diff($mColArray, $this->unset_columns));
  356.       $columns = array_values(array_diff($this->columns, $this->unset_columns));
  357.  
  358.       if($sSearch != '')
  359.         for($i = 0; $i < count($mColArray); $i++)
  360.           if($this->ci->input->post('bSearchable_' . $i) == 'true' && in_array($mColArray[$i], $columns))
  361.             $sWhere .= $this->select[$mColArray[$i]] . " LIKE '%" . $sSearch . "%' OR ";
  362.  
  363.       $sWhere = substr_replace($sWhere, '', -3);
  364.  
  365.       if($sWhere != '')
  366.         $this->ci->db->where('(' . $sWhere . ')');
  367.  
  368.       $sRangeSeparator = $this->ci->input->post('sRangeSeparator');
  369.  
  370.       for($i = 0; $i < intval($this->ci->input->post('iColumns')); $i++)
  371.       {
  372.         if(isset($_POST['sSearch_' . $i]) && $this->ci->input->post('sSearch_' . $i) != '' && in_array($mColArray[$i], $columns))
  373.         {
  374.           $miSearch = explode(',', $this->ci->input->post('sSearch_' . $i));
  375.  
  376.           foreach($miSearch as $val)
  377.           {
  378.             if(preg_match("/(<=|>=|=|<|>)(\s*)(.+)/i", trim($val), $matches))
  379.               $this->ci->db->where($this->select[$mColArray[$i]].' '.$matches[1], $matches[3]);
  380.             elseif(!empty($sRangeSeparator) && preg_match("/(.*)$sRangeSeparator(.*)/i", trim($val), $matches))
  381.             {
  382.               $rangeQuery = '';
  383.  
  384.               if(!empty($matches[1]))
  385.                 $rangeQuery = 'STR_TO_DATE(' . $this->select[$mColArray[$i]] . ",'%d/%m/%y %H:%i:%s') >= STR_TO_DATE('" . $matches[1] . " 00:00:00','%d/%m/%y %H:%i:%s')";
  386.  
  387.               if(!empty($matches[2]))
  388.                 $rangeQuery .= (!empty($rangeQuery)? ' AND ': '') . 'STR_TO_DATE('. $this->select[$mColArray[$i]] . ",'%d/%m/%y %H:%i:%s') <= STR_TO_DATE('" . $matches[2] . " 23:59:59','%d/%m/%y %H:%i:%s')";
  389.  
  390.               if(!empty($matches[1]) || !empty($matches[2]))
  391.                 $this->ci->db->where($rangeQuery);
  392.             }
  393.             else
  394.               $this->ci->db->where($this->select[$mColArray[$i]] . ' LIKE', '%' . $val . '%');
  395.           }
  396.         }
  397.       }
  398.  
  399.       foreach($this->filter as $val)
  400.         $this->ci->db->where($val[0], $val[1], $val[2]);
  401.     }
  402.  
  403.     /**
  404.     * Compiles the select statement based on the other functions called and runs the query
  405.     *
  406.     * @return mixed
  407.     */
  408.     private function get_display_result()
  409.     {
  410.       return $this->ci->db->get($this->table);
  411.     }
  412.  
  413.     /**
  414.     * Builds an encoded string data. Returns JSON by default, and an array of aaData and sColumns if output is set to raw.
  415.     *
  416.     * @param string $output
  417.     * @param string $charset
  418.     * @return mixed
  419.     */
  420.     private function produce_output($output, $charset)
  421.     {
  422.       $aaData = array();
  423.       $rResult = $this->get_display_result();
  424.  
  425.       if($output == 'json')
  426.       {
  427.         $iTotal = $this->get_total_results();
  428.         $iFilteredTotal = $this->get_total_results(TRUE);
  429.       }
  430.  
  431.       foreach($rResult->result_array() as $row_key => $row_val)
  432.       {
  433.         $aaData[$row_key] = ($this->check_mDataprop())? $row_val : array_values($row_val);
  434.  
  435.         foreach($this->add_columns as $field => $val)
  436.           if($this->check_mDataprop())
  437.             $aaData[$row_key][$field] = $this->exec_replace($val, $aaData[$row_key]);
  438.           else
  439.             $aaData[$row_key][] = $this->exec_replace($val, $aaData[$row_key]);
  440.  
  441.         foreach($this->edit_columns as $modkey => $modval)
  442.           foreach($modval as $val)
  443.             $aaData[$row_key][($this->check_mDataprop())? $modkey : array_search($modkey, $this->columns)] = $this->exec_replace($val, $aaData[$row_key]);
  444.  
  445.         $aaData[$row_key] = array_diff_key($aaData[$row_key], ($this->check_mDataprop())? $this->unset_columns : array_intersect($this->columns, $this->unset_columns));
  446.  
  447.         if(!$this->check_mDataprop())
  448.           $aaData[$row_key] = array_values($aaData[$row_key]);
  449.       }
  450.  
  451.       $sColumns = array_diff($this->columns, $this->unset_columns);
  452.       $sColumns = array_merge_recursive($sColumns, array_keys($this->add_columns));
  453.  
  454.       if($output == 'json')
  455.       {
  456.         $sOutput = array
  457.         (
  458.           'sEcho'                => intval($this->ci->input->post('sEcho')),
  459.           'iTotalRecords'        => $iTotal,
  460.           'iTotalDisplayRecords' => $iFilteredTotal,
  461.           'aaData'               => $aaData,
  462.           'sColumns'             => implode(',', $sColumns)
  463.         );
  464.  
  465.         if($charset == 'utf-8')
  466.           return json_encode($sOutput);
  467.         else
  468.           return $this->jsonify($sOutput);
  469.       }
  470.       else
  471.         return array('aaData' => $aaData, 'sColumns' => $sColumns);
  472.     }
  473.  
  474.     /**
  475.     * Get result count
  476.     *
  477.     * @return integer
  478.     */
  479.     private function get_total_results($filtering = FALSE)
  480.     {
  481.       if($filtering)
  482.         $this->get_filtering();
  483.  
  484.       foreach($this->joins as $val)
  485.         $this->ci->db->join($val[0], $val[1], $val[2]);
  486.  
  487.       foreach($this->where as $val)
  488.         $this->ci->db->where($val[0], $val[1], $val[2]);
  489.  
  490.       foreach($this->or_where as $val)
  491.         $this->ci->db->or_where($val[0], $val[1], $val[2]);
  492.  
  493.       foreach($this->where_in as $val)
  494.         $this->ci->db->where_in($val[0], $val[1], $val[2]);
  495.  
  496.       foreach($this->group_by as $val)
  497.         $this->ci->db->group_by($val);
  498.  
  499.       foreach($this->like as $val)
  500.         $this->ci->db->like($val[0], $val[1], $val[2]);
  501.  
  502.       if(strlen($this->distinct) > 0)
  503.       {
  504.         $this->ci->db->distinct($this->distinct);
  505.         $this->ci->db->select($this->columns);
  506.       }
  507.  
  508.       $query = $this->ci->db->get($this->table, NULL, NULL, FALSE);
  509.       return $query->num_rows();
  510.     }
  511.  
  512.     /**
  513.     * Runs callback functions and makes replacements
  514.     *
  515.     * @param mixed $custom_val
  516.     * @param mixed $row_data
  517.     * @return string $custom_val['content']
  518.     */
  519.     private function exec_replace($custom_val, $row_data)
  520.     {
  521.       $replace_string = '';
  522.  
  523.       if(isset($custom_val['replacement']) && is_array($custom_val['replacement']))
  524.       {
  525.         foreach($custom_val['replacement'] as $key => $val)
  526.         {
  527.           $sval = preg_replace("/(?<!\w)([\'\"])(.*)\\1(?!\w)/i", '$2', trim($val));
  528.  
  529.           if(preg_match('/(\w+::\w+|\w+)\((.*)\)/i', $val, $matches) && is_callable($matches[1]))
  530.           {
  531.             $func = $matches[1];
  532.             $args = preg_split("/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[,]+/", $matches[2], 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  533.  
  534.             foreach($args as $args_key => $args_val)
  535.             {
  536.               $args_val = preg_replace("/(?<!\w)([\'\"])(.*)\\1(?!\w)/i", '$2', trim($args_val));
  537.               $args[$args_key] = (in_array($args_val, $this->columns))? ($row_data[($this->check_mDataprop())? $args_val : array_search($args_val, $this->columns)]) : $args_val;
  538.             }
  539.  
  540.             $replace_string = call_user_func_array($func, $args);
  541.           }
  542.           elseif(in_array($sval, $this->columns))
  543.             $replace_string = $row_data[($this->check_mDataprop())? $sval : array_search($sval, $this->columns)];
  544.           else
  545.             $replace_string = $sval;
  546.  
  547.           $custom_val['content'] = str_ireplace('$' . ($key + 1), $replace_string, $custom_val['content']);
  548.         }
  549.       }
  550.  
  551.       return $custom_val['content'];
  552.     }
  553.  
  554.     /**
  555.     * Check mDataprop
  556.     *
  557.     * @return bool
  558.     */
  559.     private function check_mDataprop()
  560.     {
  561.       if(!$this->ci->input->post('mDataProp_0'))
  562.         return FALSE;
  563.  
  564.       for($i = 0; $i < intval($this->ci->input->post('iColumns')); $i++)
  565.         if(!is_numeric($this->ci->input->post('mDataProp_' . $i)))
  566.           return TRUE;
  567.  
  568.       return FALSE;
  569.     }
  570.  
  571.     /**
  572.     * Get mDataprop order
  573.     *
  574.     * @return mixed
  575.     */
  576.     private function get_mDataprop()
  577.     {
  578.       $mDataProp = array();
  579.  
  580.       for($i = 0; $i < intval($this->ci->input->post('iColumns')); $i++)
  581.         $mDataProp[] = $this->ci->input->post('mDataProp_' . $i);
  582.  
  583.       return $mDataProp;
  584.     }
  585.  
  586.     /**
  587.     * Return the difference of open and close characters
  588.     *
  589.     * @param string $str
  590.     * @param string $open
  591.     * @param string $close
  592.     * @return string $retval
  593.     */
  594.     private function balanceChars($str, $open, $close)
  595.     {
  596.       $openCount = substr_count($str, $open);
  597.       $closeCount = substr_count($str, $close);
  598.       $retval = $openCount - $closeCount;
  599.       return $retval;
  600.     }
  601.  
  602.     /**
  603.     * Explode, but ignore delimiter until closing characters are found
  604.     *
  605.     * @param string $delimiter
  606.     * @param string $str
  607.     * @param string $open
  608.     * @param string $close
  609.     * @return mixed $retval
  610.     */
  611.     private function explode($delimiter, $str, $open = '(', $close=')')
  612.     {
  613.       $retval = array();
  614.       $hold = array();
  615.       $balance = 0;
  616.       $parts = explode($delimiter, $str);
  617.  
  618.       foreach($parts as $part)
  619.       {
  620.         $hold[] = $part;
  621.         $balance += $this->balanceChars($part, $open, $close);
  622.  
  623.         if($balance < 1)
  624.         {
  625.           $retval[] = implode($delimiter, $hold);
  626.           $hold = array();
  627.           $balance = 0;
  628.         }
  629.       }
  630.  
  631.       if(count($hold) > 0)
  632.         $retval[] = implode($delimiter, $hold);
  633.  
  634.       return $retval;
  635.     }
  636.  
  637.     /**
  638.     * Workaround for json_encode's UTF-8 encoding if a different charset needs to be used
  639.     *
  640.     * @param mixed $result
  641.     * @return string
  642.     */
  643.     private function jsonify($result = FALSE)
  644.     {
  645.       if(is_null($result))
  646.         return 'null';
  647.  
  648.       if($result === FALSE)
  649.         return 'false';
  650.  
  651.       if($result === TRUE)
  652.         return 'true';
  653.  
  654.       if(is_scalar($result))
  655.       {
  656.         if(is_float($result))
  657.           return floatval(str_replace(',', '.', strval($result)));
  658.  
  659.         if(is_string($result))
  660.         {
  661.           static $jsonReplaces = array(array('\\', '/', '\n', '\t', '\r', '\b', '\f', '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
  662.           return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $result) . '"';
  663.         }
  664.         else
  665.           return $result;
  666.       }
  667.  
  668.       $isList = TRUE;
  669.  
  670.       for($i = 0, reset($result); $i < count($result); $i++, next($result))
  671.       {
  672.         if(key($result) !== $i)
  673.         {
  674.           $isList = FALSE;
  675.           break;
  676.         }
  677.       }
  678.  
  679.       $json = array();
  680.  
  681.       if($isList)
  682.       {
  683.         foreach($result as $value)
  684.           $json[] = $this->jsonify($value);
  685.  
  686.         return '[' . join(',', $json) . ']';
  687.       }
  688.       else
  689.       {
  690.         foreach($result as $key => $value)
  691.           $json[] = $this->jsonify($key) . ':' . $this->jsonify($value);
  692.  
  693.         return '{' . join(',', $json) . '}';
  694.       }
  695.     }
  696.   }
  697. /* End of file Datatables.php */
  698. /* Location: ./application/libraries/Datatables.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement