1
1
<?php
2
-
3
2
// +----------------------------------------------------------------------+
4
3
// | Copyright 2013 Madpixels (email : [email protected] ) |
5
4
// +----------------------------------------------------------------------+
30
29
*/
31
30
abstract class Visualizer_Source {
32
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 ' );
33
41
/**
34
42
* The array of data.
35
43
*
@@ -39,7 +47,6 @@ abstract class Visualizer_Source {
39
47
* @var array
40
48
*/
41
49
protected $ _data = array ();
42
-
43
50
/**
44
51
* The array of series.
45
52
*
@@ -51,14 +58,39 @@ abstract class Visualizer_Source {
51
58
protected $ _series = array ();
52
59
53
60
/**
54
- * The array of allowed types.
61
+ * Return allowed types
55
62
*
56
- * @since 1.0.0
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
57
77
*
78
+ * @static
58
79
* @access protected
59
- * @var array
80
+ *
81
+ * @param array $types The icoming series types.
82
+ *
83
+ * @return boolean TRUE if sereis types are valid, otherwise FALSE.
60
84
*/
61
- protected static $ allowed_types = array ( 'string ' , 'number ' , 'boolean ' , 'date ' , 'datetime ' , 'timeofday ' );
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
+ }
62
94
63
95
/**
64
96
* Returns source name.
@@ -117,13 +149,47 @@ public function getRawData() {
117
149
return $ this ->_data ;
118
150
}
119
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
+
120
184
/**
121
185
* Normalizes values according to series' type.
122
186
*
123
187
* @since 1.0.0
124
188
*
125
189
* @access protected
190
+ *
126
191
* @param array $data The row of data.
192
+ *
127
193
* @return array Normalized row of data.
128
194
*/
129
195
protected function _normalizeData ( $ data ) {
@@ -134,14 +200,12 @@ protected function _normalizeData( $data ) {
134
200
if ( ! isset ( $ data [ $ i ] ) ) {
135
201
$ data [ $ i ] = null ;
136
202
}
137
-
138
203
if ( is_null ( $ data [ $ i ] ) ) {
139
204
continue ;
140
205
}
141
-
142
206
switch ( $ series ['type ' ] ) {
143
207
case 'number ' :
144
- $ data [ $ i ] = ( is_numeric ( $ data [ $ i ] ) ) ? floatval ( $ data [ $ i ] ) : (is_numeric ( str_replace ( ', ' , '' , $ data [ $ i ] ) ) ? floatval ( str_replace ( ', ' , '' , $ data [ $ i ] ) ) : null );
208
+ $ data [ $ i ] = ( is_numeric ( $ data [ $ i ] ) ) ? floatval ( $ data [ $ i ] ) : ( is_numeric ( str_replace ( ', ' , '' , $ data [ $ i ] ) ) ? floatval ( str_replace ( ', ' , '' , $ data [ $ i ] ) ) : null );
145
209
break ;
146
210
case 'boolean ' :
147
211
$ data [ $ i ] = ! empty ( $ data [ $ i ] ) ? filter_validate ( $ data [ $ i ], FILTER_VALIDATE_BOOLEAN ) : null ;
@@ -159,70 +223,8 @@ protected function _normalizeData( $data ) {
159
223
break ;
160
224
}
161
225
}
162
- // error_log(print_r($data,true));
163
- return $ data ;
164
- }
165
-
166
- /**
167
- * Validates series tyeps.
168
- *
169
- * @since 1.0.1
170
- *
171
- * @static
172
- * @access protected
173
- * @param array $types The icoming series types.
174
- * @return boolean TRUE if sereis types are valid, otherwise FALSE.
175
- */
176
- protected static function _validateTypes ( $ types ) {
177
- foreach ( $ types as $ type ) {
178
- if ( ! in_array ( $ type , self ::$ allowed_types ) ) {
179
- return false ;
180
- }
181
- }
182
-
183
- return true ;
184
- }
185
-
186
- /**
187
- * Return allowed types
188
- *
189
- * @since 1.0.1
190
- *
191
- * @static
192
- * @access public
193
- * @return array the allowed types
194
- */
195
- public static function getAllowedTypes () {
196
- return self ::$ allowed_types ;
197
- }
198
-
199
-
200
-
201
- /**
202
- * Re populates series if the source is dynamic.
203
- *
204
- * @since 1.1.0
205
- *
206
- * @access public
207
- * @param array $series The actual array of series.
208
- * @param int $chart_id The chart id.
209
- * @return array The re populated array of series or old one.
210
- */
211
- public function repopulateSeries ( $ series , $ chart_id ) {
212
- return $ series ;
213
- }
214
226
215
- /**
216
- * Re populates data if the source is dynamic.
217
- *
218
- * @since 1.1.0
219
- *
220
- * @access public
221
- * @param array $data The actual array of data.
222
- * @param int $chart_id The chart id.
223
- * @return array The re populated array of data or old one.
224
- */
225
- public function repopulateData ( $ data , $ chart_id ) {
227
+ // error_log(print_r($data,true));
226
228
return $ data ;
227
229
}
228
230
0 commit comments