PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 2.1.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v2.1.9
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 3.10.4 All 148 releases
visualizer / classes / Visualizer / Source.php

Source.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 2.1.9, at classes/Visualizer/Source.php

232 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
4 // +----------------------------------------------------------------------+
5 // | This program is free software; you can redistribute it and/or modify |
6 // | it under the terms of the GNU General Public License, version 2, as |
7 // | published by the Free Software Foundation. |
8 // | |
9 // | This program is distributed in the hope that it will be useful, |
10 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 // | GNU General Public License for more details. |
13 // | |
14 // | You should have received a copy of the GNU General Public License |
15 // | along with this program; if not, write to the Free Software |
16 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
17 // | MA 02110-1301 USA |
18 // +----------------------------------------------------------------------+
19 // | Author: Eugene Manuilov <eugene@manuilov.org> |
20 // +----------------------------------------------------------------------+
21 /**
22 * The abstract class for source managers.
23 *
24 * @category Visualizer
25 * @package Source
26 *
27 * @since 1.0.0
28 * @abstract
29 */
30 abstract class Visualizer_Source {
31
32 /**
33 * The array of allowed types.
34 *
35 * @since 1.0.0
36 *
37 * @access protected
38 * @var array
39 */
40 protected static $allowed_types = array( 'string', 'number', 'boolean', 'date', 'datetime', 'timeofday' );
41 /**
42 * The array of data.
43 *
44 * @since 1.0.0
45 *
46 * @access protected
47 * @var array
48 */
49 protected $_data = array();
50 /**
51 * The array of series.
52 *
53 * @since 1.0.0
54 *
55 * @access protected
56 * @var array
57 */
58 protected $_series = array();
59
60 /**
61 * Return allowed types
62 *
63 * @since 1.0.1
64 *
65 * @static
66 * @access public
67 * @return array the allowed types
68 */
69 public static function getAllowedTypes() {
70 return self::$allowed_types;
71 }
72
73 /**
74 * Validates series tyeps.
75 *
76 * @since 1.0.1
77 *
78 * @static
79 * @access protected
80 *
81 * @param array $types The icoming series types.
82 *
83 * @return boolean TRUE if sereis types are valid, otherwise FALSE.
84 */
85 protected static function _validateTypes( $types ) {
86 foreach ( $types as $type ) {
87 if ( ! in_array( $type, self::$allowed_types ) ) {
88 return false;
89 }
90 }
91
92 return true;
93 }
94
95 /**
96 * Returns source name.
97 *
98 * @since 1.0.0
99 *
100 * @abstract
101 * @access public
102 * @return string The name of source.
103 */
104 public abstract function getSourceName();
105
106 /**
107 * Fetches information from source, parses it and builds series and data arrays.
108 *
109 * @since 1.0.0
110 *
111 * @abstract
112 * @access public
113 */
114 public abstract function fetch();
115
116 /**
117 * Returns series parsed from source.
118 *
119 * @since 1.0.0
120 *
121 * @access public
122 * @return array The array of series.
123 */
124 public function getSeries() {
125 return $this->_series;
126 }
127
128 /**
129 * Returns data parsed from source.
130 *
131 * @since 1.0.0
132 *
133 * @access public
134 * @return string The serialized array of data.
135 */
136 public function getData() {
137 return serialize( $this->_data );
138 }
139
140 /**
141 * Returns raw data array.
142 *
143 * @since 1.1.0
144 *
145 * @access public
146 * @return array
147 */
148 public function getRawData() {
149 return $this->_data;
150 }
151
152 /**
153 * Re populates series if the source is dynamic.
154 *
155 * @since 1.1.0
156 *
157 * @access public
158 *
159 * @param array $series The actual array of series.
160 * @param int $chart_id The chart id.
161 *
162 * @return array The re populated array of series or old one.
163 */
164 public function repopulateSeries( $series, $chart_id ) {
165 return $series;
166 }
167
168 /**
169 * Re populates data if the source is dynamic.
170 *
171 * @since 1.1.0
172 *
173 * @access public
174 *
175 * @param array $data The actual array of data.
176 * @param int $chart_id The chart id.
177 *
178 * @return array The re populated array of data or old one.
179 */
180 public function repopulateData( $data, $chart_id ) {
181 return $data;
182 }
183
184 /**
185 * Normalizes values according to series' type.
186 *
187 * @since 1.0.0
188 *
189 * @access protected
190 *
191 * @param array $data The row of data.
192 *
193 * @return array Normalized row of data.
194 */
195 protected function _normalizeData( $data ) {
196 // normalize values
197 // error_log(print_r($data,true));
198 foreach ( $this->_series as $i => $series ) {
199 // if no value exists for the seires, then add null
200 if ( ! isset( $data[ $i ] ) ) {
201 $data[ $i ] = null;
202 }
203 if ( is_null( $data[ $i ] ) ) {
204 continue;
205 }
206 switch ( $series['type'] ) {
207 case 'number':
208 $data[ $i ] = ( is_numeric( $data[ $i ] ) ) ? floatval( $data[ $i ] ) : ( is_numeric( str_replace( ',', '', $data[ $i ] ) ) ? floatval( str_replace( ',', '', $data[ $i ] ) ) : null );
209 break;
210 case 'boolean':
211 $data[ $i ] = ! empty( $data[ $i ] ) ? filter_validate( $data[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
212 break;
213 case 'timeofday':
214 $date = new DateTime( '1984-03-16T' . $data[ $i ] );
215 if ( $date ) {
216 $data[ $i ] = array(
217 intval( $date->format( 'H' ) ),
218 intval( $date->format( 'i' ) ),
219 intval( $date->format( 's' ) ),
220 0,
221 );
222 }
223 break;
224 }
225 }
226
227 // error_log(print_r($data,true));
228 return $data;
229 }
230
231 }
232