PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.0
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Source/Query.php +69 -30 3.3.43.4.0 View file →
@@ -35,15 +35,35 @@
35 35 */
36 36 protected $_query;
37 37
38 38 /**
39 + * The chart id.
40 + *
41 + * @access protected
42 + * @var int
43 + */
44 + protected $_chart_id;
45 +
46 + /**
47 + * Any additional parameters (e.g. for connecting to a remote db).
48 + *
49 + * @access protected
50 + * @var array
51 + */
52 + protected $_params;
53 +
54 + /**
39 55 * Constructor.
40 56 *
41 57 * @access public
42 58 * @param string $query The query.
59 + * @param int $chart_id The chart id.
60 + * @param array $params Any additional parameters (e.g. for connecting to a remote db).
43 61 */
44 - public function __construct( $query = null ) {
62 + public function __construct( $query = null, $chart_id = null, $params = null ) {
45 63 $this->_query = $query;
64 + $this->_chart_id = $chart_id;
65 + $this->_params = $params;
46 66 }
47 67
48 68 /**
49 69 * Fetches information from source, parses it and builds series and data arrays.
@@ -66,50 +86,69 @@
66 86 }
67 87
68 88 // impose a limit if no limit clause is provided.
69 89 if ( strpos( strtolower( $this->_query ), ' limit ' ) === false ) {
70 - $this->_query .= ' LIMIT ' . apply_filters( 'visualizer_sql_query_limit', 1000 );
90 + $this->_query .= ' LIMIT ' . apply_filters( 'visualizer_sql_query_limit', 1000, $this->_chart_id );
71 91 }
72 92
73 - global $wpdb;
74 - $wpdb->hide_errors();
75 - // @codingStandardsIgnoreStart
76 - $rows = $wpdb->get_results( $this->_query, $results_as_numeric_array ? ARRAY_N : ARRAY_A );
77 - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Firing query %s to get results %s with error %s', $this->_query, print_r( $rows, true ), print_r( $wpdb->last_error, true ) ), 'debug', __FILE__, __LINE__ );
78 - // @codingStandardsIgnoreEnd
79 - $wpdb->show_errors();
93 + $results = array();
94 + $headers = array();
80 95
81 - if ( $raw_results ) {
82 - return $rows;
96 + // short circuit results for remote dbs.
97 + if ( false !== ( $remote_results = apply_filters( 'visualizer_db_query_execute', false, $this->_query, $as_html, $results_as_numeric_array, $raw_results, $this->_chart_id, $this->_params ) ) ) {
98 + $error = $remote_results['error'];
99 + if ( empty( $error ) ) {
100 + $results = $remote_results['results'];
101 + $headers = $remote_results['headers'];
102 + }
103 +
104 + $this->_error = $error;
105 +
106 + if ( $raw_results ) {
107 + return $results;
108 + }
83 109 }
84 110
85 - if ( $rows ) {
86 - $results = array();
87 - $headers = array();
111 + if ( ! ( $results && $headers ) ) {
112 + global $wpdb;
113 + $wpdb->hide_errors();
114 + // @codingStandardsIgnoreStart
115 + $rows = $wpdb->get_results( $this->_query, $results_as_numeric_array ? ARRAY_N : ARRAY_A );
116 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Firing query %s to get results %s with error %s', $this->_query, print_r( $rows, true ), print_r( $wpdb->last_error, true ) ), 'debug', __FILE__, __LINE__ );
117 + // @codingStandardsIgnoreEnd
118 + $wpdb->show_errors();
119 +
120 + if ( $raw_results ) {
121 + return $rows;
122 + }
123 +
88 124 if ( $rows ) {
89 - $row_num = 0;
90 - foreach ( $rows as $row ) {
91 - $result = array();
92 - $col_num = 0;
93 - foreach ( $row as $k => $v ) {
94 - $result[] = $v;
95 - if ( 0 === $row_num ) {
96 - $headers[] = array( 'type' => $this->get_col_type( $col_num++ ), 'label' => $k );
125 + $results = array();
126 + $headers = array();
127 + if ( $rows ) {
128 + $row_num = 0;
129 + foreach ( $rows as $row ) {
130 + $result = array();
131 + $col_num = 0;
132 + foreach ( $row as $k => $v ) {
133 + $result[] = $v;
134 + if ( 0 === $row_num ) {
135 + $headers[] = array( 'type' => $this->get_col_type( $col_num++ ), 'label' => $k );
136 + }
97 137 }
138 + $results[] = $result;
139 + $row_num++;
98 140 }
99 - $results[] = $result;
100 - $row_num++;
101 141 }
102 - }
103 142
104 - if ( $as_html ) {
105 - return $this->html( $headers, $results );
143 + $this->_error = $wpdb->last_error;
106 144 }
107 - return $this->object( $headers, $results );
108 145 }
109 146
110 - $this->_error = $wpdb->last_error;
111 - return null;
147 + if ( $as_html ) {
148 + return $this->html( $headers, $results );
149 + }
150 + return $this->object( $headers, $results );
112 151 }
113 152
114 153 /**
115 154 * Get the data type of the column.