src/Traits/TableTrait.php
public function jsonRows()
    {
        $arrWhat = array_values($this->getHeaderColumns());
        $arrWhere = [];
        $arrOrder = ['`id` DESC'];
        $start = 0;
        $pageSize = 15;
        if (isset($_POST['page']) && isset($_POST['pageSize'])) {
            $page = (int) $_POST['page'];
            $pageSize = (int) $_POST['pageSize'];
            $start = $page * $pageSize;
        }
        if (isset($_POST['sort']) && isset($_POST['sortDir'])) {
            $sort = (string) $_POST['sort'];
            $sortDir = (string) $_POST['sortDir'];
            if (!in_array($sortDir, ['ASC', 'DESC'])) {
                throw new Exception('Someone is doing something evil here :(');
            }
            if (!in_array($sort, $this->getAllowedPostColumns())) {
                throw new Exception('Someone is doing something evil here :(');
            }
            $arrOrder = ['`'.$sort.'` '.$sortDir];
        }
        foreach ($arrWhat as $filter) {
            if (in_array($filter, $arrWhat) && isset($_POST['filter_'.$filter])) {
                $arrWhere[$filter] = [
                    "operator" => "like",
                    "value" => '%'.$_POST['filter_'.$filter].'%'
                ];
            }
        }
        
        $arrLimit = [$start, $pageSize];
        $rows = $this->loadByPrepStmt($arrWhat, $arrWhere, $arrOrder, $arrLimit);
        if (count($rows) < 1) {
            return "[]";
        }
        foreach ($rows as $key => $columns) {
            foreach ($columns as $cKey => $column) {
                if ($cKey == "createDate") {
                    $rows[$key][$cKey] = strftime("%d.%m.%Y %H:%M:%S", strtotime($column));
                }
            }
            $rows[$key]['actions'] = $this->renderActionLinks();
        }
        $json = json_encode($rows, JSON_UNESCAPED_UNICODE);
        return $json;
    }
public function jsonRows()
    {
        $arrWhat = array_values($this->getHeaderColumns());
        $arrWhere = [];
        $arrOrder = ['`id` DESC'];
        $start = 0;
        $pageSize = 15;
        if (isset($_POST['page']) && isset($_POST['pageSize'])) {
            $page = (int) $_POST['page'];
            $pageSize = (int) $_POST['pageSize'];
            $start = $page * $pageSize;
        }
        if (isset($_POST['sort']) && isset($_POST['sortDir'])) {
            $sort = (string) $_POST['sort'];
            $sortDir = (string) $_POST['sortDir'];
            if (!in_array($sortDir, ['ASC', 'DESC'])) {
                throw new Exception('Someone is doing something evil here :(');
            }
            if (!in_array($sort, $this->getAllowedPostColumns())) {
                throw new Exception('Someone is doing something evil here :(');
            }
            $arrOrder = ['`'.$sort.'` '.$sortDir];
        }
        foreach ($arrWhat as $filter) {
            if (in_array($filter, $arrWhat) && isset($_POST['filter_'.$filter])) {
                $arrWhere[$filter] = [
                    "operator" => "like",
                    "value" => '%'.$_POST['filter_'.$filter].'%'
                ];
            }
        }
        
        $arrLimit = [$start, $pageSize];
        $rows = $this->loadByPrepStmt($arrWhat, $arrWhere, $arrOrder, $arrLimit);
        if (count($rows) < 1) {
            return "[]";
        }
        foreach ($rows as $key => $columns) {
            foreach ($columns as $cKey => $column) {
                if ($cKey == "createDate") {
                    $rows[$key][$cKey] = strftime("%d.%m.%Y %H:%M:%S", strtotime($column));
                }
            }
            $rows[$key]['actions'] = $this->renderActionLinks();
        }
        $json = json_encode($rows, JSON_UNESCAPED_UNICODE);
        return $json;
    }
public function jsonRows ( ) { $ arrWhat = array_values ( $ this -> getHeaderColumns ( ) ) ; $ arrWhere = [ ] ; $ arrOrder = [ '`id` DESC' ] ; $ start = 0 ; $ pageSize = 15 ; if ( isset ( $ _POST [ 'page' ] ) && isset ( $ _POST [ 'pageSize' ] ) ) { $ page = ( int ) $ _POST [ 'page' ] ; $ pageSize = ( int ) $ _POST [ 'pageSize' ] ; $ start = $ page * $ pageSize ; } if ( isset ( $ _POST [ 'sort' ] ) && isset ( $ _POST [ 'sortDir' ] ) ) { $ sort = ( string ) $ _POST [ 'sort' ] ; $ sortDir = ( string ) $ _POST [ 'sortDir' ] ; if ( ! in_array ( $ sortDir , [ 'ASC' , 'DESC' ] ) ) { throw new Exception ( 'Someone is doing something evil here :(' ) ; } if ( ! in_array ( $ sort , $ this -> getAllowedPostColumns ( ) ) ) { throw new Exception ( 'Someone is doing something evil here :(' ) ; } $ arrOrder = [ '`' . $ sort . '` ' . $ sortDir ] ; } foreach ( $ arrWhat as $ filter ) { if ( in_array ( $ filter , $ arrWhat ) && isset ( $ _POST [ 'filter_' . $ filter ] ) ) { $ arrWhere [ $ filter ] = [ "operator" => "like" , "value" => '%' . $ _POST [ 'filter_' . $ filter ] . '%' ] ; } } $ arrLimit = [ $ start , $ pageSize ] ; $ rows = $ this -> loadByPrepStmt ( $ arrWhat , $ arrWhere , $ arrOrder , $ arrLimit ) ; if ( count ( $ rows ) < 1 ) { return "[]" ; } foreach ( $ rows as $ key => $ columns ) { foreach ( $ columns as $ cKey => $ column ) { if ( $ cKey == "createDate" ) { $ rows [ $ key ] [ $ cKey ] = strftime ( "%d.%m.%Y %H:%M:%S" , strtotime ( $ column ) ) ; } } $ rows [ $ key ] [ 'actions' ] = $ this -> renderActionLinks ( ) ; } $ json = json_encode ( $ rows , JSON_UNESCAPED_UNICODE ) ; return $ json ; }
Fetches Data for Table Rows and returns as json
uses POST vars page, pageSize, sort, sortDir
@return string JSON Data
@throws Exception
Fetches Data for Table Rows and returns as json uses POST vars page pageSize sort sortDir