PMA\libraries\controllers\table\TableChartController::indexAction PHP Метод

indexAction() публичный Метод

Execute the query and return the result
public indexAction ( ) : void
Результат void
    public function indexAction()
    {
        if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['pos']) && isset($_REQUEST['session_max_rows'])) {
            $this->ajaxAction();
            return;
        }
        // Throw error if no sql query is set
        if (!isset($this->sql_query) || $this->sql_query == '') {
            $this->response->setRequestStatus(false);
            $this->response->addHTML(Message::error(__('No SQL query was set to fetch data.')));
            return;
        }
        $this->response->getHeader()->getScripts()->addFiles(array('chart.js', 'tbl_chart.js', 'jqplot/jquery.jqplot.js', 'jqplot/plugins/jqplot.barRenderer.js', 'jqplot/plugins/jqplot.canvasAxisLabelRenderer.js', 'jqplot/plugins/jqplot.canvasTextRenderer.js', 'jqplot/plugins/jqplot.categoryAxisRenderer.js', 'jqplot/plugins/jqplot.dateAxisRenderer.js', 'jqplot/plugins/jqplot.pointLabels.js', 'jqplot/plugins/jqplot.pieRenderer.js', 'jqplot/plugins/jqplot.highlighter.js'));
        /**
         * Extract values for common work
         * @todo Extract common files
         */
        $db =& $this->db;
        $table =& $this->table;
        $url_params = array();
        /**
         * Runs common work
         */
        if (strlen($this->table) > 0) {
            $url_params['goto'] = Util::getScriptNameForOption($this->cfg['DefaultTabTable'], 'table');
            $url_params['back'] = 'tbl_sql.php';
            include 'libraries/tbl_common.inc.php';
            include 'libraries/tbl_info.inc.php';
        } elseif (strlen($this->db) > 0) {
            $url_params['goto'] = Util::getScriptNameForOption($this->cfg['DefaultTabDatabase'], 'database');
            $url_params['back'] = 'sql.php';
            include 'libraries/db_common.inc.php';
        } else {
            $url_params['goto'] = Util::getScriptNameForOption($this->cfg['DefaultTabServer'], 'server');
            $url_params['back'] = 'sql.php';
            include 'libraries/server_common.inc.php';
        }
        $data = array();
        $result = $this->dbi->tryQuery($this->sql_query);
        $fields_meta = $this->dbi->getFieldsMeta($result);
        while ($row = $this->dbi->fetchAssoc($result)) {
            $data[] = $row;
        }
        $keys = array_keys($data[0]);
        $numeric_types = array('int', 'real');
        $numeric_column_count = 0;
        foreach ($keys as $idx => $key) {
            if (in_array($fields_meta[$idx]->type, $numeric_types)) {
                $numeric_column_count++;
            }
        }
        if ($numeric_column_count == 0) {
            $this->response->setRequestStatus(false);
            $this->response->addJSON('message', __('No numeric columns present in the table to plot.'));
            return;
        }
        $url_params['db'] = $this->db;
        $url_params['reload'] = 1;
        /**
         * Displays the page
         */
        $this->response->addHTML(Template::get('table/chart/tbl_chart')->render(array('url_query' => $this->url_query, 'url_params' => $url_params, 'keys' => $keys, 'fields_meta' => $fields_meta, 'numeric_types' => $numeric_types, 'numeric_column_count' => $numeric_column_count, 'sql_query' => $this->sql_query)));
    }