PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 1.7.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v1.7.0
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 1.7.0, at classes/Visualizer/Source.php

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