| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | // +----------------------------------------------------------------------+ |
| 4 | 3 | // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 5 | 4 | // +----------------------------------------------------------------------+ |
| 6 | 5 | // | This program is free software; you can redistribute it and/or modify | |
| @@ -30,8 +29,17 @@ | ||
| 30 | 29 | */ |
| 31 | 30 | abstract class Visualizer_Source { |
| 32 | 31 | |
| 33 | 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 | + /** | |
| 34 | 42 | * The array of data. |
| 35 | 43 | * |
| 36 | 44 | * @since 1.0.0 |
| 37 | 45 | * |
| @@ -38,9 +46,8 @@ | ||
| 38 | 46 | * @access protected |
| 39 | 47 | * @var array |
| 40 | 48 | */ |
| 41 | 49 | protected $_data = array(); |
| 42 | - | |
| 43 | 50 | /** |
| 44 | 51 | * The array of series. |
| 45 | 52 | * |
| 46 | 53 | * @since 1.0.0 |
| @@ -50,8 +57,43 @@ | ||
| 50 | 57 | */ |
| 51 | 58 | protected $_series = array(); |
| 52 | 59 | |
| 53 | 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 | + /** | |
| 54 | 96 | * Returns source name. |
| 55 | 97 | * |
| 56 | 98 | * @since 1.0.0 |
| 57 | 99 | * |
| @@ -107,14 +149,48 @@ | ||
| 107 | 149 | return $this->_data; |
| 108 | 150 | } |
| 109 | 151 | |
| 110 | 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 | + /** | |
| 111 | 185 | * Normalizes values according to series' type. |
| 112 | 186 | * |
| 113 | 187 | * @since 1.0.0 |
| 114 | 188 | * |
| 115 | 189 | * @access protected |
| 190 | + * | |
| 116 | 191 | * @param array $data The row of data. |
| 192 | + * | |
| 117 | 193 | * @return array Normalized row of data. |
| 118 | 194 | */ |
| 119 | 195 | protected function _normalizeData( $data ) { |
| 120 | 196 | // normalize values |
| @@ -123,16 +199,14 @@ | ||
| 123 | 199 | // if no value exists for the seires, then add null |
| 124 | 200 | if ( ! isset( $data[ $i ] ) ) { |
| 125 | 201 | $data[ $i ] = null; |
| 126 | 202 | } |
| 127 | - | |
| 128 | 203 | if ( is_null( $data[ $i ] ) ) { |
| 129 | 204 | continue; |
| 130 | 205 | } |
| 131 | - | |
| 132 | 206 | switch ( $series['type'] ) { |
| 133 | 207 | case 'number': |
| 134 | - $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 ); | |
| 135 | 209 | break; |
| 136 | 210 | case 'boolean': |
| 137 | 211 | $data[ $i ] = ! empty( $data[ $i ] ) ? filter_validate( $data[ $i ], FILTER_VALIDATE_BOOLEAN ) : null; |
| 138 | 212 | break; |
| @@ -148,58 +222,10 @@ | ||
| 148 | 222 | } |
| 149 | 223 | break; |
| 150 | 224 | } |
| 151 | 225 | } |
| 226 | + | |
| 152 | 227 | // error_log(print_r($data,true)); |
| 153 | - return $data; | |
| 154 | - } | |
| 155 | - | |
| 156 | - /** | |
| 157 | - * Validates series tyeps. | |
| 158 | - * | |
| 159 | - * @since 1.0.1 | |
| 160 | - * | |
| 161 | - * @static | |
| 162 | - * @access protected | |
| 163 | - * @param array $types The icoming series types. | |
| 164 | - * @return boolean TRUE if sereis types are valid, otherwise FALSE. | |
| 165 | - */ | |
| 166 | - protected static function _validateTypes( $types ) { | |
| 167 | - $allowed_types = array( 'string', 'number', 'boolean', 'date', 'datetime', 'timeofday' ); | |
| 168 | - foreach ( $types as $type ) { | |
| 169 | - if ( ! in_array( $type, $allowed_types ) ) { | |
| 170 | - return false; | |
| 171 | - } | |
| 172 | - } | |
| 173 | - | |
| 174 | - return true; | |
| 175 | - } | |
| 176 | - | |
| 177 | - /** | |
| 178 | - * Re populates series if the source is dynamic. | |
| 179 | - * | |
| 180 | - * @since 1.1.0 | |
| 181 | - * | |
| 182 | - * @access public | |
| 183 | - * @param array $series The actual array of series. | |
| 184 | - * @param int $chart_id The chart id. | |
| 185 | - * @return array The re populated array of series or old one. | |
| 186 | - */ | |
| 187 | - public function repopulateSeries( $series, $chart_id ) { | |
| 188 | - return $series; | |
| 189 | - } | |
| 190 | - | |
| 191 | - /** | |
| 192 | - * Re populates data if the source is dynamic. | |
| 193 | - * | |
| 194 | - * @since 1.1.0 | |
| 195 | - * | |
| 196 | - * @access public | |
| 197 | - * @param array $data The actual array of data. | |
| 198 | - * @param int $chart_id The chart id. | |
| 199 | - * @return array The re populated array of data or old one. | |
| 200 | - */ | |
| 201 | - public function repopulateData( $data, $chart_id ) { | |
| 202 | 228 | return $data; |
| 203 | 229 | } |
| 204 | 230 | |
| 205 | 231 | } |